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 2020/10/15 16:48:31 UTC
[incubator-echarts] branch fix-ut updated (0d47e96 -> c6eecfe)
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a change to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git.
from 0d47e96 build: move /echarts.*.ts to src/echarts.*.ts . Otherwise if user import from 'echarts.all', it might be confused whether echarts.all.ts or echarts.all.js
new bed2ffc test: fix ut: dataZoom
new 93ede9d fix: fix dev fast entry since echarts.all.ts moved.
new 81b2efe fix: (1) clarify id and name type. (2) compat non supported name type.
new 346cccd test: fix ut code to ts.
add a7b4243 fix(theme): fix dark theme
add 957a9f1 fix(animation): use additive animation in states transition.
add 4901034 fix(graph): fix symbol scale
add ed2a14b fix(graph): fix symbol scale wrong on graph.
add 21f5973 fix(label): fix animation delay per data in label.
add c7013d0 fix: some issues in tooltip (1) `transform` may not be working in IE. (add vendor prefixes) (2) disable transition only when tooltip shows arrow. (3) reduce unnecessary imports.
add 260d078 tweak(tooltip): use `appendChild` but not concat html string for tooltip arrow.
add d4c873a fix(tooltip): still use concat html string for arrow.
add c41f58b feat(tooltip): use `opacity` to fade out but not hide directly and add opacity transition.
add 1107ec9 fix(tooltip): disable transition after a long-time hide.
add f20c30e Merge branch 'next' of https://github.com/apache/incubator-echarts into fix/tooltip
add f038591 fix(tooltip): also set `visibility` to `hidden` to prevent from responding to DOM events.
add 6eb0074 Merge pull request #13398 from apache/fix/tooltip
add 948bd77 fix(line): fix polygon shape may not update during animation.
add 2cdee9c fix(bar): fix NaN value will appear after update.
add 6b10989 fix(pie): fix incorrect label layout in some cases of gallery
add 786c2ba fix(bar): not display zero value bar on polar coord.
add 4941977 test(pie): update pie rich text test cases.
add 44ffecb fix(pie): fix wrong query path
add 3d19f5b fix(pie): fix label may still been layout if not shown.
add 1694130 test(time): update test case
add 99e8019 fix(event): support label trigger mouse event.
add 2bcd3f9 fix(extension/bmap): fix bmap first layout may be incorrect if container's layout is flex or grid.(#13424)
add 8b4330a Merge pull request #13432 from apache/fix/bmap
add 0f4a51f release: 5.0.0-beta.1
add 2f566e9 release: 5.0.0-beta.1 (dist)
add c29d496 fix(state): only leave hoverd state when it's applied. #13417
add f7ac75e fix(line): use raw points when calculating endLabel.
add a77894c Merge branch 'bugfixes' into next
new 5499a90 Merge branch 'next' into fix-ut
new c5f4ef7 fix: add the missing entry file for echarts.*.ts migrate.
new 7090bce fix: (1) fix series merge mapping (brought by some previous refactor in 5.0). (2) tweak id name type and check.
new c6eecfe test: update ut for 5.0.
The 8 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.
Summary of changes:
build/dev-fast.js | 2 +-
dist/echarts.common.js | 5128 +++++++++------
dist/echarts.common.js.map | 2 +-
dist/echarts.common.min.js | 2 +-
dist/echarts.js | 6539 ++++++++++++++------
dist/echarts.js.map | 2 +-
dist/echarts.min.js | 2 +-
dist/echarts.simple.js | 3921 +++++++-----
dist/echarts.simple.js.map | 2 +-
dist/echarts.simple.min.js | 2 +-
dist/extension/bmap.js | 147 +-
dist/extension/bmap.js.map | 2 +-
dist/extension/bmap.min.js | 2 +-
dist/extension/dataTool.min.js | 2 +-
extension-src/bmap/BMapCoordSys.ts | 6 +-
extension-src/bmap/BMapView.ts | 12 +-
i18n/langDE.js | 1 +
i18n/langES-obj.js | 38 +-
i18n/langES.js | 38 +-
i18n/langFI-obj.js | 38 +-
i18n/langFI.js | 38 +-
i18n/langTH-obj.js | 38 +-
i18n/langTH.js | 38 +-
package-lock.json | 796 ++-
package.json | 4 +-
src/chart/bar/BarView.ts | 5 +-
src/chart/custom.ts | 2 +-
src/chart/helper/Symbol.ts | 21 +-
src/chart/line/LineView.ts | 83 +-
src/chart/line/poly.ts | 50 -
src/chart/pie/PieView.ts | 19 +-
src/chart/pie/labelLayout.ts | 18 +-
src/chart/treemap/Breadcrumb.ts | 3 +-
src/chart/treemap/TreemapSeries.ts | 8 +-
src/chart/treemap/TreemapView.ts | 7 +-
src/component/tooltip/TooltipHTMLContent.ts | 111 +-
src/echarts.all.ts | 272 +
.../expect/code.expect.js => src/echarts.blank.ts | 13 +-
src/{chart/candlestick.ts => echarts.common.ts} | 31 +-
.../echarts.simple.ts | 12 +-
src/echarts.ts | 45 +-
src/label/LabelManager.ts | 5 +-
src/label/labelStyle.ts | 5 +-
src/model/Global.ts | 27 +-
src/model/globalDefault.ts | 3 +-
src/theme/dark.ts | 14 +-
src/util/event.ts | 18 +-
src/util/model.ts | 38 +-
src/util/states.ts | 8 +-
src/util/types.ts | 9 +-
test/graph-grid-life.html | 4 +-
test/label-layout.html | 94 +-
test/line-animation.html | 282 +-
test/new-tooltip.html | 1 +
test/pie-richText.html | 767 +++
test/timeScale-formatter.html | 13 +-
test/ut/core/utHelper.ts | 4 +-
test/ut/jest.config.js | 1 -
test/ut/spec/api/containPixel.test.ts | 3 +-
test/ut/spec/api/getVisual.test.ts | 1 +
test/ut/spec/component/dataZoom/helper.test.ts | 142 +-
test/ut/spec/component/helper/sliderMove.test.ts | 9 +-
test/ut/spec/component/visualMap/setOption.test.ts | 135 +-
test/ut/spec/data/completeDimensions.test.ts | 2 +-
test/ut/spec/model/Component.test.ts | 265 +-
test/ut/spec/model/Global.test.ts | 239 +-
test/ut/spec/model/timelineMediaOptions.test.ts | 59 +-
test/ut/spec/scale/interval.test.ts | 94 +-
test/ut/spec/util/graphic.test.ts | 97 +-
test/ut/spec/util/layout.test.ts | 44 +-
test/ut/spec/util/model.test.ts | 19 +-
test/ut/spec/util/number.test.ts | 434 +-
theme/dark.js | 171 +-
tsconfig.json | 1 -
74 files changed, 13680 insertions(+), 6830 deletions(-)
create mode 100644 src/echarts.all.ts
copy test/build/removeDEV/expect/code.expect.js => src/echarts.blank.ts (90%)
copy src/{chart/candlestick.ts => echarts.common.ts} (58%)
copy test/build/esm2cjs/expect/export-default1.expect.js => src/echarts.simple.ts (83%)
create mode 100644 test/pie-richText.html
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 04/08: test: fix ut code to ts.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 346cccdfd72f8dbb1b9bc15cf104383ad2cb203f
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 16:19:29 2020 +0800
test: fix ut code to ts.
---
test/ut/spec/api/containPixel.test.ts | 3 +-
test/ut/spec/component/helper/sliderMove.test.ts | 9 +-
test/ut/spec/component/visualMap/setOption.test.ts | 135 ++++++-----
test/ut/spec/data/completeDimensions.test.ts | 2 +-
test/ut/spec/model/Component.test.ts | 265 +++++++++++++--------
5 files changed, 245 insertions(+), 169 deletions(-)
diff --git a/test/ut/spec/api/containPixel.test.ts b/test/ut/spec/api/containPixel.test.ts
index ec99628..0eee5f0 100755
--- a/test/ut/spec/api/containPixel.test.ts
+++ b/test/ut/spec/api/containPixel.test.ts
@@ -23,7 +23,6 @@ import { EChartsType, registerMap } from '../../../../src/echarts';
import { GeoJSON } from '../../../../src/coord/geo/geoTypes';
-
describe('api/containPixel', function () {
const testGeoJson1: GeoJSON = {
'type': 'FeatureCollection',
@@ -150,7 +149,7 @@ describe('api/containPixel', function () {
});
const width = chart.getWidth();
- const height = chart.getWidth();
+ // const height = chart.getWidth();
expect(chart.containPixel('geo', [15, 30])).toEqual(true);
expect(chart.containPixel('geo', [9.5, 30])).toEqual(false);
diff --git a/test/ut/spec/component/helper/sliderMove.test.ts b/test/ut/spec/component/helper/sliderMove.test.ts
index 5ad85e8..ae86fa8 100644
--- a/test/ut/spec/component/helper/sliderMove.test.ts
+++ b/test/ut/spec/component/helper/sliderMove.test.ts
@@ -17,15 +17,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-const sliderMove = require('../../../../../lib/component/helper/sliderMove');
+
+import sliderMove from '../../../../../src/component/helper/sliderMove';
+
+
describe('component/helper/sliderMove', function () {
describe('sliderMove', function () {
it('normalize', function () {
// Return input handleEnds
- var inputHandleEnds = [22, 50];
- var outputHandleEnds = sliderMove(0, inputHandleEnds, [20, 50], 0);
+ const inputHandleEnds = [22, 50];
+ const outputHandleEnds = sliderMove(0, inputHandleEnds, [20, 50], 0);
expect(inputHandleEnds === outputHandleEnds).toEqual(true);
expect(outputHandleEnds).toEqual([22, 50]);
diff --git a/test/ut/spec/component/visualMap/setOption.test.ts b/test/ut/spec/component/visualMap/setOption.test.ts
index fe91478..3fe1488 100755
--- a/test/ut/spec/component/visualMap/setOption.test.ts
+++ b/test/ut/spec/component/visualMap/setOption.test.ts
@@ -17,12 +17,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-const utHelper = require('../../../core/utHelper');
+
+import { createChart } from '../../../core/utHelper';
+import { EChartsType } from '../../../../../src/echarts';
+import { EChartsFullOption } from '../../../../../src/option';
+import { ContinousVisualMapOption } from '../../../../../src/component/visualMap/ContinuousModel';
+import { PiecewiseVisualMapOption } from '../../../../../src/component/visualMap/PiecewiseModel';
+import VisualMapModel from '../../../../../src/component/visualMap/VisualMapModel';
+
describe('vsiaulMap_setOption', function () {
- var chart;
+ let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart();
+ chart = createChart();
});
afterEach(function () {
@@ -41,12 +48,13 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
+ const option = chart.getOption();
+ const visualMapOptionGotten = option.visualMap as (ContinousVisualMapOption | PiecewiseVisualMapOption)[];
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
- expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
- expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
done();
});
@@ -60,12 +68,13 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
+ const option = chart.getOption();
+ const visualMapOptionGotten = option.visualMap as (ContinousVisualMapOption | PiecewiseVisualMapOption)[];
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].color).toEqual(['yellow', 'blue', 'red']);
- expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
- expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].color).toEqual(['yellow', 'blue', 'red']);
+ expect(visualMapOptionGotten[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
done();
});
@@ -93,11 +102,12 @@ describe('vsiaulMap_setOption', function () {
expectTheSame(chart.getOption());
- function expectTheSame(option) {
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
- expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
- expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ function expectTheSame(option: EChartsFullOption) {
+ const visualMapOptionGotten = option.visualMap as (ContinousVisualMapOption | PiecewiseVisualMapOption)[];
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
+ expect(visualMapOptionGotten[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
done();
}
});
@@ -115,7 +125,7 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
+ // const option = chart.getOption();
chart.setOption({
visualMap: {
@@ -125,14 +135,15 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
+ const option = chart.getOption();
+ const visualMapOptionGotten = option.visualMap as (ContinousVisualMapOption | PiecewiseVisualMapOption)[];
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].target.inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].inRange.symbolSize).toEqual([0.4, 0.6]);
- expect(option.visualMap[0].target.inRange.symbolSize).toEqual([0.4, 0.6]);
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].target.inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].inRange.symbolSize).toEqual([0.4, 0.6]);
+ expect(visualMapOptionGotten[0].target.inRange.symbolSize).toEqual([0.4, 0.6]);
done();
// Do not compare controller.inRange.symbolSize, which will be amplified to controller size.
// expect(option.visualMap[0].controller.inRange.symbolSize).toEqual([?, ?]);
@@ -159,15 +170,15 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
-
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].target.inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
- expect(option.visualMap[0].inRange.colorAlpha).toEqual([0.4, 0.6]);
- expect(option.visualMap[0].target.inRange.colorAlpha).toEqual([0.4, 0.6]);
- expect(option.visualMap[0].controller.inRange.colorAlpha).toEqual([0.4, 0.6]);
+ let visualMapOptionGotten: (ContinousVisualMapOption | PiecewiseVisualMapOption)[];
+ visualMapOptionGotten = chart.getOption().visualMap as typeof visualMapOptionGotten;
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].target.inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
+ expect(visualMapOptionGotten[0].inRange.colorAlpha).toEqual([0.4, 0.6]);
+ expect(visualMapOptionGotten[0].target.inRange.colorAlpha).toEqual([0.4, 0.6]);
+ expect(visualMapOptionGotten[0].controller.inRange.colorAlpha).toEqual([0.4, 0.6]);
chart.setOption({
visualMap: {
@@ -175,13 +186,12 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
-
- expect(option.visualMap.length).toEqual(1);
- expect(option.visualMap[0].target.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
- expect(option.visualMap[0].controller.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
- expect(option.visualMap[0].target.inRange.color).toEqual(['green', 'blue', 'red']);
- expect(option.visualMap[0].controller.inRange.color).toEqual(['green', 'blue', 'red']);
+ visualMapOptionGotten = chart.getOption().visualMap as typeof visualMapOptionGotten;
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(visualMapOptionGotten[0].target.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
+ expect(visualMapOptionGotten[0].controller.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
+ expect(visualMapOptionGotten[0].target.inRange.color).toEqual(['green', 'blue', 'red']);
+ expect(visualMapOptionGotten[0].controller.inRange.color).toEqual(['green', 'blue', 'red']);
chart.setOption({
visualMap: {
@@ -193,20 +203,20 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
+ visualMapOptionGotten = chart.getOption().visualMap as typeof visualMapOptionGotten;
- expect(option.visualMap.length).toEqual(1);
- expect(!!option.visualMap[0].target.inRange).toEqual(true);
- var onlyColor = true;
- for (var i in option.visualMap[0].target.inRange) {
+ expect(visualMapOptionGotten.length).toEqual(1);
+ expect(!!visualMapOptionGotten[0].target.inRange).toEqual(true);
+ let onlyColor = true;
+ for (const i in visualMapOptionGotten[0].target.inRange) {
if (i !== 'color') {
onlyColor = false;
}
}
- var inRangeColor = option.visualMap[0].target.inRange.color;
+ const inRangeColor = visualMapOptionGotten[0].target.inRange.color;
expect(onlyColor).toEqual(true);
expect(inRangeColor).toEqual(['#f6efa6', '#d88273', '#bf444c']);
- expect(option.visualMap[0].controller.outOfRange.symbol).toEqual(['diamond']);
+ expect(visualMapOptionGotten[0].controller.outOfRange.symbol).toEqual(['diamond']);
done();
});
@@ -222,9 +232,10 @@ describe('vsiaulMap_setOption', function () {
}
});
- var option = chart.getOption();
-
- expect(!!option.visualMap[0].target.outOfRange.opacity).toEqual(true);
+ const visualMapOptionGotten = chart.getOption().visualMap as (
+ ContinousVisualMapOption | PiecewiseVisualMapOption
+ )[];
+ expect(!!visualMapOptionGotten[0].target.outOfRange.opacity).toEqual(true);
done();
});
@@ -245,21 +256,21 @@ describe('vsiaulMap_setOption', function () {
]
});
- var ecModel = chart.getModel();
+ const ecModel = chart.getModel();
- function getVisual(idx, visualType) {
- return ecModel.getComponent('visualMap', idx)
+ function getVisual(idx: number, visualType: 'color' | 'opacity' | 'symbol') {
+ return (ecModel.getComponent('visualMap', idx) as VisualMapModel)
.targetVisuals.inRange[visualType].option.visual;
}
- function makeCategoryVisual(val) {
- var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
- var arr = [];
- if (val != null) {
- arr[CATEGORY_DEFAULT_VISUAL_INDEX] = val;
+ function makeCategoryVisual(...args: unknown[]) {
+ const CATEGORY_DEFAULT_VISUAL_INDEX = -1;
+ const arr = [];
+ if (args[0] != null) {
+ arr[CATEGORY_DEFAULT_VISUAL_INDEX] = args[0];
}
- for (var i = 1; i < arguments.length; i++) {
- arr.push(arguments[i]);
+ for (let i = 1; i < args.length; i++) {
+ arr.push(args[i]);
}
return arr;
}
diff --git a/test/ut/spec/data/completeDimensions.test.ts b/test/ut/spec/data/completeDimensions.test.ts
index 9395d0c..24efc4b 100644
--- a/test/ut/spec/data/completeDimensions.test.ts
+++ b/test/ut/spec/data/completeDimensions.test.ts
@@ -79,7 +79,7 @@ describe('completeDimensions', function () {
},
SOURCE_FORMAT_ARRAY_ROWS,
null
- )
+ );
const opt = {
'dimsDef': [
diff --git a/test/ut/spec/model/Component.test.ts b/test/ut/spec/model/Component.test.ts
index f06c6e1..c6799c7 100755
--- a/test/ut/spec/model/Component.test.ts
+++ b/test/ut/spec/model/Component.test.ts
@@ -17,155 +17,218 @@
* specific language governing permissions and limitations
* under the License.
*/
-const ComponentModel = require('../../../../lib/model/Component');
+
+import ComponentModel, { ComponentModelConstructor } from '../../../../src/model/Component';
+import { ComponentMainType } from '../../../../src/util/types';
+
+const componentModelConstructor = ComponentModel as ComponentModelConstructor;
+
describe('Component', function () {
let idx = 0;
- function makeTypes(count) {
- let arr = [];
+ function makeTypes(count: number): string[] {
+ const arr = [];
for (let i = 0; i < count; i++) {
arr.push('type_' + idx++);
}
return arr;
}
+ type TopoResultItem = [ComponentMainType, ComponentMainType[]];
+
describe('topologicalTravel', function () {
it('topologicalTravel_base', function () {
- var [m1, a1, a2] = makeTypes(3);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a1});
- ComponentModel.extend({type: a2});
- var result = [];
- var allList = ComponentModel.getAllClassMainTypes();
- ComponentModel.topologicalTravel([m1, a1, a2], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ const [m1, a1, a2] = makeTypes(3);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a1});
+ componentModelConstructor.extend({type: a2});
+ const result: TopoResultItem[] = [];
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ componentModelConstructor.topologicalTravel(
+ [m1, a1, a2],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([[a2, ['dataset']], [a1, ['dataset']], [m1, ['dataset', a1, a2]]]);
});
it('topologicalTravel_a1IsAbsent', function () {
- var [m1, a1, a2] = makeTypes(3);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a2});
- var allList = ComponentModel.getAllClassMainTypes();
- var result = [];
- ComponentModel.topologicalTravel([m1, a2], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ const [m1, a1, a2] = makeTypes(3);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a2});
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ const result: TopoResultItem[] = [];
+ componentModelConstructor.topologicalTravel(
+ [m1, a2],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([[a2, ['dataset']], [m1, ['dataset', a1, a2]]]);
});
it('topologicalTravel_empty', function () {
- var [m1, a1, a2] = makeTypes(3);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a1});
- ComponentModel.extend({type: a2});
- var allList = ComponentModel.getAllClassMainTypes();
- var result = [];
- ComponentModel.topologicalTravel([], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ const [m1, a1, a2] = makeTypes(3);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a1});
+ componentModelConstructor.extend({type: a2});
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ const result: TopoResultItem[] = [];
+ componentModelConstructor.topologicalTravel(
+ [],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([]);
});
it('topologicalTravel_isolate', function () {
- var [m1, a1, a2] = makeTypes(3);
- ComponentModel.extend({type: a2});
- ComponentModel.extend({type: a1});
- ComponentModel.extend({type: m1, dependencies: [a2]});
- var allList = ComponentModel.getAllClassMainTypes();
- var result = [];
- ComponentModel.topologicalTravel([a1, a2, m1], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
- expect(result).toEqual([[a1, ['dataset']], [a2, ['dataset']], [m1, ['dataset',a2]]]);
+ const [m1, a1, a2] = makeTypes(3);
+ componentModelConstructor.extend({type: a2});
+ componentModelConstructor.extend({type: a1});
+ componentModelConstructor.extend({type: m1, dependencies: [a2]});
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ const result: TopoResultItem[] = [];
+ componentModelConstructor.topologicalTravel(
+ [a1, a2, m1],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
+ expect(result).toEqual([[a1, ['dataset']], [a2, ['dataset']], [m1, ['dataset', a2]]]);
});
it('topologicalTravel_diamond', function () {
- var [m1, a1, a2, a3] = makeTypes(4);
- ComponentModel.extend({type: a1, dependencies: []});
- ComponentModel.extend({type: a2, dependencies: [a1]});
- ComponentModel.extend({type: a3, dependencies: [a1]});
- ComponentModel.extend({type: m1, dependencies: [a2, a3]});
- var allList = ComponentModel.getAllClassMainTypes();
- var result = [];
- ComponentModel.topologicalTravel([m1, a1, a2, a3], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
- expect(result).toEqual([[a1, ['dataset']], [a3, ['dataset', a1]], [a2, ['dataset', a1]], [m1, ['dataset', a2, a3]]]);
+ const [m1, a1, a2, a3] = makeTypes(4);
+ componentModelConstructor.extend({type: a1, dependencies: []});
+ componentModelConstructor.extend({type: a2, dependencies: [a1]});
+ componentModelConstructor.extend({type: a3, dependencies: [a1]});
+ componentModelConstructor.extend({type: m1, dependencies: [a2, a3]});
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ const result: TopoResultItem[] = [];
+ componentModelConstructor.topologicalTravel(
+ [m1, a1, a2, a3],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
+ expect(result).toEqual(
+ [[a1, ['dataset']],
+ [a3, ['dataset', a1]],
+ [a2, ['dataset', a1]],
+ [m1, ['dataset', a2, a3]]
+ ]);
});
it('topologicalTravel_loop', function () {
- var [m1, m2, a1, a2, a3] = makeTypes(5);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: m2, dependencies: [m1, a2]});
- ComponentModel.extend({type: a1, dependencies: [m2, a2, a3]});
- ComponentModel.extend({type: a2});
- ComponentModel.extend({type: a3});
- var allList = ComponentModel.getAllClassMainTypes();
+ const [m1, m2, a1, a2, a3] = makeTypes(5);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: m2, dependencies: [m1, a2]});
+ componentModelConstructor.extend({type: a1, dependencies: [m2, a2, a3]});
+ componentModelConstructor.extend({type: a2});
+ componentModelConstructor.extend({type: a3});
+ const allList = componentModelConstructor.getAllClassMainTypes();
expect(function () {
- ComponentModel.topologicalTravel([m1, m2, a1], allList);
+ componentModelConstructor.topologicalTravel(
+ [m1, m2, a1],
+ allList,
+ () => {}
+ );
}).toThrowError(/Circl/);
});
it('topologicalTravel_multipleEchartsInstance', function () {
- var [m1, m2, a1, a2] = makeTypes(4);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a1});
- ComponentModel.extend({type: a2});
- var allList = ComponentModel.getAllClassMainTypes();
- var result = [];
- ComponentModel.topologicalTravel([m1, a1, a2], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ const [m1, m2, a1, a2] = makeTypes(4);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a1});
+ componentModelConstructor.extend({type: a2});
+ let allList = componentModelConstructor.getAllClassMainTypes();
+ let result: TopoResultItem[] = [];
+ componentModelConstructor.topologicalTravel(
+ [m1, a1, a2],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([[a2, ['dataset']], [a1, ['dataset']], [m1, ['dataset', a1, a2]]]);
result = [];
- ComponentModel.extend({type: m2, dependencies: [a1, m1]});
- var allList = ComponentModel.getAllClassMainTypes();
- ComponentModel.topologicalTravel([m2, m1, a1, a2], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
- expect(result).toEqual([[a2, ['dataset']], [a1, ['dataset']], [m1, ['dataset', a1, a2]], [m2, ['dataset', a1, m1]]]);
+ componentModelConstructor.extend({type: m2, dependencies: [a1, m1]});
+ allList = componentModelConstructor.getAllClassMainTypes();
+ componentModelConstructor.topologicalTravel(
+ [m2, m1, a1, a2],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
+ expect(result).toEqual(
+ [[a2, ['dataset']], [a1, ['dataset']], [m1, ['dataset', a1, a2]], [m2, ['dataset', a1, m1]]]
+ );
});
it('topologicalTravel_missingSomeNodeButHasDependencies', function () {
- var [m1, a1, a2, a3, a4] = makeTypes(5);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a2, dependencies: [a3]});
- ComponentModel.extend({type: a3});
- ComponentModel.extend({type: a4});
- var result = [];
- var allList = ComponentModel.getAllClassMainTypes();
- ComponentModel.topologicalTravel([a3, m1], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ const [m1, a1, a2, a3, a4] = makeTypes(5);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a2, dependencies: [a3]});
+ componentModelConstructor.extend({type: a3});
+ componentModelConstructor.extend({type: a4});
+ let result: TopoResultItem[] = [];
+ let allList = componentModelConstructor.getAllClassMainTypes();
+ componentModelConstructor.topologicalTravel(
+ [a3, m1],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([[a3, ['dataset']], [a2, ['dataset', a3]], [m1, ['dataset', a1, a2]]]);
- var result = [];
- var allList = ComponentModel.getAllClassMainTypes();
- ComponentModel.topologicalTravel([m1, a3], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
+ result = [];
+ allList = componentModelConstructor.getAllClassMainTypes();
+ componentModelConstructor.topologicalTravel(
+ [m1, a3],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
expect(result).toEqual([[a3, ['dataset']], [a2, ['dataset', a3]], [m1, ['dataset', a1, a2]]]);
});
it('topologicalTravel_subType', function () {
- var [m1, a1, a2, a3, a4] = makeTypes(5);
- ComponentModel.extend({type: m1, dependencies: [a1, a2]});
- ComponentModel.extend({type: a1 + '.aaa', dependencies: [a2]});
- ComponentModel.extend({type: a1 + '.bbb', dependencies: [a3, a4]});
- ComponentModel.extend({type: a2});
- ComponentModel.extend({type: a3});
- ComponentModel.extend({type: a4});
- var result = [];
- var allList = ComponentModel.getAllClassMainTypes();
- ComponentModel.topologicalTravel([m1, a1, a2, a4], allList, function (componentType, dependencies) {
- result.push([componentType, dependencies]);
- });
- expect(result).toEqual([[a4, ['dataset']], [a2, ['dataset']], [a1, ['dataset', a2, a3, a4]], [m1, ['dataset', a1, a2]]]);
+ const [m1, a1, a2, a3, a4] = makeTypes(5);
+ componentModelConstructor.extend({type: m1, dependencies: [a1, a2]});
+ componentModelConstructor.extend({type: a1 + '.aaa', dependencies: [a2]});
+ componentModelConstructor.extend({type: a1 + '.bbb', dependencies: [a3, a4]});
+ componentModelConstructor.extend({type: a2});
+ componentModelConstructor.extend({type: a3});
+ componentModelConstructor.extend({type: a4});
+ const result: TopoResultItem[] = [];
+ const allList = componentModelConstructor.getAllClassMainTypes();
+ componentModelConstructor.topologicalTravel(
+ [m1, a1, a2, a4],
+ allList,
+ function (componentType, dependencies) {
+ result.push([componentType, dependencies]);
+ }
+ );
+ expect(result).toEqual(
+ [[a4, ['dataset']],
+ [a2, ['dataset']],
+ [a1, ['dataset', a2, a3, a4]],
+ [m1, ['dataset', a1, a2]]
+ ]);
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 05/08: Merge branch 'next' into fix-ut
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 5499a902096bb8eb2dd1004138bd0d57281ef87b
Merge: 346cccd a77894c
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 16:45:50 2020 +0800
Merge branch 'next' into fix-ut
dist/echarts.common.js | 5128 ++++++++++++++-------
dist/echarts.common.js.map | 2 +-
dist/echarts.common.min.js | 2 +-
dist/echarts.js | 6539 ++++++++++++++++++---------
dist/echarts.js.map | 2 +-
dist/echarts.min.js | 2 +-
dist/echarts.simple.js | 3921 ++++++++++------
dist/echarts.simple.js.map | 2 +-
dist/echarts.simple.min.js | 2 +-
dist/extension/bmap.js | 147 +-
dist/extension/bmap.js.map | 2 +-
dist/extension/bmap.min.js | 2 +-
dist/extension/dataTool.min.js | 2 +-
extension-src/bmap/BMapCoordSys.ts | 6 +-
extension-src/bmap/BMapView.ts | 12 +-
i18n/langDE.js | 1 +
i18n/langES-obj.js | 38 +-
i18n/langES.js | 38 +-
i18n/langFI-obj.js | 38 +-
i18n/langFI.js | 38 +-
i18n/langTH-obj.js | 38 +-
i18n/langTH.js | 38 +-
package-lock.json | 796 +++-
package.json | 4 +-
src/chart/bar/BarView.ts | 5 +-
src/chart/custom.ts | 2 +-
src/chart/helper/Symbol.ts | 21 +-
src/chart/line/LineView.ts | 83 +-
src/chart/line/poly.ts | 50 -
src/chart/pie/PieView.ts | 19 +-
src/chart/pie/labelLayout.ts | 18 +-
src/component/tooltip/TooltipHTMLContent.ts | 111 +-
src/echarts.ts | 35 +-
src/label/LabelManager.ts | 5 +-
src/label/labelStyle.ts | 5 +-
src/model/globalDefault.ts | 3 +-
src/theme/dark.ts | 14 +-
src/util/event.ts | 18 +-
src/util/states.ts | 8 +-
src/util/types.ts | 1 +
test/graph-grid-life.html | 4 +-
test/label-layout.html | 94 +-
test/line-animation.html | 282 +-
test/new-tooltip.html | 1 +
test/pie-richText.html | 767 ++++
test/timeScale-formatter.html | 13 +-
theme/dark.js | 171 +-
47 files changed, 12475 insertions(+), 6055 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 03/08: fix: (1) clarify id and name type. (2)
compat non supported name type.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 81b2efe537d7e32892c60517ec316ab6c6df4ee3
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 16:18:56 2020 +0800
fix: (1) clarify id and name type. (2) compat non supported name type.
---
src/chart/treemap/Breadcrumb.ts | 3 ++-
src/chart/treemap/TreemapSeries.ts | 8 +++++---
src/chart/treemap/TreemapView.ts | 7 ++++---
src/echarts.ts | 10 ++++++++--
src/model/Global.ts | 27 +++++++++++++++------------
src/util/model.ts | 21 ++++++++++++++-------
src/util/types.ts | 4 +---
7 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/src/chart/treemap/Breadcrumb.ts b/src/chart/treemap/Breadcrumb.ts
index 6ee42a6..beacf13 100644
--- a/src/chart/treemap/Breadcrumb.ts
+++ b/src/chart/treemap/Breadcrumb.ts
@@ -28,6 +28,7 @@ import { curry, defaults } from 'zrender/src/core/util';
import { ZRElementEvent, BoxLayoutOptionMixin, ECElement } from '../../util/types';
import Element from 'zrender/src/Element';
import Model from '../../model/Model';
+import { convertOptionIdName } from '../../util/model';
const TEXT_PADDING = 8;
const ITEM_GAP = 8;
@@ -110,7 +111,7 @@ class Breadcrumb {
*/
_prepare(targetNode: TreeNode, layoutParam: LayoutParam, textStyleModel: BreadcrumbTextStyleModel) {
for (let node = targetNode; node; node = node.parentNode) {
- const text = node.getModel<TreemapSeriesNodeItemOption>().get('name');
+ const text = convertOptionIdName(node.getModel<TreemapSeriesNodeItemOption>().get('name'), '');
const textRect = textStyleModel.getTextRect(text);
const itemWidth = Math.max(
textRect.width + TEXT_PADDING * 2,
diff --git a/src/chart/treemap/TreemapSeries.ts b/src/chart/treemap/TreemapSeries.ts
index 9bc1852..4aa4fc8 100644
--- a/src/chart/treemap/TreemapSeries.ts
+++ b/src/chart/treemap/TreemapSeries.ts
@@ -30,7 +30,9 @@ import {
RoamOptionMixin,
CallbackDataParams,
ColorString,
- StatesOptionMixin
+ StatesOptionMixin,
+ OptionId,
+ OptionName
} from '../../util/types';
import GlobalModel from '../../model/Global';
import { LayoutRect } from '../../util/layout';
@@ -119,8 +121,8 @@ export interface TreemapSeriesLevelOption extends TreemapSeriesVisualOption,
export interface TreemapSeriesNodeItemOption extends TreemapSeriesVisualOption,
TreemapStateOption, StatesOptionMixin<TreemapStateOption, ExtraStateOption> {
- id?: string
- name?: string
+ id?: OptionId
+ name?: OptionName
value?: TreemapSeriesDataValue
diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts
index 2d97f7a..702111e 100644
--- a/src/chart/treemap/TreemapView.ts
+++ b/src/chart/treemap/TreemapView.ts
@@ -44,7 +44,7 @@ import { LayoutRect } from '../../util/layout';
import { TreemapLayoutNode } from './treemapLayout';
import Element from 'zrender/src/Element';
import Displayable from 'zrender/src/graphic/Displayable';
-import { makeInner } from '../../util/model';
+import { makeInner, convertOptionIdName } from '../../util/model';
import { PathStyleProps, PathProps } from 'zrender/src/graphic/Path';
import { TreeSeriesNodeItemOption } from '../tree/TreeSeries';
import {
@@ -954,7 +954,7 @@ function renderNode(
seriesModel.getFormattedLabel(
thisNode.dataIndex, 'normal', null, null, normalLabelModel.get('formatter')
),
- nodeModel.get('name')
+ convertOptionIdName(nodeModel.get('name'), null)
);
if (!upperLabelRect && thisLayout.isLeafRoot) {
const iconChar = seriesModel.get('drillDownIcon', true);
@@ -964,7 +964,8 @@ function renderNode(
const isShow = normalLabelModel.getShallow('show');
setLabelStyle(
- rectEl, getLabelStatesModels(nodeModel, upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL),
+ rectEl,
+ getLabelStatesModels(nodeModel, upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL),
{
defaultText: isShow ? text : null,
inheritColor: visualColor,
diff --git a/src/echarts.ts b/src/echarts.ts
index 8c1bb7e..fefd6f8 100644
--- a/src/echarts.ts
+++ b/src/echarts.ts
@@ -1381,9 +1381,15 @@ class ECharts extends Eventful {
subType && (condition.subType = subType); // subType may be '' by parseClassType;
const excludeSeriesId = payload.excludeSeriesId;
- let excludeSeriesIdMap: zrUtil.HashMap<string[], string>;
+ let excludeSeriesIdMap: zrUtil.HashMap<true, string>;
if (excludeSeriesId != null) {
- excludeSeriesIdMap = zrUtil.createHashMap(modelUtil.normalizeToArray(excludeSeriesId));
+ excludeSeriesIdMap = zrUtil.createHashMap();
+ each(modelUtil.normalizeToArray(excludeSeriesId), id => {
+ const modelId = modelUtil.convertOptionIdName(id, null);
+ if (modelId != null) {
+ excludeSeriesIdMap.set(modelId, true);
+ }
+ });
}
// If dispatchAction before setOption, do nothing.
diff --git a/src/model/Global.ts b/src/model/Global.ts
index 0b97c8d..99bd7e9 100644
--- a/src/model/Global.ts
+++ b/src/model/Global.ts
@@ -52,7 +52,9 @@ import {
ThemeOption,
ComponentOption,
ComponentMainType,
- ComponentSubType
+ ComponentSubType,
+ OptionId,
+ OptionName
} from '../util/types';
import OptionManager from './OptionManager';
import Scheduler from '../stream/Scheduler';
@@ -540,8 +542,8 @@ class GlobalModel extends Model<ECUnitOption> {
mainType: mainType,
// subType will be filtered finally.
index: q[indexAttr] as (number | number[]),
- id: q[idAttr] as (string | string[]),
- name: q[nameAttr] as (string | string[])
+ id: q[idAttr] as (OptionId | OptionId[]),
+ name: q[nameAttr] as (OptionName | OptionName[])
}
: null;
}
@@ -622,10 +624,11 @@ class GlobalModel extends Model<ECUnitOption> {
/**
* Get series list before filtered by name.
*/
- getSeriesByName(name: string): SeriesModel[] {
+ getSeriesByName(name: OptionName): SeriesModel[] {
+ const nameStr = modelUtil.convertOptionIdName(name, null);
return filter(
this._componentsMap.get('series') as SeriesModel[],
- oneSeries => !!oneSeries && oneSeries.name === name
+ oneSeries => !!oneSeries && nameStr != null && oneSeries.name === nameStr
);
}
@@ -853,8 +856,8 @@ export interface QueryConditionKindB {
mainType: ComponentMainType;
subType?: ComponentSubType;
index?: number | number[];
- id?: string | number | (string | number)[];
- name?: (string | number) | (string | number)[];
+ id?: OptionId | OptionId[];
+ name?: OptionName | OptionName[];
}
export interface EachComponentAllCallback {
(mainType: string, model: ComponentModel, componentIndex: number): void;
@@ -909,18 +912,18 @@ function queryByIdOrName<T extends { id?: string, name?: string }>(
// Here is a break from echarts4: string and number are
// traded as equal.
if (isArray(idOrName)) {
- const keyMap = createHashMap<boolean>(idOrName);
+ const keyMap = createHashMap<boolean>();
each(idOrName, function (idOrNameItem) {
if (idOrNameItem != null) {
- modelUtil.validateIdOrName(idOrNameItem);
- keyMap.set(idOrNameItem, true);
+ const idName = modelUtil.convertOptionIdName(idOrNameItem, null);
+ idName != null && keyMap.set(idOrNameItem, true);
}
});
return filter(cmpts, cmpt => cmpt && keyMap.get(cmpt[attr]));
}
else {
- modelUtil.validateIdOrName(idOrName);
- return filter(cmpts, cmpt => cmpt && cmpt[attr] === idOrName + '');
+ const idName = modelUtil.convertOptionIdName(idOrName, null);
+ return filter(cmpts, cmpt => cmpt && idName != null && cmpt[attr] === idName);
}
}
diff --git a/src/util/model.ts b/src/util/model.ts
index 35af503..5f214b8 100644
--- a/src/util/model.ts
+++ b/src/util/model.ts
@@ -52,6 +52,7 @@ import CartesianAxisModel from '../coord/cartesian/AxisModel';
import GridModel from '../coord/cartesian/GridModel';
import { isNumeric, getRandomIdBase, getPrecisionSafe, round } from './number';
import { interpolateNumber } from 'zrender/src/animation/Animator';
+import { warn } from './log';
/**
* Make the name displayable. But we should
@@ -232,8 +233,17 @@ export function mappingToExists<T extends MappingExistingItem>(
newCmptOptions[index] = null;
return;
}
- cmptOption.id == null || validateIdOrName(cmptOption.id);
- cmptOption.name == null || validateIdOrName(cmptOption.name);
+
+ if (__DEV__) {
+ // There is some legacy case that name is set as `false`.
+ // But should work normally rather than throw error.
+ if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
+ warnInvalidateIdOrName(cmptOption.id);
+ }
+ if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
+ warnInvalidateIdOrName(cmptOption.name);
+ }
+ }
});
const result = prepareResult(existings, existingIdIdxMap, mode);
@@ -535,12 +545,9 @@ export function convertOptionIdName(idOrName: unknown, defaultValue: string): st
: defaultValue;
}
-export function validateIdOrName(idOrName: unknown) {
+function warnInvalidateIdOrName(idOrName: unknown) {
if (__DEV__) {
- assert(
- isValidIdOrName(idOrName),
- '`' + idOrName + '` is invalid id or name. Must be a string.'
- );
+ warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
}
}
diff --git a/src/util/types.ts b/src/util/types.ts
index 7ce3e5f..443b382 100644
--- a/src/util/types.ts
+++ b/src/util/types.ts
@@ -133,7 +133,7 @@ export interface DataModel extends DataHost, DataFormatMixin {}
// Pick<DataFormatMixin, 'getDataParams' | 'formatTooltip'> {}
interface PayloadItem {
- excludeSeriesId?: string | string[];
+ excludeSeriesId?: OptionId | OptionId[];
animation?: PayloadAnimationPart
[other: string]: any;
}
@@ -1343,8 +1343,6 @@ export interface SeriesOption<StateOption=any, ExtraStateOpts extends {
ColorPaletteOptionMixin,
StatesOptionMixin<StateOption, ExtraStateOpts>
{
- name?: string
-
silent?: boolean
blendMode?: string
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 01/08: test: fix ut: dataZoom
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit bed2ffcc52e08ea28925866fab1094537179d63f
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Oct 14 17:11:37 2020 +0800
test: fix ut: dataZoom
---
test/ut/core/utHelper.ts | 4 +-
test/ut/spec/api/getVisual.test.ts | 1 +
test/ut/spec/component/dataZoom/helper.test.ts | 142 ++++++++++++-------------
3 files changed, 72 insertions(+), 75 deletions(-)
diff --git a/test/ut/core/utHelper.ts b/test/ut/core/utHelper.ts
index dcfdb1b..bfedb65 100755
--- a/test/ut/core/utHelper.ts
+++ b/test/ut/core/utHelper.ts
@@ -112,7 +112,7 @@ export function isValueFinite(val: unknown): boolean {
export function getGraphicElements(
chartOrGroup: EChartsType | Group,
mainType: ComponentMainType,
- index: number
+ index?: number
): Element[] {
if ((chartOrGroup as Group).type === 'group') {
return (chartOrGroup as Group).children();
@@ -135,7 +135,7 @@ export function getGraphicElements(
export function getViewGroup(
chart: EChartsType,
mainType: ComponentMainType,
- index: number
+ index?: number
): Group {
const component = chart.getModel().getComponent(mainType, index);
return component ? chart[
diff --git a/test/ut/spec/api/getVisual.test.ts b/test/ut/spec/api/getVisual.test.ts
index de3d747..c31d2dd 100755
--- a/test/ut/spec/api/getVisual.test.ts
+++ b/test/ut/spec/api/getVisual.test.ts
@@ -37,6 +37,7 @@ describe('api/getVisual', function () {
afterEach(function () {
chart.dispose();
});
+
it('scatter', function () {
chart.setOption({
xAxis: {},
diff --git a/test/ut/spec/component/dataZoom/helper.test.ts b/test/ut/spec/component/dataZoom/helper.test.ts
index 358f3fb..f51da55 100755
--- a/test/ut/spec/component/dataZoom/helper.test.ts
+++ b/test/ut/spec/component/dataZoom/helper.test.ts
@@ -17,91 +17,87 @@
* specific language governing permissions and limitations
* under the License.
*/
-const helper = require('../../../../../lib/component/dataZoom/helper');
-const utHelper = require('../../../core/utHelper');
+
+import { findEffectedDataZooms } from '../../../../../src/component/dataZoom/helper';
+import { createChart } from '../../../core/utHelper';
+import { EChartsType } from '../../../../../src/echarts';
+
+
+
describe('dataZoom/helper', function () {
- function makeRecords(result) {
- var o = {};
- helper.eachAxisDim(function (dimNames) {
- o[dimNames.name] = {};
- var r = result[dimNames.name] || [];
- for (var i = 0; i < r.length; i++) {
- o[dimNames.name][r[i]] = true;
- }
+ describe('findLinkedNodes', function () {
+
+ let chart: EChartsType;
+ beforeEach(function () {
+ chart = createChart();
});
- return o;
- }
- describe('findLinkedNodes', function () {
+ afterEach(function () {
+ chart.dispose();
+ });
- function forEachModel(models, callback) {
- for (var i = 0; i < models.length; i++) {
- callback(models[i]);
- }
- }
-
- function axisIndicesGetter(model, dimNames) {
- return model[dimNames.axisIndex];
- }
-
- it('findLinkedNodes_base', function (done) {
- var models = [
- {xAxisIndex: [1, 2], yAxisIndex: [0]},
- {xAxisIndex: [3], yAxisIndex: [1]},
- {xAxisIndex: [5], yAxisIndex: []},
- {xAxisIndex: [2, 5], yAxisIndex: []}
- ];
- var result = helper.createLinkedNodesFinder(
- utHelper.curry(forEachModel, models),
- helper.eachAxisDim,
- axisIndicesGetter
- )(models[0]);
- expect(result).toEqual({
- nodes: [models[0], models[3], models[2]],
- records: makeRecords({x: [1, 2, 5], y: [0]})
+ it('findLinkedNodes_base', function () {
+ chart.setOption({
+ xAxis: [{}, {}, {}, {}, {}, {}],
+ yAxis: [{}, {}, {}, {}, {}, {}],
+ dataZoom: [
+ { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+ { id: 'dz1', xAxisIndex: [3], yAxisIndex: [1] },
+ { id: 'dz2', xAxisIndex: [5], yAxisIndex: [] },
+ { id: 'dz3', xAxisIndex: [2, 5], yAxisIndex: [] }
+ ]
});
- done();
+
+ const payload = { type: 'dataZoom', dataZoomIndex: 0 };
+ const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+ expect(dzModels.length === 3);
+ expect(dzModels[0] === chart.getModel().getComponent('dataZoom', 0)).toEqual(true);
+ expect(dzModels[1] === chart.getModel().getComponent('dataZoom', 3)).toEqual(true);
+ expect(dzModels[2] === chart.getModel().getComponent('dataZoom', 2)).toEqual(true);
});
- it('findLinkedNodes_crossXY', function (done) {
- var models = [
- {xAxisIndex: [1, 2], yAxisIndex: [0]},
- {xAxisIndex: [3], yAxisIndex: [3, 0]},
- {xAxisIndex: [6, 3], yAxisIndex: [9]},
- {xAxisIndex: [5, 3], yAxisIndex: []},
- {xAxisIndex: [8], yAxisIndex: [4]}
- ];
- var result = helper.createLinkedNodesFinder(
- utHelper.curry(forEachModel, models),
- helper.eachAxisDim,
- axisIndicesGetter
- )(models[0]);
- expect(result).toEqual({
- nodes: [models[0], models[1], models[2], models[3]],
- records: makeRecords({x: [1, 2, 3, 5, 6], y: [0, 3, 9]})
+ it('findLinkedNodes_crossXY', function () {
+ chart.setOption({
+ xAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
+ yAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
+ dataZoom: [
+ { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+ { id: 'dz1', xAxisIndex: [3], yAxisIndex: [3, 0] },
+ { id: 'dz2', xAxisIndex: [6, 3], yAxisIndex: [9] },
+ { id: 'dz3', xAxisIndex: [5, 3], yAxisIndex: [] },
+ { id: 'dz4', xAxisIndex: [8], yAxisIndex: [4] }
+ ]
});
- done();
+
+ const payload = { type: 'dataZoom', dataZoomIndex: 0 };
+ const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+ expect(dzModels.length === 4);
+ expect(dzModels[0] === chart.getModel().getComponent('dataZoom', 0)).toEqual(true);
+ expect(dzModels[1] === chart.getModel().getComponent('dataZoom', 1)).toEqual(true);
+ expect(dzModels[2] === chart.getModel().getComponent('dataZoom', 2)).toEqual(true);
+ expect(dzModels[3] === chart.getModel().getComponent('dataZoom', 3)).toEqual(true);
});
- it('findLinkedNodes_emptySourceModel', function (done) {
- var models = [
- {xAxisIndex: [1, 2], yAxisIndex: [0]},
- {xAxisIndex: [3], yAxisIndex: [3, 0]},
- {xAxisIndex: [6, 3], yAxisIndex: [9]},
- {xAxisIndex: [5, 3], yAxisIndex: []},
- {xAxisIndex: [8], yAxisIndex: [4]}
- ];
- var result = helper.createLinkedNodesFinder(
- utHelper.curry(forEachModel, models),
- helper.eachAxisDim,
- axisIndicesGetter
- )();
- expect(result).toEqual({
- nodes: [],
- records: makeRecords({x: [], y: []})
+ it('findLinkedNodes_emptySourceModel', function () {
+ chart.setOption({
+ xAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}],
+ yAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}],
+ dataZoom: [
+ { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+ { id: 'dz1', xAxisIndex: [3], yAxisIndex: [3, 0] },
+ { id: 'dz2', xAxisIndex: [6, 3], yAxisIndex: [9] },
+ { id: 'dz3', xAxisIndex: [5, 3], yAxisIndex: [] },
+ { id: 'dz4', xAxisIndex: [8], yAxisIndex: [4] }
+ ]
});
- done();
+
+ const payload = { type: 'other' };
+ const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+ expect(dzModels.length === 0);
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 08/08: test: update ut for 5.0.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit c6eecfe2c6730345f9fce25b78cf4186f487dd5d
Author: 100pah <su...@gmail.com>
AuthorDate: Fri Oct 16 00:47:36 2020 +0800
test: update ut for 5.0.
---
test/ut/jest.config.js | 1 -
test/ut/spec/model/Global.test.ts | 239 +++++++------
test/ut/spec/model/timelineMediaOptions.test.ts | 59 ++--
test/ut/spec/scale/interval.test.ts | 94 ++---
test/ut/spec/util/graphic.test.ts | 97 +++---
test/ut/spec/util/layout.test.ts | 44 ++-
test/ut/spec/util/model.test.ts | 19 +-
test/ut/spec/util/number.test.ts | 434 +++++++++++++-----------
8 files changed, 523 insertions(+), 464 deletions(-)
diff --git a/test/ut/jest.config.js b/test/ut/jest.config.js
index a5fc425..8e61d79 100644
--- a/test/ut/jest.config.js
+++ b/test/ut/jest.config.js
@@ -39,7 +39,6 @@ module.exports = {
'**/spec/model/*.test.ts',
'**/spec/scale/*.test.ts',
'**/spec/util/*.test.ts',
- '!**/spec/api/containPixel.test.ts',
'!**/spec/component/graphic/setOption.test.ts'
]
};
diff --git a/test/ut/spec/model/Global.test.ts b/test/ut/spec/model/Global.test.ts
index 63ae4f9..399f653 100755
--- a/test/ut/spec/model/Global.test.ts
+++ b/test/ut/spec/model/Global.test.ts
@@ -18,45 +18,60 @@
* under the License.
*/
-const utHelper = require('../../core/utHelper');
+import { EChartsType } from '../../../../src/echarts';
+import { createChart } from '../../core/utHelper';
+import { ComponentMainType, ParsedValue } from '../../../../src/util/types';
+import SeriesModel from '../../../../src/model/Series';
+import ComponentModel from '../../../../src/model/Component';
+import ChartView from '../../../../src/view/Chart';
+import { EChartsFullOption } from '../../../../src/option';
+
+type OriginModelView = {
+ model: SeriesModel;
+ view: ChartView;
+};
+
describe('modelAndOptionMapping', function () {
- function getData0(chart, seriesIndex) {
+ function getData0(chart: EChartsType, seriesIndex: number): ParsedValue {
return getSeries(chart, seriesIndex).getData().get('y', 0);
}
- function getSeries(chart, seriesIndex) {
- return chart.getModel().getComponent('series', seriesIndex);
+ function getSeries(chart: EChartsType, seriesIndex: number): SeriesModel {
+ return chart.getModel().getComponent('series', seriesIndex) as SeriesModel;
}
- function getModel(chart, type, index) {
+ function getModel(chart: EChartsType, type: ComponentMainType, index: number): ComponentModel {
return chart.getModel().getComponent(type, index);
}
- function countSeries(chart) {
+ function countSeries(chart: EChartsType): number {
return countModel(chart, 'series');
}
- function countModel(chart, type) {
+ function countModel(chart: EChartsType, type: ComponentMainType): number {
// FIXME
// access private
+ // @ts-ignore
return chart.getModel()._componentsMap.get(type).length;
}
- function getChartView(chart, series) {
+ function getChartView(chart: EChartsType, series: SeriesModel): ChartView {
+ // @ts-ignore
return chart._chartsMap[series.__viewId];
}
- function countChartViews(chart) {
+ function countChartViews(chart: EChartsType): number {
+ // @ts-ignore
return chart._chartsViews.length;
}
- function saveOrigins(chart) {
- var count = countSeries(chart);
- var origins = [];
- for (var i = 0; i < count; i++) {
- var series = getSeries(chart, i);
+ function saveOrigins(chart: EChartsType): OriginModelView[] {
+ const count = countSeries(chart);
+ const origins = [];
+ for (let i = 0; i < count; i++) {
+ const series = getSeries(chart, i);
origins.push({
model: series,
view: getChartView(chart, series)
@@ -65,16 +80,26 @@ describe('modelAndOptionMapping', function () {
return origins;
}
- function modelEqualsToOrigin(chart, idxList, origins, boolResult) {
- for (var i = 0; i < idxList.length; i++) {
- var idx = idxList[i];
+ function modelEqualsToOrigin(
+ chart: EChartsType,
+ idxList: number[],
+ origins: OriginModelView[],
+ boolResult: boolean
+ ): void {
+ for (let i = 0; i < idxList.length; i++) {
+ const idx = idxList[i];
expect(origins[idx].model === getSeries(chart, idx)).toEqual(boolResult);
}
}
- function viewEqualsToOrigin(chart, idxList, origins, boolResult) {
- for (var i = 0; i < idxList.length; i++) {
- var idx = idxList[i];
+ function viewEqualsToOrigin(
+ chart: EChartsType,
+ idxList: number[],
+ origins: OriginModelView[],
+ boolResult: boolean
+ ): void {
+ for (let i = 0; i < idxList.length; i++) {
+ const idx = idxList[i];
expect(
origins[idx].view === getChartView(chart, getSeries(chart, idx))
).toEqual(boolResult);
@@ -82,9 +107,9 @@ describe('modelAndOptionMapping', function () {
}
- var chart;
+ let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart();
+ chart = createChart();
});
afterEach(function () {
@@ -94,7 +119,7 @@ describe('modelAndOptionMapping', function () {
describe('idNoNameNo', function () {
it('sameTypeNotMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -106,7 +131,7 @@ describe('modelAndOptionMapping', function () {
chart.setOption(option);
// Not merge
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(3);
expect(countSeries(chart)).toEqual(3);
@@ -115,7 +140,7 @@ describe('modelAndOptionMapping', function () {
});
it('sameTypeMergeFull', function () {
- var option = {
+ chart.setOption({
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -123,11 +148,10 @@ describe('modelAndOptionMapping', function () {
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
- };
- chart.setOption(option);
+ });
// Merge
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption({
series: [
{type: 'line', data: [111]},
@@ -146,7 +170,7 @@ describe('modelAndOptionMapping', function () {
});
it('sameTypeMergePartial', function () {
- var option = {
+ chart.setOption({
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -154,11 +178,10 @@ describe('modelAndOptionMapping', function () {
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
- };
- chart.setOption(option);
+ });
// Merge
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption({
series: [
{data: [22222]}
@@ -175,7 +198,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMerge', function () {
- var option = {
+ chart.setOption({
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -183,11 +206,10 @@ describe('modelAndOptionMapping', function () {
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
- };
- chart.setOption(option);
+ });
// Merge
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption({
series: [
{type: 'line', data: [111]},
@@ -217,7 +239,7 @@ describe('modelAndOptionMapping', function () {
describe('idSpecified', function () {
it('sameTypeNotMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -238,7 +260,7 @@ describe('modelAndOptionMapping', function () {
expect(getData0(chart, 3)).toEqual(44);
expect(getData0(chart, 4)).toEqual(55);
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
@@ -248,7 +270,7 @@ describe('modelAndOptionMapping', function () {
});
it('sameTypeMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -261,7 +283,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption(option);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
@@ -271,7 +293,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeNotMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -284,8 +306,8 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
- var option2 = {
+ const origins = saveOrigins(chart);
+ const option2: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -306,7 +328,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMergeFull', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -319,8 +341,8 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
- var option2 = {
+ const origins = saveOrigins(chart);
+ const option2: EChartsFullOption = {
series: [
{type: 'line', data: [11]},
{type: 'bar', data: [22], id: 20, name: 'a'},
@@ -340,7 +362,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMergePartial1', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -353,8 +375,8 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
- var option2 = {
+ const origins = saveOrigins(chart);
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
@@ -377,7 +399,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMergePartial2', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -387,7 +409,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var option2 = {
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
@@ -407,7 +429,7 @@ describe('modelAndOptionMapping', function () {
it('mergePartialDoNotMapToOtherId', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -417,7 +439,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var option2 = {
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], id: 40}
]
@@ -433,7 +455,7 @@ describe('modelAndOptionMapping', function () {
it('idDuplicate', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -451,7 +473,7 @@ describe('modelAndOptionMapping', function () {
it('nameTheSameButIdNotTheSame', function () {
- var option = {
+ const option = {
grid: {},
xAxis: [
{id: 'x1', name: 'a', xxxx: 'x1_a'},
@@ -462,13 +484,16 @@ describe('modelAndOptionMapping', function () {
chart.setOption(option);
- var xAxisModel0 = getModel(chart, 'xAxis', 0);
- var xAxisModel1 = getModel(chart, 'xAxis', 1);
- expect(xAxisModel0.option.xxxx).toEqual('x1_a');
- expect(xAxisModel1.option.xxxx).toEqual('x2_b');
+ let xAxisModel0;
+ let xAxisModel1;
+
+ xAxisModel0 = getModel(chart, 'xAxis', 0);
+ xAxisModel1 = getModel(chart, 'xAxis', 1);
+ expect((xAxisModel0.option as any).xxxx).toEqual('x1_a');
+ expect((xAxisModel1.option as any).xxxx).toEqual('x2_b');
expect(xAxisModel1.option.name).toEqual('b');
- var option2 = {
+ const option2 = {
xAxis: [
{id: 'k1', name: 'a', xxxx: 'k1_a'},
{id: 'x2', name: 'a', xxxx: 'x2_a'}
@@ -476,13 +501,13 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option2);
- var xAxisModel0 = getModel(chart, 'xAxis', 0);
- var xAxisModel1 = getModel(chart, 'xAxis', 1);
- var xAxisModel2 = getModel(chart, 'xAxis', 2);
- expect(xAxisModel0.option.xxxx).toEqual('x1_a');
- expect(xAxisModel1.option.xxxx).toEqual('x2_a');
+ xAxisModel0 = getModel(chart, 'xAxis', 0);
+ xAxisModel1 = getModel(chart, 'xAxis', 1);
+ const xAxisModel2 = getModel(chart, 'xAxis', 2);
+ expect((xAxisModel0.option as any).xxxx).toEqual('x1_a');
+ expect((xAxisModel1.option as any).xxxx).toEqual('x2_a');
expect(xAxisModel1.option.name).toEqual('a');
- expect(xAxisModel2.option.xxxx).toEqual('k1_a');
+ expect((xAxisModel2.option as any).xxxx).toEqual('k1_a');
});
});
@@ -499,7 +524,7 @@ describe('modelAndOptionMapping', function () {
describe('noIdButNameExists', function () {
it('sameTypeNotMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -523,7 +548,7 @@ describe('modelAndOptionMapping', function () {
expect(getData0(chart, 3)).toEqual(44);
expect(getData0(chart, 4)).toEqual(55);
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
@@ -533,7 +558,7 @@ describe('modelAndOptionMapping', function () {
});
it('sameTypeMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -546,7 +571,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
+ const origins = saveOrigins(chart);
chart.setOption(option);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
@@ -556,7 +581,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeNotMerge', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -569,8 +594,8 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
- var option2 = {
+ const origins = saveOrigins(chart);
+ const option2: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -591,7 +616,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMergePartialOneMapTwo', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -604,8 +629,8 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var origins = saveOrigins(chart);
- var option2 = {
+ const origins = saveOrigins(chart);
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
@@ -629,7 +654,7 @@ describe('modelAndOptionMapping', function () {
});
it('differentTypeMergePartialTwoMapOne', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -639,7 +664,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var option2 = {
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], name: 'a'},
{type: 'line', data: [333]},
@@ -659,7 +684,7 @@ describe('modelAndOptionMapping', function () {
it('mergePartialCanMapToOtherName', function () {
// Consider case: axis.name = 'some label', which can be overwritten.
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
series: [
@@ -669,7 +694,7 @@ describe('modelAndOptionMapping', function () {
};
chart.setOption(option);
- var option2 = {
+ const option2: EChartsFullOption = {
series: [
{type: 'bar', data: [444], name: 40},
{type: 'bar', data: [999], name: 40},
@@ -695,24 +720,22 @@ describe('modelAndOptionMapping', function () {
describe('ohters', function () {
it('aBugCase', function () {
- var option = {
+ const option: EChartsFullOption = {
series: [
{
type: 'pie',
radius: ['20%', '25%'],
center: ['20%', '20%'],
avoidLabelOverlap: true,
- hoverAnimation: false,
label: {
- normal: {
- show: true,
- position: 'center',
- textStyle: {
- fontSize: '30',
- fontWeight: 'bold'
- }
- },
- emphasis: {
+ show: true,
+ position: 'center',
+ fontSize: '30',
+ fontWeight: 'bold'
+ },
+ emphasis: {
+ scale: false,
+ label: {
show: true
}
},
@@ -732,16 +755,11 @@ describe('modelAndOptionMapping', function () {
radius: ['20%', '25%'],
center: ['20%', '20%'],
avoidLabelOverlap: true,
- hoverAnimation: false,
label: {
- normal: {
- show: true,
- position: 'center',
- textStyle: {
- fontSize: '30',
- fontWeight: 'bold'
- }
- }
+ show: true,
+ position: 'center',
+ fontSize: '30',
+ fontWeight: 'bold'
},
data: [
{value: 135, name: '视频广告'},
@@ -753,16 +771,11 @@ describe('modelAndOptionMapping', function () {
radius: ['20%', '25%'],
center: ['60%', '20%'],
avoidLabelOverlap: true,
- hoverAnimation: false,
label: {
- normal: {
- show: true,
- position: 'center',
- textStyle: {
- fontSize: '30',
- fontWeight: 'bold'
- }
- }
+ show: true,
+ position: 'center',
+ fontSize: '30',
+ fontWeight: 'bold'
},
data: [
{value: 135, name: '视频广告'},
@@ -777,7 +790,7 @@ describe('modelAndOptionMapping', function () {
});
it('color', function () {
- var option = {
+ const option: EChartsFullOption = {
backgroundColor: 'rgba(1,1,1,1)',
xAxis: {data: ['a']},
yAxis: {},
@@ -788,18 +801,18 @@ describe('modelAndOptionMapping', function () {
]
};
chart.setOption(option);
- expect(chart._model.option.backgroundColor).toEqual('rgba(1,1,1,1)');
+ expect(chart.getModel().option.backgroundColor).toEqual('rgba(1,1,1,1)');
// Not merge
chart.setOption({
backgroundColor: '#fff'
}, true);
- expect(chart._model.option.backgroundColor).toEqual('#fff');
+ expect(chart.getModel().option.backgroundColor).toEqual('#fff');
});
it('innerId', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: {data: ['a']},
yAxis: {},
toolbox: {
diff --git a/test/ut/spec/model/timelineMediaOptions.test.ts b/test/ut/spec/model/timelineMediaOptions.test.ts
index 07db6bf..2751a14 100755
--- a/test/ut/spec/model/timelineMediaOptions.test.ts
+++ b/test/ut/spec/model/timelineMediaOptions.test.ts
@@ -17,26 +17,37 @@
* specific language governing permissions and limitations
* under the License.
*/
-const utHelper = require('../../core/utHelper');
+
+import { EChartsType } from '../../../../src/echarts';
+import SeriesModel from '../../../../src/model/Series';
+import { ParsedValue } from '../../../../src/util/types';
+import { LegendOption } from '../../../../src/component/legend/LegendModel';
+import TimelineModel from '../../../../src/component/timeline/TimelineModel';
+import { createChart } from '../../core/utHelper';
+import { EChartsFullOption } from '../../../../src/option';
+
describe('timelineMediaOptions', function () {
- function getData0(chart, seriesIndex) {
+ function getData0(chart: EChartsType, seriesIndex: number): ParsedValue {
return getSeries(chart, seriesIndex).getData().get('y', 0);
}
- function getSeries(chart, seriesIndex) {
- return chart.getModel().getComponent('series', seriesIndex);
+ function getSeries(chart: EChartsType, seriesIndex: number): SeriesModel {
+ return chart.getModel().getComponent('series', seriesIndex) as SeriesModel;
}
- function getLegendOption(chart) {
+ function getLegendOption(chart: EChartsType): LegendOption {
return chart.getModel().getComponent('legend', 0).option;
}
- function getTimelineComponent(chart) {
- return chart.getModel().getComponent('timeline', 0);
+ function getTimelineComponent(chart: EChartsType): TimelineModel {
+ return chart.getModel().getComponent('timeline', 0) as TimelineModel;
}
- var chart;
+ let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart(10, 10);
+ chart = createChart({
+ width: 10,
+ height: 10
+ });
});
afterEach(function () {
@@ -49,7 +60,7 @@ describe('timelineMediaOptions', function () {
describe('parse_timeline_media_option', function () {
it('parse_media_has_baseOption_has_default', function () {
- var option = {
+ const option: EChartsFullOption = {
baseOption: {
xAxis: { data: ['a'] },
yAxis: {},
@@ -77,7 +88,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_media_no_baseOption_has_default', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: { data: ['a'] },
yAxis: {},
legend: { left: 10 },
@@ -101,7 +112,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_media_no_baseOption_no_default', function () {
- var option = {
+ const option: EChartsFullOption = {
xAxis: { data: ['a'] },
yAxis: {},
legend: { left: 10 },
@@ -121,7 +132,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_media_has_baseOption', function () {
- var option = {
+ const option: EChartsFullOption = {
baseOption: {
timeline: { axisType: 'category' },
xAxis: { data: ['a'] },
@@ -161,7 +172,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_media_no_baseOption', function () {
- var option = {
+ const option: EChartsFullOption = {
timeline: { axisType: 'category' },
xAxis: { data: ['a'] },
yAxis: {},
@@ -197,7 +208,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_has_baseOption', function () {
- var option = {
+ const option: EChartsFullOption = {
baseOption: {
timeline: { axisType: 'category' },
xAxis: { data: ['a'] },
@@ -221,7 +232,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_has_baseOption_compat', function () {
- var option = {
+ const option: EChartsFullOption = {
timeline: { axisType: 'category' },
baseOption: {
xAxis: { data: ['a'] },
@@ -245,7 +256,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_has_baseOption_compat', function () {
- var option = {
+ const option: EChartsFullOption = {
timeline: { axisType: 'category' },
baseOption: {
xAxis: { data: ['a'] },
@@ -269,7 +280,7 @@ describe('timelineMediaOptions', function () {
});
it('parse_timeline_no_baseOption', function () {
- var option = {
+ const option: EChartsFullOption = {
timeline: { axisType: 'category' },
xAxis: { data: ['a'] },
yAxis: {},
@@ -299,7 +310,7 @@ describe('timelineMediaOptions', function () {
describe('timeline_onceMore', function () {
it('timeline_setOptionOnceMore_baseOption', function () {
- var option = {
+ const option: EChartsFullOption = {
baseOption: {
timeline: {
axisType: 'category',
@@ -347,7 +358,7 @@ describe('timelineMediaOptions', function () {
it('timeline_setOptionOnceMore_substitudeTimelineOptions', function () {
- var option = {
+ const option: EChartsFullOption = {
baseOption: {
timeline: {
axisType: 'category',
@@ -377,7 +388,7 @@ describe('timelineMediaOptions', function () {
};
chart.setOption(option);
- var ecModel = chart.getModel();
+ let ecModel = chart.getModel();
expect(getData0(chart, 0)).toEqual(1111);
expect(getData0(chart, 1)).toEqual(2222);
@@ -399,9 +410,9 @@ describe('timelineMediaOptions', function () {
}]
});
- var ecModel = chart.getModel();
- var option = ecModel.getOption();
- expect(option.backgroundColor).toEqual('#987654');
+ ecModel = chart.getModel();
+ const optionGotten = ecModel.getOption();
+ expect(optionGotten.backgroundColor).toEqual('#987654');
expect(getData0(chart, 0)).toEqual(1111);
expect(getData0(chart, 1)).toEqual(2222);
diff --git a/test/ut/spec/scale/interval.test.ts b/test/ut/spec/scale/interval.test.ts
index e663306..c151ad0 100755
--- a/test/ut/spec/scale/interval.test.ts
+++ b/test/ut/spec/scale/interval.test.ts
@@ -18,15 +18,19 @@
* under the License.
*/
-const scaleHelper = require('../../../../lib/scale/helper');
-const numberUtil = require('../../../../lib/util/number');
-const IntervalScale = require('../../../../lib/scale/Interval');
-const utHelper = require('../../core/utHelper');
+import { createChart, isValueFinite } from '../../core/utHelper';
+import { EChartsType } from '../../../../src/echarts';
+import CartesianAxisModel from '../../../../src/coord/cartesian/AxisModel';
+import IntervalScale from '../../../../src/scale/Interval';
+import { intervalScaleNiceTicks } from '../../../../src/scale/helper';
+import { getPrecisionSafe } from '../../../../src/util/number';
+
describe('scale_interval', function () {
- var chart;
+
+ let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart();
+ chart = createChart();
});
afterEach(function () {
@@ -37,9 +41,9 @@ describe('scale_interval', function () {
describe('extreme', function () {
it('ticks_min_max', function () {
- var min = 0;
- var max = 54.090909;
- var splitNumber = 5;
+ const min = 0;
+ const max = 54.090909;
+ const splitNumber = 5;
chart.setOption({
xAxis: {},
@@ -53,12 +57,12 @@ describe('scale_interval', function () {
series: [{type: 'line', data: []}]
});
- var yAxis = chart.getModel().getComponent('yAxis', 0);
- var scale = yAxis.axis.scale;
- var ticks = scale.getTicks();
+ const yAxis = chart.getModel().getComponent('yAxis', 0) as CartesianAxisModel;
+ const scale = yAxis.axis.scale;
+ const ticks = scale.getTicks();
- expect(ticks[0]).toEqual(min);
- expect(ticks[ticks.length - 1]).toEqual(max);
+ expect(ticks[0].value).toEqual(min);
+ expect(ticks[ticks.length - 1].value).toEqual(max);
});
it('ticks_small_value', function () {
@@ -87,16 +91,16 @@ describe('scale_interval', function () {
]
});
- var yAxis = chart.getModel().getComponent('yAxis', 0);
- var scale = yAxis.axis.scale;
- var ticks = scale.getTicks();
- var labels = yAxis.axis.getViewLabels().map(function (item) {
+ const yAxis = chart.getModel().getComponent('yAxis', 0) as CartesianAxisModel;
+ const scale = yAxis.axis.scale as IntervalScale;
+ const ticks = scale.getTicks();
+ const labels = yAxis.axis.getViewLabels().map(function (item) {
return item.formattedLabel;
});
- var labelPrecisioned = scale.getLabel(0.0000005, {precision: 10});
+ const labelPrecisioned = scale.getLabel({ value: 0.0000005 }, { precision: 10 });
- expect(ticks).toEqual(
+ expect(ticks.map(tick => tick.value)).toEqual(
[0, 0.0000005, 0.000001, 0.0000015, 0.000002, 0.0000025, 0.000003, 0.0000035]
);
expect(labels).toEqual(
@@ -110,51 +114,51 @@ describe('scale_interval', function () {
describe('ticks', function () {
- function randomNumber(quantity) {
+ function randomNumber(quantity: number): number {
return (Math.random() - 0.5) * Math.pow(10, (Math.random() - 0.5) * quantity);
}
- function doSingleTest(extent, splitNumber) {
- var result = scaleHelper.intervalScaleNiceTicks(extent, splitNumber);
- var intervalPrecision = result.intervalPrecision;
- var interval = result.interval;
- var niceTickExtent = result.niceTickExtent;
+ function doSingleTest(extent: [number, number], splitNumber: number): void {
+ const result = intervalScaleNiceTicks(extent, splitNumber);
+ const intervalPrecision = result.intervalPrecision;
+ const resultInterval = result.interval;
+ const niceTickExtent = result.niceTickExtent;
- expect(interval).toBeFinite();
- expect(intervalPrecision).toBeFinite();
- expect(niceTickExtent[0]).toBeFinite();
- expect(niceTickExtent[1]).toBeFinite();
+ expect(isValueFinite(resultInterval)).toEqual(true);
+ expect(isValueFinite(intervalPrecision)).toEqual(true);
+ expect(isValueFinite(niceTickExtent[0])).toEqual(true);
+ expect(isValueFinite(niceTickExtent[1])).toEqual(true);
- expect(niceTickExtent[0]).toBeGeaterThanOrEqualTo(extent[0]);
+ expect(niceTickExtent[0]).toBeGreaterThanOrEqual(extent[0]);
expect(niceTickExtent[1]).not.toBeGreaterThan(extent[1]);
- expect(niceTickExtent[1]).toBeGeaterThanOrEqualTo(niceTickExtent[1]);
+ expect(niceTickExtent[1]).toBeGreaterThanOrEqual(niceTickExtent[1]);
- var interval = new IntervalScale();
+ const interval = new IntervalScale();
interval.setExtent(extent[0], extent[1]);
interval.niceExtent({
fixMin: true,
fixMax: true,
splitNumber
});
- var ticks = interval.getTicks();
+ const ticks = interval.getTicks();
- expect(ticks).not.toBeEmptyArray();
- expect(ticks[0]).toEqual(extent[0]);
- expect(ticks[ticks.length - 1]).toEqual(extent[1]);
+ expect(ticks.length > 0);
+ expect(ticks[0].value).toEqual(extent[0]);
+ expect(ticks[ticks.length - 1].value).toEqual(extent[1]);
- for (var i = 1; i < ticks.length; i++) {
- expect(ticks[i - 1]).not.toBeGeaterThanOrEqualTo(ticks[i]);
+ for (let i = 1; i < ticks.length; i++) {
+ expect(ticks[i - 1].value).not.toBeGreaterThanOrEqual(ticks[i].value);
- if (ticks[i] !== extent[0] && ticks[i] !== extent[1]) {
- var tickPrecision = numberUtil.getPrecisionSafe(ticks[i]);
+ if (ticks[i].value !== extent[0] && ticks[i].value !== extent[1]) {
+ const tickPrecision = getPrecisionSafe(ticks[i].value);
expect(tickPrecision).not.toBeGreaterThan(intervalPrecision);
}
}
}
- function doRandomTest(count, splitNumber, quantity) {
- for (var i = 0; i < count; i++) {
- var extent = [];
+ function doRandomTest(count: number, splitNumber: number, quantity: number): void {
+ for (let i = 0; i < count; i++) {
+ const extent: number[] = [];
extent[0] = randomNumber(quantity);
extent[1] = extent[0] + randomNumber(quantity);
if (extent[1] === extent[0]) {
@@ -163,7 +167,7 @@ describe('scale_interval', function () {
if (extent[0] > extent[1]) {
extent.reverse();
}
- doSingleTest(extent, splitNumber);
+ doSingleTest(extent as [number, number], splitNumber);
}
}
diff --git a/test/ut/spec/util/graphic.test.ts b/test/ut/spec/util/graphic.test.ts
index d68df34..5a3b196 100755
--- a/test/ut/spec/util/graphic.test.ts
+++ b/test/ut/spec/util/graphic.test.ts
@@ -18,67 +18,70 @@
* under the License.
*/
-const graphic = require('../../../../lib/util/graphic');
+import {
+ subPixelOptimize, subPixelOptimizeLine, subPixelOptimizeRect
+} from 'zrender/src/graphic/helper/subPixelOptimize';
+import { lineLineIntersect } from '../../../../src/util/graphic';
+
describe('util/graphic', function () {
describe('subPixelOptimize', function () {
- it('subPixelOptimize_base', function (done) {
- expect(graphic.subPixelOptimize(5, 1)).toEqual(4.5);
- expect(graphic.subPixelOptimize(5, 2)).toEqual(5);
- expect(graphic.subPixelOptimize(5, 43)).toEqual(4.5);
- expect(graphic.subPixelOptimize(7.5, 1)).toEqual(7.5);
- expect(graphic.subPixelOptimize(7.5, 2)).toEqual(7);
- expect(graphic.subPixelOptimize(14, 1, true)).toEqual(14.5);
- expect(graphic.subPixelOptimize(14, 2, true)).toEqual(14);
- expect(graphic.subPixelOptimize(-11, 1)).toEqual(-11.5);
- expect(graphic.subPixelOptimize(-11, 2)).toEqual(-11);
- expect(graphic.subPixelOptimize(0, 2)).toEqual(0);
- expect(graphic.subPixelOptimize(0, 1)).toEqual(-0.5);
- expect(graphic.subPixelOptimize(5, 0)).toEqual(5);
- done();
+ it('subPixelOptimize_base', function () {
+ expect(subPixelOptimize(5, 1)).toEqual(4.5);
+ expect(subPixelOptimize(5, 2)).toEqual(5);
+ expect(subPixelOptimize(5, 43)).toEqual(4.5);
+ expect(subPixelOptimize(7.5, 1)).toEqual(7.5);
+ expect(subPixelOptimize(7.5, 2)).toEqual(7);
+ expect(subPixelOptimize(14, 1, true)).toEqual(14.5);
+ expect(subPixelOptimize(14, 2, true)).toEqual(14);
+ expect(subPixelOptimize(-11, 1)).toEqual(-11.5);
+ expect(subPixelOptimize(-11, 2)).toEqual(-11);
+ expect(subPixelOptimize(0, 2)).toEqual(0);
+ expect(subPixelOptimize(0, 1)).toEqual(-0.5);
+ expect(subPixelOptimize(5, 0)).toEqual(5);
});
- it('subPixelOptimize_line', function (done) {
- function doSubPixelOptimizeLine(x, y, width, height, lineWidth) {
- return graphic.subPixelOptimizeLine(makeParam(x, y, width, height, lineWidth));
+ it('subPixelOptimize_line', function () {
+ function doSubPixelOptimizeLine(x: number, y: number, width: number, height: number, lineWidth: number) {
+ const params = makeParam(x, y, width, height, lineWidth);
+ return subPixelOptimizeLine(params.shape, params.shape, params.style);
}
- function makeParam(x1, y1, x2, y2, lineWidth) {
+ function makeParam(x1: number, y1: number, x2: number, y2: number, lineWidth: number) {
return {
shape: {x1: x1, y1: y1, x2: x2, y2: y2},
style: {lineWidth: lineWidth}
};
}
- expect(doSubPixelOptimizeLine(5, 11, 3, 7, 1)).toEqual(makeParam(5, 11, 3, 7, 1));
- expect(doSubPixelOptimizeLine(5, 11, 5, 7, 1)).toEqual(makeParam(5.5, 11, 5.5, 7, 1));
- expect(doSubPixelOptimizeLine(5, 11, 5, 7, 2)).toEqual(makeParam(5, 11, 5, 7, 2));
- expect(doSubPixelOptimizeLine(5, 11, 15, 11, 1)).toEqual(makeParam(5, 11.5, 15, 11.5, 1));
- expect(doSubPixelOptimizeLine(5, 11, 15, 11, 2)).toEqual(makeParam(5, 11, 15, 11, 2));
- expect(doSubPixelOptimizeLine(5, 11, 15, 11, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
- expect(doSubPixelOptimizeLine(5, 11, 15, 11.5, 3)).toEqual(makeParam(5, 11, 15, 11.5, 3));
- expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
- expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 4)).toEqual(makeParam(5, 12, 15, 12, 4));
- done();
+ expect(doSubPixelOptimizeLine(5, 11, 3, 7, 1)).toEqual(makeParam(5, 11, 3, 7, 1).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 5, 7, 1)).toEqual(makeParam(5.5, 11, 5.5, 7, 1).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 5, 7, 2)).toEqual(makeParam(5, 11, 5, 7, 2).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 15, 11, 1)).toEqual(makeParam(5, 11.5, 15, 11.5, 1).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 15, 11, 2)).toEqual(makeParam(5, 11, 15, 11, 2).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 15, 11, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3).shape);
+ expect(doSubPixelOptimizeLine(5, 11, 15, 11.5, 3)).toEqual(makeParam(5, 11, 15, 11.5, 3).shape);
+ expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3).shape);
+ expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 4)).toEqual(makeParam(5, 12, 15, 12, 4).shape);
});
- it('subPixelOptimize_rect', function (done) {
- function doSubPixelOptimizeRect(x, y, width, height, lineWidth) {
- return graphic.subPixelOptimizeRect(makeParam(x, y, width, height, lineWidth));
+ it('subPixelOptimize_rect', function () {
+ function doSubPixelOptimizeRect(x: number, y: number, width: number, height: number, lineWidth: number) {
+ const params = makeParam(x, y, width, height, lineWidth);
+ return subPixelOptimizeRect(params.shape, params.shape, params.style);
}
- function makeParam(x, y, width, height, lineWidth) {
+ function makeParam(x: number, y: number, width: number, height: number, lineWidth: number) {
return {
shape: {x: x, y: y, width: width, height: height},
style: {lineWidth: lineWidth}
};
}
- expect(doSubPixelOptimizeRect(5, 11, 3, 7, 1)).toEqual(makeParam(5.5, 11.5, 2, 6, 1));
- expect(doSubPixelOptimizeRect(5, 11, 3, 7, 2)).toEqual(makeParam(5, 11, 3, 7, 2));
- expect(doSubPixelOptimizeRect(5, 11, 3, 7, 3)).toEqual(makeParam(5.5, 11.5, 2, 6, 3));
+ expect(doSubPixelOptimizeRect(5, 11, 3, 7, 1)).toEqual(makeParam(5.5, 11.5, 2, 6, 1).shape);
+ expect(doSubPixelOptimizeRect(5, 11, 3, 7, 2)).toEqual(makeParam(5, 11, 3, 7, 2).shape);
+ expect(doSubPixelOptimizeRect(5, 11, 3, 7, 3)).toEqual(makeParam(5.5, 11.5, 2, 6, 3).shape);
// Boundary value tests
- expect(doSubPixelOptimizeRect(5, 11, 1, 7, 1)).toEqual(makeParam(5.5, 11.5, 1, 6, 1));
- expect(doSubPixelOptimizeRect(5, 11, 1, 0, 1)).toEqual(makeParam(5.5, 11.5, 1, 0, 1));
- done();
+ expect(doSubPixelOptimizeRect(5, 11, 1, 7, 1)).toEqual(makeParam(5.5, 11.5, 1, 6, 1).shape);
+ expect(doSubPixelOptimizeRect(5, 11, 1, 0, 1)).toEqual(makeParam(5.5, 11.5, 1, 0, 1).shape);
});
});
@@ -86,20 +89,20 @@ describe('util/graphic', function () {
describe('lineLineIntersect', function () {
it('extreme', function () {
- expect(graphic.lineLineIntersect(10, 10, 30, 30, 10, 10, 10, 10)).toEqual(false);
+ expect(lineLineIntersect(10, 10, 30, 30, 10, 10, 10, 10)).toEqual(false);
});
it('parallel and colinear', function () {
- expect(graphic.lineLineIntersect(10, 20, 30, 40, 100, 220, 120, 240)).toEqual(false);
- expect(graphic.lineLineIntersect(10, 10, 30, 30, 40, 40, 50, 50)).toEqual(false);
- expect(graphic.lineLineIntersect(10, 10, 30, 30, 10, 10, 30, 30)).toEqual(false);
- expect(graphic.lineLineIntersect(10, 10, 30, 30, 20, 20, 30, 30)).toEqual(false);
- expect(graphic.lineLineIntersect(10, 10, 30, 30, 20, 20, 22, 22)).toEqual(false);
+ expect(lineLineIntersect(10, 20, 30, 40, 100, 220, 120, 240)).toEqual(false);
+ expect(lineLineIntersect(10, 10, 30, 30, 40, 40, 50, 50)).toEqual(false);
+ expect(lineLineIntersect(10, 10, 30, 30, 10, 10, 30, 30)).toEqual(false);
+ expect(lineLineIntersect(10, 10, 30, 30, 20, 20, 30, 30)).toEqual(false);
+ expect(lineLineIntersect(10, 10, 30, 30, 20, 20, 22, 22)).toEqual(false);
});
it('intersect', function () {
- expect(graphic.lineLineIntersect(10, 20, 30, 40, 12, 20, 30, 40)).toEqual(true);
- expect(graphic.lineLineIntersect(10, 20, 30, 40, 12, 20, 20, 42)).toEqual(true);
+ expect(lineLineIntersect(10, 20, 30, 40, 12, 20, 30, 40)).toEqual(true);
+ expect(lineLineIntersect(10, 20, 30, 40, 12, 20, 20, 42)).toEqual(true);
});
});
diff --git a/test/ut/spec/util/layout.test.ts b/test/ut/spec/util/layout.test.ts
index 46ab3d2..4c43ceb 100644
--- a/test/ut/spec/util/layout.test.ts
+++ b/test/ut/spec/util/layout.test.ts
@@ -17,22 +17,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-const layoutUtil = require('../../../../lib/util/layout');
+
+// import { Dictionary } from 'zrender/src/core/types';
+import { mergeLayoutParam } from '../../../../src/util/layout';
+import { BoxLayoutOptionMixin } from '../../../../src/util/types';
describe('util/number', function () {
describe('mergeLayoutParam', function () {
// The given obj has exactly the given props, has no other props.
- function expectPropsEqual(obj, props) {
+ function expectPropsEqual(obj: object, props: object): void {
expect(propContain(obj, props) && propContain(props, obj)).toEqual(true);
}
- function propContain(more, less) {
- for (var key in more) {
+ function propContain(more: object, less: object): boolean {
+ for (const key in more) {
if (more.hasOwnProperty(key)) {
- if (more[key] !== less[key]
- && !(more[key] == null && less[key] == null)
+ if ((more as any)[key] !== (less as any)[key]
+ && !((more as any)[key] == null && (less as any)[key] == null)
) {
return false;
}
@@ -41,9 +44,9 @@ describe('util/number', function () {
return true;
}
- function shadowClone(obj) {
- var newObj = {};
- for (var key in obj) {
+ function shadowClone<T extends object>(obj: T): T {
+ const newObj = {} as T;
+ for (const key in obj) {
if (obj.hasOwnProperty(key)) {
newObj[key] = obj[key];
}
@@ -53,18 +56,23 @@ describe('util/number', function () {
it('all', function () {
- function testMerge(targetOption, newOption, result, resultIgnoreSize) {
- var t1 = shadowClone(targetOption);
- var t2 = shadowClone(targetOption);
- var n1 = shadowClone(newOption);
- var n2 = shadowClone(newOption);
- layoutUtil.mergeLayoutParam(t1, n1);
- layoutUtil.mergeLayoutParam(t2, n2, {ignoreSize: true});
+ function testMerge(
+ targetOption: BoxLayoutOptionMixin,
+ newOption: BoxLayoutOptionMixin,
+ result: BoxLayoutOptionMixin,
+ resultIgnoreSize?: BoxLayoutOptionMixin
+ ) {
+ const t1 = shadowClone(targetOption);
+ const t2 = shadowClone(targetOption);
+ const n1 = shadowClone(newOption);
+ const n2 = shadowClone(newOption);
+ mergeLayoutParam(t1, n1);
+ mergeLayoutParam(t2, n2, {ignoreSize: true});
expectPropsEqual(t1, result);
expectPropsEqual(t2, resultIgnoreSize || result);
}
- function singleValueAdd(val) {
+ function singleValueAdd(val: number | string): void {
testMerge({}, {width: val}, {width: val});
testMerge({}, {left: val}, {left: val});
testMerge({}, {right: val}, {right: val});
@@ -79,7 +87,7 @@ describe('util/number', function () {
singleValueAdd('right');
singleValueAdd('center');
- function singleValueReplace(val) {
+ function singleValueReplace(val: number | string): void {
testMerge({width: -999}, {width: val}, {width: val});
testMerge({left: -999}, {left: val}, {left: val});
testMerge({right: -999}, {right: val}, {right: val});
diff --git a/test/ut/spec/util/model.test.ts b/test/ut/spec/util/model.test.ts
index 8decb98..bde8882 100755
--- a/test/ut/spec/util/model.test.ts
+++ b/test/ut/spec/util/model.test.ts
@@ -18,20 +18,21 @@
* under the License.
*/
-const modelUtil = require('../../../../lib/util/model');
+import { compressBatches } from '../../../../src/util/model';
+
describe('util/model', function () {
describe('compressBatches', function () {
- function item(seriesId, dataIndex) {
+ function item(seriesId: number | string, dataIndex: number | number[]) {
return {seriesId, dataIndex};
}
it('base', function () {
// Remove dupliate between A and B
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, 4), item(3, 5), item(4, 5)],
[item(4, 6), item(4, 5), item(3, 3), item(3, 4)]
)).toEqual([
@@ -40,7 +41,7 @@ describe('util/model', function () {
]);
// Compress
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, 4), item(3, 6), item(3, 5), item(4, 5)],
[item(4, 6), item(4, 5), item(3, 3), item(3, 4), item(4, 7)]
)).toEqual([
@@ -49,7 +50,7 @@ describe('util/model', function () {
]);
// Remove duplicate in themselves
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, 4), item(3, 6), item(3, 5), item(4, 5)],
[item(4, 6), item(4, 5), item(3, 3), item(3, 4), item(4, 7), item(4, 6)]
)).toEqual([
@@ -58,7 +59,7 @@ describe('util/model', function () {
]);
// dataIndex is array
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])],
[item(3, [8, 9])]
)).toEqual([
@@ -67,14 +68,14 @@ describe('util/model', function () {
]);
// empty
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])],
[]
)).toEqual([
[item('3', [4, 5, 7, 8]), item('4', [4])],
[]
]);
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[],
[item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])]
)).toEqual([
@@ -83,7 +84,7 @@ describe('util/model', function () {
]);
// should not has empty array
- expect(modelUtil.compressBatches(
+ expect(compressBatches(
[item(3, [4, 5, 8])],
[item(3, [4, 5, 8])]
)).toEqual([
diff --git a/test/ut/spec/util/number.test.ts b/test/ut/spec/util/number.test.ts
index 205b59a..1e5d2d2 100755
--- a/test/ut/spec/util/number.test.ts
+++ b/test/ut/spec/util/number.test.ts
@@ -18,147 +18,161 @@
* under the License.
*/
-const numberUtil = require('../../../../lib/util/number');
+import {
+ linearMap, parseDate, reformIntervals, getPrecisionSafe,
+ getPercentWithPrecision, quantityExponent, quantity, nice,
+ isNumeric, numericToNumber
+} from '../../../../src/util/number';
+
describe('util/number', function () {
describe('linearMap', function () {
it('accuracyError', function () {
- var range = [-15918.3, 17724.9];
- var result = numberUtil.linearMap(100, [0, 100], range, true);
+ let range;
+ let result;
+
+ range = [-15918.3, 17724.9];
+ result = linearMap(100, [0, 100], range, true);
// Should not be 17724.899999999998.
expect(result).toEqual(range[1]);
- var range = [-62.83, 83.56];
- var result = numberUtil.linearMap(100, [0, 100], range, true);
+ range = [-62.83, 83.56];
+ result = linearMap(100, [0, 100], range, true);
// Should not be 83.55999999999999.
expect(result).toEqual(range[1]);
});
it('clamp', function () {
+ let range;
+ let result;
+
// (1) normal order.
- var range = [-15918.3, 17724.9];
+ range = [-15918.3, 17724.9];
// bigger than max
- var result = numberUtil.linearMap(100.1, [0, 100], range, true);
+ result = linearMap(100.1, [0, 100], range, true);
expect(result).toEqual(range[1]);
// smaller than min
- var result = numberUtil.linearMap(-2, [0, 100], range, true);
+ result = linearMap(-2, [0, 100], range, true);
expect(result).toEqual(range[0]);
// equals to max
- var result = numberUtil.linearMap(100, [0, 100], range, true);
+ result = linearMap(100, [0, 100], range, true);
expect(result).toEqual(range[1]);
// equals to min
- var result = numberUtil.linearMap(0, [0, 100], range, true);
+ result = linearMap(0, [0, 100], range, true);
expect(result).toEqual(range[0]);
// (2) inverse range
- var range = [17724.9, -15918.3];
+ range = [17724.9, -15918.3];
// bigger than max
- var result = numberUtil.linearMap(102, [0, 100], range, true);
+ result = linearMap(102, [0, 100], range, true);
expect(result).toEqual(range[1]);
// smaller than min
- var result = numberUtil.linearMap(-0.001, [0, 100], range, true);
+ result = linearMap(-0.001, [0, 100], range, true);
expect(result).toEqual(range[0]);
// equals to max
- var result = numberUtil.linearMap(100, [0, 100], range, true);
+ result = linearMap(100, [0, 100], range, true);
expect(result).toEqual(range[1]);
// equals to min
- var result = numberUtil.linearMap(0, [0, 100], range, true);
+ result = linearMap(0, [0, 100], range, true);
expect(result).toEqual(range[0]);
// (2) inverse domain
// bigger than max, inverse domain
- var range = [-15918.3, 17724.9];
+ range = [-15918.3, 17724.9];
// bigger than max
- var result = numberUtil.linearMap(102, [100, 0], range, true);
+ result = linearMap(102, [100, 0], range, true);
expect(result).toEqual(range[0]);
// smaller than min
- var result = numberUtil.linearMap(-0.001, [100, 0], range, true);
+ result = linearMap(-0.001, [100, 0], range, true);
expect(result).toEqual(range[1]);
// equals to max
- var result = numberUtil.linearMap(100, [100, 0], range, true);
+ result = linearMap(100, [100, 0], range, true);
expect(result).toEqual(range[0]);
// equals to min
- var result = numberUtil.linearMap(0, [100, 0], range, true);
+ result = linearMap(0, [100, 0], range, true);
expect(result).toEqual(range[1]);
// (3) inverse domain, inverse range
- var range = [17724.9, -15918.3];
+ range = [17724.9, -15918.3];
// bigger than max
- var result = numberUtil.linearMap(100.1, [100, 0], range, true);
+ result = linearMap(100.1, [100, 0], range, true);
expect(result).toEqual(range[0]);
// smaller than min
- var result = numberUtil.linearMap(-2, [100, 0], range, true);
+ result = linearMap(-2, [100, 0], range, true);
expect(result).toEqual(range[1]);
// equals to max
- var result = numberUtil.linearMap(100, [100, 0], range, true);
+ result = linearMap(100, [100, 0], range, true);
expect(result).toEqual(range[0]);
// equals to min
- var result = numberUtil.linearMap(0, [100, 0], range, true);
+ result = linearMap(0, [100, 0], range, true);
expect(result).toEqual(range[1]);
});
it('noClamp', function () {
+ let range;
+ let result;
+
// (1) normal order.
- var range = [-15918.3, 17724.9];
+ range = [-15918.3, 17724.9];
// bigger than max
- var result = numberUtil.linearMap(100.1, [0, 100], range, false);
+ result = linearMap(100.1, [0, 100], range, false);
expect(result).toEqual(17758.543199999996);
// smaller than min
- var result = numberUtil.linearMap(-2, [0, 100], range, false);
+ result = linearMap(-2, [0, 100], range, false);
expect(result).toEqual(-16591.164);
// equals to max
- var result = numberUtil.linearMap(100, [0, 100], range, false);
+ result = linearMap(100, [0, 100], range, false);
expect(result).toEqual(17724.9);
// equals to min
- var result = numberUtil.linearMap(0, [0, 100], range, false);
+ result = linearMap(0, [0, 100], range, false);
expect(result).toEqual(-15918.3);
// (2) inverse range
- var range = [17724.9, -15918.3];
+ range = [17724.9, -15918.3];
// bigger than max
- var result = numberUtil.linearMap(102, [0, 100], range, false);
+ result = linearMap(102, [0, 100], range, false);
expect(result).toEqual(-16591.163999999997);
// smaller than min
- var result = numberUtil.linearMap(-0.001, [0, 100], range, false);
+ result = linearMap(-0.001, [0, 100], range, false);
expect(result).toEqual(17725.236432);
// equals to max
- var result = numberUtil.linearMap(100, [0, 100], range, false);
+ result = linearMap(100, [0, 100], range, false);
expect(result).toEqual(-15918.3);
// equals to min
- var result = numberUtil.linearMap(0, [0, 100], range, false);
+ result = linearMap(0, [0, 100], range, false);
expect(result).toEqual(17724.9);
// (2) inverse domain
// bigger than max, inverse domain
- var range = [-15918.3, 17724.9];
+ range = [-15918.3, 17724.9];
// bigger than max
- var result = numberUtil.linearMap(102, [100, 0], range, false);
+ result = linearMap(102, [100, 0], range, false);
expect(result).toEqual(-16591.164);
// smaller than min
- var result = numberUtil.linearMap(-0.001, [100, 0], range, false);
+ result = linearMap(-0.001, [100, 0], range, false);
expect(result).toEqual(17725.236432);
// equals to max
- var result = numberUtil.linearMap(100, [100, 0], range, false);
+ result = linearMap(100, [100, 0], range, false);
expect(result).toEqual(-15918.3);
// equals to min
- var result = numberUtil.linearMap(0, [100, 0], range, false);
+ result = linearMap(0, [100, 0], range, false);
expect(result).toEqual(17724.9);
// (3) inverse domain, inverse range
- var range = [17724.9, -15918.3];
+ range = [17724.9, -15918.3];
// bigger than max
- var result = numberUtil.linearMap(100.1, [100, 0], range, false);
+ result = linearMap(100.1, [100, 0], range, false);
expect(result).toEqual(17758.5432);
// smaller than min
- var result = numberUtil.linearMap(-2, [100, 0], range, false);
+ result = linearMap(-2, [100, 0], range, false);
expect(result).toEqual(-16591.163999999997);
// equals to max
- var result = numberUtil.linearMap(100, [100, 0], range, false);
+ result = linearMap(100, [100, 0], range, false);
expect(result).toEqual(17724.9);
// equals to min
- var result = numberUtil.linearMap(0, [100, 0], range, false);
+ result = linearMap(0, [100, 0], range, false);
expect(result).toEqual(-15918.3);
});
@@ -167,25 +181,28 @@ describe('util/number', function () {
doTest(true);
doTest(false);
- function doTest(clamp) {
+ function doTest(clamp: boolean) {
+ let range;
+ let result;
+
// normal
- var range = [444, 555];
- var result = numberUtil.linearMap(40, [0, 100], range, clamp);
+ range = [444, 555];
+ result = linearMap(40, [0, 100], range, clamp);
expect(result).toEqual(488.4);
// inverse range
- var range = [555, 444];
- var result = numberUtil.linearMap(40, [0, 100], range, clamp);
+ range = [555, 444];
+ result = linearMap(40, [0, 100], range, clamp);
expect(result).toEqual(510.6);
// inverse domain and range
- var range = [555, 444];
- var result = numberUtil.linearMap(40, [100, 0], range, clamp);
+ range = [555, 444];
+ result = linearMap(40, [100, 0], range, clamp);
expect(result).toEqual(488.4);
// inverse domain
- var range = [444, 555];
- var result = numberUtil.linearMap(40, [100, 0], range, clamp);
+ range = [444, 555];
+ result = linearMap(40, [100, 0], range, clamp);
expect(result).toEqual(510.6);
}
});
@@ -195,20 +212,23 @@ describe('util/number', function () {
doTest(true);
doTest(false);
- function doTest(clamp) {
+ function doTest(clamp: boolean) {
+ let range;
+ let result;
+
// zero domain interval
- var range = [444, 555];
- var result = numberUtil.linearMap(40, [1212222223.2323232, 1212222223.2323232], range, clamp);
+ range = [444, 555];
+ result = linearMap(40, [1212222223.2323232, 1212222223.2323232], range, clamp);
expect(result).toEqual(499.5); // half of range.
// zero range interval
- var range = [1221212.1221372238, 1221212.1221372238];
- var result = numberUtil.linearMap(40, [0, 100], range, clamp);
+ range = [1221212.1221372238, 1221212.1221372238];
+ result = linearMap(40, [0, 100], range, clamp);
expect(result).toEqual(1221212.1221372238);
// zero domain interval and range interval
- var range = [1221212.1221372238, 1221212.1221372238];
- var result = numberUtil.linearMap(40, [43.55454545, 43.55454545], range, clamp);
+ range = [1221212.1221372238, 1221212.1221372238];
+ result = linearMap(40, [43.55454545, 43.55454545], range, clamp);
expect(result).toEqual(1221212.1221372238);
}
});
@@ -218,53 +238,53 @@ describe('util/number', function () {
it('parseDate', function () {
// Invalid Date
- expect('' + numberUtil.parseDate(null)).toEqual('Invalid Date');
- expect('' + numberUtil.parseDate(void 0)).toEqual('Invalid Date');
- expect('' + numberUtil.parseDate('asdf')).toEqual('Invalid Date');
- expect('' + numberUtil.parseDate(NaN)).toEqual('Invalid Date');
- expect('' + numberUtil.parseDate('-')).toEqual('Invalid Date');
- expect('' + numberUtil.parseDate('20120304')).toEqual('Invalid Date');
+ expect('' + parseDate(null)).toEqual('Invalid Date');
+ expect('' + parseDate(void 0)).toEqual('Invalid Date');
+ expect('' + parseDate('asdf')).toEqual('Invalid Date');
+ expect('' + parseDate(NaN)).toEqual('Invalid Date');
+ expect('' + parseDate('-')).toEqual('Invalid Date');
+ expect('' + parseDate('20120304')).toEqual('Invalid Date');
// Input instance of Date or timestamp
- expect(+numberUtil.parseDate(new Date('2012-03-04'))).toEqual(1330819200000);
- expect(+numberUtil.parseDate(1330819200000)).toEqual(1330819200000);
- expect(+numberUtil.parseDate(1330819199999.99)).toEqual(1330819200000);
- expect(+numberUtil.parseDate(1330819200000.01)).toEqual(1330819200000);
+ expect(+parseDate(new Date('2012-03-04'))).toEqual(1330819200000);
+ expect(+parseDate(1330819200000)).toEqual(1330819200000);
+ expect(+parseDate(1330819199999.99)).toEqual(1330819200000);
+ expect(+parseDate(1330819200000.01)).toEqual(1330819200000);
// ISO string
- expect(+numberUtil.parseDate('2012-03')).toEqual(+new Date('2012-03-01T00:00:00'));
- expect(+numberUtil.parseDate('2012-03-04')).toEqual(+new Date('2012-03-04T00:00:00'));
- expect(+numberUtil.parseDate('2012-03-04 05')).toEqual(+new Date('2012-03-04T05:00:00'));
- expect(+numberUtil.parseDate('2012-03-04T05')).toEqual(+new Date('2012-03-04T05:00:00'));
- expect(+numberUtil.parseDate('2012-03-04 05:06')).toEqual(+new Date('2012-03-04T05:06:00'));
- expect(+numberUtil.parseDate('2012-03-04T05:06')).toEqual(+new Date('2012-03-04T05:06:00'));
- expect(+numberUtil.parseDate('2012-03-04 05:06:07')).toEqual(+new Date('2012-03-04T05:06:07'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07')).toEqual(+new Date('2012-03-04T05:06:07'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.123')).toEqual(+new Date('2012-03-04T05:06:07.123'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07,123')).toEqual(+new Date('2012-03-04T05:06:07.123'));
+ expect(+parseDate('2012-03')).toEqual(+new Date('2012-03-01T00:00:00'));
+ expect(+parseDate('2012-03-04')).toEqual(+new Date('2012-03-04T00:00:00'));
+ expect(+parseDate('2012-03-04 05')).toEqual(+new Date('2012-03-04T05:00:00'));
+ expect(+parseDate('2012-03-04T05')).toEqual(+new Date('2012-03-04T05:00:00'));
+ expect(+parseDate('2012-03-04 05:06')).toEqual(+new Date('2012-03-04T05:06:00'));
+ expect(+parseDate('2012-03-04T05:06')).toEqual(+new Date('2012-03-04T05:06:00'));
+ expect(+parseDate('2012-03-04 05:06:07')).toEqual(+new Date('2012-03-04T05:06:07'));
+ expect(+parseDate('2012-03-04T05:06:07')).toEqual(+new Date('2012-03-04T05:06:07'));
+ expect(+parseDate('2012-03-04T05:06:07.123')).toEqual(+new Date('2012-03-04T05:06:07.123'));
+ expect(+parseDate('2012-03-04T05:06:07,123')).toEqual(+new Date('2012-03-04T05:06:07.123'));
// TODO new Date('2012-03-04T05:06:07.12') is same to '2012-03-04T05:06:07.120', not '2012-03-04T05:06:07.012'
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.12')).toEqual(+new Date('2012-03-04T05:06:07.012'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.1')).toEqual(+new Date('2012-03-04T05:06:07.001'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07,123Z')).toEqual(+new Date('2012-03-04T05:06:07.123Z'));
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.123+0800')).toEqual(1330808767123);
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.123+08:00')).toEqual(1330808767123);
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.123-0700')).toEqual(1330862767123);
- expect(+numberUtil.parseDate('2012-03-04T05:06:07.123-07:00')).toEqual(1330862767123);
- expect(+numberUtil.parseDate('2012-03-04T5:6:7.123-07:00')).toEqual(1330862767123);
+ expect(+parseDate('2012-03-04T05:06:07.12')).toEqual(+new Date('2012-03-04T05:06:07.012'));
+ expect(+parseDate('2012-03-04T05:06:07.1')).toEqual(+new Date('2012-03-04T05:06:07.001'));
+ expect(+parseDate('2012-03-04T05:06:07,123Z')).toEqual(+new Date('2012-03-04T05:06:07.123Z'));
+ expect(+parseDate('2012-03-04T05:06:07.123+0800')).toEqual(1330808767123);
+ expect(+parseDate('2012-03-04T05:06:07.123+08:00')).toEqual(1330808767123);
+ expect(+parseDate('2012-03-04T05:06:07.123-0700')).toEqual(1330862767123);
+ expect(+parseDate('2012-03-04T05:06:07.123-07:00')).toEqual(1330862767123);
+ expect(+parseDate('2012-03-04T5:6:7.123-07:00')).toEqual(1330862767123);
// Other string
- expect(+numberUtil.parseDate('2012')).toEqual(+new Date('2012-01-01T00:00:00'));
- expect(+numberUtil.parseDate('2012/03')).toEqual(+new Date('2012-03-01T00:00:00'));
- expect(+numberUtil.parseDate('2012/03/04')).toEqual(+new Date('2012-03-04T00:00:00'));
- expect(+numberUtil.parseDate('2012-3-4')).toEqual(+new Date('2012-03-04T00:00:00'));
- expect(+numberUtil.parseDate('2012/3')).toEqual(+new Date('2012-03-01T00:00:00'));
- expect(+numberUtil.parseDate('2012/3/4')).toEqual(+new Date('2012-03-04T00:00:00'));
- expect(+numberUtil.parseDate('2012/3/4 2:05')).toEqual(+new Date('2012-03-04T02:05:00'));
- expect(+numberUtil.parseDate('2012/03/04 2:05')).toEqual(+new Date('2012-03-04T02:05:00'));
- expect(+numberUtil.parseDate('2012/3/4 2:05:08')).toEqual(+new Date('2012-03-04T02:05:08'));
- expect(+numberUtil.parseDate('2012/03/04 2:05:08')).toEqual(+new Date('2012-03-04T02:05:08'));
- expect(+numberUtil.parseDate('2012/3/4 2:05:08.123')).toEqual(+new Date('2012-03-04T02:05:08.123'));
- expect(+numberUtil.parseDate('2012/03/04 2:05:08.123')).toEqual(+new Date('2012-03-04T02:05:08.123'));
+ expect(+parseDate('2012')).toEqual(+new Date('2012-01-01T00:00:00'));
+ expect(+parseDate('2012/03')).toEqual(+new Date('2012-03-01T00:00:00'));
+ expect(+parseDate('2012/03/04')).toEqual(+new Date('2012-03-04T00:00:00'));
+ expect(+parseDate('2012-3-4')).toEqual(+new Date('2012-03-04T00:00:00'));
+ expect(+parseDate('2012/3')).toEqual(+new Date('2012-03-01T00:00:00'));
+ expect(+parseDate('2012/3/4')).toEqual(+new Date('2012-03-04T00:00:00'));
+ expect(+parseDate('2012/3/4 2:05')).toEqual(+new Date('2012-03-04T02:05:00'));
+ expect(+parseDate('2012/03/04 2:05')).toEqual(+new Date('2012-03-04T02:05:00'));
+ expect(+parseDate('2012/3/4 2:05:08')).toEqual(+new Date('2012-03-04T02:05:08'));
+ expect(+parseDate('2012/03/04 2:05:08')).toEqual(+new Date('2012-03-04T02:05:08'));
+ expect(+parseDate('2012/3/4 2:05:08.123')).toEqual(+new Date('2012-03-04T02:05:08.123'));
+ expect(+parseDate('2012/03/04 2:05:08.123')).toEqual(+new Date('2012-03-04T02:05:08.123'));
});
});
@@ -273,7 +293,7 @@ describe('util/number', function () {
it('basic', function () {
// all
- expect(numberUtil.reformIntervals([
+ expect(reformIntervals([
{interval: [18, 62], close: [1, 1]},
{interval: [-Infinity, -70], close: [0, 0]},
{interval: [-70, -26], close: [1, 1]},
@@ -291,7 +311,7 @@ describe('util/number', function () {
]);
// remove overlap
- expect(numberUtil.reformIntervals([
+ expect(reformIntervals([
{interval: [18, 62], close: [1, 1]},
{interval: [50, 150], close: [1, 1]}
])).toEqual([
@@ -300,7 +320,7 @@ describe('util/number', function () {
]);
// remove overlap on edge
- expect(numberUtil.reformIntervals([
+ expect(reformIntervals([
{interval: [18, 62], close: [1, 1]},
{interval: [62, 150], close: [1, 1]}
])).toEqual([
@@ -309,7 +329,7 @@ describe('util/number', function () {
]);
// remove included interval
- expect(numberUtil.reformIntervals([
+ expect(reformIntervals([
{interval: [30, 40], close: [1, 1]},
{interval: [42, 54], close: [1, 1]},
{interval: [45, 60], close: [1, 1]},
@@ -319,7 +339,7 @@ describe('util/number', function () {
]);
// remove edge
- expect(numberUtil.reformIntervals([
+ expect(reformIntervals([
{interval: [18, 62], close: [1, 1]},
{interval: [30, 62], close: [1, 1]}
])).toEqual([
@@ -331,16 +351,16 @@ describe('util/number', function () {
describe('getPrecisionSafe', function () {
it('basic', function () {
- expect(numberUtil.getPrecisionSafe(10)).toEqual(0);
- expect(numberUtil.getPrecisionSafe(1)).toEqual(0);
- expect(numberUtil.getPrecisionSafe(0)).toEqual(0);
- expect(numberUtil.getPrecisionSafe(100000000000000000000000000000)).toEqual(0);
- expect(numberUtil.getPrecisionSafe(1e+100)).toEqual(0);
- expect(numberUtil.getPrecisionSafe(0.1)).toEqual(1);
- expect(numberUtil.getPrecisionSafe(0.100)).toEqual(1);
- expect(numberUtil.getPrecisionSafe(0.0032)).toEqual(4);
- expect(numberUtil.getPrecisionSafe(0.0000000000034)).toEqual(12);
- expect(numberUtil.getPrecisionSafe(3.4e-10)).toEqual(10);
+ expect(getPrecisionSafe(10)).toEqual(0);
+ expect(getPrecisionSafe(1)).toEqual(0);
+ expect(getPrecisionSafe(0)).toEqual(0);
+ expect(getPrecisionSafe(100000000000000000000000000000)).toEqual(0);
+ expect(getPrecisionSafe(1e+100)).toEqual(0);
+ expect(getPrecisionSafe(0.1)).toEqual(1);
+ expect(getPrecisionSafe(0.100)).toEqual(1);
+ expect(getPrecisionSafe(0.0032)).toEqual(4);
+ expect(getPrecisionSafe(0.0000000000034)).toEqual(12);
+ expect(getPrecisionSafe(3.4e-10)).toEqual(10);
});
});
@@ -349,102 +369,102 @@ describe('util/number', function () {
// console.log(numberUtil.getPercentWithPrecision([-1.678, -4.783, -2.664, -0.875], 0, 2));
- // var arr = [49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5];
- var arr = [49.5, NaN];
- var result = [];
- for (var i = 0; i < arr.length; i++) {
+ // const arr = [49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5];
+ const arr = [49.5, NaN];
+ const result = [];
+ for (let i = 0; i < arr.length; i++) {
result.push(
- numberUtil.getPercentWithPrecision(arr, i, 0)
+ getPercentWithPrecision(arr, i, 0)
);
}
- var sum = 0;
- for (var i = 0; i < result.length; i++) {
- sum += result[i];
- }
-
- expect(numberUtil.getPercentWithPrecision([50.5, 49.5], 0, 0)).toEqual(51);
- expect(numberUtil.getPercentWithPrecision([50.5, 49.5], 1, 0)).toEqual(49);
-
- expect(numberUtil.getPercentWithPrecision([12.34, 34.56, 53.1], 0, 1)).toEqual(12.3);
- expect(numberUtil.getPercentWithPrecision([12.34, 34.56, 53.1], 1, 1)).toEqual(34.6);
- expect(numberUtil.getPercentWithPrecision([12.34, 34.56, 53.1], 2, 1)).toEqual(53.1);
-
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 0, 0)).toEqual(17);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 1, 0)).toEqual(48);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 2, 0)).toEqual(26);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 3, 0)).toEqual(9);
+ // let sum = 0;
+ // for (let i = 0; i < result.length; i++) {
+ // sum += result[i];
+ // }
+
+ expect(getPercentWithPrecision([50.5, 49.5], 0, 0)).toEqual(51);
+ expect(getPercentWithPrecision([50.5, 49.5], 1, 0)).toEqual(49);
+
+ expect(getPercentWithPrecision([12.34, 34.56, 53.1], 0, 1)).toEqual(12.3);
+ expect(getPercentWithPrecision([12.34, 34.56, 53.1], 1, 1)).toEqual(34.6);
+ expect(getPercentWithPrecision([12.34, 34.56, 53.1], 2, 1)).toEqual(53.1);
+
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 0, 0)).toEqual(17);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 1, 0)).toEqual(48);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 2, 0)).toEqual(26);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875], 3, 0)).toEqual(9);
});
it('NaN data', function () {
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-'], 0, 0)).toEqual(17);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-'], 1, 0)).toEqual(48);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-'], 2, 0)).toEqual(26);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-'], 3, 0)).toEqual(9);
- expect(numberUtil.getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-'], 4, 0)).toEqual(0);
-
- expect(numberUtil.getPercentWithPrecision([0, undefined, '-', null, NaN], 0, 0)).toEqual(0);
- expect(numberUtil.getPercentWithPrecision([0, undefined, '-', null, NaN], 1, 0)).toEqual(0);
- expect(numberUtil.getPercentWithPrecision([0, undefined, '-', null, NaN], 2, 0)).toEqual(0);
- expect(numberUtil.getPercentWithPrecision([0, undefined, '-', null, NaN], 3, 0)).toEqual(0);
- expect(numberUtil.getPercentWithPrecision([0, undefined, '-', null, NaN], 4, 0)).toEqual(0);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-' as any], 0, 0)).toEqual(17);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-' as any], 1, 0)).toEqual(48);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-' as any], 2, 0)).toEqual(26);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-' as any], 3, 0)).toEqual(9);
+ expect(getPercentWithPrecision([1.678, 4.783, 2.664, 0.875, '-' as any], 4, 0)).toEqual(0);
+
+ expect(getPercentWithPrecision([0, undefined, '-' as any, null, NaN], 0, 0)).toEqual(0);
+ expect(getPercentWithPrecision([0, undefined, '-' as any, null, NaN], 1, 0)).toEqual(0);
+ expect(getPercentWithPrecision([0, undefined, '-' as any, null, NaN], 2, 0)).toEqual(0);
+ expect(getPercentWithPrecision([0, undefined, '-' as any, null, NaN], 3, 0)).toEqual(0);
+ expect(getPercentWithPrecision([0, undefined, '-' as any, null, NaN], 4, 0)).toEqual(0);
});
});
describe('quantityExponent', function () {
it('basic', function () {
- expect(numberUtil.quantityExponent(1)).toEqual(0);
- expect(numberUtil.quantityExponent(9)).toEqual(0);
- expect(numberUtil.quantityExponent(12)).toEqual(1);
- expect(numberUtil.quantityExponent(123)).toEqual(2);
- expect(numberUtil.quantityExponent(1234)).toEqual(3);
- expect(numberUtil.quantityExponent(1234.5678)).toEqual(3);
- expect(numberUtil.quantityExponent(10)).toEqual(1);
- expect(numberUtil.quantityExponent(1000)).toEqual(3);
- expect(numberUtil.quantityExponent(10000)).toEqual(4);
+ expect(quantityExponent(1)).toEqual(0);
+ expect(quantityExponent(9)).toEqual(0);
+ expect(quantityExponent(12)).toEqual(1);
+ expect(quantityExponent(123)).toEqual(2);
+ expect(quantityExponent(1234)).toEqual(3);
+ expect(quantityExponent(1234.5678)).toEqual(3);
+ expect(quantityExponent(10)).toEqual(1);
+ expect(quantityExponent(1000)).toEqual(3);
+ expect(quantityExponent(10000)).toEqual(4);
});
it('decimals', function () {
- expect(numberUtil.quantityExponent(0.1)).toEqual(-1);
- expect(numberUtil.quantityExponent(0.001)).toEqual(-3);
- expect(numberUtil.quantityExponent(0.00123)).toEqual(-3);
+ expect(quantityExponent(0.1)).toEqual(-1);
+ expect(quantityExponent(0.001)).toEqual(-3);
+ expect(quantityExponent(0.00123)).toEqual(-3);
});
it('large number', function () {
- expect(numberUtil.quantityExponent(3.14e100)).toEqual(100);
- expect(numberUtil.quantityExponent(3.14e-100)).toEqual(-100);
+ expect(quantityExponent(3.14e100)).toEqual(100);
+ expect(quantityExponent(3.14e-100)).toEqual(-100);
});
it('zero', function () {
- expect(numberUtil.quantityExponent(0)).toEqual(0);
+ expect(quantityExponent(0)).toEqual(0);
});
});
describe('quantity', function () {
it('basic', function () {
- expect(numberUtil.quantity(1)).toEqual(1);
- expect(numberUtil.quantity(9)).toEqual(1);
- expect(numberUtil.quantity(12)).toEqual(10);
- expect(numberUtil.quantity(123)).toEqual(100);
- expect(numberUtil.quantity(1234)).toEqual(1000);
- expect(numberUtil.quantity(1234.5678)).toEqual(1000);
- expect(numberUtil.quantity(10)).toEqual(10);
- expect(numberUtil.quantity(1000)).toEqual(1000);
- expect(numberUtil.quantity(10000)).toEqual(10000);
+ expect(quantity(1)).toEqual(1);
+ expect(quantity(9)).toEqual(1);
+ expect(quantity(12)).toEqual(10);
+ expect(quantity(123)).toEqual(100);
+ expect(quantity(1234)).toEqual(1000);
+ expect(quantity(1234.5678)).toEqual(1000);
+ expect(quantity(10)).toEqual(10);
+ expect(quantity(1000)).toEqual(1000);
+ expect(quantity(10000)).toEqual(10000);
});
it('decimals', function () {
- expect(numberUtil.quantity(0.2)).toEqual(0.1);
- expect(numberUtil.quantity(0.002)).toEqual(0.001);
- expect(numberUtil.quantity(0.00123)).toEqual(0.001);
+ expect(quantity(0.2)).toEqual(0.1);
+ expect(quantity(0.002)).toEqual(0.001);
+ expect(quantity(0.00123)).toEqual(0.001);
});
it('large number', function () {
- // expect(numberUtil.quantity(3.14e100)).toEqual(1e100);
- // expect(numberUtil.quantity(3.14e-100)).toEqual(1e-100);
+ // expect(quantity(3.14e100)).toEqual(1e100);
+ // expect(quantity(3.14e-100)).toEqual(1e-100);
});
it('zero', function () {
- expect(numberUtil.quantity(0)).toEqual(1);
+ expect(quantity(0)).toEqual(1);
});
});
@@ -452,28 +472,28 @@ describe('util/number', function () {
describe('nice', function () {
it('extreme', function () {
// Should not be 0.30000000000000004
- expect(numberUtil.nice(0.3869394696651766, true)).toEqual(0.3);
- expect(numberUtil.nice(0.3869394696651766)).toEqual(0.5);
- expect(numberUtil.nice(0.00003869394696651766, true)).toEqual(0.00003);
- expect(numberUtil.nice(0.00003869394696651766, false)).toEqual(0.00005);
- // expect(numberUtil.nice(0, true)).toEqual(0);
- // expect(numberUtil.nice(0)).toEqual(0);
- expect(numberUtil.nice(13, true)).toEqual(10);
- expect(numberUtil.nice(13)).toEqual(20);
- expect(numberUtil.nice(3900000000000000000021, true)).toEqual(3000000000000000000000);
- expect(numberUtil.nice(3900000000000000000021)).toEqual(5000000000000000000000);
- expect(numberUtil.nice(0.00000000000000000656939, true)).toEqual(0.000000000000000005);
- expect(numberUtil.nice(0.00000000000000000656939)).toEqual(0.00000000000000001);
- expect(numberUtil.nice(0.10000000000000000656939, true)).toEqual(0.1);
- expect(numberUtil.nice(0.10000000000000000656939)).toEqual(0.2);
+ expect(nice(0.3869394696651766, true)).toEqual(0.3);
+ expect(nice(0.3869394696651766)).toEqual(0.5);
+ expect(nice(0.00003869394696651766, true)).toEqual(0.00003);
+ expect(nice(0.00003869394696651766, false)).toEqual(0.00005);
+ // expect(nice(0, true)).toEqual(0);
+ // expect(nice(0)).toEqual(0);
+ expect(nice(13, true)).toEqual(10);
+ expect(nice(13)).toEqual(20);
+ expect(nice(3900000000000000000021, true)).toEqual(3000000000000000000000);
+ expect(nice(3900000000000000000021)).toEqual(5000000000000000000000);
+ expect(nice(0.00000000000000000656939, true)).toEqual(0.000000000000000005);
+ expect(nice(0.00000000000000000656939)).toEqual(0.00000000000000001);
+ expect(nice(0.10000000000000000656939, true)).toEqual(0.1);
+ expect(nice(0.10000000000000000656939)).toEqual(0.2);
});
});
describe('numeric', function () {
- function testNumeric(rawVal, tarVal, beNumeric) {
- expect(numberUtil.isNumeric(rawVal)).toEqual(beNumeric);
- expect(numberUtil.numericToNumber(rawVal)).toEqual(tarVal);
+ function testNumeric(rawVal: unknown, tarVal: number, beNumeric: boolean) {
+ expect(isNumeric(rawVal)).toEqual(beNumeric);
+ expect(numericToNumber(rawVal)).toEqual(tarVal);
}
testNumeric(123, 123, true);
@@ -485,20 +505,20 @@ describe('util/number', function () {
testNumeric('-555.6', -555.6, true);
testNumeric(' 555 ', 555, true);
testNumeric(' -555 ', -555, true);
- testNumeric(1e3, 1000, true, true);
- testNumeric(-1e3, -1000, true, true);
- testNumeric('1e3', 1000, true, true);
- testNumeric('-1e3', -1000, true, true);
+ testNumeric(1e3, 1000, true);
+ testNumeric(-1e3, -1000, true);
+ testNumeric('1e3', 1000, true);
+ testNumeric('-1e3', -1000, true);
testNumeric(' \r \n 555 \t ', 555, true);
testNumeric(' \r \n -555.6 \t ', -555.6, true);
- testNumeric(Infinity, Infinity, true, true);
- testNumeric(-Infinity, -Infinity, true, true);
- testNumeric('Infinity', Infinity, true, true);
- testNumeric('-Infinity', -Infinity, true, true);
-
- testNumeric(NaN, NaN);
- testNumeric(-NaN, NaN);
- testNumeric('NaN', NaN);
+ testNumeric(Infinity, Infinity, true);
+ testNumeric(-Infinity, -Infinity, true);
+ testNumeric('Infinity', Infinity, true);
+ testNumeric('-Infinity', -Infinity, true);
+
+ testNumeric(NaN, NaN, false);
+ testNumeric(-NaN, NaN, false);
+ testNumeric('NaN', NaN, false);
testNumeric('-NaN', NaN, false);
testNumeric(' NaN ', NaN, false);
testNumeric(true, NaN, false);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 02/08: fix: fix dev fast entry since
echarts.all.ts moved.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 93ede9d164e0ad1a032a1891ecb7f57885466d9e
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 16:06:04 2020 +0800
fix: fix dev fast entry since echarts.all.ts moved.
---
build/dev-fast.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build/dev-fast.js b/build/dev-fast.js
index 50799cb..b609ef4 100644
--- a/build/dev-fast.js
+++ b/build/dev-fast.js
@@ -49,7 +49,7 @@ async function wrapUMDCode() {
function rebuild() {
build({
stdio: 'inherit',
- entryPoints: [path.resolve(__dirname, '../echarts.all.ts')],
+ entryPoints: [path.resolve(__dirname, '../src/echarts.all.ts')],
outfile: outFilePath,
format: 'cjs',
sourcemap: true,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 07/08: fix: (1) fix series merge mapping
(brought by some previous refactor in 5.0). (2) tweak id name type and
check.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 7090bceb82179962daac7568e9148d2f16c02fa1
Author: 100pah <su...@gmail.com>
AuthorDate: Fri Oct 16 00:46:01 2020 +0800
fix: (1) fix series merge mapping (brought by some previous refactor in 5.0). (2) tweak id name type and check.
---
src/util/model.ts | 17 ++++++++++-------
src/util/types.ts | 4 ++--
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/util/model.ts b/src/util/model.ts
index 5f214b8..9ee4127 100644
--- a/src/util/model.ts
+++ b/src/util/model.ts
@@ -366,7 +366,6 @@ function mappingByIndex<T extends MappingExistingItem>(
newCmptOptions: ComponentOption[],
brandNew: boolean
): void {
- let nextIdx = 0;
each(newCmptOptions, function (cmptOption) {
if (!cmptOption) {
return;
@@ -374,6 +373,7 @@ function mappingByIndex<T extends MappingExistingItem>(
// Find the first place that not mapped by id and not internal component (consider the "hole").
let resultItem;
+ let nextIdx = 0;
while (
// Be `!resultItem` only when `nextIdx >= result.length`.
(resultItem = result[nextIdx])
@@ -518,10 +518,10 @@ function keyExistAndEqual(
obj1: { id?: OptionId, name?: OptionName },
obj2: { id?: OptionId, name?: OptionName }
): boolean {
- const key1 = obj1[attr];
- const key2 = obj2[attr];
+ const key1 = convertOptionIdName(obj1[attr], null);
+ const key2 = convertOptionIdName(obj2[attr], null);
// See `MappingExistingItem`. `id` and `name` trade string equals to number.
- return key1 != null && key2 != null && key1 + '' === key2 + '';
+ return key1 != null && key2 != null && key1 === key2;
}
/**
@@ -610,8 +610,8 @@ function determineSubType(
type BatchItem = {
- seriesId: string,
- dataIndex: number[]
+ seriesId: OptionId,
+ dataIndex: number | number[]
};
/**
* A helper for removing duplicate items between batchA and batchB,
@@ -641,7 +641,10 @@ export function compressBatches(
function makeMap(sourceBatch: BatchItem[], map: InnerMap, otherMap?: InnerMap): void {
for (let i = 0, len = sourceBatch.length; i < len; i++) {
- const seriesId = sourceBatch[i].seriesId;
+ const seriesId = convertOptionIdName(sourceBatch[i].seriesId, null);
+ if (seriesId == null) {
+ return;
+ }
const dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
const otherDataIndices = otherMap && otherMap[seriesId];
diff --git a/src/util/types.ts b/src/util/types.ts
index 3206567..f014c2e 100644
--- a/src/util/types.ts
+++ b/src/util/types.ts
@@ -636,13 +636,13 @@ export interface MediaQuery {
maxAspectRatio?: number;
};
export type MediaUnit = {
- query: MediaQuery,
+ query?: MediaQuery,
option: ECUnitOption
};
export type ComponentLayoutMode = {
// Only support 'box' now.
- type: 'box',
+ type?: 'box',
ignoreSize?: boolean | boolean[]
};
/******************* Mixins for Common Option Properties ********************** */
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[incubator-echarts] 06/08: fix: add the missing entry file for
echarts.*.ts migrate.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit c5f4ef71153829cfbd966dda27157287c3d11a6c
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 17:00:57 2020 +0800
fix: add the missing entry file for echarts.*.ts migrate.
---
src/echarts.all.ts | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/echarts.blank.ts | 23 +++++
src/echarts.common.ts | 44 ++++++++
src/echarts.simple.ts | 27 +++++
tsconfig.json | 1 -
5 files changed, 366 insertions(+), 1 deletion(-)
diff --git a/src/echarts.all.ts b/src/echarts.all.ts
new file mode 100644
index 0000000..4d69e35
--- /dev/null
+++ b/src/echarts.all.ts
@@ -0,0 +1,272 @@
+/*
+* 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.
+*/
+
+export * from './echarts';
+export * from './export';
+
+import './component/dataset';
+import './component/transform';
+
+// ----------------------------------------------
+// All of the modules that are allowed to be
+// imported are listed below.
+//
+// Users MUST NOT import other modules that are
+// not included in this list.
+// ----------------------------------------------
+
+
+
+// ----------------
+// Charts (series)
+// ----------------
+
+
+
+// All of the series types, for example:
+// chart.setOption({
+// series: [{
+// type: 'line' // or 'bar', 'pie', ...
+// }]
+// });
+
+import './chart/line';
+import './chart/bar';
+import './chart/pie';
+import './chart/scatter';
+import './chart/radar';
+import './chart/map';
+import './chart/tree';
+import './chart/treemap';
+import './chart/graph';
+import './chart/gauge';
+import './chart/funnel';
+import './chart/parallel';
+import './chart/sankey';
+import './chart/boxplot';
+import './chart/candlestick';
+import './chart/effectScatter';
+import './chart/lines';
+import './chart/heatmap';
+import './chart/pictorialBar';
+import './chart/themeRiver';
+import './chart/sunburst';
+import './chart/custom';
+
+
+
+// -------------------
+// Coordinate systems
+// -------------------
+
+
+
+// All of the axis modules have been included in the
+// coordinate system module below, do not need to
+// make extra import.
+
+// `cartesian` coordinate system. For some historical
+// reasons, it is named as grid, for example:
+// chart.setOption({
+// grid: {...},
+// xAxis: {...},
+// yAxis: {...},
+// series: [{...}]
+// });
+import './component/grid';
+
+// `polar` coordinate system, for example:
+// chart.setOption({
+// polar: {...},
+// radiusAxis: {...},
+// angleAxis: {...},
+// series: [{
+// coordinateSystem: 'polar'
+// }]
+// });
+import './component/polar';
+
+// `geo` coordinate system, for example:
+// chart.setOption({
+// geo: {...},
+// series: [{
+// coordinateSystem: 'geo'
+// }]
+// });
+import './component/geo';
+
+// `singleAxis` coordinate system (notice, it is a coordinate system
+// with only one axis, work for chart like theme river), for example:
+// chart.setOption({
+// singleAxis: {...}
+// series: [{type: 'themeRiver', ...}]
+// });
+import './component/singleAxis';
+
+// `parallel` coordinate system, only work for parallel series, for example:
+// chart.setOption({
+// parallel: {...},
+// parallelAxis: [{...}, ...],
+// series: [{
+// type: 'parallel'
+// }]
+// });
+import './component/parallel';
+
+// `calendar` coordinate system. for example,
+// chart.setOptionp({
+// calendar: {...},
+// series: [{
+// coordinateSystem: 'calendar'
+// }]
+// );
+import './component/calendar';
+
+
+
+// ------------------
+// Other components
+// ------------------
+
+
+
+// `graphic` component, for example:
+// chart.setOption({
+// graphic: {...}
+// });
+import './component/graphic';
+
+// `toolbox` component, for example:
+// chart.setOption({
+// toolbox: {...}
+// });
+import './component/toolbox';
+
+// `tooltip` component, for example:
+// chart.setOption({
+// tooltip: {...}
+// });
+import './component/tooltip';
+
+// `axisPointer` component, for example:
+// chart.setOption({
+// tooltip: {axisPointer: {...}, ...}
+// });
+// Or
+// chart.setOption({
+// axisPointer: {...}
+// });
+import './component/axisPointer';
+
+// `brush` component, for example:
+// chart.setOption({
+// brush: {...}
+// });
+// Or
+// chart.setOption({
+// tooltip: {feature: {brush: {...}}
+// })
+import './component/brush';
+
+// `title` component, for example:
+// chart.setOption({
+// title: {...}
+// });
+import './component/title';
+
+// `timeline` component, for example:
+// chart.setOption({
+// timeline: {...}
+// });
+import './component/timeline';
+
+// `markPoint` component, for example:
+// chart.setOption({
+// series: [{markPoint: {...}}]
+// });
+import './component/markPoint';
+
+// `markLine` component, for example:
+// chart.setOption({
+// series: [{markLine: {...}}]
+// });
+import './component/markLine';
+
+// `markArea` component, for example:
+// chart.setOption({
+// series: [{markArea: {...}}]
+// });
+import './component/markArea';
+
+// `legend` component scrollable, for example:
+// chart.setOption({
+// legend: {type: 'scroll'}
+// });
+import './component/legendScroll';
+
+// `legend` component not scrollable. for example:
+// chart.setOption({
+// legend: {...}
+// });
+import './component/legend';
+
+// `dataZoom` component including both `dataZoomInside` and `dataZoomSlider`.
+import './component/dataZoom';
+
+// `dataZoom` component providing drag, pinch, wheel behaviors
+// inside coodinate system, for example:
+// chart.setOption({
+// dataZoom: {type: 'inside'}
+// });
+import './component/dataZoomInside';
+
+// `dataZoom` component providing a slider bar, for example:
+// chart.setOption({
+// dataZoom: {type: 'slider'}
+// });
+import './component/dataZoomSlider';
+
+// `dataZoom` component including both `visualMapContinuous` and `visualMapPiecewise`.
+import './component/visualMap';
+
+// `visualMap` component providing continuous bar, for example:
+// chart.setOption({
+// visualMap: {type: 'continuous'}
+// });
+import './component/visualMapContinuous';
+
+// `visualMap` component providing pieces bar, for example:
+// chart.setOption({
+// visualMap: {type: 'piecewise'}
+// });
+import './component/visualMapPiecewise';
+
+
+
+// -----------------
+// Render engines
+// -----------------
+
+
+
+// Provide IE 6,7,8 compatibility.
+// import 'zrender/vml/vml';
+
+// Render via SVG rather than canvas.
+import 'zrender/src/svg/svg';
diff --git a/src/echarts.blank.ts b/src/echarts.blank.ts
new file mode 100644
index 0000000..b900e3a
--- /dev/null
+++ b/src/echarts.blank.ts
@@ -0,0 +1,23 @@
+/*
+* 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.
+*/
+
+export * from './echarts';
+export * from './export';
+
+import './component/dataset';
diff --git a/src/echarts.common.ts b/src/echarts.common.ts
new file mode 100644
index 0000000..1b56c32
--- /dev/null
+++ b/src/echarts.common.ts
@@ -0,0 +1,44 @@
+/*
+* 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.
+*/
+
+export * from './echarts';
+export * from './export';
+
+import './component/dataset';
+
+import './chart/line';
+import './chart/bar';
+import './chart/pie';
+import './chart/scatter';
+import './component/graphic';
+import './component/tooltip';
+import './component/axisPointer';
+import './component/legendScroll';
+
+import './component/grid';
+import './component/title';
+
+import './component/markPoint';
+import './component/markLine';
+import './component/markArea';
+import './component/dataZoom';
+import './component/toolbox';
+
+// import 'zrender/vml/vml';
+import 'zrender/src/svg/svg';
diff --git a/src/echarts.simple.ts b/src/echarts.simple.ts
new file mode 100644
index 0000000..08b8f0b
--- /dev/null
+++ b/src/echarts.simple.ts
@@ -0,0 +1,27 @@
+/*
+* 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.
+*/
+
+export * from './echarts';
+
+import './component/dataset';
+
+import './chart/line';
+import './chart/bar';
+import './chart/pie';
+import './component/gridSimple';
diff --git a/tsconfig.json b/tsconfig.json
index dfbbd5d..adedaa4 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -22,7 +22,6 @@
},
"include": [
"src/**/*.ts",
- "echarts.*.ts",
"extension-src/**/*.ts"
]
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org