You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2021/01/15 07:48:17 UTC
[echarts] branch fix/remove-test-transform created (now 49c9829)
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a change to branch fix/remove-test-transform
in repository https://gitbox.apache.org/repos/asf/echarts.git.
at 49c9829 test: migrate to ecSimpleTransition and ecSimpleOptionPlayer.
This branch includes the following new commits:
new 49c9829 test: migrate to ecSimpleTransition and ecSimpleOptionPlayer.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[echarts] 01/01: test: migrate to ecSimpleTransition and
ecSimpleOptionPlayer.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix/remove-test-transform
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 49c9829e36224f62af0ae6fe1072cec085bd78ed
Author: 100pah <su...@gmail.com>
AuthorDate: Fri Jan 15 15:47:24 2021 +0800
test: migrate to ecSimpleTransition and ecSimpleOptionPlayer.
---
test/custom-shape-morphing2.html | 13 +-
test/custom-shape-morphing3.html | 15 +-
test/data-transform-aggregate.html | 18 +-
test/lib/config.js | 3 +-
test/lib/ecSimpleOptionPlayer.js | 139 +++++++
test/lib/ecSimpleTransform.js | 362 ++++++++++++++++
test/lib/myTransform/dist/myTransform.js | 476 ---------------------
test/lib/myTransform/dist/myTransform.js.map | 1 -
test/lib/myTransform/src/.eslintrc.yaml | 47 ---
test/lib/myTransform/src/aggregate.ts | 593 ---------------------------
test/lib/myTransform/src/id.ts | 90 ----
test/lib/myTransform/src/index.ts | 3 -
test/lib/transitionPlayer.js | 256 ------------
13 files changed, 527 insertions(+), 1489 deletions(-)
diff --git a/test/custom-shape-morphing2.html b/test/custom-shape-morphing2.html
index f55d367..2388028 100644
--- a/test/custom-shape-morphing2.html
+++ b/test/custom-shape-morphing2.html
@@ -27,7 +27,6 @@ under the License.
<script src='lib/jquery.min.js'></script>
<script src="../dist/echarts.js"></script>
<script src="lib/testHelper.js"></script>
- <script src="lib/transitionPlayer.js"></script>
<link rel="stylesheet" href="lib/reset.css" />
</head>
<body>
@@ -75,9 +74,11 @@ under the License.
<script>
- require(['echarts', 'ecStat', 'myTransform'], function (echarts, ecStat, myTransform) {
+ require([
+ 'echarts', 'ecStat', 'ecSimpleTransform', 'ecSimpleOptionPlayer'
+ ], function (echarts, ecStat, ecSimpleTransform, ecSimpleOptionPlayer) {
- echarts.registerTransform(myTransform.aggregate);
+ echarts.registerTransform(ecSimpleTransform.aggregate);
echarts.registerTransform(ecStat.transform.clustering);
@@ -145,7 +146,7 @@ under the License.
id: 'mTagSum',
fromDatasetId: 'raw',
transform: {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
config: {
resultDimensions: [
{ from: 'ATA', method: 'sum' },
@@ -182,7 +183,7 @@ under the License.
id: 'rawClusterCenters',
fromDatasetId: 'rawClusters',
transform: {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
print: true,
config: {
resultDimensions: [
@@ -582,7 +583,7 @@ under the License.
});
- var player = transitionPlayer.create({
+ var player = ecSimpleOptionPlayer.create({
chart: function () {
return chart;
},
diff --git a/test/custom-shape-morphing3.html b/test/custom-shape-morphing3.html
index 1e762df..ca651a3 100644
--- a/test/custom-shape-morphing3.html
+++ b/test/custom-shape-morphing3.html
@@ -27,7 +27,6 @@ under the License.
<script src='lib/jquery.min.js'></script>
<script src="../dist/echarts.js"></script>
<script src="lib/testHelper.js"></script>
- <script src="lib/transitionPlayer.js"></script>
<link rel="stylesheet" href="lib/reset.css" />
</head>
<body>
@@ -40,11 +39,13 @@ under the License.
<script>
- require(['echarts', 'ecStat', 'myTransform'], function (echarts, ecStat, myTransform) {
+ require([
+ 'echarts', 'ecStat', 'ecSimpleTransform', 'ecSimpleOptionPlayer'
+ ], function (echarts, ecStat, ecSimpleTransform, ecSimpleOptionPlayer) {
$.get('data/life-expectancy-table.json', function (rawData) {
- echarts.registerTransform(myTransform.aggregate);
- echarts.registerTransform(myTransform.id);
+ echarts.registerTransform(ecSimpleTransform.aggregate);
+ echarts.registerTransform(ecSimpleTransform.id);
const COLORS = [
'#37A2DA', '#e06343', '#37a354', '#b55dba', '#b5bd48', '#8378EA', '#96BFFF'
@@ -92,7 +93,7 @@ under the License.
dimension: 'Year', gte: 1950
}
}, {
- type: 'myTransform:id',
+ type: 'ecSimpleTransform:id',
config: {
dimensionIndex: ID_RAW_DATA_DIMENSIONS.indexOf('Id'),
dimensionName: 'Id'
@@ -115,7 +116,7 @@ under the License.
id: 'CountryABSumIncome',
fromDatasetId: 'CountryABData',
transform: {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
config: {
resultDimensions: [
{ from: 'Income', method: 'sum' },
@@ -347,7 +348,7 @@ under the License.
};
- var player = transitionPlayer.create({
+ var player = ecSimpleOptionPlayer.create({
chart: function () {
return chart;
},
diff --git a/test/data-transform-aggregate.html b/test/data-transform-aggregate.html
index cfce0ab..5828e30 100644
--- a/test/data-transform-aggregate.html
+++ b/test/data-transform-aggregate.html
@@ -45,11 +45,11 @@ under the License.
<script>
- require(['echarts', 'myTransform'], function (echarts, myTransform) {
+ require(['echarts', 'ecSimpleTransform'], function (echarts, ecSimpleTransform) {
$.get('data/life-expectancy-table.json', function (_rawData) {
- echarts.registerTransform(myTransform.aggregate);
+ echarts.registerTransform(ecSimpleTransform.aggregate);
option = {
dataset: [{
@@ -64,7 +64,7 @@ under the License.
dimension: 'Year', gte: 1950
}
}, {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
config: {
resultDimensions: [
{ from: 'Income', method: 'sum' },
@@ -121,11 +121,11 @@ under the License.
<script>
- require(['echarts', 'myTransform'], function (echarts, myTransform) {
+ require(['echarts', 'ecSimpleTransform'], function (echarts, ecSimpleTransform) {
$.get('data/life-expectancy-table.json', function (_rawData) {
- echarts.registerTransform(myTransform.aggregate);
+ echarts.registerTransform(ecSimpleTransform.aggregate);
option = {
dataset: [{
@@ -144,7 +144,7 @@ under the License.
}]
}
}, {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
config: {
resultDimensions: [
{ name: 'min', from: 'Income', method: 'min' },
@@ -209,11 +209,11 @@ under the License.
<script>
- require(['echarts', 'myTransform'], function (echarts, myTransform) {
+ require(['echarts', 'ecSimpleTransform'], function (echarts, ecSimpleTransform) {
$.get('data/life-expectancy-table.json', function (_rawData) {
- echarts.registerTransform(myTransform.aggregate);
+ echarts.registerTransform(ecSimpleTransform.aggregate);
option = {
dataset: [{
@@ -233,7 +233,7 @@ under the License.
}]
}
}, {
- type: 'myTransform:aggregate',
+ type: 'ecSimpleTransform:aggregate',
config: {
resultDimensions: [
{ from: 'Income', method: 'average' },
diff --git a/test/lib/config.js b/test/lib/config.js
index ad8e68b..3560a43 100644
--- a/test/lib/config.js
+++ b/test/lib/config.js
@@ -64,7 +64,8 @@
'echarts': ecDistPath,
'zrender': 'node_modules/zrender/dist/zrender',
'ecStat': 'test/lib/ecStat.min',
- 'myTransform': 'test/lib/myTransform/dist/myTransform',
+ 'ecSimpleTransform': 'test/lib/ecSimpleTransform',
+ 'ecSimpleOptionPlayer': 'test/lib/ecSimpleOptionPlayer',
// 'ecStat': 'http://localhost:8001/echarts/echarts-stat/dist/ecStat',
'geoJson': '../geoData/geoJson',
'theme': 'theme',
diff --git a/test/lib/ecSimpleOptionPlayer.js b/test/lib/ecSimpleOptionPlayer.js
new file mode 100644
index 0000000..f251a56
--- /dev/null
+++ b/test/lib/ecSimpleOptionPlayer.js
@@ -0,0 +1,139 @@
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ecSimpleOptionPlayer = {}));
+}(this, (function (exports) { 'use strict';
+
+ function assert(condition, message) {
+ if (!condition) {
+ throw new Error(message);
+ }
+ }
+ function hasOwn(own, prop) {
+ return own.hasOwnProperty(prop);
+ }
+ function isObject(value) {
+ var type = typeof value;
+ return type === 'function' || (!!value && type === 'object');
+ }
+ function isArray(value) {
+ if (Array.isArray) {
+ return Array.isArray(value);
+ }
+ return Object.prototype.toString.call(value) === '[object Array]';
+ }
+ function isFunction(value) {
+ return typeof value === 'function';
+ }
+ function getMapValue(map, key) {
+ return (key != null && hasOwn(map, key)) ? map[key] : null;
+ }
+
+ function create(opt) {
+ return new SimpleOptionPlayer(opt);
+ }
+ var SimpleOptionPlayer = (function () {
+ function SimpleOptionPlayer(opt) {
+ assert(opt.chart
+ && isObject(opt.dataMeta)
+ && isArray(opt.optionList)
+ && opt.seriesIndex != null
+ && opt.optionList.length);
+ this._chart = opt.chart;
+ this._dataMeta = opt.dataMeta;
+ var optionList = this._optionList = opt.optionList;
+ var optionMap = this._optionMap = {};
+ this._replaceMerge = opt.replaceMerge;
+ this._seriesIndex = opt.seriesIndex;
+ this._currOptionIdx = null;
+ for (var i = 0; i < optionList.length; i++) {
+ var optionWrap = optionList[i];
+ var optionKey = optionWrap.key;
+ if (optionKey != null) {
+ assert(!hasOwn(optionMap, optionKey), 'option key duplicat: ' + optionKey);
+ optionMap[optionKey] = i;
+ }
+ }
+ }
+ SimpleOptionPlayer.prototype.next = function () {
+ var optionList = this._optionList;
+ var newOptionIdx = this._currOptionIdx == null
+ ? 0
+ : Math.min(optionList.length - 1, this._currOptionIdx + 1);
+ this._doChangeOption(newOptionIdx);
+ };
+ SimpleOptionPlayer.prototype.previous = function () {
+ var optionList = this._optionList;
+ var newOptionIdx = this._currOptionIdx == null
+ ? optionList.length - 1
+ : Math.max(0, this._currOptionIdx - 1);
+ this._doChangeOption(newOptionIdx);
+ };
+ SimpleOptionPlayer.prototype.go = function (optionKey) {
+ var newOptionIdx = getMapValue(this._optionMap, optionKey);
+ assert(newOptionIdx != null, 'Can not find option by option key: ' + optionKey);
+ this._doChangeOption(newOptionIdx);
+ };
+ SimpleOptionPlayer.prototype._doChangeOption = function (newOptionIdx) {
+ var optionList = this._optionList;
+ var oldOptionWrap = this._currOptionIdx != null ? optionList[this._currOptionIdx] : null;
+ var newOptionWrap = optionList[newOptionIdx];
+ var dataMeta = this._dataMeta;
+ var targetSeriesIndex = this._seriesIndex;
+ var transitionOpt = {
+ to: { seriesIndex: targetSeriesIndex }
+ };
+ if (oldOptionWrap) {
+ var common = findCommonDimension(oldOptionWrap, newOptionWrap)
+ || findCommonDimension(newOptionWrap, oldOptionWrap);
+ if (common != null) {
+ transitionOpt = {
+ from: {
+ seriesIndex: targetSeriesIndex,
+ dimension: common.uniqueDimension
+ },
+ to: {
+ seriesIndex: targetSeriesIndex,
+ dimension: common.uniqueDimension,
+ },
+ dividingMethod: common.dividingMethod
+ };
+ }
+ }
+ this._currOptionIdx = newOptionIdx;
+ this._getChart().setOption(newOptionWrap.option, {
+ replaceMerge: this._replaceMerge,
+ transition: transitionOpt
+ });
+ function findCommonDimension(optionWrapA, optionWrapB) {
+ var metaA = getMapValue(dataMeta, optionWrapA.dataMetaKey);
+ var metaB = getMapValue(dataMeta, optionWrapB.dataMetaKey);
+ var uniqueDimensionB = metaB.uniqueDimension;
+ if (uniqueDimensionB != null && metaA.dimensions.indexOf(uniqueDimensionB) >= 0) {
+ return {
+ uniqueDimension: uniqueDimensionB,
+ dividingMethod: metaB.dividingMethod
+ };
+ }
+ }
+ };
+ SimpleOptionPlayer.prototype._getChart = function () {
+ return isFunction(this._chart) ? this._chart() : this._chart;
+ };
+ SimpleOptionPlayer.prototype.getOptionKeys = function () {
+ var optionKeys = [];
+ var optionList = this._optionList;
+ for (var i = 0; i < optionList.length; i++) {
+ optionKeys.push(optionList[i].key);
+ }
+ return optionKeys;
+ };
+ return SimpleOptionPlayer;
+ }());
+
+ exports.create = create;
+
+ Object.defineProperty(exports, '__esModule', { value: true });
+
+})));
+//# sourceMappingURL=ecSimpleOptionPlayer.js.map
diff --git a/test/lib/ecSimpleTransform.js b/test/lib/ecSimpleTransform.js
new file mode 100644
index 0000000..d780fc4
--- /dev/null
+++ b/test/lib/ecSimpleTransform.js
@@ -0,0 +1,362 @@
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ecSimpleTransform = {}));
+}(this, (function (exports) { 'use strict';
+
+ var transform = {
+ type: 'ecSimpleTransform:id',
+ transform: function (params) {
+ var upstream = params.upstream;
+ var config = params.config;
+ var dimensionIndex = config.dimensionIndex;
+ var dimensionName = config.dimensionName;
+ var dimsDef = upstream.cloneAllDimensionInfo();
+ dimsDef[dimensionIndex] = dimensionName;
+ var data = upstream.cloneRawData();
+ for (var i = 0, len = data.length; i < len; i++) {
+ var line = data[i];
+ line[dimensionIndex] = i;
+ }
+ return {
+ dimensions: dimsDef,
+ data: data
+ };
+ }
+ };
+
+ function assert(condition, message) {
+ if (!condition) {
+ throw new Error(message);
+ }
+ }
+ function hasOwn(own, prop) {
+ return own.hasOwnProperty(prop);
+ }
+ function quantile(ascArr, p) {
+ var H = (ascArr.length - 1) * p + 1;
+ var h = Math.floor(H);
+ var v = +ascArr[h - 1];
+ var e = H - h;
+ return e ? v + e * (ascArr[h] - v) : v;
+ }
+
+ var METHOD_INTERNAL = {
+ 'SUM': true,
+ 'COUNT': true,
+ 'FIRST': true,
+ 'AVERAGE': true,
+ 'Q1': true,
+ 'Q2': true,
+ 'Q3': true,
+ 'MIN': true,
+ 'MAX': true
+ };
+ var METHOD_NEEDS_COLLECT = {
+ AVERAGE: ['COUNT']
+ };
+ var METHOD_NEEDS_GATHER_VALUES = {
+ Q1: true,
+ Q2: true,
+ Q3: true
+ };
+ var METHOD_ALIAS = {
+ MEDIAN: 'Q2'
+ };
+ var ResultDimInfoInternal = (function () {
+ function ResultDimInfoInternal(index, indexInUpstream, method, name, needGatherValues) {
+ this.collectionInfoList = [];
+ this.gatheredValuesByGroup = {};
+ this.gatheredValuesNoGroup = [];
+ this.needGatherValues = false;
+ this._collectionInfoMap = {};
+ this.method = method;
+ this.name = name;
+ this.index = index;
+ this.indexInUpstream = indexInUpstream;
+ this.needGatherValues = needGatherValues;
+ }
+ ResultDimInfoInternal.prototype.addCollectionInfo = function (item) {
+ this._collectionInfoMap[item.method] = this.collectionInfoList.length;
+ this.collectionInfoList.push(item);
+ };
+ ResultDimInfoInternal.prototype.getCollectionInfo = function (method) {
+ return this.collectionInfoList[this._collectionInfoMap[method]];
+ };
+ ResultDimInfoInternal.prototype.gatherValue = function (groupByDimInfo, groupVal, value) {
+ value = +value;
+ if (groupByDimInfo) {
+ if (groupVal != null) {
+ var groupValStr = groupVal + '';
+ var values = this.gatheredValuesByGroup[groupValStr]
+ || (this.gatheredValuesByGroup[groupValStr] = []);
+ values.push(value);
+ }
+ }
+ else {
+ this.gatheredValuesNoGroup.push(value);
+ }
+ };
+ return ResultDimInfoInternal;
+ }());
+ var transform$1 = {
+ type: 'ecSimpleTransform:aggregate',
+ transform: function (params) {
+ var upstream = params.upstream;
+ var config = params.config;
+ var groupByDimInfo = prepareGroupByDimInfo(config, upstream);
+ var _a = prepareDimensions(config, upstream, groupByDimInfo), finalResultDimInfoList = _a.finalResultDimInfoList, collectionDimInfoList = _a.collectionDimInfoList;
+ var collectionResult;
+ if (collectionDimInfoList.length) {
+ collectionResult = travel(groupByDimInfo, upstream, collectionDimInfoList, createCollectionResultLine, updateCollectionResultLine);
+ }
+ for (var i = 0; i < collectionDimInfoList.length; i++) {
+ var dimInfo = collectionDimInfoList[i];
+ dimInfo.__collectionResult = collectionResult;
+ asc(dimInfo.gatheredValuesNoGroup);
+ var gatheredValuesByGroup = dimInfo.gatheredValuesByGroup;
+ for (var key in gatheredValuesByGroup) {
+ if (hasOwn(gatheredValuesByGroup, key)) {
+ asc(gatheredValuesByGroup[key]);
+ }
+ }
+ }
+ var finalResult = travel(groupByDimInfo, upstream, finalResultDimInfoList, createFinalResultLine, updateFinalResultLine);
+ var dimensions = [];
+ for (var i = 0; i < finalResultDimInfoList.length; i++) {
+ dimensions.push(finalResultDimInfoList[i].name);
+ }
+ return {
+ dimensions: dimensions,
+ data: finalResult.outList
+ };
+ }
+ };
+ function prepareDimensions(config, upstream, groupByDimInfo) {
+ var resultDimensionsConfig = config.resultDimensions;
+ var finalResultDimInfoList = [];
+ var collectionDimInfoList = [];
+ var gIndexInLine = 0;
+ for (var i = 0; i < resultDimensionsConfig.length; i++) {
+ var resultDimInfoConfig = resultDimensionsConfig[i];
+ var dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from);
+ assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from);
+ var rawMethod = resultDimInfoConfig.method;
+ assert(groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null, "Dimension " + dimInfoInUpstream.name + " is the \"groupBy\" dimension, must not have any \"method\".");
+ var method = normalizeMethod(rawMethod);
+ assert(method, 'method is required');
+ var name_1 = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name;
+ var finalResultDimInfo = new ResultDimInfoInternal(finalResultDimInfoList.length, dimInfoInUpstream.index, method, name_1, hasOwn(METHOD_NEEDS_GATHER_VALUES, method));
+ finalResultDimInfoList.push(finalResultDimInfo);
+ var needCollect = false;
+ if (hasOwn(METHOD_NEEDS_COLLECT, method)) {
+ needCollect = true;
+ var collectionTargetMethods = METHOD_NEEDS_COLLECT[method];
+ for (var j = 0; j < collectionTargetMethods.length; j++) {
+ finalResultDimInfo.addCollectionInfo({
+ method: collectionTargetMethods[j],
+ indexInLine: gIndexInLine++
+ });
+ }
+ }
+ if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) {
+ needCollect = true;
+ }
+ if (needCollect) {
+ collectionDimInfoList.push(finalResultDimInfo);
+ }
+ }
+ return { collectionDimInfoList: collectionDimInfoList, finalResultDimInfoList: finalResultDimInfoList };
+ }
+ function prepareGroupByDimInfo(config, upstream) {
+ var groupByConfig = config.groupBy;
+ var groupByDimInfo;
+ if (groupByConfig != null) {
+ groupByDimInfo = upstream.getDimensionInfo(groupByConfig);
+ assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig);
+ }
+ return groupByDimInfo;
+ }
+ function travel(groupByDimInfo, upstream, resultDimInfoList, doCreate, doUpdate) {
+ var outList = [];
+ var mapByGroup;
+ if (groupByDimInfo) {
+ mapByGroup = {};
+ for (var dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) {
+ var groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index);
+ if (groupByVal == null) {
+ continue;
+ }
+ var groupByValStr = groupByVal + '';
+ if (!hasOwn(mapByGroup, groupByValStr)) {
+ var newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal);
+ outList.push(newLine);
+ mapByGroup[groupByValStr] = newLine;
+ }
+ else {
+ var targetLine = mapByGroup[groupByValStr];
+ doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal);
+ }
+ }
+ }
+ else {
+ var targetLine = doCreate(upstream, 0, resultDimInfoList);
+ outList.push(targetLine);
+ for (var dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) {
+ doUpdate(upstream, dataIndex, targetLine, resultDimInfoList);
+ }
+ }
+ return { mapByGroup: mapByGroup, outList: outList };
+ }
+ function normalizeMethod(method) {
+ if (method == null) {
+ return 'FIRST';
+ }
+ var methodInternal = method.toUpperCase();
+ methodInternal = hasOwn(METHOD_ALIAS, methodInternal)
+ ? METHOD_ALIAS[methodInternal]
+ : methodInternal;
+ assert(hasOwn(METHOD_INTERNAL, methodInternal), "Illegal method " + method + ".");
+ return methodInternal;
+ }
+ var createCollectionResultLine = function (upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal) {
+ var newLine = [];
+ for (var i = 0; i < collectionDimInfoList.length; i++) {
+ var dimInfo = collectionDimInfoList[i];
+ var collectionInfoList = dimInfo.collectionInfoList;
+ for (var j = 0; j < collectionInfoList.length; j++) {
+ var collectionInfo = collectionInfoList[j];
+ newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
+ }
+ if (dimInfo.needGatherValues) {
+ var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
+ }
+ }
+ return newLine;
+ };
+ var updateCollectionResultLine = function (upstream, dataIndex, targetLine, collectionDimInfoList, groupByDimInfo, groupByVal) {
+ for (var i = 0; i < collectionDimInfoList.length; i++) {
+ var dimInfo = collectionDimInfoList[i];
+ var collectionInfoList = dimInfo.collectionInfoList;
+ for (var j = 0; j < collectionInfoList.length; j++) {
+ var collectionInfo = collectionInfoList[j];
+ var indexInLine = collectionInfo.indexInLine;
+ targetLine[indexInLine] = +lineUpdater[collectionInfo.method](targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
+ }
+ if (dimInfo.needGatherValues) {
+ var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
+ }
+ }
+ };
+ var createFinalResultLine = function (upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal) {
+ var newLine = [];
+ for (var i = 0; i < finalResultDimInfoList.length; i++) {
+ var dimInfo = finalResultDimInfoList[i];
+ var method = dimInfo.method;
+ newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo)
+ ? groupByVal
+ : lineCreator[method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
+ }
+ return newLine;
+ };
+ var updateFinalResultLine = function (upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal) {
+ for (var i = 0; i < finalResultDimInfoList.length; i++) {
+ var dimInfo = finalResultDimInfoList[i];
+ if (isGroupByDimension(groupByDimInfo, dimInfo)) {
+ continue;
+ }
+ var method = dimInfo.method;
+ targetLine[i] = lineUpdater[method](targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
+ }
+ };
+ function isGroupByDimension(groupByDimInfo, targetDimInfo) {
+ return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index;
+ }
+ function asc(list) {
+ list.sort(function (a, b) {
+ return a - b;
+ });
+ }
+ var lineCreator = {
+ 'SUM': function () {
+ return 0;
+ },
+ 'COUNT': function () {
+ return 1;
+ },
+ 'FIRST': function (upstream, dataIndex, dimInfo) {
+ return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ },
+ 'MIN': function (upstream, dataIndex, dimInfo) {
+ return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ },
+ 'MAX': function (upstream, dataIndex, dimInfo) {
+ return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ },
+ 'AVERAGE': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
+ var collectLine = groupByDimInfo
+ ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']
+ : dimInfo.__collectionResult.outList[0];
+ return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream)
+ / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
+ },
+ 'Q1': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
+ return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal);
+ },
+ 'Q2': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
+ return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal);
+ },
+ 'Q3': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
+ return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal);
+ }
+ };
+ var lineUpdater = {
+ 'SUM': function (val, upstream, dataIndex, dimInfo) {
+ return val + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
+ },
+ 'COUNT': function (val) {
+ return val + 1;
+ },
+ 'FIRST': function (val) {
+ return val;
+ },
+ 'MIN': function (val, upstream, dataIndex, dimInfo) {
+ return Math.min(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream));
+ },
+ 'MAX': function (val, upstream, dataIndex, dimInfo) {
+ return Math.max(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream));
+ },
+ 'AVERAGE': function (val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
+ var collectLine = groupByDimInfo
+ ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']
+ : dimInfo.__collectionResult.outList[0];
+ return val
+ + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream)
+ / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
+ },
+ 'Q1': function (val, upstream, dataIndex, dimInfo) {
+ return val;
+ },
+ 'Q2': function (val, upstream, dataIndex, dimInfo) {
+ return val;
+ },
+ 'Q3': function (val, upstream, dataIndex, dimInfo) {
+ return val;
+ }
+ };
+ function lineCreatorForQ(percent, dimInfo, groupByDimInfo, groupByVal) {
+ var gatheredValues = groupByDimInfo
+ ? dimInfo.gatheredValuesByGroup[groupByVal + '']
+ : dimInfo.gatheredValuesNoGroup;
+ return quantile(gatheredValues, percent);
+ }
+
+ exports.aggregate = transform$1;
+ exports.id = transform;
+
+ Object.defineProperty(exports, '__esModule', { value: true });
+
+})));
+//# sourceMappingURL=index.js.map
diff --git a/test/lib/myTransform/dist/myTransform.js b/test/lib/myTransform/dist/myTransform.js
deleted file mode 100644
index a2f97b5..0000000
--- a/test/lib/myTransform/dist/myTransform.js
+++ /dev/null
@@ -1,476 +0,0 @@
-(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global.myTransform = {}));
-})(this, function (exports) {
- 'use strict';
-
- var transform = {
- type: 'myTransform:id',
- transform: function (params) {
- var upstream = params.upstream;
- var config = params.config;
- var dimensionIndex = config.dimensionIndex;
- var dimensionName = config.dimensionName;
- var dimsDef = upstream.cloneAllDimensionInfo();
- dimsDef[dimensionIndex] = dimensionName;
- var data = upstream.cloneRawData();
-
- for (var i = 0, len = data.length; i < len; i++) {
- var line = data[i];
- line[dimensionIndex] = i;
- }
-
- return {
- dimensions: dimsDef,
- data: data
- };
- }
- };
- var arrayProto = Array.prototype;
- var nativeForEach = arrayProto.forEach;
- var nativeSlice = arrayProto.slice;
- var nativeMap = arrayProto.map;
-
- var ctorFunction = function () {}.constructor;
-
- var protoFunction = ctorFunction ? ctorFunction.prototype : null;
-
- function each(arr, cb, context) {
- if (!(arr && cb)) {
- return;
- }
-
- if (arr.forEach && arr.forEach === nativeForEach) {
- arr.forEach(cb, context);
- } else if (arr.length === +arr.length) {
- for (var i = 0, len = arr.length; i < len; i++) {
- cb.call(context, arr[i], i, arr);
- }
- } else {
- for (var key in arr) {
- if (arr.hasOwnProperty(key)) {
- cb.call(context, arr[key], key, arr);
- }
- }
- }
- }
-
- function map(arr, cb, context) {
- if (!arr) {
- return [];
- }
-
- if (!cb) {
- return slice(arr);
- }
-
- if (arr.map && arr.map === nativeMap) {
- return arr.map(cb, context);
- } else {
- var result = [];
-
- for (var i = 0, len = arr.length; i < len; i++) {
- result.push(cb.call(context, arr[i], i, arr));
- }
-
- return result;
- }
- }
-
- function bindPolyfill(func, context) {
- var args = [];
-
- for (var _i = 2; _i < arguments.length; _i++) {
- args[_i - 2] = arguments[_i];
- }
-
- return function () {
- return func.apply(context, args.concat(nativeSlice.call(arguments)));
- };
- }
-
- var bind = protoFunction && isFunction(protoFunction.bind) ? protoFunction.call.bind(protoFunction.bind) : bindPolyfill;
-
- function isFunction(value) {
- return typeof value === 'function';
- }
-
- function slice(arr) {
- var args = [];
-
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
-
- return nativeSlice.apply(arr, args);
- }
-
- function assert(condition, message) {
- if (!condition) {
- throw new Error(message);
- }
- }
-
- function hasOwn(own, prop) {
- return own.hasOwnProperty(prop);
- }
-
- function quantile(ascArr, p) {
- var H = (ascArr.length - 1) * p + 1;
- var h = Math.floor(H);
- var v = +ascArr[h - 1];
- var e = H - h;
- return e ? v + e * (ascArr[h] - v) : v;
- }
-
- var METHOD_INTERNAL = {
- 'SUM': true,
- 'COUNT': true,
- 'FIRST': true,
- 'AVERAGE': true,
- 'Q1': true,
- 'Q2': true,
- 'Q3': true,
- 'MIN': true,
- 'MAX': true
- };
- var METHOD_NEEDS_COLLECT = {
- AVERAGE: ['COUNT']
- };
- var METHOD_NEEDS_GATHER_VALUES = {
- Q1: true,
- Q2: true,
- Q3: true
- };
- var METHOD_ALIAS = {
- MEDIAN: 'Q2'
- };
-
- var ResultDimInfoInternal = function () {
- function ResultDimInfoInternal(index, indexInUpstream, method, name, needGatherValues) {
- this.collectionInfoList = [];
- this.gatheredValuesByGroup = {};
- this.gatheredValuesNoGroup = [];
- this.needGatherValues = false;
- this._collectionInfoMap = {};
- this.method = method;
- this.name = name;
- this.index = index;
- this.indexInUpstream = indexInUpstream;
- this.needGatherValues = needGatherValues;
- }
-
- ResultDimInfoInternal.prototype.addCollectionInfo = function (item) {
- this._collectionInfoMap[item.method] = this.collectionInfoList.length;
- this.collectionInfoList.push(item);
- };
-
- ResultDimInfoInternal.prototype.getCollectionInfo = function (method) {
- return this.collectionInfoList[this._collectionInfoMap[method]];
- };
-
- ResultDimInfoInternal.prototype.gatherValue = function (groupByDimInfo, groupVal, value) {
- value = +value;
-
- if (groupByDimInfo) {
- if (groupVal != null) {
- var groupValStr = groupVal + '';
- var values = this.gatheredValuesByGroup[groupValStr] || (this.gatheredValuesByGroup[groupValStr] = []);
- values.push(value);
- }
- } else {
- this.gatheredValuesNoGroup.push(value);
- }
- };
-
- return ResultDimInfoInternal;
- }();
-
- var transform$1 = {
- type: 'myTransform:aggregate',
- transform: function (params) {
- var upstream = params.upstream;
- var config = params.config;
- var groupByDimInfo = prepareGroupByDimInfo(config, upstream);
-
- var _a = prepareDimensions(config, upstream, groupByDimInfo),
- finalResultDimInfoList = _a.finalResultDimInfoList,
- collectionDimInfoList = _a.collectionDimInfoList;
-
- var collectionResult;
-
- if (collectionDimInfoList.length) {
- collectionResult = travel(groupByDimInfo, upstream, collectionDimInfoList, createCollectionResultLine, updateCollectionResultLine);
- }
-
- each(collectionDimInfoList, function (dimInfo) {
- dimInfo.__collectionResult = collectionResult;
- asc(dimInfo.gatheredValuesNoGroup);
- each(dimInfo.gatheredValuesByGroup, function (values) {
- asc(values);
- });
- });
- var finalResult = travel(groupByDimInfo, upstream, finalResultDimInfoList, createFinalResultLine, updateFinalResultLine);
- return {
- dimensions: map(finalResultDimInfoList, function (item) {
- return item.name;
- }),
- data: finalResult.outList
- };
- }
- };
-
- function prepareDimensions(config, upstream, groupByDimInfo) {
- var resultDimensionsConfig = config.resultDimensions;
- var finalResultDimInfoList = [];
- var collectionDimInfoList = [];
- var gIndexInLine = 0;
-
- for (var i = 0; i < resultDimensionsConfig.length; i++) {
- var resultDimInfoConfig = resultDimensionsConfig[i];
- var dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from);
- assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from);
- var rawMethod = resultDimInfoConfig.method;
- assert(groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null, "Dimension " + dimInfoInUpstream.name + " is the \"groupBy\" dimension, must not have any \"method\".");
- var method = normalizeMethod(rawMethod);
- assert(method, 'method is required');
- var name_1 = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name;
- var finalResultDimInfo = new ResultDimInfoInternal(finalResultDimInfoList.length, dimInfoInUpstream.index, method, name_1, hasOwn(METHOD_NEEDS_GATHER_VALUES, method));
- finalResultDimInfoList.push(finalResultDimInfo);
- var needCollect = false;
-
- if (hasOwn(METHOD_NEEDS_COLLECT, method)) {
- needCollect = true;
- var collectionTargetMethods = METHOD_NEEDS_COLLECT[method];
-
- for (var j = 0; j < collectionTargetMethods.length; j++) {
- finalResultDimInfo.addCollectionInfo({
- method: collectionTargetMethods[j],
- indexInLine: gIndexInLine++
- });
- }
- }
-
- if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) {
- needCollect = true;
- }
-
- if (needCollect) {
- collectionDimInfoList.push(finalResultDimInfo);
- }
- }
-
- return {
- collectionDimInfoList: collectionDimInfoList,
- finalResultDimInfoList: finalResultDimInfoList
- };
- }
-
- function prepareGroupByDimInfo(config, upstream) {
- var groupByConfig = config.groupBy;
- var groupByDimInfo;
-
- if (groupByConfig != null) {
- groupByDimInfo = upstream.getDimensionInfo(groupByConfig);
- assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig);
- }
-
- return groupByDimInfo;
- }
-
- function travel(groupByDimInfo, upstream, resultDimInfoList, doCreate, doUpdate) {
- var outList = [];
- var mapByGroup;
-
- if (groupByDimInfo) {
- mapByGroup = {};
-
- for (var dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) {
- var groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index);
-
- if (groupByVal == null) {
- continue;
- }
-
- var groupByValStr = groupByVal + '';
-
- if (!hasOwn(mapByGroup, groupByValStr)) {
- var newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal);
- outList.push(newLine);
- mapByGroup[groupByValStr] = newLine;
- } else {
- var targetLine = mapByGroup[groupByValStr];
- doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal);
- }
- }
- } else {
- var targetLine = doCreate(upstream, 0, resultDimInfoList);
- outList.push(targetLine);
-
- for (var dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) {
- doUpdate(upstream, dataIndex, targetLine, resultDimInfoList);
- }
- }
-
- return {
- mapByGroup: mapByGroup,
- outList: outList
- };
- }
-
- function normalizeMethod(method) {
- if (method == null) {
- return 'FIRST';
- }
-
- var methodInternal = method.toUpperCase();
- methodInternal = hasOwn(METHOD_ALIAS, methodInternal) ? METHOD_ALIAS[methodInternal] : methodInternal;
- assert(hasOwn(METHOD_INTERNAL, methodInternal), "Illegal method " + method + ".");
- return methodInternal;
- }
-
- var createCollectionResultLine = function (upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal) {
- var newLine = [];
-
- for (var i = 0; i < collectionDimInfoList.length; i++) {
- var dimInfo = collectionDimInfoList[i];
- var collectionInfoList = dimInfo.collectionInfoList;
-
- for (var j = 0; j < collectionInfoList.length; j++) {
- var collectionInfo = collectionInfoList[j];
- newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
- }
-
- if (dimInfo.needGatherValues) {
- var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
- }
- }
-
- return newLine;
- };
-
- var updateCollectionResultLine = function (upstream, dataIndex, targetLine, collectionDimInfoList, groupByDimInfo, groupByVal) {
- for (var i = 0; i < collectionDimInfoList.length; i++) {
- var dimInfo = collectionDimInfoList[i];
- var collectionInfoList = dimInfo.collectionInfoList;
-
- for (var j = 0; j < collectionInfoList.length; j++) {
- var collectionInfo = collectionInfoList[j];
- var indexInLine = collectionInfo.indexInLine;
- targetLine[indexInLine] = +lineUpdater[collectionInfo.method](targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
- }
-
- if (dimInfo.needGatherValues) {
- var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
- }
- }
- };
-
- var createFinalResultLine = function (upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal) {
- var newLine = [];
-
- for (var i = 0; i < finalResultDimInfoList.length; i++) {
- var dimInfo = finalResultDimInfoList[i];
- var method = dimInfo.method;
- newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo) ? groupByVal : lineCreator[method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
- }
-
- return newLine;
- };
-
- var updateFinalResultLine = function (upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal) {
- for (var i = 0; i < finalResultDimInfoList.length; i++) {
- var dimInfo = finalResultDimInfoList[i];
-
- if (isGroupByDimension(groupByDimInfo, dimInfo)) {
- continue;
- }
-
- var method = dimInfo.method;
- targetLine[i] = lineUpdater[method](targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal);
- }
- };
-
- function isGroupByDimension(groupByDimInfo, targetDimInfo) {
- return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index;
- }
-
- function asc(list) {
- list.sort(function (a, b) {
- return a - b;
- });
- }
-
- var lineCreator = {
- 'SUM': function () {
- return 0;
- },
- 'COUNT': function () {
- return 1;
- },
- 'FIRST': function (upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'MIN': function (upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'MAX': function (upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'AVERAGE': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- var collectLine = groupByDimInfo ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] : dimInfo.__collectionResult.outList[0];
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
- },
- 'Q1': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal);
- },
- 'Q2': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal);
- },
- 'Q3': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal);
- }
- };
- var lineUpdater = {
- 'SUM': function (val, upstream, dataIndex, dimInfo) {
- return val + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'COUNT': function (val) {
- return val + 1;
- },
- 'FIRST': function (val) {
- return val;
- },
- 'MIN': function (val, upstream, dataIndex, dimInfo) {
- return Math.min(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream));
- },
- 'MAX': function (val, upstream, dataIndex, dimInfo) {
- return Math.max(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream));
- },
- 'AVERAGE': function (val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- var collectLine = groupByDimInfo ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] : dimInfo.__collectionResult.outList[0];
- return val + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
- },
- 'Q1': function (val, upstream, dataIndex, dimInfo) {
- return val;
- },
- 'Q2': function (val, upstream, dataIndex, dimInfo) {
- return val;
- },
- 'Q3': function (val, upstream, dataIndex, dimInfo) {
- return val;
- }
- };
-
- function lineCreatorForQ(percent, dimInfo, groupByDimInfo, groupByVal) {
- var gatheredValues = groupByDimInfo ? dimInfo.gatheredValuesByGroup[groupByVal + ''] : dimInfo.gatheredValuesNoGroup;
- return quantile(gatheredValues, percent);
- }
-
- exports.aggregate = transform$1;
- exports.id = transform;
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
-});
\ No newline at end of file
diff --git a/test/lib/myTransform/dist/myTransform.js.map b/test/lib/myTransform/dist/myTransform.js.map
deleted file mode 100644
index 7628c23..0000000
--- a/test/lib/myTransform/dist/myTransform.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"myTransform.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [...]
\ No newline at end of file
diff --git a/test/lib/myTransform/src/.eslintrc.yaml b/test/lib/myTransform/src/.eslintrc.yaml
deleted file mode 100644
index 6bda6d7..0000000
--- a/test/lib/myTransform/src/.eslintrc.yaml
+++ /dev/null
@@ -1,47 +0,0 @@
-
-# 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.
-
-# Note:
-# If eslint does not work in VSCode, please check:
-# (1) Whether "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser"
-# are npm installed locally. Should better in the same version.
-# (2) Whether "VSCode ESlint extension" is installed.
-# (3) If the project folder is not the root folder of your working space, please
-# config the "VSCode ESlint extension" in "settings":
-# ```json
-# "eslint.workingDirectories": [{"mode": "auto"}]
-# ```
-# Note that it should be "workingDirectories" rather than "WorkingDirectories".
-
-parser: "@typescript-eslint/parser"
-parserOptions:
- ecmaVersion: 6
- sourceType: module
- ecmaFeatures:
- modules: true
- project: "tsconfig.json"
-plugins: ["@typescript-eslint"]
-env:
- browser: true
- node: true
- es6: false
-globals:
- jQuery: false
- Promise: false
- __DEV__: false
-extends: '../../../../.eslintrc-common.yaml'
diff --git a/test/lib/myTransform/src/aggregate.ts b/test/lib/myTransform/src/aggregate.ts
deleted file mode 100644
index 4b6e02a..0000000
--- a/test/lib/myTransform/src/aggregate.ts
+++ /dev/null
@@ -1,593 +0,0 @@
-/*
-* 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, ExternalSource, ExternalDimensionDefinition
-} from '../../../../src/data/helper/transform';
-import {
- DimensionName, DimensionLoose, OptionDataValue
-} from '../../../../src/util/types';
-import { hasOwn, assert, map, each } from 'zrender/src/core/util';
-import { quantile } from '../../../../src/util/number';
-
-
-/**
- * @usage
- *
- * ```js
- * dataset: [{
- * source: [
- * ['aa', 'bb', 'cc', 'tag'],
- * [12, 0.33, 5200, 'AA'],
- * [21, 0.65, 7100, 'AA'],
- * [51, 0.15, 1100, 'BB'],
- * [71, 0.75, 9100, 'BB'],
- * ...
- * ]
- * }, {
- * transform: {
- * type: 'my:aggregate',
- * config: {
- * resultDimensions: [
- * // by default, use the same name with `from`.
- * { from: 'aa', method: 'sum' },
- * { from: 'bb', method: 'count' },
- * { from: 'cc' }, // method by default: use the first value.
- * { from: 'dd', method: 'Q1' },
- * { from: 'tag' }
- * ],
- * groupBy: 'tag'
- * }
- * }
- * // Then the result data will be:
- * // [
- * // ['aa', 'bb', 'cc', 'tag'],
- * // [12, 0.33, 5200, 'AA'],
- * // [21, 0.65, 8100, 'BB'],
- * // ...
- * // ]
- * }]
- * ```
- *
- * Current supported methods (case insensitive):
- * 'sum'
- * 'count'
- * 'average'
- * 'Q1'
- * 'Q3'
- * 'Q2' or 'median'
- * 'min'
- * 'max'
- */
-
-export interface AggregateTransformOption extends DataTransformOption {
- type: 'myTransform:aggregate';
- config: {
- // Mandatory
- resultDimensions: {
- // Optional. The name of the result dimensions.
- // If not provided, inherit the name from `from`.
- name: DimensionName;
- // Mandatory. `from` is used to reference dimension from `source`.
- from: DimensionLoose;
- // Optional. Aggregate method. Currently only these method supported.
- // If not provided, use `'first'`.
- method: AggregateMethodLoose;
- }[];
- // Optional
- groupBy: DimensionLoose;
- };
-}
-
-const METHOD_INTERNAL = {
- 'SUM': true,
- 'COUNT': true,
- 'FIRST': true,
- 'AVERAGE': true,
- 'Q1': true,
- 'Q2': true,
- 'Q3': true,
- 'MIN': true,
- 'MAX': true
-} as const;
-const METHOD_NEEDS_COLLECT = {
- AVERAGE: ['COUNT']
-} as const;
-const METHOD_NEEDS_GATHER_VALUES = {
- Q1: true,
- Q2: true,
- Q3: true
-} as const;
-const METHOD_ALIAS = {
- MEDIAN: 'Q2'
-} as const;
-
-type AggregateMethodLoose =
- AggregateMethodInternal
- | 'sum' | 'count' | 'first' | 'average' | 'Q1' | 'Q2' | 'Q3' | 'median' | 'min' | 'max';
-type AggregateMethodInternal = keyof typeof METHOD_INTERNAL;
-
-
-class ResultDimInfoInternal {
-
- readonly method: AggregateMethodInternal;
- readonly name: DimensionName;
- readonly index: number;
- readonly indexInUpstream: number;
-
- readonly collectionInfoList = [] as {
- method: AggregateMethodInternal;
- indexInLine: number;
- }[];
-
- // FIXME: refactor
- readonly gatheredValuesByGroup: { [groupVal: string]: number[] } = {};
- readonly gatheredValuesNoGroup = [] as number[];
- readonly needGatherValues: boolean = false;
-
- __collectionResult: TravelResult<CollectionResultLine>;
-
- private _collectionInfoMap = {} as {
- // number is the index of `list`
- [method in AggregateMethodInternal]: number
- };
-
- constructor(
- index: number,
- indexInUpstream: number,
- method: AggregateMethodInternal,
- name: DimensionName,
- needGatherValues: boolean
- ) {
- this.method = method;
- this.name = name;
- this.index = index;
- this.indexInUpstream = indexInUpstream;
- this.needGatherValues = needGatherValues;
- }
-
- addCollectionInfo(item: ResultDimInfoInternal['collectionInfoList'][number]) {
- this._collectionInfoMap[item.method] = this.collectionInfoList.length;
- this.collectionInfoList.push(item);
- }
-
- getCollectionInfo(method: AggregateMethodInternal) {
- return this.collectionInfoList[this._collectionInfoMap[method]];
- }
-
- // FIXME: temp implementation. Need refactor.
- gatherValue(groupByDimInfo: ExternalDimensionDefinition, groupVal: OptionDataValue, value: OptionDataValue) {
- // FIXME: convert to number compulsorily temporarily.
- value = +value;
- if (groupByDimInfo) {
- if (groupVal != null) {
- const groupValStr = groupVal + '';
- const values = this.gatheredValuesByGroup[groupValStr]
- || (this.gatheredValuesByGroup[groupValStr] = []);
- values.push(value);
- }
- }
- else {
- this.gatheredValuesNoGroup.push(value);
- }
- }
-}
-
-type CreateInTravel<LINE> = (
- upstream: ExternalSource,
- dataIndex: number,
- dimInfoList: ResultDimInfoInternal[],
- groupByDimInfo?: ExternalDimensionDefinition,
- groupByVal?: OptionDataValue
-) => LINE;
-type UpdateInTravel<LINE> = (
- upstream: ExternalSource,
- dataIndex: number,
- targetLine: LINE,
- dimInfoList: ResultDimInfoInternal[],
- groupByDimInfo?: ExternalDimensionDefinition,
- groupByVal?: OptionDataValue
-) => void;
-
-export const transform: ExternalDataTransform<AggregateTransformOption> = {
-
- type: 'myTransform:aggregate',
-
- transform: function (params) {
- const upstream = params.upstream;
- const config = params.config;
-
- const groupByDimInfo = prepareGroupByDimInfo(config, upstream);
- const { finalResultDimInfoList, collectionDimInfoList } = prepareDimensions(
- config, upstream, groupByDimInfo
- );
-
- // Collect
- let collectionResult: TravelResult<CollectionResultLine>;
- if (collectionDimInfoList.length) {
- collectionResult = travel(
- groupByDimInfo,
- upstream,
- collectionDimInfoList,
- createCollectionResultLine,
- updateCollectionResultLine
- );
- }
-
- each(collectionDimInfoList, dimInfo => {
- dimInfo.__collectionResult = collectionResult;
- // FIXME: just for Q1, Q2, Q3: need asc.
- asc(dimInfo.gatheredValuesNoGroup);
- each(dimInfo.gatheredValuesByGroup, values => {
- asc(values);
- });
- });
-
- // Calculate
- const finalResult = travel(
- groupByDimInfo,
- upstream,
- finalResultDimInfoList,
- createFinalResultLine,
- updateFinalResultLine
- );
-
- return {
- dimensions: map(finalResultDimInfoList, item => item.name),
- data: finalResult.outList
- };
- }
-};
-
-function prepareDimensions(
- config: AggregateTransformOption['config'],
- upstream: ExternalSource,
- groupByDimInfo: ExternalDimensionDefinition
-): {
- finalResultDimInfoList: ResultDimInfoInternal[];
- collectionDimInfoList: ResultDimInfoInternal[];
-} {
- const resultDimensionsConfig = config.resultDimensions;
- const finalResultDimInfoList: ResultDimInfoInternal[] = [];
- const collectionDimInfoList: ResultDimInfoInternal[] = [];
- let gIndexInLine = 0;
-
- for (let i = 0; i < resultDimensionsConfig.length; i++) {
- const resultDimInfoConfig = resultDimensionsConfig[i];
-
- const dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from);
- assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from);
-
- const rawMethod = resultDimInfoConfig.method;
-
- assert(
- groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null,
- `Dimension ${dimInfoInUpstream.name} is the "groupBy" dimension, must not have any "method".`
- );
-
- const method = normalizeMethod(rawMethod);
- assert(method, 'method is required');
-
- const name = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name;
-
- const finalResultDimInfo = new ResultDimInfoInternal(
- finalResultDimInfoList.length,
- dimInfoInUpstream.index,
- method,
- name,
- hasOwn(METHOD_NEEDS_GATHER_VALUES, method)
- );
- finalResultDimInfoList.push(finalResultDimInfo);
-
- // For collection.
- let needCollect = false;
- if (hasOwn(METHOD_NEEDS_COLLECT, method)) {
- needCollect = true;
- const collectionTargetMethods = METHOD_NEEDS_COLLECT[method as keyof typeof METHOD_NEEDS_COLLECT];
- for (let j = 0; j < collectionTargetMethods.length; j++) {
- finalResultDimInfo.addCollectionInfo({
- method: collectionTargetMethods[j],
- indexInLine: gIndexInLine++
- });
- }
- }
- if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) {
- needCollect = true;
- }
- if (needCollect) {
- collectionDimInfoList.push(finalResultDimInfo);
- }
- }
-
- return { collectionDimInfoList, finalResultDimInfoList };
-}
-
-function prepareGroupByDimInfo(
- config: AggregateTransformOption['config'],
- upstream: ExternalSource
-): ExternalDimensionDefinition {
- const groupByConfig = config.groupBy;
- let groupByDimInfo;
- if (groupByConfig != null) {
- groupByDimInfo = upstream.getDimensionInfo(groupByConfig);
- assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig);
- }
- return groupByDimInfo;
-}
-
-interface TravelResult<LINE> {
- mapByGroup: { [groupVal: string]: LINE };
- outList: LINE[];
-}
-
-function travel<LINE>(
- groupByDimInfo: ExternalDimensionDefinition,
- upstream: ExternalSource,
- resultDimInfoList: ResultDimInfoInternal[],
- doCreate: CreateInTravel<LINE>,
- doUpdate: UpdateInTravel<LINE>
-): TravelResult<LINE> {
- const outList: TravelResult<LINE>['outList'] = [];
- let mapByGroup: TravelResult<LINE>['mapByGroup'];
-
- if (groupByDimInfo) {
- mapByGroup = {};
-
- for (let dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) {
- const groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index);
-
- // PENDING: when value is null/undefined
- if (groupByVal == null) {
- continue;
- }
-
- const groupByValStr = groupByVal + '';
-
- if (!hasOwn(mapByGroup, groupByValStr)) {
- const newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal);
- outList.push(newLine);
- mapByGroup[groupByValStr] = newLine;
- }
- else {
- const targetLine = mapByGroup[groupByValStr];
- doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal);
- }
- }
- }
- else {
- const targetLine = doCreate(upstream, 0, resultDimInfoList);
- outList.push(targetLine);
- for (let dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) {
- doUpdate(upstream, dataIndex, targetLine, resultDimInfoList);
- }
- }
-
- return { mapByGroup, outList };
-}
-
-function normalizeMethod(method: AggregateMethodLoose): AggregateMethodInternal {
- if (method == null) {
- return 'FIRST';
- }
- let methodInternal = method.toUpperCase() as AggregateMethodInternal;
- methodInternal = hasOwn(METHOD_ALIAS, methodInternal)
- ? METHOD_ALIAS[methodInternal as keyof typeof METHOD_ALIAS]
- : methodInternal;
- assert(hasOwn(METHOD_INTERNAL, methodInternal), `Illegal method ${method}.`);
- return methodInternal;
-}
-
-
-
-type CollectionResultLine = number[];
-
-const createCollectionResultLine: CreateInTravel<CollectionResultLine> = (
- upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal
-) => {
- const newLine = [] as number[];
- for (let i = 0; i < collectionDimInfoList.length; i++) {
- const dimInfo = collectionDimInfoList[i];
- const collectionInfoList = dimInfo.collectionInfoList;
- for (let j = 0; j < collectionInfoList.length; j++) {
- const collectionInfo = collectionInfoList[j];
- // FIXME: convert to number compulsorily temporarily.
- newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method](
- upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal
- );
- }
- // FIXME: refactor
- if (dimInfo.needGatherValues) {
- const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
- }
- }
- return newLine;
-};
-
-const updateCollectionResultLine: UpdateInTravel<CollectionResultLine> = (
- upstream, dataIndex, targetLine: number[], collectionDimInfoList, groupByDimInfo, groupByVal
-) => {
- for (let i = 0; i < collectionDimInfoList.length; i++) {
- const dimInfo = collectionDimInfoList[i];
- const collectionInfoList = dimInfo.collectionInfoList;
- for (let j = 0; j < collectionInfoList.length; j++) {
- const collectionInfo = collectionInfoList[j];
- const indexInLine = collectionInfo.indexInLine;
- // FIXME: convert to number compulsorily temporarily.
- targetLine[indexInLine] = +lineUpdater[collectionInfo.method](
- targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal
- );
- }
- // FIXME: refactor
- if (dimInfo.needGatherValues) {
- const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- dimInfo.gatherValue(groupByDimInfo, groupByVal, val);
- }
- }
-};
-
-
-
-type FinalResultLine = OptionDataValue[];
-
-const createFinalResultLine: CreateInTravel<FinalResultLine> = (
- upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal
-) => {
- const newLine = [];
- for (let i = 0; i < finalResultDimInfoList.length; i++) {
- const dimInfo = finalResultDimInfoList[i];
- const method = dimInfo.method;
- newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo)
- ? groupByVal
- : lineCreator[method](
- upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal
- );
- }
- return newLine;
-};
-
-const updateFinalResultLine: UpdateInTravel<FinalResultLine> = (
- upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal
-) => {
- for (let i = 0; i < finalResultDimInfoList.length; i++) {
- const dimInfo = finalResultDimInfoList[i];
- if (isGroupByDimension(groupByDimInfo, dimInfo)) {
- continue;
- }
- const method = dimInfo.method;
- targetLine[i] = lineUpdater[method](
- targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal
- );
- }
-};
-
-function isGroupByDimension(
- groupByDimInfo: ExternalDimensionDefinition,
- targetDimInfo: ResultDimInfoInternal
-): boolean {
- return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index;
-}
-
-function asc(list: number[]) {
- list.sort((a, b) => {
- return a - b;
- });
-}
-
-const lineCreator: {
- [key in AggregateMethodInternal]: (
- upstream: ExternalSource,
- dataIndex: number,
- dimInfo: ResultDimInfoInternal,
- groupByDimInfo: ExternalDimensionDefinition,
- groupByVal: OptionDataValue
- ) => OptionDataValue
-} = {
- 'SUM'() {
- return 0;
- },
- 'COUNT'() {
- return 1;
- },
- 'FIRST'(upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'MIN'(upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'MAX'(upstream, dataIndex, dimInfo) {
- return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);
- },
- 'AVERAGE'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- // FIXME: refactor, bad implementation.
- const collectLine = groupByDimInfo
- ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']
- : dimInfo.__collectionResult.outList[0];
- return (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number)
- / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
- },
- // FIXME: refactor
- 'Q1'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal);
- },
- 'Q2'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal);
- },
- 'Q3'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal);
- }
-};
-
-const lineUpdater: {
- [key in AggregateMethodInternal]: (
- val: OptionDataValue,
- upstream: ExternalSource,
- dataIndex: number,
- dimInfo: ResultDimInfoInternal,
- groupByDimInfo: ExternalDimensionDefinition,
- groupByVal: OptionDataValue
- ) => OptionDataValue
-} = {
- 'SUM'(val, upstream, dataIndex, dimInfo) {
- // FIXME: handle other types
- return (val as number) + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);
- },
- 'COUNT'(val) {
- return (val as number) + 1;
- },
- 'FIRST'(val) {
- return val;
- },
- 'MIN'(val, upstream, dataIndex, dimInfo) {
- return Math.min(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);
- },
- 'MAX'(val, upstream, dataIndex, dimInfo) {
- return Math.max(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);
- },
- 'AVERAGE'(val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {
- // FIXME: refactor, bad implementation.
- const collectLine = groupByDimInfo
- ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']
- : dimInfo.__collectionResult.outList[0];
- return (val as number)
- + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number)
- / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];
- },
- 'Q1'(val, upstream, dataIndex, dimInfo) {
- return val;
- },
- 'Q2'(val, upstream, dataIndex, dimInfo) {
- return val;
- },
- 'Q3'(val, upstream, dataIndex, dimInfo) {
- return val;
- }
-};
-
-function lineCreatorForQ(
- percent: number,
- dimInfo: ResultDimInfoInternal,
- groupByDimInfo: ExternalDimensionDefinition,
- groupByVal: OptionDataValue
-) {
- const gatheredValues = groupByDimInfo
- ? dimInfo.gatheredValuesByGroup[groupByVal + '']
- : dimInfo.gatheredValuesNoGroup;
- return quantile(gatheredValues, percent);
-}
diff --git a/test/lib/myTransform/src/id.ts b/test/lib/myTransform/src/id.ts
deleted file mode 100644
index d466d8b..0000000
--- a/test/lib/myTransform/src/id.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-* 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 { ExternalDataTransform, DataTransformOption } from '../../../../src/data/helper/transform';
-import { DimensionIndex, DimensionName, DimensionDefinitionLoose, OptionSourceDataArrayRows } from '../../../../src/util/types';
-
-
-/**
- * @usage
- *
- * ```js
- * dataset: [{
- * source: [
- * ['aa', 'bb', 'cc', 'tag'],
- * [12, 0.33, 5200, 'AA'],
- * [21, 0.65, 8100, 'AA'],
- * ...
- * ]
- * }, {
- * transform: {
- * type: 'my:id',
- * config: {
- * dimensionIndex: 4,
- * dimensionName: 'ID'
- * }
- * }
- * // Then the result data will be:
- * // [
- * // ['aa', 'bb', 'cc', 'tag', 'ID'],
- * // [12, 0.33, 5200, 'AA', 0],
- * // [21, 0.65, 8100, 'BB', 1],
- * // ...
- * // ]
- * }]
- * ```
- */
-
-export interface IdTransformOption extends DataTransformOption {
- type: 'myTransform:id';
- config: {
- // Mandatory. Specify where to put the new id dimension.
- dimensionIndex: DimensionIndex;
- // Optional. If not provided, left the dimension name not defined.
- dimensionName: DimensionName;
- };
-}
-
-export const transform: ExternalDataTransform<IdTransformOption> = {
-
- type: 'myTransform:id',
-
- transform: function (params) {
- const upstream = params.upstream;
- const config = params.config;
- const dimensionIndex = config.dimensionIndex;
- const dimensionName = config.dimensionName;
-
- const dimsDef = upstream.cloneAllDimensionInfo() as DimensionDefinitionLoose[];
- dimsDef[dimensionIndex] = dimensionName;
-
- const data = upstream.cloneRawData() as OptionSourceDataArrayRows;
-
- // TODO: support objectRows
- for (let i = 0, len = data.length; i < len; i++) {
- const line = data[i];
- line[dimensionIndex] = i;
- }
-
- return {
- dimensions: dimsDef,
- data: data
- };
- }
-};
diff --git a/test/lib/myTransform/src/index.ts b/test/lib/myTransform/src/index.ts
deleted file mode 100644
index a8138ad..0000000
--- a/test/lib/myTransform/src/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-
-export { transform as id } from './id';
-export { transform as aggregate } from './aggregate';
diff --git a/test/lib/transitionPlayer.js b/test/lib/transitionPlayer.js
deleted file mode 100644
index 6355e99..0000000
--- a/test/lib/transitionPlayer.js
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
-* 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.
-*/
-
-(function (exports) {
-
- var transitionPlayer = {};
-
- /**
- * @usage
- * ```js
- * // Initialize with an array of echarts option info:
- * var player = transitionPlayer.create({
- *
- * // The echarts instance or chart instance getter.
- * chart: function () {
- * return myChart;
- * },
- * seriesIndex: 0,
- * replaceMerge: ['xAxis', 'yAxis']
- *
- * // The data meta info used to determine how to
- * // make transition mapping.
- * // The strategy: If `uniqueDimension` provided and is a common
- * // dimension, use `uniqueDimension`.
- * dataMeta: {
- * aaa: {
- * dimensions: ['qqq', 'www', 'eee', 'rrr']
- * },
- * bbb: {
- * dimensions: ['ccc', 'www', 'eee'],
- * uniqueDimension: 'www',
- * dividingMethod: 'duplicate'
- * },
- * ...
- * },
- *
- * // echarts option collection:
- * optionList: [
- * // dataMetaKey is the key of 'dataMeta'.
- * { key: 'Time_Income_Bar', option: option0, dataMetaKey: 'aaa' },
- * { key: 'Population_Income_Scatter', option: option1, dataMetaKey: 'bbb' },
- * { key: 'Time_Income_Pie', option: option2, dataMetaKey: 'aaa' },
- * ...
- * ]
- * });
- *
- * // Then start to play:
- * player.next(); // Display next option (from the first option).
- * player.previous(); // Display previous optoin.
- * player.go('Time_Income_Pie'); // Display the specified option.
- * player.getOptionKeys(); // return `['Time_Income_Bar', 'Population_Income_Scatter', 'Time_Income_Pie']`
- * ```
- *
- * @parma opt See the constructor of `TransitionPlayer`.
- */
- transitionPlayer.create = function (opt) {
- return new TransitionPlayer(opt);
- };
-
- /**
- * @param opt
- * @param opt.chart
- * (EChartsInstance | () => EChartsInstance)
- * echarts instance or echarts instance getter.
- * @param opt.dataMeta
- * {
- * [dataMetaKey in string]: {
- * dimensions: string[];
- * uniqueDimension?: string;
- * dividingMethod?: 'split' | 'duplicate'
- * }
- * }
- * @param opt.optionList
- * {
- * key: string;
- * option: EChartsOption;
- * dataMetaKey: string;
- * }[]
- * @param opt.seriesIndex number
- * Target series index to be transitioned.
- * @param opt.replaceMerge? string[]
- */
- function TransitionPlayer(opt) {
- assert(
- opt.chart
- && isObject(opt.dataMeta)
- && isArray(opt.optionList)
- && opt.seriesIndex != null
- && opt.optionList.length
- );
-
- this._chart = opt.chart;
- this._dataMeta = opt.dataMeta;
- var optionList = this._optionList = opt.optionList;
- var optionMap = this._optionMap = {};
- this._replaceMerge = opt.replaceMerge;
- this._seriesIndex = opt.seriesIndex;
- this._currOptionIdx = null;
-
- for (var i = 0; i < optionList.length; i++) {
- var optionWrap = optionList[i];
- var optionKey = optionWrap.key;
- if (optionKey != null) {
- assert(!hasOwn(optionMap, optionKey), 'option key duplicat: ' + optionKey);
- optionMap[optionKey] = i;
- }
- }
- }
-
- var proto = TransitionPlayer.prototype;
-
- proto.next = function () {
- var optionList = this._optionList;
- var newOptionIdx = this._currOptionIdx == null
- ? 0
- : Math.min(optionList.length - 1, this._currOptionIdx + 1);
-
- this._doChangeOption(newOptionIdx);
- };
-
- proto.previous = function () {
- var optionList = this._optionList;
- var newOptionIdx = this._currOptionIdx == null
- ? optionList.length - 1
- : Math.max(0, this._currOptionIdx - 1);
-
- this._doChangeOption(newOptionIdx);
- };
-
- /**
- * @param optionKey string
- */
- proto.go = function (optionKey) {
- var newOptionIdx = getMapValue(this._optionMap, optionKey);
- assert(newOptionIdx != null, 'Can not find option by option key: ' + optionKey);
-
- this._doChangeOption(newOptionIdx);
- };
-
- proto._doChangeOption = function (newOptionIdx) {
- var optionList = this._optionList;
- var oldOptionWrap = this._currOptionIdx != null ? optionList[this._currOptionIdx] : null;
- var newOptionWrap = optionList[newOptionIdx];
- var dataMeta = this._dataMeta;
- var targetSeriesIndex = this._seriesIndex;
-
- var transitionOpt = {
- // If can not find mapped dimensions, do not make transition animation
- // by default, becuase this transition probably bring about misleading.
- to: { seriesIndex: targetSeriesIndex }
- };
-
- if (oldOptionWrap) {
- var commonDimension =
- findCommonDimension(oldOptionWrap, newOptionWrap)
- || findCommonDimension(newOptionWrap, oldOptionWrap);
- if (commonDimension != null) {
- transitionOpt = {
- from: {
- seriesIndex: targetSeriesIndex,
- dimension: commonDimension
- },
- to: {
- seriesIndex: targetSeriesIndex,
- dimension: commonDimension,
- },
- dividingMethod: dataMeta.dividingMethod
- };
- }
- }
-
- this._currOptionIdx = newOptionIdx;
-
- this._getChart().setOption(newOptionWrap.option, {
- replaceMerge: this._replaceMerge,
- transition: transitionOpt
- });
-
- function findCommonDimension(optionWrapA, optionWrapB) {
- var metaA = getMapValue(dataMeta, optionWrapA.dataMetaKey);
- var metaB = getMapValue(dataMeta, optionWrapB.dataMetaKey);
- var uniqueDimensionB = metaB.uniqueDimension;
- if (uniqueDimensionB != null && metaA.dimensions.indexOf(uniqueDimensionB) >= 0) {
- return uniqueDimensionB;
- }
- }
-
- };
-
- proto._getChart = function () {
- return isFunction(this._chart) ? this._chart() : this._chart;
- };
-
- /**
- * @return string[]
- */
- proto.getOptionKeys = function () {
- var optionKeys = [];
- var optionList = this._optionList;
- for (var i = 0; i < optionList.length; i++) {
- optionKeys.push(optionList[i].key);
- }
- return optionKeys;
- };
-
-
- function assert(cond, msg) {
- if (!cond) {
- throw new Error(msg || 'transition player error');
- }
- }
-
- function isObject(value) {
- const type = typeof value;
- return type === 'function' || (!!value && type === 'object');
- }
-
- function isArray(value) {
- if (Array.isArray) {
- return Array.isArray(value);
- }
- return Object.prototype.toString.call(value) === '[object Array]';
- }
-
- function isFunction(value) {
- return typeof value === 'function';
- }
-
- function hasOwn(obj, key) {
- return obj.hasOwnProperty(key);
- }
-
- function getMapValue(map, key) {
- return (key != null && hasOwn(map, key)) ? map[key] : null;
- }
-
-
- exports.transitionPlayer = transitionPlayer;
-
-})(this);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org