This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch dataset-trans in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 9881368b1668ca7f91d85d9f0d3504c974358533 Author: 100pah <sushuang0...@gmail.com> AuthorDate: Fri Jul 31 17:32:38 2020 +0800 feature: add boxplot transform. --- extension-src/dataTool/boxplotTransform.ts | 70 +++++++++++++++++ extension-src/dataTool/index.ts | 3 + test/data-transform-external.html | 116 +++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) diff --git a/extension-src/dataTool/boxplotTransform.ts b/extension-src/dataTool/boxplotTransform.ts new file mode 100644 index 0000000..4a51370 --- /dev/null +++ b/extension-src/dataTool/boxplotTransform.ts @@ -0,0 +1,70 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import { DataTransformOption, ExternalDataTransform } from '../../src/data/helper/transform'; +import prepareBoxplotData from './prepareBoxplotData'; +import { isArray, each } from 'zrender/src/core/util'; +// import { throwError, makePrintable } from '../../src/util/log'; + + +export interface BoxplotTransformOption extends DataTransformOption { + type: 'echarts-extension:boxplot'; + config: { + boundIQR?: number | 'none', + layout?: 'horizontal' | 'vertical' + } +} + +export const boxplotTransform: ExternalDataTransform<BoxplotTransformOption> = { + + type: 'echarts-extension:boxplot', + + // PEDING: enhance to filter by index rather than create new data + transform: function transform(params) { + const source = params.source; + const config = params.config || {}; + + const sourceData = source.data; + if ( + !isArray(sourceData) + || (sourceData[0] && !isArray(sourceData[0])) + ) { + throw new Error( + 'source data is not applicable for this boxplot transform. Expect number[][].' + ); + } + + const result = prepareBoxplotData( + source.data as number[][], + config + ); + + const boxData = result.boxData as (number | string)[][]; + each(boxData, function (item, dataIdx) { + item.unshift(result.axisData[dataIdx]); + }); + + return [{ + data: boxData + }, { + data: result.outliers + }]; + } +}; + diff --git a/extension-src/dataTool/index.ts b/extension-src/dataTool/index.ts index 6724942..c4cc447 100644 --- a/extension-src/dataTool/index.ts +++ b/extension-src/dataTool/index.ts @@ -21,12 +21,14 @@ import * as echarts from 'echarts'; import * as gexf from './gexf'; import prepareBoxplotData from './prepareBoxplotData'; +import { boxplotTransform } from './boxplotTransform'; export const version = '1.0.0'; export {gexf}; export {prepareBoxplotData}; +export {boxplotTransform}; // For backward compatibility, where the namespace `dataTool` will // be mounted on `echarts` is the extension `dataTool` is imported. @@ -36,4 +38,5 @@ if (echarts.dataTool) { echarts.dataTool.version = version; echarts.dataTool.gexf = gexf; echarts.dataTool.prepareBoxplotData = prepareBoxplotData; + echarts.dataTool.boxplotTransform = boxplotTransform; } diff --git a/test/data-transform-external.html b/test/data-transform-external.html new file mode 100644 index 0000000..f204874 --- /dev/null +++ b/test/data-transform-external.html @@ -0,0 +1,116 @@ +<!DOCTYPE html> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + + +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <script src="lib/esl.js"></script> + <script src="lib/config.js"></script> + <script src="lib/jquery.min.js"></script> + <script src="lib/facePrint.js"></script> + <script src="lib/testHelper.js"></script> + <!-- <script src="ut/lib/canteen.js"></script> --> + <link rel="stylesheet" href="lib/reset.css" /> + </head> + <body> + <style> + </style> + + + + <div id="main_boxplot"></div> + + + + + <script> + require(['echarts', 'data/Michelson-Morley.json', 'extension/dataTool'], function (echarts, rawData, dataTool) { + var boxplotTransform = dataTool.boxplotTransform; + + echarts.registerTransform(boxplotTransform); + + var option = { + dataset: [{ + source: rawData + }, { + transform: { + type: 'echarts-extension:boxplot' + } + }, { + fromDatasetIndex: 1, + fromTransformResult: 1 + }], + title: [ + { + text: 'Michelson-Morley Experiment', + left: 'center' + }, + { + text: 'upper: Q3 + 1.5 * IRQ \nlower: Q1 - 1.5 * IRQ', + borderColor: '#999', + borderWidth: 1, + textStyle: { + fontSize: 14 + }, + left: '10%', + top: '90%' + } + ], + legend: { + bottom: 20 + }, + tooltip: { + }, + grid: { + bottom: 80 + }, + xAxis: { + type: 'category', + }, + yAxis: { + type: 'value', + name: 'km/s minus 299,000', + }, + series: [{ + name: 'boxplot', + type: 'boxplot', + datasetIndex: 1 + }, { + name: 'outlier', + type: 'scatter', + datasetIndex: 2 + }] + }; + + var chart = testHelper.create(echarts, 'main_boxplot', { + title: [ + 'Boxplot', + ], + option: option + }); + }); + </script> + + + </body> +</html> + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org