This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch next in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/next by this push: new 87bc7fb fix: make boxplot transform more reasonable: add config.itemNameFormatter and remove config.layout. 87bc7fb is described below commit 87bc7fb730d0e091d4a64820645271cdb402f328 Author: 100pah <sushuang0...@gmail.com> AuthorDate: Fri Aug 7 02:07:28 2020 +0800 fix: make boxplot transform more reasonable: add config.itemNameFormatter and remove config.layout. --- src/chart/boxplot/boxplotTransform.ts | 11 +++------ src/chart/boxplot/prepareBoxplotData.ts | 30 ++++++++++++++--------- test/boxplot-multi.html | 43 ++++++++++++++++++++++----------- test/boxplot.html | 5 +--- 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/chart/boxplot/boxplotTransform.ts b/src/chart/boxplot/boxplotTransform.ts index 2a8f1e0..bd92e7a 100644 --- a/src/chart/boxplot/boxplotTransform.ts +++ b/src/chart/boxplot/boxplotTransform.ts @@ -18,17 +18,14 @@ */ import { DataTransformOption, ExternalDataTransform } from '../../data/helper/transform'; -import prepareBoxplotData from './prepareBoxplotData'; +import prepareBoxplotData, { PrepareBoxplotDataOpt } from './prepareBoxplotData'; import { isArray } from 'zrender/src/core/util'; import { throwError, makePrintable } from '../../util/log'; export interface BoxplotTransformOption extends DataTransformOption { type: 'boxplot'; - config: { - boundIQR?: number | 'none', - layout?: 'horizontal' | 'vertical' - } + config: PrepareBoxplotDataOpt; } export const boxplotTransform: ExternalDataTransform<BoxplotTransformOption> = { @@ -37,8 +34,6 @@ export const boxplotTransform: ExternalDataTransform<BoxplotTransformOption> = { transform: function transform(params) { const source = params.source; - const config = params.config || {}; - const sourceData = source.data; if ( !isArray(sourceData) @@ -56,7 +51,7 @@ export const boxplotTransform: ExternalDataTransform<BoxplotTransformOption> = { const result = prepareBoxplotData( source.data as number[][], - config + params.config ); return [{ diff --git a/src/chart/boxplot/prepareBoxplotData.ts b/src/chart/boxplot/prepareBoxplotData.ts index 0a63a23..c7cb47c 100644 --- a/src/chart/boxplot/prepareBoxplotData.ts +++ b/src/chart/boxplot/prepareBoxplotData.ts @@ -18,6 +18,13 @@ */ import { quantile, asc } from '../../util/number'; +import { isFunction, isString } from 'zrender/src/core/util'; + +export interface PrepareBoxplotDataOpt { + boundIQR?: number | 'none'; + // Like "expriment{value}" produce: "expriment0", "expriment1", ... + itemNameFormatter?: string | ((params: { value: number }) => string); +} /** @@ -36,18 +43,13 @@ import { quantile, asc } from '../../util/number'; * @param opt.boundIQR=1.5 Data less than min bound is outlier. * default 1.5, means Q1 - 1.5 * (Q3 - Q1). * If 'none'/0 passed, min bound will not be used. - * @param opt.layout='horizontal' - * Box plot layout, can be 'horizontal' or 'vertical' */ export default function ( rawData: number[][], - opt: { - boundIQR?: number | 'none', - layout?: 'horizontal' | 'vertical' - } + opt: PrepareBoxplotDataOpt ): { - boxData: number[][] - outliers: number[][] + boxData: (number | string)[][]; + outliers: (number | string)[][]; } { opt = opt || {}; const boxData = []; @@ -73,13 +75,19 @@ export default function ( ? max : Math.min(max, Q3 + bound); - boxData.push([i, low, Q1, Q2, Q3, high]); + const itemNameFormatter = opt.itemNameFormatter; + const itemName = isFunction(itemNameFormatter) + ? itemNameFormatter({ value: i }) + : isString(itemNameFormatter) + ? itemNameFormatter.replace('{value}', i + '') + : i + ''; + + boxData.push([itemName, low, Q1, Q2, Q3, high]); for (let j = 0; j < ascList.length; j++) { const dataItem = ascList[j]; if (dataItem < low || dataItem > high) { - const outlier = [i, dataItem]; - opt.layout === 'vertical' && outlier.reverse(); + const outlier = [itemName, dataItem]; outliers.push(outlier); } } diff --git a/test/boxplot-multi.html b/test/boxplot-multi.html index ef09919..ed4300d 100644 --- a/test/boxplot-multi.html +++ b/test/boxplot-multi.html @@ -69,9 +69,6 @@ under the License. splitArea: { show: true }, - axisLabel: { - formatter: 'expr {value}' - }, splitLine: { show: false } @@ -85,12 +82,10 @@ under the License. }; chart.setOption({ - title: [ - { - text: 'Multiple Categories', - left: 'center', - } - ], + title: [{ + text: 'Multiple Categories', + left: 'center', + }], dataset: [{ source: sourceData[0] }, { @@ -99,17 +94,37 @@ under the License. source: sourceData[2] }, { fromDatasetIndex: 0, - transform: { type: 'boxplot', layout: layout } + transform: { + type: 'boxplot', + config: { + itemNameFormatter: function (params) { + return 'expr ' + params.value; + } + } + } }, { fromDatasetIndex: 1, - transform: { type: 'boxplot', layout: layout } + transform: { + type: 'boxplot', + config: { + itemNameFormatter: function (params) { + return 'expr ' + params.value; + } + } + } }, { fromDatasetIndex: 2, - transform: { type: 'boxplot', layout: layout } + transform: { + type: 'boxplot', + config: { + itemNameFormatter: function (params) { + return 'expr ' + params.value; + } + } + } }], legend: { - top: '10%', - data: ['category0', 'category1', 'category2', 'category3'] + top: '10%' }, tooltip: { trigger: 'axis', diff --git a/test/boxplot.html b/test/boxplot.html index 56818ef..195a15a 100644 --- a/test/boxplot.html +++ b/test/boxplot.html @@ -70,9 +70,6 @@ under the License. splitArea: { show: false }, - axisLabel: { - formatter: 'expr {value}' - }, splitLine: { show: false } @@ -94,7 +91,7 @@ under the License. }, { transform: { type: 'boxplot', - layout: layout + config: { itemNameFormatter: 'expr {value}' } } }, { fromDatasetIndex: 1, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org