You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/03/02 13:04:40 UTC
[incubator-echarts] branch typescript updated: ts: add types for
line
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch typescript
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/typescript by this push:
new 47585d1 ts: add types for line
47585d1 is described below
commit 47585d19beb2e04b497902d080bdf29108678548
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Mar 2 21:04:07 2020 +0800
ts: add types for line
---
src/chart/bar/BarSeries.ts | 6 +-
src/chart/bar/BaseBarSeries.ts | 4 +-
src/chart/bar/PictorialBarSeries.ts | 12 +-
src/chart/gauge/PointerPath.ts | 2 +-
src/chart/helper/Symbol.ts | 617 +++++++++++++-------------
src/chart/helper/SymbolDraw.ts | 312 ++++++-------
src/chart/helper/createListFromArray.ts | 37 +-
src/chart/line/LineSeries.ts | 91 +++-
src/chart/line/LineView.ts | 243 ++++++----
src/chart/line/helper.ts | 49 +-
src/chart/line/lineAnimationDiff.ts | 72 ++-
src/chart/line/poly.ts | 156 +++----
src/chart/themeRiver/ThemeRiverView.ts | 4 +-
src/component/axisPointer.ts | 4 +
src/component/axisPointer/AxisPointerModel.ts | 2 -
src/component/dataZoom/InsideZoomView.ts | 6 +-
src/component/toolbox/feature/MagicType.ts | 2 +-
src/component/visualMap/VisualMapModel.ts | 6 +-
src/component/visualMap/helper.ts | 4 +-
src/component/visualMap/visualEncoding.ts | 33 +-
src/coord/cartesian/Cartesian2D.ts | 4 +-
src/coord/polar/Polar.ts | 13 +-
src/data/DataDimensionInfo.ts | 20 +-
src/data/List.ts | 5 +-
src/data/Source.ts | 4 -
src/data/helper/completeDimensions.ts | 3 +-
src/data/helper/dataProvider.ts | 4 +-
src/data/helper/dataStackHelper.ts | 62 +--
src/export.ts | 2 +-
src/helper.ts | 5 -
src/model/referHelper.ts | 90 ++--
src/util/types.ts | 7 +-
src/visual/visualSolution.ts | 4 +-
33 files changed, 1028 insertions(+), 857 deletions(-)
diff --git a/src/chart/bar/BarSeries.ts b/src/chart/bar/BarSeries.ts
index 8ef8334..10ea4cf 100644
--- a/src/chart/bar/BarSeries.ts
+++ b/src/chart/bar/BarSeries.ts
@@ -19,7 +19,7 @@
import BaseBarSeriesModel, {BaseBarSeriesOption} from './BaseBarSeries';
import SeriesModel from '../../model/Series';
-import { ItemStyleOption, OptionDataValue, LabelOption } from '../../util/types';
+import { ItemStyleOption, OptionDataValue, LabelOption, StackOptionMixin } from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Polar from '../../coord/polar/Polar';
@@ -47,13 +47,11 @@ export interface BarDataItemOption {
}
}
-export interface BarSeriesOption extends BaseBarSeriesOption {
+export interface BarSeriesOption extends BaseBarSeriesOption, StackOptionMixin {
coordinateSystem?: 'cartesian2d' | 'polar'
clip?: boolean
- stack?: string
-
/**
* If use caps on two sides of bars
* Only available on tangential polar bar
diff --git a/src/chart/bar/BaseBarSeries.ts b/src/chart/bar/BaseBarSeries.ts
index d8c5dc7..8d6f4c5 100644
--- a/src/chart/bar/BaseBarSeries.ts
+++ b/src/chart/bar/BaseBarSeries.ts
@@ -29,6 +29,7 @@ import {
} from '../../util/types';
import GlobalModel from '../../model/Global';
import Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import List from '../../data/List';
export interface BaseBarSeriesOption extends SeriesOption, SeriesOnCartesianOptionMixin, SeriesOnPolarOptionMixin {
@@ -81,8 +82,7 @@ class BaseBarSeriesModel<Opts extends BaseBarSeriesOption = BaseBarSeriesOption>
static type = 'series.__base_bar__'
type = BaseBarSeriesModel.type
-
- getInitialData(option: Opts, ecModel: GlobalModel) {
+ getInitialData(option: Opts, ecModel: GlobalModel): List {
return createListFromArray(this.getSource(), this, {useEncodeDefaulter: true});
}
diff --git a/src/chart/bar/PictorialBarSeries.ts b/src/chart/bar/PictorialBarSeries.ts
index fb41cb0..1b81676 100644
--- a/src/chart/bar/PictorialBarSeries.ts
+++ b/src/chart/bar/PictorialBarSeries.ts
@@ -19,7 +19,13 @@
import BaseBarSeriesModel, { BaseBarSeriesOption } from './BaseBarSeries';
import SeriesModel from '../../model/Series';
-import { OptionDataValue, ItemStyleOption, LabelOption, AnimationOptionMixin } from '../../util/types';
+import {
+ OptionDataValue,
+ ItemStyleOption,
+ LabelOption,
+ AnimationOptionMixin,
+ StackOptionMixin
+} from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
interface PictorialBarSeriesSymbolOption {
@@ -99,7 +105,9 @@ export interface PictorialBarDataItemOption extends PictorialBarSeriesSymbolOpti
cursor?: string
}
-export interface PictorialBarSeriesOption extends BaseBarSeriesOption, PictorialBarSeriesSymbolOption {
+export interface PictorialBarSeriesOption extends BaseBarSeriesOption,
+ PictorialBarSeriesSymbolOption,
+ StackOptionMixin {
coordinateSystem?: 'cartesian2d'
data?: (PictorialBarDataItemOption | PictorialBarValue)[]
diff --git a/src/chart/gauge/PointerPath.ts b/src/chart/gauge/PointerPath.ts
index 7c2ad62..6fc8e89 100644
--- a/src/chart/gauge/PointerPath.ts
+++ b/src/chart/gauge/PointerPath.ts
@@ -33,7 +33,7 @@ interface PointerPathProps extends PathProps {
export default class PointerPath extends Path<PointerPathProps> {
- type = 'pointer'
+ readonly type = 'pointer'
shape: PointerShape
diff --git a/src/chart/helper/Symbol.ts b/src/chart/helper/Symbol.ts
index 0929933..6c7242d 100644
--- a/src/chart/helper/Symbol.ts
+++ b/src/chart/helper/Symbol.ts
@@ -17,331 +17,347 @@
* under the License.
*/
-// @ts-nocheck
-
-/**
- * @module echarts/chart/helper/Symbol
- */
-
import * as zrUtil from 'zrender/src/core/util';
import {createSymbol} from '../../util/symbol';
import * as graphic from '../../util/graphic';
import {parsePercent} from '../../util/number';
import {getDefaultLabel} from './labelHelper';
+import List from '../../data/List';
+import { StyleProps } from 'zrender/src/graphic/Style';
+import { LabelOption, ItemStyleOption, ColorString, DisplayState } from '../../util/types';
+import Model from '../../model/Model';
+import SeriesModel from '../../model/Series';
+import { PathProps } from 'zrender/src/graphic/Path';
-
-/**
- * @constructor
- * @alias {module:echarts/chart/helper/Symbol}
- * @param {module:echarts/data/List} data
- * @param {number} idx
- * @extends {module:zrender/graphic/Group}
- */
-function SymbolClz(data, idx, seriesScope) {
- graphic.Group.call(this);
- this.updateData(data, idx, seriesScope);
+// Update common properties
+const normalStyleAccessPath = ['itemStyle'] as const;
+const emphasisStyleAccessPath = ['emphasis', 'itemStyle'] as const;
+const normalLabelAccessPath = ['label'] as const;
+const emphasisLabelAccessPath = ['emphasis', 'label'] as const;
+
+type ECSymbol = ReturnType<typeof createSymbol> & {
+ __symbolOriginalScale: number[]
+ __z2Origin: number
+ highDownOnUpdate(fromState: DisplayState, toState: DisplayState): void
}
-var symbolProto = SymbolClz.prototype;
-
-/**
- * @public
- * @static
- * @param {module:echarts/data/List} data
- * @param {number} dataIndex
- * @return {Array.<number>} [width, height]
- */
-var getSymbolSize = SymbolClz.getSymbolSize = function (data, idx) {
- var symbolSize = data.getItemVisual(idx, 'symbolSize');
- return symbolSize instanceof Array
- ? symbolSize.slice()
- : [+symbolSize, +symbolSize];
-};
-
-function getScale(symbolSize) {
- return [symbolSize[0] / 2, symbolSize[1] / 2];
+export interface SeriesScope {
+ itemStyle?: StyleProps
+ hoverItemStyle?: StyleProps
+ symbolRotate?: number
+ symbolOffset?: [number, number]
+ labelModel?: Model<LabelOption>
+ hoverLabelModel?: Model<LabelOption>
+ hoverAnimation?: boolean
+ itemModel?: Model<ItemStyleOption>
+ symbolInnerColor?: ColorString
+ cursorStyle?: string
+ fadeIn?: boolean
+ useNameLabel?: boolean
}
+class Symbol extends graphic.Group {
-function driftSymbol(dx, dy) {
- this.parent.drift(dx, dy);
-}
+ dataIndex: number
-symbolProto._createSymbol = function (
- symbolType,
- data,
- idx,
- symbolSize,
- keepAspect
-) {
- // Remove paths created before
- this.removeAll();
-
- var color = data.getItemVisual(idx, 'color');
-
- // var symbolPath = createSymbol(
- // symbolType, -0.5, -0.5, 1, 1, color
- // );
- // If width/height are set too small (e.g., set to 1) on ios10
- // and macOS Sierra, a circle stroke become a rect, no matter what
- // the scale is set. So we set width/height as 2. See #4150.
- var symbolPath = createSymbol(
- symbolType, -1, -1, 2, 2, color, keepAspect
- );
-
- symbolPath.attr({
- z2: 100,
- culling: true,
- scale: getScale(symbolSize)
- });
- // Rewrite drift method
- symbolPath.drift = driftSymbol;
-
- this._symbolType = symbolType;
-
- this.add(symbolPath);
-};
-
-/**
- * Stop animation
- * @param {boolean} toLastFrame
- */
-symbolProto.stopSymbolAnimation = function (toLastFrame) {
- this.childAt(0).stopAnimation(toLastFrame);
-};
-
-/**
- * FIXME:
- * Caution: This method breaks the encapsulation of this module,
- * but it indeed brings convenience. So do not use the method
- * unless you detailedly know all the implements of `Symbol`,
- * especially animation.
- *
- * Get symbol path element.
- */
-symbolProto.getSymbolPath = function () {
- return this.childAt(0);
-};
-
-/**
- * Get scale(aka, current symbol size).
- * Including the change caused by animation
- */
-symbolProto.getScale = function () {
- return this.childAt(0).scale;
-};
-
-/**
- * Highlight symbol
- */
-symbolProto.highlight = function () {
- this.childAt(0).trigger('emphasis');
-};
-
-/**
- * Downplay symbol
- */
-symbolProto.downplay = function () {
- this.childAt(0).trigger('normal');
-};
-
-/**
- * @param {number} zlevel
- * @param {number} z
- */
-symbolProto.setZ = function (zlevel, z) {
- var symbolPath = this.childAt(0);
- symbolPath.zlevel = zlevel;
- symbolPath.z = z;
-};
-
-symbolProto.setDraggable = function (draggable) {
- var symbolPath = this.childAt(0);
- symbolPath.draggable = draggable;
- symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
-};
-
-/**
- * Update symbol properties
- * @param {module:echarts/data/List} data
- * @param {number} idx
- * @param {Object} [seriesScope]
- * @param {Object} [seriesScope.itemStyle]
- * @param {Object} [seriesScope.hoverItemStyle]
- * @param {Object} [seriesScope.symbolRotate]
- * @param {Object} [seriesScope.symbolOffset]
- * @param {module:echarts/model/Model} [seriesScope.labelModel]
- * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
- * @param {boolean} [seriesScope.hoverAnimation]
- * @param {Object} [seriesScope.cursorStyle]
- * @param {module:echarts/model/Model} [seriesScope.itemModel]
- * @param {string} [seriesScope.symbolInnerColor]
- * @param {Object} [seriesScope.fadeIn=false]
- */
-symbolProto.updateData = function (data, idx, seriesScope) {
- this.silent = false;
-
- var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
- var seriesModel = data.hostModel;
- var symbolSize = getSymbolSize(data, idx);
- var isInit = symbolType !== this._symbolType;
-
- if (isInit) {
- var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
- this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
- }
- else {
- var symbolPath = this.childAt(0);
- symbolPath.silent = false;
- graphic.updateProps(symbolPath, {
- scale: getScale(symbolSize)
- }, seriesModel, idx);
+ private _seriesModel: SeriesModel
+
+ private _symbolType: string
+
+ constructor(data: List, idx: number, seriesScope?: SeriesScope) {
+ super();
+ this.updateData(data, idx, seriesScope);
}
- this._updateCommon(data, idx, symbolSize, seriesScope);
+ _createSymbol(
+ symbolType: string,
+ data: List,
+ idx: number,
+ symbolSize: number[],
+ keepAspect: boolean
+ ) {
+ // Remove paths created before
+ this.removeAll();
+
+ var color = data.getItemVisual(idx, 'color');
+
+ // var symbolPath = createSymbol(
+ // symbolType, -0.5, -0.5, 1, 1, color
+ // );
+ // If width/height are set too small (e.g., set to 1) on ios10
+ // and macOS Sierra, a circle stroke become a rect, no matter what
+ // the scale is set. So we set width/height as 2. See #4150.
+ var symbolPath = createSymbol(
+ symbolType, -1, -1, 2, 2, color, keepAspect
+ );
+
+ symbolPath.attr({
+ z2: 100,
+ culling: true,
+ scale: getScale(symbolSize)
+ });
+ // Rewrite drift method
+ symbolPath.drift = driftSymbol;
- if (isInit) {
- var symbolPath = this.childAt(0);
- var fadeIn = seriesScope && seriesScope.fadeIn;
+ this._symbolType = symbolType;
- var target = {scale: symbolPath.scale.slice()};
- fadeIn && (target.style = {opacity: symbolPath.style.opacity});
+ this.add(symbolPath);
+ }
- symbolPath.scale = [0, 0];
- fadeIn && (symbolPath.style.opacity = 0);
+ /**
+ * Stop animation
+ * @param {boolean} toLastFrame
+ */
+ stopSymbolAnimation(toLastFrame: boolean) {
+ this.childAt(0).stopAnimation(toLastFrame);
+ }
- graphic.initProps(symbolPath, target, seriesModel, idx);
+ /**
+ * FIXME:
+ * Caution: This method breaks the encapsulation of this module,
+ * but it indeed brings convenience. So do not use the method
+ * unless you detailedly know all the implements of `Symbol`,
+ * especially animation.
+ *
+ * Get symbol path element.
+ */
+ getSymbolPath() {
+ return this.childAt(0);
}
- this._seriesModel = seriesModel;
-};
+ /**
+ * Get scale(aka, current symbol size).
+ * Including the change caused by animation
+ */
+ getScale() {
+ return this.childAt(0).scale;
+ }
-// Update common properties
-var normalStyleAccessPath = ['itemStyle'];
-var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
-var normalLabelAccessPath = ['label'];
-var emphasisLabelAccessPath = ['emphasis', 'label'];
-
-/**
- * @param {module:echarts/data/List} data
- * @param {number} idx
- * @param {Array.<number>} symbolSize
- * @param {Object} [seriesScope]
- */
-symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
- var symbolPath = this.childAt(0);
- var seriesModel = data.hostModel;
- var color = data.getItemVisual(idx, 'color');
-
- // Reset style
- if (symbolPath.type !== 'image') {
- symbolPath.useStyle({
- strokeNoScale: true
- });
+ /**
+ * Highlight symbol
+ */
+ highlight() {
+ this.childAt(0).trigger('emphasis');
}
- else {
- symbolPath.setStyle({
- opacity: null,
- shadowBlur: null,
- shadowOffsetX: null,
- shadowOffsetY: null,
- shadowColor: null
- });
+
+ /**
+ * Downplay symbol
+ */
+ downplay() {
+ this.childAt(0).trigger('normal');
}
- var itemStyle = seriesScope && seriesScope.itemStyle;
- var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
- var symbolRotate = seriesScope && seriesScope.symbolRotate;
- var symbolOffset = seriesScope && seriesScope.symbolOffset;
- var labelModel = seriesScope && seriesScope.labelModel;
- var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
- var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
- var cursorStyle = seriesScope && seriesScope.cursorStyle;
-
- if (!seriesScope || data.hasItemOption) {
- var itemModel = (seriesScope && seriesScope.itemModel)
- ? seriesScope.itemModel : data.getItemModel(idx);
-
- // Color must be excluded.
- // Because symbol provide setColor individually to set fill and stroke
- itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
- hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
-
- symbolRotate = itemModel.getShallow('symbolRotate');
- symbolOffset = itemModel.getShallow('symbolOffset');
-
- labelModel = itemModel.getModel(normalLabelAccessPath);
- hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
- hoverAnimation = itemModel.getShallow('hoverAnimation');
- cursorStyle = itemModel.getShallow('cursor');
+ /**
+ * @param {number} zlevel
+ * @param {number} z
+ */
+ setZ(zlevel: number, z: number) {
+ var symbolPath = this.childAt(0) as ECSymbol;
+ symbolPath.zlevel = zlevel;
+ symbolPath.z = z;
}
- else {
- hoverItemStyle = zrUtil.extend({}, hoverItemStyle);
+
+ setDraggable(draggable: boolean) {
+ var symbolPath = this.childAt(0) as ECSymbol;
+ symbolPath.draggable = draggable;
+ symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
}
- var elStyle = symbolPath.style;
+ /**
+ * Update symbol properties
+ */
+ updateData(data: List, idx: number, seriesScope?: SeriesScope) {
+ this.silent = false;
- symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
+ var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
+ var seriesModel = data.hostModel as SeriesModel;
+ var symbolSize = Symbol.getSymbolSize(data, idx);
+ var isInit = symbolType !== this._symbolType;
- if (symbolOffset) {
- symbolPath.attr('position', [
- parsePercent(symbolOffset[0], symbolSize[0]),
- parsePercent(symbolOffset[1], symbolSize[1])
- ]);
- }
+ if (isInit) {
+ var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
+ this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
+ }
+ else {
+ const symbolPath = this.childAt(0) as ECSymbol;
+ symbolPath.silent = false;
+ graphic.updateProps(symbolPath, {
+ scale: getScale(symbolSize)
+ }, seriesModel, idx);
+ }
- cursorStyle && symbolPath.attr('cursor', cursorStyle);
+ this._updateCommon(data, idx, symbolSize, seriesScope);
- // PENDING setColor before setStyle!!!
- symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
+ if (isInit) {
+ const symbolPath = this.childAt(0) as ECSymbol;
+ var fadeIn = seriesScope && seriesScope.fadeIn;
- symbolPath.setStyle(itemStyle);
+ var target: PathProps = {
+ scale: symbolPath.scale.slice()
+ };
+ fadeIn && (target.style = {
+ opacity: symbolPath.style.opacity
+ });
- var opacity = data.getItemVisual(idx, 'opacity');
- if (opacity != null) {
- elStyle.opacity = opacity;
- }
+ symbolPath.scale = [0, 0];
+ fadeIn && (symbolPath.style.opacity = 0);
- var liftZ = data.getItemVisual(idx, 'liftZ');
- var z2Origin = symbolPath.__z2Origin;
- if (liftZ != null) {
- if (z2Origin == null) {
- symbolPath.__z2Origin = symbolPath.z2;
- symbolPath.z2 += liftZ;
+ graphic.initProps(symbolPath, target, seriesModel, idx);
}
- }
- else if (z2Origin != null) {
- symbolPath.z2 = z2Origin;
- symbolPath.__z2Origin = null;
+
+ this._seriesModel = seriesModel;
}
- var useNameLabel = seriesScope && seriesScope.useNameLabel;
+ _updateCommon(
+ data: List,
+ idx: number,
+ symbolSize: number[],
+ seriesScope?: SeriesScope
+ ) {
+ var symbolPath = this.childAt(0) as ECSymbol;
+ var seriesModel = data.hostModel as SeriesModel;
+ var color = data.getItemVisual(idx, 'color');
+
+ // Reset style
+ if (symbolPath.type !== 'image') {
+ symbolPath.useStyle({
+ strokeNoScale: true
+ });
+ }
+ else {
+ symbolPath.setStyle({
+ opacity: null,
+ shadowBlur: null,
+ shadowOffsetX: null,
+ shadowOffsetY: null,
+ shadowColor: null
+ });
+ }
+
+ var itemStyle = seriesScope && seriesScope.itemStyle;
+ var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
+ var symbolRotate = seriesScope && seriesScope.symbolRotate;
+ var symbolOffset = seriesScope && seriesScope.symbolOffset;
+ var labelModel = seriesScope && seriesScope.labelModel;
+ var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
+ var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
+ var cursorStyle = seriesScope && seriesScope.cursorStyle;
+
+ if (!seriesScope || data.hasItemOption) {
+ var itemModel = (seriesScope && seriesScope.itemModel)
+ ? seriesScope.itemModel : data.getItemModel(idx);
+
+ // Color must be excluded.
+ // Because symbol provide setColor individually to set fill and stroke
+ itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
+ hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
+
+ symbolRotate = itemModel.getShallow('symbolRotate');
+ symbolOffset = itemModel.getShallow('symbolOffset');
+
+ labelModel = itemModel.getModel(normalLabelAccessPath);
+ hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
+ hoverAnimation = itemModel.getShallow('hoverAnimation');
+ cursorStyle = itemModel.getShallow('cursor');
+ }
+ else {
+ hoverItemStyle = zrUtil.extend({}, hoverItemStyle);
+ }
+
+ var elStyle = symbolPath.style;
+
+ symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
+
+ if (symbolOffset) {
+ symbolPath.attr('position', [
+ parsePercent(symbolOffset[0], symbolSize[0]),
+ parsePercent(symbolOffset[1], symbolSize[1])
+ ]);
+ }
+
+ cursorStyle && symbolPath.attr('cursor', cursorStyle);
+
+ // PENDING setColor before setStyle!!!
+ symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
+
+ symbolPath.setStyle(itemStyle);
- graphic.setLabelStyle(
- elStyle, hoverItemStyle, labelModel, hoverLabelModel,
- {
- labelFetcher: seriesModel,
- labelDataIndex: idx,
- defaultText: getLabelDefaultText,
- isRectText: true,
- autoColor: color
+ var opacity = data.getItemVisual(idx, 'opacity');
+ if (opacity != null) {
+ elStyle.opacity = opacity;
+ }
+
+ var liftZ = data.getItemVisual(idx, 'liftZ');
+ var z2Origin = symbolPath.__z2Origin;
+ if (liftZ != null) {
+ if (z2Origin == null) {
+ symbolPath.__z2Origin = symbolPath.z2;
+ symbolPath.z2 += liftZ;
+ }
+ }
+ else if (z2Origin != null) {
+ symbolPath.z2 = z2Origin;
+ symbolPath.__z2Origin = null;
}
- );
- // Do not execute util needed.
- function getLabelDefaultText(idx, opt) {
- return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
+ var useNameLabel = seriesScope && seriesScope.useNameLabel;
+
+ graphic.setLabelStyle(
+ elStyle, hoverItemStyle, labelModel, hoverLabelModel,
+ {
+ labelFetcher: seriesModel,
+ labelDataIndex: idx,
+ defaultText: getLabelDefaultText,
+ isRectText: true,
+ autoColor: color
+ }
+ );
+
+ // Do not execute util needed.
+ function getLabelDefaultText(idx: number) {
+ return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
+ }
+
+ symbolPath.__symbolOriginalScale = getScale(symbolSize);
+ symbolPath.hoverStyle = hoverItemStyle;
+ symbolPath.highDownOnUpdate = (
+ hoverAnimation && seriesModel.isAnimationEnabled()
+ ) ? highDownOnUpdate : null;
+
+ graphic.setHoverStyle(symbolPath);
}
- symbolPath.__symbolOriginalScale = getScale(symbolSize);
- symbolPath.hoverStyle = hoverItemStyle;
- symbolPath.highDownOnUpdate = (
- hoverAnimation && seriesModel.isAnimationEnabled()
- ) ? highDownOnUpdate : null;
+ fadeOut(cb: () => void, opt?: {
+ keepLabel: boolean
+ }) {
+ var symbolPath = this.childAt(0) as ECSymbol;
+ // Avoid mistaken hover when fading out
+ this.silent = symbolPath.silent = true;
+ // Not show text when animating
+ !(opt && opt.keepLabel) && (symbolPath.style.text = null);
+
+ graphic.updateProps(
+ symbolPath,
+ {
+ style: {
+ opacity: 0
+ },
+ scale: [0, 0]
+ },
+ this._seriesModel,
+ this.dataIndex,
+ cb
+ );
+ }
- graphic.setHoverStyle(symbolPath);
-};
+ static getSymbolSize(data: List, idx: number) {
+ var symbolSize = data.getItemVisual(idx, 'symbolSize');
+ return symbolSize instanceof Array
+ ? symbolSize.slice()
+ : [+symbolSize, +symbolSize];
+ }
+}
-function highDownOnUpdate(fromState, toState) {
+function highDownOnUpdate(this: ECSymbol, fromState: DisplayState, toState: DisplayState) {
// Do not support this hover animation util some scenario required.
// Animation can only be supported in hover layer when using `el.incremetal`.
if (this.incremental || this.useHoverLayer) {
@@ -370,30 +386,13 @@ function highDownOnUpdate(fromState, toState) {
}
}
-/**
- * @param {Function} cb
- * @param {Object} [opt]
- * @param {Object} [opt.keepLabel=true]
- */
-symbolProto.fadeOut = function (cb, opt) {
- var symbolPath = this.childAt(0);
- // Avoid mistaken hover when fading out
- this.silent = symbolPath.silent = true;
- // Not show text when animating
- !(opt && opt.keepLabel) && (symbolPath.style.text = null);
-
- graphic.updateProps(
- symbolPath,
- {
- style: {opacity: 0},
- scale: [0, 0]
- },
- this._seriesModel,
- this.dataIndex,
- cb
- );
-};
-
-zrUtil.inherits(SymbolClz, graphic.Group);
-
-export default SymbolClz;
\ No newline at end of file
+function getScale(symbolSize: number[]) {
+ return [symbolSize[0] / 2, symbolSize[1] / 2];
+}
+
+function driftSymbol(this: ECSymbol, dx: number, dy: number) {
+ this.parent.drift(dx, dy);
+}
+
+
+export default Symbol;
\ No newline at end of file
diff --git a/src/chart/helper/SymbolDraw.ts b/src/chart/helper/SymbolDraw.ts
index dff8124..2805054 100644
--- a/src/chart/helper/SymbolDraw.ts
+++ b/src/chart/helper/SymbolDraw.ts
@@ -17,30 +17,30 @@
* under the License.
*/
-// @ts-nocheck
-
-/**
- * @module echarts/chart/helper/SymbolDraw
- */
-
import * as graphic from '../../util/graphic';
-import SymbolClz from './Symbol';
+import SymbolClz, {SeriesScope} from './Symbol';
import { isObject } from 'zrender/src/core/util';
+import List from '../../data/List';
+import { TaskProgressParams } from '../../stream/task';
+import type Displayable from 'zrender/src/graphic/Displayable';
+
+interface UpdateOpt {
+ isIgnore?(idx: number): boolean
+ clipShape?: {
+ contain(x: number, y: number): boolean
+ }
+}
-/**
- * @constructor
- * @alias module:echarts/chart/helper/SymbolDraw
- * @param {module:zrender/graphic/Group} [symbolCtor]
- */
-function SymbolDraw(symbolCtor) {
- this.group = new graphic.Group();
-
- this._symbolCtor = symbolCtor || SymbolClz;
+interface SymbolLike extends graphic.Group {
+ updateData(data: List, idx: number, scope?: SeriesScope): void
+ fadeOut?(cb: () => void): void
}
-var symbolDrawProto = SymbolDraw.prototype;
+interface SymbolLikeCtor {
+ new(data: List, idx: number, scope?: SeriesScope): SymbolLike
+}
-function symbolNeedsDraw(data, point, idx, opt) {
+function symbolNeedsDraw(data: List, point: number[], idx: number, opt: UpdateOpt) {
return point && !isNaN(point[0]) && !isNaN(point[1])
&& !(opt.isIgnore && opt.isIgnore(idx))
// We do not set clipShape on group, because it will cut part of
@@ -50,156 +50,164 @@ function symbolNeedsDraw(data, point, idx, opt) {
&& data.getItemVisual(idx, 'symbol') !== 'none';
}
-/**
- * Update symbols draw by new data
- * @param {module:echarts/data/List} data
- * @param {Object} [opt] Or isIgnore
- * @param {Function} [opt.isIgnore]
- * @param {Object} [opt.clipShape]
- */
-symbolDrawProto.updateData = function (data, opt) {
- opt = normalizeUpdateOpt(opt);
-
- var group = this.group;
- var seriesModel = data.hostModel;
- var oldData = this._data;
- var SymbolCtor = this._symbolCtor;
-
- var seriesScope = makeSeriesScope(data);
-
- // There is no oldLineData only when first rendering or switching from
- // stream mode to normal mode, where previous elements should be removed.
- if (!oldData) {
- group.removeAll();
- }
-
- data.diff(oldData)
- .add(function (newIdx) {
- var point = data.getItemLayout(newIdx);
- if (symbolNeedsDraw(data, point, newIdx, opt)) {
- var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
- symbolEl.attr('position', point);
- data.setItemGraphicEl(newIdx, symbolEl);
- group.add(symbolEl);
- }
- })
- .update(function (newIdx, oldIdx) {
- var symbolEl = oldData.getItemGraphicEl(oldIdx);
- var point = data.getItemLayout(newIdx);
- if (!symbolNeedsDraw(data, point, newIdx, opt)) {
- group.remove(symbolEl);
- return;
- }
- if (!symbolEl) {
- symbolEl = new SymbolCtor(data, newIdx);
- symbolEl.attr('position', point);
- }
- else {
- symbolEl.updateData(data, newIdx, seriesScope);
- graphic.updateProps(symbolEl, {
- position: point
- }, seriesModel);
- }
-
- // Add back
- group.add(symbolEl);
-
- data.setItemGraphicEl(newIdx, symbolEl);
- })
- .remove(function (oldIdx) {
- var el = oldData.getItemGraphicEl(oldIdx);
- el && el.fadeOut(function () {
- group.remove(el);
- });
- })
- .execute();
-
- this._data = data;
-};
-
-symbolDrawProto.isPersistent = function () {
- return true;
-};
-
-symbolDrawProto.updateLayout = function () {
- var data = this._data;
- if (data) {
- // Not use animation
- data.eachItemGraphicEl(function (el, idx) {
- var point = data.getItemLayout(idx);
- el.attr('position', point);
- });
- }
-};
-
-symbolDrawProto.incrementalPrepareUpdate = function (data) {
- this._seriesScope = makeSeriesScope(data);
- this._data = null;
- this.group.removeAll();
-};
-
-/**
- * Update symbols draw by new data
- * @param {module:echarts/data/List} data
- * @param {Object} [opt] Or isIgnore
- * @param {Function} [opt.isIgnore]
- * @param {Object} [opt.clipShape]
- */
-symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
- opt = normalizeUpdateOpt(opt);
-
- function updateIncrementalAndHover(el) {
- if (!el.isGroup) {
- el.incremental = el.useHoverLayer = true;
- }
- }
- for (var idx = taskParams.start; idx < taskParams.end; idx++) {
- var point = data.getItemLayout(idx);
- if (symbolNeedsDraw(data, point, idx, opt)) {
- var el = new this._symbolCtor(data, idx, this._seriesScope);
- el.traverse(updateIncrementalAndHover);
- el.attr('position', point);
- this.group.add(el);
- data.setItemGraphicEl(idx, el);
- }
- }
-};
-
-function normalizeUpdateOpt(opt) {
+function normalizeUpdateOpt(opt: UpdateOpt) {
if (opt != null && !isObject(opt)) {
opt = {isIgnore: opt};
}
return opt || {};
}
-symbolDrawProto.remove = function (enableAnimation) {
- var group = this.group;
- var data = this._data;
- // Incremental model do not have this._data.
- if (data && enableAnimation) {
- data.eachItemGraphicEl(function (el) {
- el.fadeOut(function () {
- group.remove(el);
- });
- });
- }
- else {
- group.removeAll();
- }
-};
-function makeSeriesScope(data) {
+function makeSeriesScope(data: List): SeriesScope {
var seriesModel = data.hostModel;
return {
itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
- hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
+ hoverItemStyle: seriesModel.getModel(['emphasis', 'itemStyle']).getItemStyle(),
symbolRotate: seriesModel.get('symbolRotate'),
symbolOffset: seriesModel.get('symbolOffset'),
hoverAnimation: seriesModel.get('hoverAnimation'),
labelModel: seriesModel.getModel('label'),
- hoverLabelModel: seriesModel.getModel('emphasis.label'),
+ hoverLabelModel: seriesModel.getModel(['emphasis', 'label']),
cursorStyle: seriesModel.get('cursor')
};
}
+class SymbolDraw {
+ group = new graphic.Group();
+
+ private _data: List
+
+ private _SymbolCtor: SymbolLikeCtor
+
+ private _seriesScope: SeriesScope
+
+ constructor(SymbolCtor?: SymbolLikeCtor) {
+ this._SymbolCtor = SymbolCtor || SymbolClz;
+ }
+
+ /**
+ * Update symbols draw by new data
+ */
+ updateData(data: List, opt?: UpdateOpt) {
+ opt = normalizeUpdateOpt(opt);
+
+ var group = this.group;
+ var seriesModel = data.hostModel;
+ var oldData = this._data;
+ var SymbolCtor = this._SymbolCtor;
+
+ var seriesScope = makeSeriesScope(data);
+
+ // There is no oldLineData only when first rendering or switching from
+ // stream mode to normal mode, where previous elements should be removed.
+ if (!oldData) {
+ group.removeAll();
+ }
+
+ data.diff(oldData)
+ .add(function (newIdx) {
+ var point = data.getItemLayout(newIdx) as number[];
+ if (symbolNeedsDraw(data, point, newIdx, opt)) {
+ var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
+ symbolEl.attr('position', point);
+ data.setItemGraphicEl(newIdx, symbolEl);
+ group.add(symbolEl);
+ }
+ })
+ .update(function (newIdx, oldIdx) {
+ var symbolEl = oldData.getItemGraphicEl(oldIdx) as SymbolLike;
+ var point = data.getItemLayout(newIdx) as number[];
+ if (!symbolNeedsDraw(data, point, newIdx, opt)) {
+ group.remove(symbolEl);
+ return;
+ }
+ if (!symbolEl) {
+ symbolEl = new SymbolCtor(data, newIdx);
+ symbolEl.attr('position', point);
+ }
+ else {
+ symbolEl.updateData(data, newIdx, seriesScope);
+ graphic.updateProps(symbolEl, {
+ position: point
+ }, seriesModel);
+ }
+
+ // Add back
+ group.add(symbolEl);
+
+ data.setItemGraphicEl(newIdx, symbolEl);
+ })
+ .remove(function (oldIdx) {
+ var el = oldData.getItemGraphicEl(oldIdx) as SymbolLike;
+ el && el.fadeOut(function () {
+ group.remove(el);
+ });
+ })
+ .execute();
+
+ this._data = data;
+ };
+
+ isPersistent() {
+ return true;
+ };
+
+ updateLayout() {
+ var data = this._data;
+ if (data) {
+ // Not use animation
+ data.eachItemGraphicEl(function (el, idx) {
+ var point = data.getItemLayout(idx);
+ el.attr('position', point);
+ });
+ }
+ };
+
+ incrementalPrepareUpdate(data: List) {
+ this._seriesScope = makeSeriesScope(data);
+ this._data = null;
+ this.group.removeAll();
+ };
+
+ /**
+ * Update symbols draw by new data
+ */
+ incrementalUpdate(taskParams: TaskProgressParams, data: List, opt?: UpdateOpt) {
+ opt = normalizeUpdateOpt(opt);
+
+ function updateIncrementalAndHover(el: Displayable) {
+ if (!el.isGroup) {
+ el.incremental = el.useHoverLayer = true;
+ }
+ }
+ for (var idx = taskParams.start; idx < taskParams.end; idx++) {
+ var point = data.getItemLayout(idx) as number[];
+ if (symbolNeedsDraw(data, point, idx, opt)) {
+ var el = new this._SymbolCtor(data, idx, this._seriesScope);
+ el.traverse(updateIncrementalAndHover);
+ el.attr('position', point);
+ this.group.add(el);
+ data.setItemGraphicEl(idx, el);
+ }
+ }
+ };
+
+ remove(enableAnimation?: boolean) {
+ var group = this.group;
+ var data = this._data;
+ // Incremental model do not have this._data.
+ if (data && enableAnimation) {
+ data.eachItemGraphicEl(function (el: SymbolLike) {
+ el.fadeOut(function () {
+ group.remove(el);
+ });
+ });
+ }
+ else {
+ group.removeAll();
+ }
+ };
+
+}
+
export default SymbolDraw;
\ No newline at end of file
diff --git a/src/chart/helper/createListFromArray.ts b/src/chart/helper/createListFromArray.ts
index 690d973..f360b97 100644
--- a/src/chart/helper/createListFromArray.ts
+++ b/src/chart/helper/createListFromArray.ts
@@ -17,8 +17,6 @@
* under the License.
*/
-// @ts-nocheck
-
import * as zrUtil from 'zrender/src/core/util';
import List from '../../data/List';
import createDimensions from '../../data/helper/createDimensions';
@@ -29,19 +27,16 @@ import {getCoordSysInfoBySeries} from '../../model/referHelper';
import Source from '../../data/Source';
import {enableDataStack} from '../../data/helper/dataStackHelper';
import {makeSeriesEncodeForAxisCoordSys} from '../../data/helper/sourceHelper';
-import { SOURCE_FORMAT_ORIGINAL } from '../../util/types';
-
-/**
- * @param {module:echarts/data/Source|Array} source Or raw data.
- * @param {module:echarts/model/Series} seriesModel
- * @param {Object} [opt]
- * @param {string} [opt.generateCoord]
- * @param {boolean} [opt.useEncodeDefaulter]
- */
-function createListFromArray(source, seriesModel, opt) {
+import { SOURCE_FORMAT_ORIGINAL, DimensionDefinitionLoose, DimensionDefinition } from '../../util/types';
+import SeriesModel from '../../model/Series';
+
+function createListFromArray(source: Source | any[], seriesModel: SeriesModel, opt?: {
+ generateCoord?: boolean
+ useEncodeDefaulter?: boolean
+}): List {
opt = opt || {};
- if (!Source.isInstance(source)) {
+ if (!(source instanceof Source)) {
source = Source.seriesDataToSource(source);
}
@@ -50,11 +45,13 @@ function createListFromArray(source, seriesModel, opt) {
var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
- var coordSysDimDefs;
+ var coordSysDimDefs: DimensionDefinitionLoose[];
if (coordSysInfo) {
coordSysDimDefs = zrUtil.map(coordSysInfo.coordSysDims, function (dim) {
- var dimInfo = {name: dim};
+ var dimInfo = {
+ name: dim
+ } as DimensionDefinition;
var axisModel = coordSysInfo.axisMap.get(dim);
if (axisModel) {
var axisType = axisModel.get('type');
@@ -82,8 +79,8 @@ function createListFromArray(source, seriesModel, opt) {
: null
});
- var firstCategoryDimIndex;
- var hasNameEncode;
+ var firstCategoryDimIndex: number;
+ var hasNameEncode: boolean;
coordSysInfo && zrUtil.each(dimInfoList, function (dimInfo, dimIndex) {
var coordDim = dimInfo.coordDim;
var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
@@ -108,7 +105,7 @@ function createListFromArray(source, seriesModel, opt) {
list.setCalculationInfo(stackCalculationInfo);
var dimValueGetter = (firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source))
- ? function (itemOpt, dimName, dataIndex, dimIndex) {
+ ? function (this: List, itemOpt: any, dimName: string, dataIndex: number, dimIndex: number) {
// Use dataIndex as ordinal value in categoryAxis
return dimIndex === firstCategoryDimIndex
? dataIndex
@@ -124,13 +121,13 @@ function createListFromArray(source, seriesModel, opt) {
function isNeedCompleteOrdinalData(source: Source) {
if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
- var sampleItem = firstDataNotNull(source.data || []);
+ var sampleItem = firstDataNotNull(source.data as ArrayLike<any> || []);
return sampleItem != null
&& !zrUtil.isArray(getDataItemValue(sampleItem));
}
}
-function firstDataNotNull(data) {
+function firstDataNotNull(data: ArrayLike<any>) {
var i = 0;
while (i < data.length && data[i] == null) {
i++;
diff --git a/src/chart/line/LineSeries.ts b/src/chart/line/LineSeries.ts
index 70b2e55..39152da 100644
--- a/src/chart/line/LineSeries.ts
+++ b/src/chart/line/LineSeries.ts
@@ -17,50 +17,99 @@
* under the License.
*/
-// @ts-nocheck
-
import {__DEV__} from '../../config';
import createListFromArray from '../helper/createListFromArray';
import SeriesModel from '../../model/Series';
+import {
+ SeriesOnCartesianOptionMixin,
+ SeriesOption,
+ SeriesOnPolarOptionMixin,
+ StackOptionMixin,
+ LabelOption,
+ LineStyleOption,
+ ItemStyleOption,
+ AreaStyleOption
+} from '../../util/types';
+import List from '../../data/List';
+import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import type Polar from '../../coord/polar/Polar';
+
+type SamplingFunc = (frame: number[]) => number
+
+export interface LineSeriesOption extends SeriesOption,
+ SeriesOnCartesianOptionMixin,
+ SeriesOnPolarOptionMixin,
+ StackOptionMixin {
+ coordinateSystem?: 'cartesian2d' | 'polar'
+
+ hoverAnimation?: boolean
+
+ // If clip the overflow value
+ clip?: boolean
+
+ label?: LabelOption
+
+ lineStyle?: LineStyleOption
+
+ itemStyle?: ItemStyleOption
+
+ areaStyle?: AreaStyleOption & {
+ origin?: 'auto' | 'start' | 'end'
+ }
+
+ step?: false | 'start' | 'end' | 'middle'
-export default SeriesModel.extend({
+ smooth?: boolean
- type: 'series.line',
+ smoothMonotone?: 'x' | 'y' | 'none'
- dependencies: ['grid', 'polar'],
+ connectNulls?: boolean
- getInitialData: function (option, ecModel) {
+ symbol?: string
+ symbolSize?: number | number[]
+ symbolRotate?: number
+
+ showSymbol?: boolean
+ // false | 'auto': follow the label interval strategy.
+ // true: show all symbols.
+ showAllSymbol?: 'auto'
+
+ sampling?: 'none' | 'average' | 'min' | 'max' | 'sum' | SamplingFunc
+}
+
+class LineSeriesModel extends SeriesModel<LineSeriesOption> {
+ static readonly type = 'series.line'
+ type = LineSeriesModel.type
+
+ static readonly dependencies = ['grid', 'polar']
+
+ coordinateSystem: Cartesian2D | Polar
+
+ getInitialData(option: LineSeriesOption): List {
if (__DEV__) {
var coordSys = option.coordinateSystem;
if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
throw new Error('Line not support coordinateSystem besides cartesian and polar');
}
}
- return createListFromArray(this.getSource(), this, {useEncodeDefaulter: true});
- },
+ return createListFromArray(this.getSource(), this, {
+ useEncodeDefaulter: true
+ });
+ }
- defaultOption: {
+ static defaultOption: LineSeriesOption = {
zlevel: 0,
z: 2,
coordinateSystem: 'cartesian2d',
legendHoverLink: true,
hoverAnimation: true,
- // stack: null
- // xAxisIndex: 0,
- // yAxisIndex: 0,
-
- // polarIndex: 0,
- // If clip the overflow value
clip: true,
- // cursor: null,
label: {
position: 'top'
},
- // itemStyle: {
- // },
lineStyle: {
width: 2,
@@ -102,4 +151,8 @@ export default SeriesModel.extend({
progressive: 0,
hoverLayerThreshold: Infinity
}
-});
\ No newline at end of file
+}
+
+SeriesModel.registerClass(LineSeriesModel);
+
+export default LineSeriesModel;
\ No newline at end of file
diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts
index 47ca269..2e2b8c0 100644
--- a/src/chart/line/LineView.ts
+++ b/src/chart/line/LineView.ts
@@ -17,8 +17,6 @@
* under the License.
*/
-// @ts-nocheck
-
// FIXME step not support polar
import {__DEV__} from '../../config';
@@ -28,12 +26,31 @@ import SymbolClz from '../helper/Symbol';
import lineAnimationDiff from './lineAnimationDiff';
import * as graphic from '../../util/graphic';
import * as modelUtil from '../../util/model';
-import {Polyline, Polygon} from './poly';
+import {ECPolyline, ECPolygon} from './poly';
import ChartView from '../../view/Chart';
import {prepareDataCoordInfo, getStackedOnPoint} from './helper';
import {createGridClipPath, createPolarClipPath} from '../helper/createClipPathFromCoordSys';
+import LineSeriesModel, { LineSeriesOption } from './LineSeries';
+import type GlobalModel from '../../model/Global';
+import type ExtensionAPI from '../../ExtensionAPI';
+// TODO
+import Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import Polar from '../../coord/polar/Polar';
+import type List from '../../data/List';
+import type { VisualMeta } from '../../component/visualMap/VisualMapModel';
+import type { Payload, Dictionary, ColorString } from '../../util/types';
+import type OrdinalScale from '../../scale/Ordinal';
+import type Axis2D from '../../coord/cartesian/Axis2D';
+
+
+type PolarArea = ReturnType<Polar['getArea']>
+type Cartesian2DArea = ReturnType<Cartesian2D['getArea']>
+
+interface SymbolExtended extends SymbolClz {
+ __temp: boolean
+}
-function isPointsSame(points1, points2) {
+function isPointsSame(points1: number[][], points2: number[][]) {
if (points1.length !== points2.length) {
return;
}
@@ -47,17 +64,15 @@ function isPointsSame(points1, points2) {
return true;
}
-function getSmooth(smooth) {
- return typeof (smooth) === 'number' ? smooth : (smooth ? 0.5 : 0);
+function getSmooth(smooth: number | boolean) {
+ return typeof smooth === 'number' ? smooth : (smooth ? 0.5 : 0);
}
-/**
- * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
- * @param {module:echarts/data/List} data
- * @param {Object} dataCoordInfo
- * @param {Array.<Array.<number>>} points
- */
-function getStackedOnPoints(coordSys, data, dataCoordInfo) {
+function getStackedOnPoints(
+ coordSys: Cartesian2D | Polar,
+ data: List,
+ dataCoordInfo: ReturnType<typeof prepareDataCoordInfo>
+) {
if (!dataCoordInfo.valueDim) {
return [];
}
@@ -70,7 +85,11 @@ function getStackedOnPoints(coordSys, data, dataCoordInfo) {
return points;
}
-function turnPointsIntoStep(points, coordSys, stepTurnAt) {
+function turnPointsIntoStep(
+ points: number[][],
+ coordSys: Cartesian2D | Polar,
+ stepTurnAt: 'start' | 'end' | 'middle'
+) {
var baseAxis = coordSys.getBaseAxis();
var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
@@ -110,8 +129,11 @@ function turnPointsIntoStep(points, coordSys, stepTurnAt) {
return stepPoints;
}
-function getVisualGradient(data, coordSys) {
- var visualMetaList = data.getVisual('visualMeta');
+function getVisualGradient(
+ data: List,
+ coordSys: Cartesian2D | Polar
+) {
+ var visualMetaList = data.getVisual('visualMeta') as VisualMeta[];
if (!visualMetaList || !visualMetaList.length || !data.count()) {
// When data.count() is 0, gradient range can not be calculated.
return;
@@ -124,14 +146,14 @@ function getVisualGradient(data, coordSys) {
return;
}
- var coordDim;
+ var coordDim: 'x' | 'y';
var visualMeta;
for (var i = visualMetaList.length - 1; i >= 0; i--) {
var dimIndex = visualMetaList[i].dimension;
var dimName = data.dimensions[dimIndex];
var dimInfo = data.getDimensionInfo(dimName);
- coordDim = dimInfo && dimInfo.coordDim;
+ coordDim = (dimInfo && dimInfo.coordDim) as 'x' | 'y';
// Can only be x or y
if (coordDim === 'x' || coordDim === 'y') {
visualMeta = visualMetaList[i];
@@ -155,9 +177,15 @@ function getVisualGradient(data, coordSys) {
var axis = coordSys.getAxis(coordDim);
+ interface ColorStop {
+ offset: number
+ coord?: number
+ color: ColorString
+ }
// dataToCoor mapping may not be linear, but must be monotonic.
- var colorStops = zrUtil.map(visualMeta.stops, function (stop) {
+ var colorStops: ColorStop[] = zrUtil.map(visualMeta.stops, function (stop) {
return {
+ offset: 0,
coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
color: stop.color
};
@@ -198,12 +226,16 @@ function getVisualGradient(data, coordSys) {
var gradient = new graphic.LinearGradient(0, 0, 0, 0, colorStops, true);
gradient[coordDim] = minCoord;
- gradient[coordDim + '2'] = maxCoord;
+ gradient[coordDim + '2' as 'x2' | 'y2'] = maxCoord;
return gradient;
}
-function getIsIgnoreFunc(seriesModel, data, coordSys) {
+function getIsIgnoreFunc(
+ seriesModel: LineSeriesModel,
+ data: List,
+ coordSys: Cartesian2D
+) {
var showAllSymbol = seriesModel.get('showAllSymbol');
var isAuto = showAllSymbol === 'auto';
@@ -228,24 +260,27 @@ function getIsIgnoreFunc(seriesModel, data, coordSys) {
// Otherwise follow the label interval strategy on category axis.
var categoryDataDim = data.mapDimension(categoryAxis.dim);
- var labelMap = {};
+ var labelMap: Dictionary<1> = {};
zrUtil.each(categoryAxis.getViewLabels(), function (labelItem) {
labelMap[labelItem.tickValue] = 1;
});
- return function (dataIndex) {
+ return function (dataIndex: number) {
return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
};
}
-function canShowAllSymbolForCategory(categoryAxis, data) {
+function canShowAllSymbolForCategory(
+ categoryAxis: Axis2D,
+ data: List
+) {
// In mose cases, line is monotonous on category axis, and the label size
// is close with each other. So we check the symbol size and some of the
// label size alone with the category axis to estimate whether all symbol
// can be shown without overlap.
var axisExtent = categoryAxis.getExtent();
- var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
+ var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / (categoryAxis.scale as OrdinalScale).count();
isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
// Sampling some points, max 5.
@@ -266,7 +301,11 @@ function canShowAllSymbolForCategory(categoryAxis, data) {
return true;
}
-function createLineClipPath(coordSys, hasAnimation, seriesModel) {
+function createLineClipPath(
+ coordSys: Cartesian2D | Polar,
+ hasAnimation: boolean,
+ seriesModel: LineSeriesModel
+) {
if (coordSys.type === 'cartesian2d') {
var isHorizontal = coordSys.getBaseAxis().isHorizontal();
var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel);
@@ -291,11 +330,31 @@ function createLineClipPath(coordSys, hasAnimation, seriesModel) {
}
-export default ChartView.extend({
+class LineView extends ChartView {
+
+ static readonly type = 'line'
+
+ _symbolDraw: SymbolDraw
+
+ _lineGroup: graphic.Group
+ _coordSys: Cartesian2D | Polar
+
+ _polyline: ECPolyline
+ _polygon: ECPolygon
+
+ _stackedOnPoints: number[][]
+ _points: number[][]
- type: 'line',
+ _step: LineSeriesOption['step']
+ _valueOrigin: LineSeriesOption['areaStyle']['origin']
- init: function () {
+ _clipShapeForSymbol: {
+ contain(x: number, y: number): boolean
+ }
+
+ _data: List
+
+ init() {
var lineGroup = new graphic.Group();
var symbolDraw = new SymbolDraw();
@@ -303,9 +362,9 @@ export default ChartView.extend({
this._symbolDraw = symbolDraw;
this._lineGroup = lineGroup;
- },
+ }
- render: function (seriesModel, ecModel, api) {
+ render(seriesModel: LineSeriesModel, ecModel: GlobalModel, api: ExtensionAPI) {
var coordSys = seriesModel.coordinateSystem;
var group = this.group;
var data = seriesModel.getData();
@@ -335,11 +394,11 @@ export default ChartView.extend({
var showSymbol = seriesModel.get('showSymbol');
var isIgnoreFunc = showSymbol && !isCoordSysPolar
- && getIsIgnoreFunc(seriesModel, data, coordSys);
+ && getIsIgnoreFunc(seriesModel, data, coordSys as Cartesian2D);
// Remove temporary symbols
var oldData = this._data;
- oldData && oldData.eachItemGraphicEl(function (el, idx) {
+ oldData && oldData.eachItemGraphicEl(function (el: SymbolExtended, idx) {
if (el.__temp) {
group.remove(el);
oldData.setItemGraphicEl(idx, null);
@@ -354,21 +413,21 @@ export default ChartView.extend({
group.add(lineGroup);
// FIXME step not support polar
- var step = !isCoordSysPolar && seriesModel.get('step');
- var clipShapeForSymbol;
+ var step = !isCoordSysPolar ? seriesModel.get('step') : false;
+ var clipShapeForSymbol: PolarArea | Cartesian2DArea;
if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
clipShapeForSymbol = coordSys.getArea();
// Avoid float number rounding error for symbol on the edge of axis extent.
// See #7913 and `test/dataZoom-clip.html`.
- if (clipShapeForSymbol.width != null) {
- clipShapeForSymbol.x -= 0.1;
- clipShapeForSymbol.y -= 0.1;
- clipShapeForSymbol.width += 0.2;
- clipShapeForSymbol.height += 0.2;
+ if ((clipShapeForSymbol as Cartesian2DArea).width != null) {
+ (clipShapeForSymbol as Cartesian2DArea).x -= 0.1;
+ (clipShapeForSymbol as Cartesian2DArea).y -= 0.1;
+ (clipShapeForSymbol as Cartesian2DArea).width += 0.2;
+ (clipShapeForSymbol as Cartesian2DArea).height += 0.2;
}
- else if (clipShapeForSymbol.r0) {
- clipShapeForSymbol.r0 -= 0.5;
- clipShapeForSymbol.r1 += 0.5;
+ else if ((clipShapeForSymbol as PolarArea).r0) {
+ (clipShapeForSymbol as PolarArea).r0 -= 0.5;
+ (clipShapeForSymbol as PolarArea).r += 0.5;
}
}
this._clipShapeForSymbol = clipShapeForSymbol;
@@ -387,11 +446,10 @@ export default ChartView.extend({
stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
}
- polyline = this._newPolyline(points, coordSys, hasAnimation);
+ polyline = this._newPolyline(points);
if (isAreaChart) {
polygon = this._newPolygon(
- points, stackedOnPoints,
- coordSys, hasAnimation
+ points, stackedOnPoints
);
}
lineGroup.setClipPath(createLineClipPath(coordSys, true, seriesModel));
@@ -400,8 +458,7 @@ export default ChartView.extend({
if (isAreaChart && !polygon) {
// If areaStyle is added
polygon = this._newPolygon(
- points, stackedOnPoints,
- coordSys, hasAnimation
+ points, stackedOnPoints
);
}
else if (polygon && !isAreaChart) {
@@ -467,8 +524,7 @@ export default ChartView.extend({
}
));
- var smooth = seriesModel.get('smooth');
- smooth = getSmooth(seriesModel.get('smooth'));
+ var smooth = getSmooth(seriesModel.get('smooth'));
polyline.setShape({
smooth: smooth,
smoothMonotone: seriesModel.get('smoothMonotone'),
@@ -507,19 +563,24 @@ export default ChartView.extend({
this._points = points;
this._step = step;
this._valueOrigin = valueOrigin;
- },
+ }
- dispose: function () {},
+ dispose() {}
- highlight: function (seriesModel, ecModel, api, payload) {
+ highlight(
+ seriesModel: LineSeriesModel,
+ ecModel: GlobalModel,
+ api: ExtensionAPI,
+ payload: Payload
+ ) {
var data = seriesModel.getData();
var dataIndex = modelUtil.queryDataIndex(data, payload);
if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
- var symbol = data.getItemGraphicEl(dataIndex);
+ var symbol = data.getItemGraphicEl(dataIndex) as SymbolClz;
if (!symbol) {
// Create a temporary symbol if it is not exists
- var pt = data.getItemLayout(dataIndex);
+ var pt = data.getItemLayout(dataIndex) as number[];
if (!pt) {
// Null data
return;
@@ -535,7 +596,7 @@ export default ChartView.extend({
seriesModel.get('z')
);
symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
- symbol.__temp = true;
+ (symbol as SymbolExtended).__temp = true;
data.setItemGraphicEl(dataIndex, symbol);
// Stop scale animation
@@ -551,13 +612,18 @@ export default ChartView.extend({
this, seriesModel, ecModel, api, payload
);
}
- },
+ }
- downplay: function (seriesModel, ecModel, api, payload) {
+ downplay(
+ seriesModel: LineSeriesModel,
+ ecModel: GlobalModel,
+ api: ExtensionAPI,
+ payload: Payload
+ ) {
var data = seriesModel.getData();
- var dataIndex = modelUtil.queryDataIndex(data, payload);
+ var dataIndex = modelUtil.queryDataIndex(data, payload) as number;
if (dataIndex != null && dataIndex >= 0) {
- var symbol = data.getItemGraphicEl(dataIndex);
+ var symbol = data.getItemGraphicEl(dataIndex) as SymbolExtended;
if (symbol) {
if (symbol.__temp) {
data.setItemGraphicEl(dataIndex, null);
@@ -576,21 +642,16 @@ export default ChartView.extend({
this, seriesModel, ecModel, api, payload
);
}
- },
+ }
- /**
- * @param {module:zrender/container/Group} group
- * @param {Array.<Array.<number>>} points
- * @private
- */
- _newPolyline: function (points) {
+ _newPolyline(points: number[][]) {
var polyline = this._polyline;
// Remove previous created polyline
if (polyline) {
this._lineGroup.remove(polyline);
}
- polyline = new Polyline({
+ polyline = new ECPolyline({
shape: {
points: points
},
@@ -603,22 +664,16 @@ export default ChartView.extend({
this._polyline = polyline;
return polyline;
- },
+ }
- /**
- * @param {module:zrender/container/Group} group
- * @param {Array.<Array.<number>>} stackedOnPoints
- * @param {Array.<Array.<number>>} points
- * @private
- */
- _newPolygon: function (points, stackedOnPoints) {
+ _newPolygon(points: number[][], stackedOnPoints: number[][]) {
var polygon = this._polygon;
// Remove previous created polygon
if (polygon) {
this._lineGroup.remove(polygon);
}
- polygon = new Polygon({
+ polygon = new ECPolygon({
shape: {
points: points,
stackedOnPoints: stackedOnPoints
@@ -630,13 +685,20 @@ export default ChartView.extend({
this._polygon = polygon;
return polygon;
- },
+ }
/**
* @private
*/
// FIXME Two value axis
- _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
+ _updateAnimation(
+ data: List,
+ stackedOnPoints: number[][],
+ coordSys: Cartesian2D | Polar,
+ api: ExtensionAPI,
+ step: LineSeriesOption['step'],
+ valueOrigin: LineSeriesOption['areaStyle']['origin']
+ ) {
var polyline = this._polyline;
var polygon = this._polygon;
var seriesModel = data.hostModel;
@@ -662,7 +724,7 @@ export default ChartView.extend({
// `diff.current` is subset of `current` (which should be ensured by
// turnPointsIntoStep), so points in `__points` can be updated when
// points in `current` are update during animation.
- polyline.shape.__points = diff.current;
+ (polyline.shape as any).__points = diff.current;
polyline.shape.points = current;
graphic.updateProps(polyline, {
@@ -684,13 +746,16 @@ export default ChartView.extend({
}, seriesModel);
}
- var updatedDataInfo = [];
+ var updatedDataInfo: {
+ el: SymbolExtended,
+ ptIdx: number
+ }[] = [];
var diffStatus = diff.status;
for (var i = 0; i < diffStatus.length; i++) {
var cmd = diffStatus[i].cmd;
if (cmd === '=') {
- var el = data.getItemGraphicEl(diffStatus[i].idx1);
+ var el = data.getItemGraphicEl(diffStatus[i].idx1) as SymbolExtended;
if (el) {
updatedDataInfo.push({
el: el,
@@ -704,19 +769,19 @@ export default ChartView.extend({
polyline.animators[0].during(function () {
for (var i = 0; i < updatedDataInfo.length; i++) {
var el = updatedDataInfo[i].el;
- el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
+ el.attr('position', (polyline.shape as any).__points[updatedDataInfo[i].ptIdx]);
}
});
}
- },
+ }
- remove: function (ecModel) {
+ remove(ecModel: GlobalModel) {
var group = this.group;
var oldData = this._data;
this._lineGroup.removeAll();
this._symbolDraw.remove(true);
// Remove temporary created elements when highlighting
- oldData && oldData.eachItemGraphicEl(function (el, idx) {
+ oldData && oldData.eachItemGraphicEl(function (el: SymbolExtended, idx) {
if (el.__temp) {
group.remove(el);
oldData.setItemGraphicEl(idx, null);
@@ -730,4 +795,8 @@ export default ChartView.extend({
this._stackedOnPoints =
this._data = null;
}
-});
\ No newline at end of file
+}
+
+ChartView.registerClass(LineView);
+
+export default ChartView;
\ No newline at end of file
diff --git a/src/chart/line/helper.ts b/src/chart/line/helper.ts
index 7fb5216..2090ae6 100644
--- a/src/chart/line/helper.ts
+++ b/src/chart/line/helper.ts
@@ -17,19 +17,33 @@
* under the License.
*/
-// @ts-nocheck
-
import {isDimensionStacked} from '../../data/helper/dataStackHelper';
import {map} from 'zrender/src/core/util';
+import type Polar from '../../coord/polar/Polar';
+import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import List from '../../data/List';
+import Axis from '../../coord/Axis';
+import type { LineSeriesOption } from './LineSeries';
+
+interface CoordInfo {
+ dataDimsForPoint: string[]
+ valueStart: number
+ valueAxisDim: string
+ baseAxisDim: string
+ stacked: boolean
+ valueDim: string
+ baseDim: string
+ baseDataOffset: number
+ stackedOverDimension: string
+}
-/**
- * @param {Object} coordSys
- * @param {module:echarts/data/List} data
- * @param {string} valueOrigin lineSeries.option.areaStyle.origin
- */
-export function prepareDataCoordInfo(coordSys, data, valueOrigin) {
+export function prepareDataCoordInfo(
+ coordSys: Cartesian2D | Polar,
+ data: List,
+ valueOrigin?: LineSeriesOption['areaStyle']['origin']
+): CoordInfo {
var baseAxis = coordSys.getBaseAxis();
- var valueAxis = coordSys.getOtherAxis(baseAxis);
+ var valueAxis = coordSys.getOtherAxis(baseAxis as any);
var valueStart = getValueStart(valueAxis, valueOrigin);
var baseAxisDim = baseAxis.dim;
@@ -42,12 +56,12 @@ export function prepareDataCoordInfo(coordSys, data, valueOrigin) {
return data.mapDimension(coordDim);
});
- var stacked;
+ var stacked = false;
var stackResultDim = data.getCalculationInfo('stackResultDimension');
- if (stacked |= isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
+ if (stacked = stacked || isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
dims[0] = stackResultDim;
}
- if (stacked |= isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
+ if (stacked = stacked || isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
dims[1] = stackResultDim;
}
@@ -64,7 +78,7 @@ export function prepareDataCoordInfo(coordSys, data, valueOrigin) {
};
}
-function getValueStart(valueAxis, valueOrigin) {
+function getValueStart(valueAxis: Axis, valueOrigin: LineSeriesOption['areaStyle']['origin']) {
var valueStart = 0;
var extent = valueAxis.scale.getExtent();
@@ -90,10 +104,15 @@ function getValueStart(valueAxis, valueOrigin) {
return valueStart;
}
-export function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
+export function getStackedOnPoint(
+ dataCoordInfo: CoordInfo,
+ coordSys: Cartesian2D | Polar,
+ data: List,
+ idx: number
+ ) {
var value = NaN;
if (dataCoordInfo.stacked) {
- value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
+ value = data.get(data.getCalculationInfo('stackedOverDimension'), idx) as number;
}
if (isNaN(value)) {
value = dataCoordInfo.valueStart;
diff --git a/src/chart/line/lineAnimationDiff.ts b/src/chart/line/lineAnimationDiff.ts
index 449ad29..f6ccda6 100644
--- a/src/chart/line/lineAnimationDiff.ts
+++ b/src/chart/line/lineAnimationDiff.ts
@@ -17,39 +17,20 @@
* under the License.
*/
-// @ts-nocheck
-
import {prepareDataCoordInfo, getStackedOnPoint} from './helper';
+import List from '../../data/List';
+import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import type Polar from '../../coord/polar/Polar';
+import { LineSeriesOption } from './LineSeries';
+
+interface DiffItem {
+ cmd: '+' | '=' | '-'
+ idx: number
+ idx1?: number
+}
-// var arrayDiff = require('zrender/src/core/arrayDiff');
-// 'zrender/src/core/arrayDiff' has been used before, but it did
-// not do well in performance when roam with fixed dataZoom window.
-
-// function convertToIntId(newIdList, oldIdList) {
-// // Generate int id instead of string id.
-// // Compare string maybe slow in score function of arrDiff
-
-// // Assume id in idList are all unique
-// var idIndicesMap = {};
-// var idx = 0;
-// for (var i = 0; i < newIdList.length; i++) {
-// idIndicesMap[newIdList[i]] = idx;
-// newIdList[i] = idx++;
-// }
-// for (var i = 0; i < oldIdList.length; i++) {
-// var oldId = oldIdList[i];
-// // Same with newIdList
-// if (idIndicesMap[oldId]) {
-// oldIdList[i] = idIndicesMap[oldId];
-// }
-// else {
-// oldIdList[i] = idx++;
-// }
-// }
-// }
-
-function diffData(oldData, newData) {
- var diffResult = [];
+function diffData(oldData: List, newData: List) {
+ var diffResult: DiffItem[] = [];
newData.diff(oldData)
.add(function (idx) {
@@ -67,10 +48,11 @@ function diffData(oldData, newData) {
}
export default function (
- oldData, newData,
- oldStackedOnPoints, newStackedOnPoints,
- oldCoordSys, newCoordSys,
- oldValueOrigin, newValueOrigin
+ oldData: List, newData: List,
+ oldStackedOnPoints: number[][], newStackedOnPoints: number[][],
+ oldCoordSys: Cartesian2D | Polar, newCoordSys: Cartesian2D | Polar,
+ oldValueOrigin: LineSeriesOption['areaStyle']['origin'],
+ newValueOrigin: LineSeriesOption['areaStyle']['origin']
) {
var diff = diffData(oldData, newData);
@@ -82,15 +64,15 @@ export default function (
// // FIXME One data ?
// diff = arrayDiff(oldIdList, newIdList);
- var currPoints = [];
- var nextPoints = [];
+ var currPoints: number[][] = [];
+ var nextPoints: number[][] = [];
// Points for stacking base line
- var currStackedPoints = [];
- var nextStackedPoints = [];
+ var currStackedPoints: number[][] = [];
+ var nextStackedPoints: number[][] = [];
var status = [];
- var sortedIndices = [];
- var rawIndices = [];
+ var sortedIndices: number[] = [];
+ var rawIndices: number[] = [];
var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
@@ -103,8 +85,8 @@ export default function (
// Which is in case remvoing or add more than one data in the tail or head
switch (diffItem.cmd) {
case '=':
- var currentPt = oldData.getItemLayout(diffItem.idx);
- var nextPt = newData.getItemLayout(diffItem.idx1);
+ var currentPt = oldData.getItemLayout(diffItem.idx) as number[];
+ var nextPt = newData.getItemLayout(diffItem.idx1) as number[];
// If previous data is NaN, use next point directly
if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
currentPt = nextPt.slice();
@@ -126,7 +108,7 @@ export default function (
])
);
- nextPoints.push(newData.getItemLayout(idx).slice());
+ nextPoints.push((newData.getItemLayout(idx) as number[]).slice());
currStackedPoints.push(
getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx)
@@ -141,7 +123,7 @@ export default function (
// Data is replaced. In the case of dynamic data queue
// FIXME FIXME FIXME
if (rawIndex !== idx) {
- currPoints.push(oldData.getItemLayout(idx));
+ currPoints.push(oldData.getItemLayout(idx) as number[]);
nextPoints.push(newCoordSys.dataToPoint([
oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx),
oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)
diff --git a/src/chart/line/poly.ts b/src/chart/line/poly.ts
index 02d0d79..c9904f6 100644
--- a/src/chart/line/poly.ts
+++ b/src/chart/line/poly.ts
@@ -17,11 +17,9 @@
* under the License.
*/
-// @ts-nocheck
-
// Poly path support NaN point
-import Path from 'zrender/src/graphic/Path';
+import Path, { PathProps } from 'zrender/src/graphic/Path';
import * as vec2 from 'zrender/src/core/vector';
import fixClipWithShadow from 'zrender/src/graphic/helper/fixClipWithShadow';
@@ -32,42 +30,32 @@ var scaleAndAdd = vec2.scaleAndAdd;
var v2Copy = vec2.copy;
// Temporary variable
-var v = [];
-var cp0 = [];
-var cp1 = [];
+var v: number[] = [];
+var cp0: number[] = [];
+var cp1: number[] = [];
-function isPointNull(p) {
+function isPointNull(p: number[]) {
return isNaN(p[0]) || isNaN(p[1]);
}
function drawSegment(
- ctx, points, start, segLen, allLen,
- dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
+ ctx: CanvasRenderingContext2D,
+ points: number[][],
+ start: number,
+ segLen: number,
+ allLen: number,
+ dir: number,
+ smoothMin: number[],
+ smoothMax: number[],
+ smooth: number,
+ smoothMonotone: 'x' | 'y' | 'none',
+ connectNulls: boolean
) {
- // if (smoothMonotone == null) {
- // if (isMono(points, 'x')) {
- // return drawMono(ctx, points, start, segLen, allLen,
- // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
- // }
- // else if (isMono(points, 'y')) {
- // return drawMono(ctx, points, start, segLen, allLen,
- // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
- // }
- // else {
- // return drawNonMono.apply(this, arguments);
- // }
- // }
- // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
- // return drawMono.apply(this, arguments);
- // }
- // else {
- // return drawNonMono.apply(this, arguments);
- // }
if (smoothMonotone === 'none' || !smoothMonotone) {
- return drawNonMono.apply(this, arguments);
+ return drawNonMono.apply(null, arguments as any);
}
else {
- return drawMono.apply(this, arguments);
+ return drawMono.apply(null, arguments as any);
}
}
@@ -112,8 +100,17 @@ function drawSegment(
* either in x or y dimension.
*/
function drawMono(
- ctx, points, start, segLen, allLen,
- dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
+ ctx: CanvasRenderingContext2D,
+ points: number[][],
+ start: number,
+ segLen: number,
+ allLen: number,
+ dir: number,
+ smoothMin: number[],
+ smoothMax: number[],
+ smooth: number,
+ smoothMonotone: 'x' | 'y' | 'none',
+ connectNulls: boolean
) {
var prevIdx = 0;
var idx = start;
@@ -171,8 +168,17 @@ function drawMono(
* y dimension.
*/
function drawNonMono(
- ctx, points, start, segLen, allLen,
- dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
+ ctx: CanvasRenderingContext2D,
+ points: number[][],
+ start: number,
+ segLen: number,
+ allLen: number,
+ dir: number,
+ smoothMin: number[],
+ smoothMax: number[],
+ smooth: number,
+ smoothMonotone: 'x' | 'y' | 'none',
+ connectNulls: boolean
) {
var prevIdx = 0;
var idx = start;
@@ -263,7 +269,7 @@ function drawNonMono(
return k;
}
-function getBoundingBox(points, smoothConstraint) {
+function getBoundingBox(points: number[][], smoothConstraint?: boolean) {
var ptMin = [Infinity, Infinity];
var ptMax = [-Infinity, -Infinity];
if (smoothConstraint) {
@@ -289,31 +295,34 @@ function getBoundingBox(points, smoothConstraint) {
};
}
-export var Polyline = Path.extend({
-
- type: 'ec-polyline',
-
- shape: {
- points: [],
-
- smooth: 0,
+class ECPolylineShape {
+ points: number[][]
+ smooth = 0
+ smoothConstraint = true
+ smoothMonotone: 'x' | 'y' | 'none'
+ connectNulls = false
+}
- smoothConstraint: true,
+interface ECPolylineProps extends PathProps {
+ shape?: Partial<ECPolylineShape>
+}
- smoothMonotone: null,
+export class ECPolyline extends Path<ECPolylineProps> {
- connectNulls: false
- },
+ readonly type = 'ec-polyline'
- style: {
- fill: null,
+ shape: ECPolylineShape
- stroke: '#000'
- },
+ brush = fixClipWithShadow(Path.prototype.brush)
- brush: fixClipWithShadow(Path.prototype.brush),
+ constructor(opts?: ECPolylineProps) {
+ super(opts, {
+ stroke: '#000',
+ fill: null
+ }, new ECPolylineShape());
+ }
- buildPath: function (ctx, shape) {
+ buildPath(ctx: CanvasRenderingContext2D, shape: ECPolylineShape) {
var points = shape.points;
var i = 0;
@@ -342,32 +351,29 @@ export var Polyline = Path.extend({
) + 1;
}
}
-});
-
-export var Polygon = Path.extend({
-
- type: 'ec-polygon',
-
- shape: {
- points: [],
-
- // Offset between stacked base points and points
- stackedOnPoints: [],
-
- smooth: 0,
-
- stackedOnSmooth: 0,
+}
+class ECPolygonShape extends ECPolylineShape {
+ // Offset between stacked base points and points
+ stackedOnPoints: number[][]
+ stackedOnSmooth: number
+}
- smoothConstraint: true,
+interface ECPolygonProps extends PathProps {
+ shape?: Partial<ECPolygonShape>
+}
+export class ECPolygon extends Path {
- smoothMonotone: null,
+ readonly type = 'ec-polygon'
- connectNulls: false
- },
+ shape: ECPolygonShape
- brush: fixClipWithShadow(Path.prototype.brush),
+ // @ts-ignore
+ brush = fixClipWithShadow(Path.prototype.brush)
- buildPath: function (ctx, shape) {
+ constructor(opts?: ECPolygonProps) {
+ super(opts, null, new ECPolygonShape());
+ }
+ buildPath(ctx: CanvasRenderingContext2D, shape: ECPolygonShape) {
var points = shape.points;
var stackedOnPoints = shape.stackedOnPoints;
@@ -406,4 +412,4 @@ export var Polygon = Path.extend({
ctx.closePath();
}
}
-});
+}
\ No newline at end of file
diff --git a/src/chart/themeRiver/ThemeRiverView.ts b/src/chart/themeRiver/ThemeRiverView.ts
index d3a44be..f809cc7 100644
--- a/src/chart/themeRiver/ThemeRiverView.ts
+++ b/src/chart/themeRiver/ThemeRiverView.ts
@@ -20,7 +20,7 @@
// @ts-nocheck
import * as echarts from '../../echarts';
-import {Polygon} from '../line/poly';
+import {ECPolygon} from '../line/poly';
import * as graphic from '../../util/graphic';
import {bind, extend} from 'zrender/src/core/util';
import DataDiffer from '../../data/DataDiffer';
@@ -92,7 +92,7 @@ export default echarts.extendChartView({
var margin = labelModel.get('margin');
if (status === 'add') {
var layerGroup = newLayersGroups[idx] = new graphic.Group();
- polygon = new Polygon({
+ polygon = new ECPolygon({
shape: {
points: points0,
stackedOnPoints: points1,
diff --git a/src/component/axisPointer.ts b/src/component/axisPointer.ts
index 3cb58ff..53a6013 100644
--- a/src/component/axisPointer.ts
+++ b/src/component/axisPointer.ts
@@ -29,6 +29,9 @@ import './axisPointer/AxisPointerView';
// CartesianAxisPointer should be able to required somewhere.
import './axisPointer/CartesianAxisPointer';
import AxisPointerModel from './axisPointer/AxisPointerModel';
+import ComponentModel from '../model/Component';
+
+ComponentModel.registerClass(AxisPointerModel);
echarts.registerPreprocessor(function (option) {
// Always has a global axisPointerModel for default setting.
@@ -61,3 +64,4 @@ echarts.registerAction({
event: 'updateAxisPointer',
update: ':updateAxisPointer'
}, axisTrigger);
+
diff --git a/src/component/axisPointer/AxisPointerModel.ts b/src/component/axisPointer/AxisPointerModel.ts
index dbf7d5b..ebc49c0 100644
--- a/src/component/axisPointer/AxisPointerModel.ts
+++ b/src/component/axisPointer/AxisPointerModel.ts
@@ -147,6 +147,4 @@ class AxisPointerModel extends ComponentModel<AxisPointerOption> {
}
}
-ComponentModel.registerClass(AxisPointerModel);
-
export default AxisPointerModel;
diff --git a/src/component/dataZoom/InsideZoomView.ts b/src/component/dataZoom/InsideZoomView.ts
index 45366ec..7f1d124 100644
--- a/src/component/dataZoom/InsideZoomView.ts
+++ b/src/component/dataZoom/InsideZoomView.ts
@@ -26,11 +26,9 @@ import ExtensionAPI from '../../ExtensionAPI';
import ComponentView from '../../view/Component';
import { each, map, bind } from 'zrender/src/core/util';
import RoamController, {RoamEventParams} from '../helper/RoamController';
-import { ZRElementEvent } from '../../util/types';
import { AxisBaseModel } from '../../coord/AxisBaseModel';
import Polar from '../../coord/polar/Polar';
import SingleAxis from '../../coord/single/SingleAxis';
-import { CoordinateSystem } from '../../coord/CoordinateSystem';
type SupportedCoordSysName = 'polar' | 'grid' | 'singleAxis';
@@ -224,9 +222,7 @@ interface GetDirectionInfo {
): DirectionInfo
}
-var getDirectionInfo: {
- [key in 'grid' | 'polar' | 'singleAxis']: GetDirectionInfo
-} = {
+var getDirectionInfo: Record<'grid' | 'polar' | 'singleAxis', GetDirectionInfo> = {
grid(oldPoint, newPoint, axisModel, controller, coordInfo) {
var axis = axisModel.axis;
diff --git a/src/component/toolbox/feature/MagicType.ts b/src/component/toolbox/feature/MagicType.ts
index 95456e0..8081e49 100644
--- a/src/component/toolbox/feature/MagicType.ts
+++ b/src/component/toolbox/feature/MagicType.ts
@@ -185,7 +185,7 @@ type SeriesOptGenreator = (
}>,
model: ToolboxFeatureModel<ToolboxMagicTypeFeatureOption>
) => SeriesOption
-const seriesOptGenreator: {[key in IconType]: SeriesOptGenreator} = {
+const seriesOptGenreator: Record<IconType, SeriesOptGenreator> = {
'line': function (seriesType, seriesId, seriesModel, model) {
if (seriesType === 'bar') {
return zrUtil.merge({
diff --git a/src/component/visualMap/VisualMapModel.ts b/src/component/visualMap/VisualMapModel.ts
index 15de99c..99c3037 100644
--- a/src/component/visualMap/VisualMapModel.ts
+++ b/src/component/visualMap/VisualMapModel.ts
@@ -151,7 +151,9 @@ export interface VisualMapOption<T extends VisualOptionBase = VisualOptionBase>
export interface VisualMeta {
stops: { value: number, color: ColorString}[]
- outerColors: [ColorString, ColorString]
+ outerColors: ColorString[]
+
+ dimension?: number
}
class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends ComponentModel<Opts> {
@@ -178,7 +180,7 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com
protected _dataExtent: [number, number]
- targetVisuals = {}
+ targetVisuals = {} as ReturnType<typeof visualSolution.createVisualMappings>
controllerVisuals = {} as ReturnType<typeof visualSolution.createVisualMappings>
diff --git a/src/component/visualMap/helper.ts b/src/component/visualMap/helper.ts
index 3910653..3e2eae5 100644
--- a/src/component/visualMap/helper.ts
+++ b/src/component/visualMap/helper.ts
@@ -56,9 +56,7 @@ export function getItemAlign(
var reals = paramsSet[realIndex];
var fakeValue = [0, null, 10];
- var layoutInput = {} as {
- [key in ItemAlign]: number | string
- };
+ var layoutInput = {} as Record<ItemAlign, number | string>;
for (var i = 0; i < 3; i++) {
layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
diff --git a/src/component/visualMap/visualEncoding.ts b/src/component/visualMap/visualEncoding.ts
index df2377d..40049b5 100644
--- a/src/component/visualMap/visualEncoding.ts
+++ b/src/component/visualMap/visualEncoding.ts
@@ -17,20 +17,21 @@
* under the License.
*/
-// @ts-nocheck
-
import * as echarts from '../../echarts';
import * as zrUtil from 'zrender/src/core/util';
import * as visualSolution from '../../visual/visualSolution';
import VisualMapping from '../../visual/VisualMapping';
+import VisualMapModel, { VisualMeta } from './VisualMapModel';
+import { StageHandlerProgressExecutor, BuiltinVisualProperty, ParsedValue } from '../../util/types';
+import SeriesModel from '../../model/Series';
var VISUAL_PRIORITY = echarts.PRIORITY.VISUAL.COMPONENT;
echarts.registerVisual(VISUAL_PRIORITY, {
createOnAllSeries: true,
reset: function (seriesModel, ecModel) {
- var resetDefines = [];
- ecModel.eachComponent('visualMap', function (visualMapModel) {
+ var resetDefines: StageHandlerProgressExecutor[] = [];
+ ecModel.eachComponent('visualMap', function (visualMapModel: VisualMapModel) {
var pipelineContext = seriesModel.pipelineContext;
if (!visualMapModel.isTargetSeries(seriesModel)
|| (pipelineContext && pipelineContext.large)
@@ -55,13 +56,16 @@ echarts.registerVisual(VISUAL_PRIORITY, {
createOnAllSeries: true,
reset: function (seriesModel, ecModel) {
var data = seriesModel.getData();
- var visualMetaList = [];
+ var visualMetaList: VisualMeta[] = [];
- ecModel.eachComponent('visualMap', function (visualMapModel) {
+ ecModel.eachComponent('visualMap', function (visualMapModel: VisualMapModel) {
if (visualMapModel.isTargetSeries(seriesModel)) {
var visualMeta = visualMapModel.getVisualMeta(
zrUtil.bind(getColorVisual, null, seriesModel, visualMapModel)
- ) || {stops: [], outerColors: []};
+ ) || {
+ stops: [],
+ outerColors: []
+ } as VisualMeta;
var concreteDim = visualMapModel.getDataDimension(data);
var dimInfo = data.getDimensionInfo(concreteDim);
@@ -81,28 +85,33 @@ echarts.registerVisual(VISUAL_PRIORITY, {
// FIXME
// performance and export for heatmap?
// value can be Infinity or -Infinity
-function getColorVisual(seriesModel, visualMapModel, value, valueState) {
+function getColorVisual(
+ seriesModel: SeriesModel,
+ visualMapModel: VisualMapModel,
+ value: ParsedValue,
+ valueState: VisualMapModel['stateList'][number]
+) {
var mappings = visualMapModel.targetVisuals[valueState];
var visualTypes = VisualMapping.prepareVisualTypes(mappings);
- var resultVisual = {
+ var resultVisual: Partial<Record<BuiltinVisualProperty, any>> = {
color: seriesModel.getData().getVisual('color') // default color.
};
for (var i = 0, len = visualTypes.length; i < len; i++) {
var type = visualTypes[i];
var mapping = mappings[
- type === 'opacity' ? '__alphaForOpacity' : type
+ (type === 'opacity' ? '__alphaForOpacity' : type) as BuiltinVisualProperty
];
mapping && mapping.applyVisual(value, getVisual, setVisual);
}
return resultVisual.color;
- function getVisual(key) {
+ function getVisual(key: BuiltinVisualProperty) {
return resultVisual[key];
}
- function setVisual(key, value) {
+ function setVisual(key: BuiltinVisualProperty, value: any) {
resultVisual[key] = value;
}
}
diff --git a/src/coord/cartesian/Cartesian2D.ts b/src/coord/cartesian/Cartesian2D.ts
index 8105fbd..4daae85 100644
--- a/src/coord/cartesian/Cartesian2D.ts
+++ b/src/coord/cartesian/Cartesian2D.ts
@@ -103,7 +103,7 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem {
* Get rect area of cartesian.
* Area will have a contain function to determine if a point is in the coordinate system.
*/
- getArea(): BoundingRect {
+ getArea(): Cartesian2DArea {
var xExtent = this.getAxis('x').getGlobalExtent();
var yExtent = this.getAxis('y').getGlobalExtent();
var x = Math.min(xExtent[0], xExtent[1]);
@@ -116,4 +116,6 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem {
};
+interface Cartesian2DArea extends BoundingRect {}
+
export default Cartesian2D;
diff --git a/src/coord/polar/Polar.ts b/src/coord/polar/Polar.ts
index b711d3e..ec76586 100644
--- a/src/coord/polar/Polar.ts
+++ b/src/coord/polar/Polar.ts
@@ -202,7 +202,7 @@ class Polar implements CoordinateSystem, CoordinateSystemMaster {
* Get ring area of cartesian.
* Area will have a contain function to determine if a point is in the coordinate system.
*/
- getArea() {
+ getArea(): PolarArea {
var angleAxis = this.getAngleAxis();
var radiusAxis = this.getRadiusAxis();
@@ -253,4 +253,15 @@ function getCoordSys(finder: ParsedModelFinder) {
|| seriesModel && seriesModel.coordinateSystem as Polar;
}
+interface PolarArea {
+ cx: number
+ cy: number
+ r0: number
+ r: number
+ startAngle: number
+ endAngle: number
+ clockwise: boolean
+ contain(x: number, y: number): boolean
+}
+
export default Polar;
\ No newline at end of file
diff --git a/src/data/DataDimensionInfo.ts b/src/data/DataDimensionInfo.ts
index 71aa57b..cc15369 100644
--- a/src/data/DataDimensionInfo.ts
+++ b/src/data/DataDimensionInfo.ts
@@ -40,7 +40,7 @@ class DataDimensionInfo {
* If displayName given, the tooltip will displayed vertically.
* Optional.
*/
- displayName: string;
+ displayName?: string;
// FIXME: check whether it is still used.
// See Series.ts#formatArrayValue
@@ -54,19 +54,19 @@ class DataDimensionInfo {
* (That is determined by whether `isExtraCoord` is `true`).
* Mandatory.
*/
- coordDim: string;
+ coordDim?: string;
/**
* The index of this dimension in `series.encode[coordDim]`.
* Mandatory.
*/
- coordDimIndex: number;
+ coordDimIndex?: number;
/**
* This index of this dimension info in `data/List#_dimensionInfos`.
* Mandatory after added to `data/List`.
*/
- index: number;
+ index?: number;
/**
* The format of `otherDims` is:
@@ -101,27 +101,27 @@ class DataDimensionInfo {
*
* This prop should never be `null`/`undefined` after initialized.
*/
- otherDims: DataVisualDimensions = {};
+ otherDims?: DataVisualDimensions = {};
/**
* Be `true` if this dimension is not mapped to any "coordSysDim" that the
* "coordSys" required.
* Mandatory.
*/
- isExtraCoord: boolean;
+ isExtraCoord?: boolean;
/**
* If this dimension if for calculated value like stacking
*/
- isCalculationCoord: boolean
+ isCalculationCoord?: boolean
- defaultTooltip: boolean;
+ defaultTooltip?: boolean;
- ordinalMeta: OrdinalMeta;
+ ordinalMeta?: OrdinalMeta;
/**
* Whether to create inverted indices.
*/
- createInvertedIndices: boolean;
+ createInvertedIndices?: boolean;
/**
* @param opt All of the fields will be shallow copied.
diff --git a/src/data/List.ts b/src/data/List.ts
index 602df5e..6a1be69 100644
--- a/src/data/List.ts
+++ b/src/data/List.ts
@@ -27,7 +27,7 @@ import {__DEV__} from '../config';
import * as zrUtil from 'zrender/src/core/util';
import Model from '../model/Model';
import DataDiffer from './DataDiffer';
-import Source, { SourceConstructor } from './Source';
+import Source from './Source';
import {DefaultDataProvider, DataProvider} from './helper/dataProvider';
import {summarizeDimensions, DimensionSummary} from './helper/dimensionHelper';
import DataDimensionInfo from './DataDimensionInfo';
@@ -361,8 +361,7 @@ class List <HostModel extends Model = Model> {
dimValueGetter?: DimValueGetter
): void {
- var notProvider = (Source as SourceConstructor).isInstance(data)
- || zrUtil.isArrayLike(data);
+ var notProvider = data instanceof Source || zrUtil.isArrayLike(data);
if (notProvider) {
data = new DefaultDataProvider(data, this.dimensions.length);
}
diff --git a/src/data/Source.ts b/src/data/Source.ts
index 4d1b5fb..2f06452 100644
--- a/src/data/Source.ts
+++ b/src/data/Source.ts
@@ -18,7 +18,6 @@
*/
import {createHashMap, isTypedArray, HashMap} from 'zrender/src/core/util';
-import {enableClassCheck, CheckableConstructor} from '../util/clazz';
import {
SourceFormat, SeriesLayoutBy, DimensionDefinition,
OptionEncodeValue, OptionSourceData, OptionEncode,
@@ -147,7 +146,4 @@ class Source {
};
}
-export type SourceConstructor = typeof Source & CheckableConstructor;
-enableClassCheck(Source as SourceConstructor);
-
export default Source;
\ No newline at end of file
diff --git a/src/data/helper/completeDimensions.ts b/src/data/helper/completeDimensions.ts
index 24e766a..4bbed70 100644
--- a/src/data/helper/completeDimensions.ts
+++ b/src/data/helper/completeDimensions.ts
@@ -18,7 +18,6 @@
*/
// @ts-nocheck
-
/**
* @deprecated
* Use `echarts/data/helper/createDimensions` instead.
@@ -71,7 +70,7 @@ import DataDimensionInfo from '../DataDimensionInfo';
* @return {Array.<module:data/DataDimensionInfo>}
*/
function completeDimensions(sysDims, source, opt) {
- if (!Source.isInstance(source)) {
+ if (!(source instanceof Source)) {
source = Source.seriesDataToSource(source);
}
diff --git a/src/data/helper/dataProvider.ts b/src/data/helper/dataProvider.ts
index 7e4670c..6893e2a 100644
--- a/src/data/helper/dataProvider.ts
+++ b/src/data/helper/dataProvider.ts
@@ -24,7 +24,7 @@
import {__DEV__} from '../../config';
import {isTypedArray, extend, assert, each, isObject} from 'zrender/src/core/util';
import {getDataItemValue} from '../../util/model';
-import Source, { SourceConstructor } from '../Source';
+import Source from '../Source';
import {ArrayLike, Dictionary} from 'zrender/src/core/types';
import {
SOURCE_FORMAT_ORIGINAL,
@@ -82,7 +82,7 @@ export class DefaultDataProvider implements DataProvider {
constructor(sourceParam: Source | OptionSourceData, dimSize?: number) {
// var source: Source;
- var source: Source = !(Source as SourceConstructor).isInstance(sourceParam)
+ var source: Source = !(source instanceof Source)
? Source.seriesDataToSource(sourceParam as OptionSourceData)
: sourceParam as Source;
diff --git a/src/data/helper/dataStackHelper.ts b/src/data/helper/dataStackHelper.ts
index c3c45fc..fc4d15c 100644
--- a/src/data/helper/dataStackHelper.ts
+++ b/src/data/helper/dataStackHelper.ts
@@ -17,22 +17,32 @@
* under the License.
*/
-// @ts-nocheck
-
import {each, isString} from 'zrender/src/core/util';
+import DataDimensionInfo from '../DataDimensionInfo';
+import SeriesModel from '../../model/Series';
+import List from '../List';
+import type { SeriesOption, StackOptionMixin } from '../../util/types';
+
+interface DataStackResult {
+ stackedDimension: string
+ stackedByDimension: string
+ isStackedByIndex: boolean
+ stackedOverDimension: string
+ stackResultDimension: string
+}
/**
* Note that it is too complicated to support 3d stack by value
* (have to create two-dimension inverted index), so in 3d case
* we just support that stacked by index.
*
- * @param {module:echarts/model/Series} seriesModel
- * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
+ * @param seriesModel
+ * @param dimensionInfoList The same as the input of <module:echarts/data/List>.
* The input dimensionInfoList will be modified.
- * @param {Object} [opt]
- * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
- * @param {boolean} [opt.byIndex=false]
- * @return {Object} calculationInfo
+ * @param opt
+ * @param opt.stackedCoordDimension Specify a coord dimension if needed.
+ * @param opt.byIndex=false
+ * @return calculationInfo
* {
* stackedDimension: string
* stackedByDimension: string
@@ -41,21 +51,30 @@ import {each, isString} from 'zrender/src/core/util';
* stackResultDimension: string
* }
*/
-export function enableDataStack(seriesModel, dimensionInfoList, opt) {
+export function enableDataStack(
+ seriesModel: SeriesModel<SeriesOption & StackOptionMixin>,
+ dimensionInfoList: DataDimensionInfo[],
+ opt?: {
+ stackedCoordDimension?: string
+ byIndex?: boolean
+ }
+): DataStackResult {
opt = opt || {};
var byIndex = opt.byIndex;
var stackedCoordDimension = opt.stackedCoordDimension;
// Compatibal: when `stack` is set as '', do not stack.
var mayStack = !!(seriesModel && seriesModel.get('stack'));
- var stackedByDimInfo;
- var stackedDimInfo;
- var stackResultDimension;
- var stackedOverDimension;
+ var stackedByDimInfo: DataDimensionInfo;
+ var stackedDimInfo: DataDimensionInfo;
+ var stackResultDimension: string;
+ var stackedOverDimension: string;
each(dimensionInfoList, function (dimensionInfo, index) {
if (isString(dimensionInfo)) {
- dimensionInfoList[index] = dimensionInfo = {name: dimensionInfo};
+ dimensionInfoList[index] = dimensionInfo = {
+ name: dimensionInfo as string
+ } as DataDimensionInfo;
}
if (mayStack && !dimensionInfo.isExtraCoord) {
@@ -135,11 +154,7 @@ export function enableDataStack(seriesModel, dimensionInfoList, opt) {
};
}
-/**
- * @param {module:echarts/data/List} data
- * @param {string} stackedDim
- */
-export function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
+export function isDimensionStacked(data: List, stackedDim: string /*, stackedByDim*/) {
// Each single series only maps to one pair of axis. So we do not need to
// check stackByDim, whatever stacked by a dimension or stacked by index.
return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
@@ -150,14 +165,7 @@ export function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
// );
}
-/**
- * @param {module:echarts/data/List} data
- * @param {string} targetDim
- * @param {string} [stackedByDim] If not input this parameter, check whether
- * stacked by index.
- * @return {string} dimension
- */
-export function getStackedDimension(data, targetDim) {
+export function getStackedDimension(data: List, targetDim: string) {
return isDimensionStacked(data, targetDim)
? data.getCalculationInfo('stackResultDimension')
: targetDim;
diff --git a/src/export.ts b/src/export.ts
index 8842264..5177c69 100644
--- a/src/export.ts
+++ b/src/export.ts
@@ -89,7 +89,7 @@ const GRAPHIC_KEYS = [
'BoundingRect'
] as const;
-var graphic = {} as {[key in typeof GRAPHIC_KEYS[number]]: any};
+var graphic = {} as Record<typeof GRAPHIC_KEYS[number], any>;
zrUtil.each(
GRAPHIC_KEYS,
function (name) {
diff --git a/src/helper.ts b/src/helper.ts
index 1d03dfc..b99c9e0 100644
--- a/src/helper.ts
+++ b/src/helper.ts
@@ -49,11 +49,6 @@ export function createList(seriesModel) {
export {getLayoutRect};
-/**
- * // TODO: @deprecated
- */
-export {default as completeDimensions} from './data/helper/completeDimensions';
-
export {default as createDimensions} from './data/helper/createDimensions';
export var dataStack = {
diff --git a/src/model/referHelper.ts b/src/model/referHelper.ts
index bf83bbd..7d8f272 100644
--- a/src/model/referHelper.ts
+++ b/src/model/referHelper.ts
@@ -17,8 +17,6 @@
* under the License.
*/
-// @ts-nocheck
-
/**
* Helper for model references.
* There are many manners to refer axis/coordSys.
@@ -29,7 +27,11 @@
// check: "modelHelper" of tooltip and "BrushTargetManager".
import {__DEV__} from '../config';
-import {createHashMap, retrieve, each} from 'zrender/src/core/util';
+import {createHashMap, retrieve, each, HashMap} from 'zrender/src/core/util';
+import SeriesModel from './Series';
+import type PolarModel from '../coord/polar/PolarModel';
+import type { SeriesOption, SeriesOnCartesianOptionMixin } from '../util/types';
+import type { AxisBaseModel } from '../coord/AxisBaseModel';
/**
* @class
@@ -51,34 +53,34 @@ import {createHashMap, retrieve, each} from 'zrender/src/core/util';
* // To replace user specified encode.
* }
*/
-function CoordSysInfo(coordSysName) {
- /**
- * @type {string}
- */
- this.coordSysName = coordSysName;
- /**
- * @type {Array.<string>}
- */
- this.coordSysDims = [];
- /**
- * @type {module:zrender/core/util#HashMap}
- */
- this.axisMap = createHashMap();
- /**
- * @type {module:zrender/core/util#HashMap}
- */
- this.categoryAxisMap = createHashMap();
- /**
- * @type {number}
- */
- this.firstCategoryDimIndex = null;
+
+class CoordSysInfo {
+
+ coordSysName: string
+
+ coordSysDims: string[] = []
+
+ axisMap = createHashMap<AxisBaseModel>()
+
+ categoryAxisMap = createHashMap<AxisBaseModel>()
+
+ firstCategoryDimIndex: number
+
+ constructor(coordSysName: string) {
+ this.coordSysName = coordSysName;
+ }
}
-/**
- * @return {module:model/referHelper#CoordSysInfo}
- */
-export function getCoordSysInfoBySeries(seriesModel) {
- var coordSysName = seriesModel.get('coordinateSystem');
+type SupportedCoordSys = 'cartesian2d' | 'polar' | 'singleAxis' | 'geo' | 'parallel'
+type Fetcher = (
+ seriesModel: SeriesModel,
+ result: CoordSysInfo,
+ axisMap: HashMap<AxisBaseModel>,
+ categoryAxisMap: HashMap<AxisBaseModel>
+) => void;
+
+export function getCoordSysInfoBySeries(seriesModel: SeriesModel) {
+ var coordSysName = seriesModel.get('coordinateSystem') as SupportedCoordSys;
var result = new CoordSysInfo(coordSysName);
var fetch = fetchers[coordSysName];
if (fetch) {
@@ -87,22 +89,24 @@ export function getCoordSysInfoBySeries(seriesModel) {
}
}
-var fetchers = {
+var fetchers: Record<SupportedCoordSys, Fetcher> = {
- cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
- var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
- var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
+ cartesian2d: function (
+ seriesModel: SeriesModel<SeriesOption & SeriesOnCartesianOptionMixin>, result, axisMap, categoryAxisMap
+ ) {
+ var xAxisModel = seriesModel.getReferringComponents('xAxis')[0] as AxisBaseModel;
+ var yAxisModel = seriesModel.getReferringComponents('yAxis')[0] as AxisBaseModel;
if (__DEV__) {
if (!xAxisModel) {
- throw new Error('xAxis "' + retrieve(
+ throw new Error('xAxis "' + retrieve<number | string>(
seriesModel.get('xAxisIndex'),
seriesModel.get('xAxisId'),
0
) + '" not found');
}
if (!yAxisModel) {
- throw new Error('yAxis "' + retrieve(
+ throw new Error('yAxis "' + retrieve<number | string>(
seriesModel.get('xAxisIndex'),
seriesModel.get('yAxisId'),
0
@@ -120,12 +124,12 @@ var fetchers = {
}
if (isCategory(yAxisModel)) {
categoryAxisMap.set('y', yAxisModel);
- result.firstCategoryDimIndex == null & (result.firstCategoryDimIndex = 1);
+ result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
}
},
singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
- var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
+ var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0] as AxisBaseModel;
if (__DEV__) {
if (!singleAxisModel) {
@@ -143,7 +147,7 @@ var fetchers = {
},
polar: function (seriesModel, result, axisMap, categoryAxisMap) {
- var polarModel = seriesModel.getReferringComponents('polar')[0];
+ var polarModel = seriesModel.getReferringComponents('polar')[0] as PolarModel;
var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
var angleAxisModel = polarModel.findAxisModel('angleAxis');
@@ -177,24 +181,32 @@ var fetchers = {
parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
var ecModel = seriesModel.ecModel;
var parallelModel = ecModel.getComponent(
+ // @ts-ignore
'parallel', seriesModel.get('parallelIndex')
);
+ // @ts-ignore
var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
+ // @ts-ignore
each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
+ // @ts-ignore
var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
var axisDim = coordSysDims[index];
+ // @ts-ignore
axisMap.set(axisDim, axisModel);
+ // @ts-ignore
if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
+ // @ts-ignore
categoryAxisMap.set(axisDim, axisModel);
+ // @ts-ignore
result.firstCategoryDimIndex = index;
}
});
}
};
-function isCategory(axisModel) {
+function isCategory(axisModel: AxisBaseModel) {
return axisModel.get('type') === 'category';
}
diff --git a/src/util/types.ts b/src/util/types.ts
index 0393688..3e93444 100644
--- a/src/util/types.ts
+++ b/src/util/types.ts
@@ -249,7 +249,7 @@ export type ParsedValue = ParsedValueNumeric | OrdinalRawValue;
// will not be performed. But "scale parse" will be performed.
export type ScaleDataValue = ParsedValue | Date;
-// Can only be string or index, because it is used in object key in s ome code.
+// Can only be string or index, because it is used in object key in some code.
// Making the type alias here just intending to show the meaning clearly in code.
export type DimensionIndex = number;
// If being a number-like string but not being defined a dimension name.
@@ -275,7 +275,9 @@ export interface DataVisualDimensions {
}
export type DimensionDefinition = {
- type: string, name: string, displayName?: string
+ type?: string,
+ name: string,
+ displayName?: string
};
export type DimensionDefinitionLoose = DimensionDefinition['type'] | DimensionDefinition;
@@ -1016,6 +1018,7 @@ export interface SeriesOption extends
*/
coordinateSystem?: string
+ hoverLayerThreshold?: number
// FIXME:TS more
}
diff --git a/src/visual/visualSolution.ts b/src/visual/visualSolution.ts
index 693ee0e..0780ca2 100644
--- a/src/visual/visualSolution.ts
+++ b/src/visual/visualSolution.ts
@@ -132,7 +132,7 @@ export function replaceVisualOption<T extends string>(
*/
// ???! handle brush?
export function applyVisual<VisualState extends string, Scope>(
- stateList: VisualState[],
+ stateList: readonly VisualState[],
visualMappings: VisualMappingCollection<VisualState>,
data: List,
getValueState: (this: Scope, valueOrIndex: ParsedValue | number) => VisualState,
@@ -195,7 +195,7 @@ export function applyVisual<VisualState extends string, Scope>(
* @param dim dimension or dimension index.
*/
export function incrementalApplyVisual<VisualState extends string>(
- stateList: VisualState[],
+ stateList: readonly VisualState[],
visualMappings: VisualMappingCollection<VisualState>,
getValueState: (valueOrIndex: ParsedValue | number) => VisualState,
dim?: DimensionLoose
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org