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/13 15:02:23 UTC

[incubator-echarts] branch typescript updated: ts: add types for radar

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 d3a7d18  ts: add types for radar
d3a7d18 is described below

commit d3a7d18286a36a1a1e9839442a3fbbe7f27a5e70
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Mar 13 23:01:37 2020 +0800

    ts: add types for radar
---
 src/chart/radar/RadarSeries.ts    |  90 +++++++++++++++++++------
 src/chart/radar/RadarView.ts      |  95 ++++++++++++++++----------
 src/chart/radar/radarLayout.ts    |  16 +++--
 src/component/radar/RadarView.ts  |  61 ++++++++++-------
 src/coord/Axis.ts                 |   2 +-
 src/coord/axisCommonTypes.ts      |   4 +-
 src/coord/axisHelper.ts           | 138 ++++++++++++++++++++------------------
 src/coord/axisModelCommonMixin.ts |   8 +--
 src/helper.ts                     |   7 +-
 src/layout/barGrid.ts             |   8 ++-
 src/model/mixin/textStyle.ts      |   5 +-
 src/scale/Log.ts                  |   4 +-
 src/scale/Ordinal.ts              |   3 +-
 src/scale/Scale.ts                |   4 +-
 14 files changed, 273 insertions(+), 172 deletions(-)

diff --git a/src/chart/radar/RadarSeries.ts b/src/chart/radar/RadarSeries.ts
index 93ce3b8..a8c2af3 100644
--- a/src/chart/radar/RadarSeries.ts
+++ b/src/chart/radar/RadarSeries.ts
@@ -17,24 +17,74 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import SeriesModel from '../../model/Series';
 import createListSimply from '../helper/createListSimply';
 import * as zrUtil from 'zrender/src/core/util';
 import {encodeHTML} from '../../util/format';
 import LegendVisualProvider from '../../visual/LegendVisualProvider';
+import {
+    SeriesOption,
+    LineStyleOption,
+    LabelOption,
+    SymbolOptionMixin,
+    ItemStyleOption,
+    AreaStyleOption,
+    OptionDataValue
+} from '../../util/types';
+import GlobalModel from '../../model/Global';
+import List from '../../data/List';
+import Radar from '../../coord/radar/Radar';
+
+type RadarSeriesDataValue = OptionDataValue[];
+
+export interface RadarSeriesDataItemOption extends SymbolOptionMixin {
+    lineStyle?: LineStyleOption
+    areaStyle?: AreaStyleOption
+    label?: LabelOption
+    itemStyle?: ItemStyleOption
+
+    emphasis?: {
+        lineStyle?: LineStyleOption
+        areaStyle?: AreaStyleOption
+        label?: LabelOption
+        itemStyle?: ItemStyleOption
+    }
+
+    value?: RadarSeriesDataValue
+}
+
+export interface RadarSeriesOption extends SeriesOption, SymbolOptionMixin {
+    type?: 'radar'
+    coordinateSystem: 'radar'
+
+    radarIndex?: number
+    radarId?: string
 
-var RadarSeries = SeriesModel.extend({
+    lineStyle?: LineStyleOption
+    areaStyle?: AreaStyleOption
+    label?: LabelOption
+    itemStyle?: ItemStyleOption
 
-    type: 'series.radar',
+    emphasis?: {
+        lineStyle?: LineStyleOption
+        areaStyle?: AreaStyleOption
+        label?: LabelOption
+        itemStyle?: ItemStyleOption
+    }
+}
+
+class RadarSeriesModel extends SeriesModel<RadarSeriesOption> {
 
-    dependencies: ['radar'],
+    static readonly type = 'series.radar'
+    readonly type = RadarSeriesModel.type
 
+    dependencies = ['radar']
+
+    coordinateSystem: Radar
 
     // Overwrite
-    init: function (option) {
-        RadarSeries.superApply(this, 'init', arguments);
+    init(option: RadarSeriesOption) {
+        super.init.apply(this, arguments as any);
 
         // Enable legend selection for each data item
         // Use a function instead of direct access because data reference may changed
@@ -42,16 +92,16 @@ var RadarSeries = SeriesModel.extend({
             zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this)
         );
 
-    },
+    }
 
-    getInitialData: function (option, ecModel) {
+    getInitialData(option: RadarSeriesOption, ecModel: GlobalModel): List {
         return createListSimply(this, {
             generateCoord: 'indicator_',
             generateCoordCount: Infinity
         });
-    },
+    }
 
-    formatTooltip: function (dataIndex) {
+    formatTooltip(dataIndex: number) {
         var data = this.getData();
         var coordSys = this.coordinateSystem;
         var indicatorAxes = coordSys.getIndicatorAxes();
@@ -61,31 +111,31 @@ var RadarSeries = SeriesModel.extend({
                 var val = data.get(data.mapDimension(axis.dim), dataIndex);
                 return encodeHTML(axis.name + ' : ' + val);
             }).join('<br />');
-    },
+    }
 
     /**
      * @implement
      */
-    getTooltipPosition: function (dataIndex) {
+    getTooltipPosition(dataIndex: number) {
         if (dataIndex != null) {
             var data = this.getData();
             var coordSys = this.coordinateSystem;
             var values = data.getValues(
                 zrUtil.map(coordSys.dimensions, function (dim) {
                     return data.mapDimension(dim);
-                }), dataIndex, true
+                }), dataIndex
             );
 
             for (var i = 0, len = values.length; i < len; i++) {
-                if (!isNaN(values[i])) {
+                if (!isNaN(values[i] as number)) {
                     var indicatorAxes = coordSys.getIndicatorAxes();
                     return coordSys.coordToPoint(indicatorAxes[i].dataToCoord(values[i]), i);
                 }
             }
         }
-    },
+    }
 
-    defaultOption: {
+    static defaultOption: RadarSeriesOption = {
         zlevel: 0,
         z: 2,
         coordinateSystem: 'radar',
@@ -105,6 +155,8 @@ var RadarSeries = SeriesModel.extend({
         symbolSize: 4
         // symbolRotate: null
     }
-});
+}
+
+SeriesModel.registerClass(RadarSeriesModel);
 
-export default RadarSeries;
\ No newline at end of file
+export default RadarSeriesModel;
\ No newline at end of file
diff --git a/src/chart/radar/RadarView.ts b/src/chart/radar/RadarView.ts
index d523381..d3233e3 100644
--- a/src/chart/radar/RadarView.ts
+++ b/src/chart/radar/RadarView.ts
@@ -17,34 +17,43 @@
 * under the License.
 */
 
-// @ts-nocheck
-
-import * as echarts from '../../echarts';
 import * as graphic from '../../util/graphic';
 import * as zrUtil from 'zrender/src/core/util';
 import * as symbolUtil from '../../util/symbol';
-
-function normalizeSymbolSize(symbolSize) {
+import ChartView from '../../view/Chart';
+import RadarSeriesModel, { RadarSeriesDataItemOption } from './RadarSeries';
+import ExtensionAPI from '../../ExtensionAPI';
+import List from '../../data/List';
+import { ZRColor, DisplayState, ECElement } from '../../util/types';
+import GlobalModel from '../../model/Global';
+
+function normalizeSymbolSize(symbolSize: number | number[]) {
     if (!zrUtil.isArray(symbolSize)) {
         symbolSize = [+symbolSize, +symbolSize];
     }
     return symbolSize;
 }
 
-export default echarts.extendChartView({
+type RadarSymbol = ReturnType<typeof symbolUtil.createSymbol> & {
+    __dimIdx: number
+}
+
+class RadarView extends ChartView {
+    static type = 'radar'
+    type = RadarView.type
 
-    type: 'radar',
+    private _data: List<RadarSeriesModel>
 
-    render: function (seriesModel, ecModel, api) {
+    render(seriesModel: RadarSeriesModel, ecModel: GlobalModel, api: ExtensionAPI) {
         var polar = seriesModel.coordinateSystem;
         var group = this.group;
 
         var data = seriesModel.getData();
         var oldData = this._data;
 
-        function createSymbol(data, idx) {
-            var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
-            var color = data.getItemVisual(idx, 'color');
+        function createSymbol(data: List<RadarSeriesModel>, idx: number) {
+            var symbolType = data.getItemVisual(idx, 'symbol') as string || 'circle';
+            var color = data.getItemVisual(idx, 'color') as ZRColor;
             if (symbolType === 'none') {
                 return;
             }
@@ -61,10 +70,17 @@ export default echarts.extendChartView({
                 z2: 100,
                 scale: [symbolSize[0] / 2, symbolSize[1] / 2]
             });
-            return symbolPath;
+            return symbolPath as RadarSymbol;
         }
 
-        function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
+        function updateSymbols(
+            oldPoints: number[][],
+            newPoints: number[][],
+            symbolGroup: graphic.Group,
+            data: List<RadarSeriesModel>,
+            idx: number,
+            isInit?: boolean
+        ) {
             // Simply rerender all
             symbolGroup.removeAll();
             for (var i = 0; i < newPoints.length - 1; i++) {
@@ -87,7 +103,7 @@ export default echarts.extendChartView({
             }
         }
 
-        function getInitialPoints(points) {
+        function getInitialPoints(points: number[][]) {
             return zrUtil.map(points, function (pt) {
                 return [polar.cx, polar.cy];
             });
@@ -124,10 +140,10 @@ export default echarts.extendChartView({
                 data.setItemGraphicEl(idx, itemGroup);
             })
             .update(function (newIdx, oldIdx) {
-                var itemGroup = oldData.getItemGraphicEl(oldIdx);
-                var polyline = itemGroup.childAt(0);
-                var polygon = itemGroup.childAt(1);
-                var symbolGroup = itemGroup.childAt(2);
+                var itemGroup = oldData.getItemGraphicEl(oldIdx) as graphic.Group;
+                var polyline = itemGroup.childAt(0) as graphic.Polyline;
+                var polygon = itemGroup.childAt(1) as graphic.Polygon;
+                var symbolGroup = itemGroup.childAt(2) as graphic.Group;
                 var target = {
                     shape: {
                         points: data.getItemLayout(newIdx)
@@ -138,7 +154,12 @@ export default echarts.extendChartView({
                     return;
                 }
                 updateSymbols(
-                    polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false
+                    polyline.shape.points,
+                    target.shape.points,
+                    symbolGroup,
+                    data,
+                    newIdx,
+                    false
                 );
 
                 graphic.updateProps(polyline, target, seriesModel);
@@ -151,11 +172,11 @@ export default echarts.extendChartView({
             })
             .execute();
 
-        data.eachItemGraphicEl(function (itemGroup, idx) {
-            var itemModel = data.getItemModel(idx);
-            var polyline = itemGroup.childAt(0);
-            var polygon = itemGroup.childAt(1);
-            var symbolGroup = itemGroup.childAt(2);
+        data.eachItemGraphicEl(function (itemGroup: graphic.Group, idx) {
+            var itemModel = data.getItemModel<RadarSeriesDataItemOption>(idx);
+            var polyline = itemGroup.childAt(0) as graphic.Polyline;
+            var polygon = itemGroup.childAt(1) as graphic.Polygon;
+            var symbolGroup = itemGroup.childAt(2) as graphic.Group;
             var color = data.getItemVisual(idx, 'color');
 
             group.add(itemGroup);
@@ -169,10 +190,10 @@ export default echarts.extendChartView({
                     }
                 )
             );
-            polyline.hoverStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
+            polyline.hoverStyle = itemModel.getModel(['emphasis', 'lineStyle']).getLineStyle();
 
             var areaStyleModel = itemModel.getModel('areaStyle');
-            var hoverAreaStyleModel = itemModel.getModel('emphasis.areaStyle');
+            var hoverAreaStyleModel = itemModel.getModel(['emphasis', 'areaStyle']);
             var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
             var hoverPolygonIgnore = hoverAreaStyleModel.isEmpty() && hoverAreaStyleModel.parentModel.isEmpty();
 
@@ -191,14 +212,14 @@ export default echarts.extendChartView({
             polygon.hoverStyle = hoverAreaStyleModel.getAreaStyle();
 
             var itemStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
-            var itemHoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
+            var itemHoverStyle = itemModel.getModel(['emphasis', 'itemStyle']).getItemStyle();
             var labelModel = itemModel.getModel('label');
-            var labelHoverModel = itemModel.getModel('emphasis.label');
-            symbolGroup.eachChild(function (symbolPath) {
+            var labelHoverModel = itemModel.getModel(['emphasis', 'label']);
+            symbolGroup.eachChild(function (symbolPath: RadarSymbol) {
                 symbolPath.setStyle(itemStyle);
                 symbolPath.hoverStyle = zrUtil.clone(itemHoverStyle);
                 var defaultText = data.get(data.dimensions[symbolPath.__dimIdx], idx);
-                (defaultText == null || isNaN(defaultText)) && (defaultText = '');
+                (defaultText == null || isNaN(defaultText as number)) && (defaultText = '');
 
                 graphic.setLabelStyle(
                     symbolPath.style, symbolPath.hoverStyle, labelModel, labelHoverModel,
@@ -206,26 +227,26 @@ export default echarts.extendChartView({
                         labelFetcher: data.hostModel,
                         labelDataIndex: idx,
                         labelDimIndex: symbolPath.__dimIdx,
-                        defaultText: defaultText,
+                        defaultText: defaultText + '',
                         autoColor: color,
                         isRectText: true
                     }
                 );
             });
 
-            itemGroup.highDownOnUpdate = function (fromState, toState) {
+            (itemGroup as ECElement).highDownOnUpdate = function (fromState: DisplayState, toState: DisplayState) {
                 polygon.attr('ignore', toState === 'emphasis' ? hoverPolygonIgnore : polygonIgnore);
             };
             graphic.setHoverStyle(itemGroup);
         });
 
         this._data = data;
-    },
+    }
 
-    remove: function () {
+    remove() {
         this.group.removeAll();
         this._data = null;
-    },
+    }
+}
 
-    dispose: function () {}
-});
\ No newline at end of file
+ChartView.registerClass(RadarView);
\ No newline at end of file
diff --git a/src/chart/radar/radarLayout.ts b/src/chart/radar/radarLayout.ts
index 017e64a..55c5a3e 100644
--- a/src/chart/radar/radarLayout.ts
+++ b/src/chart/radar/radarLayout.ts
@@ -17,14 +17,16 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import * as zrUtil from 'zrender/src/core/util';
+import GlobalModel from '../../model/Global';
+import RadarSeriesModel from './RadarSeries';
+import Radar from '../../coord/radar/Radar';
 
-export default function (ecModel) {
-    ecModel.eachSeriesByType('radar', function (seriesModel) {
+type Point = number[];
+export default function (ecModel: GlobalModel) {
+    ecModel.eachSeriesByType('radar', function (seriesModel: RadarSeriesModel) {
         var data = seriesModel.getData();
-        var points = [];
+        var points: Point[][] = [];
         var coordSys = seriesModel.coordinateSystem;
         if (!coordSys) {
             return;
@@ -57,11 +59,11 @@ export default function (ecModel) {
     });
 }
 
-function isValidPoint(point) {
+function isValidPoint(point: Point) {
     return !isNaN(point[0]) && !isNaN(point[1]);
 }
 
-function getValueMissingPoint(coordSys) {
+function getValueMissingPoint(coordSys: Radar): Point {
     // It is error-prone to input [NaN, NaN] into polygon, polygon.
     // (probably cause problem when refreshing or animating)
     return [coordSys.cx, coordSys.cy];
diff --git a/src/component/radar/RadarView.ts b/src/component/radar/RadarView.ts
index 22fe86e..e72f753 100644
--- a/src/component/radar/RadarView.ts
+++ b/src/component/radar/RadarView.ts
@@ -17,31 +17,34 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import {__DEV__} from '../../config';
-import * as echarts from '../../echarts';
 import * as zrUtil from 'zrender/src/core/util';
 import AxisBuilder from '../axis/AxisBuilder';
 import * as graphic from '../../util/graphic';
+import ComponentView from '../../view/Component';
+import RadarModel from '../../coord/radar/RadarModel';
+import GlobalModel from '../../model/Global';
+import ExtensionAPI from '../../ExtensionAPI';
+import { ZRColor } from '../../util/types';
 
 var axisBuilderAttrs = [
     'axisLine', 'axisTickLabel', 'axisName'
-];
+] as const;
 
-export default echarts.extendComponentView({
+class RadarView extends ComponentView {
 
-    type: 'radar',
+    static type = 'radar'
+    type = RadarView.type
 
-    render: function (radarModel, ecModel, api) {
+    render(radarModel: RadarModel, ecModel: GlobalModel, api: ExtensionAPI) {
         var group = this.group;
         group.removeAll();
 
         this._buildAxes(radarModel);
         this._buildSplitLineAndArea(radarModel);
-    },
+    }
 
-    _buildAxes: function (radarModel) {
+    _buildAxes(radarModel: RadarModel) {
         var radar = radarModel.coordinateSystem;
         var indicatorAxes = radar.getIndicatorAxes();
         var axisBuilders = zrUtil.map(indicatorAxes, function (indicatorAxis) {
@@ -59,9 +62,9 @@ export default echarts.extendComponentView({
             zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
             this.group.add(axisBuilder.getGroup());
         }, this);
-    },
+    }
 
-    _buildSplitLineAndArea: function (radarModel) {
+    _buildSplitLineAndArea(radarModel: RadarModel) {
         var radar = radarModel.coordinateSystem;
         var indicatorAxes = radar.getIndicatorAxes();
         if (!indicatorAxes.length) {
@@ -78,13 +81,17 @@ export default echarts.extendComponentView({
         var splitLineColors = lineStyleModel.get('color');
         var splitAreaColors = areaStyleModel.get('color');
 
-        splitLineColors = zrUtil.isArray(splitLineColors) ? splitLineColors : [splitLineColors];
-        splitAreaColors = zrUtil.isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
+        var splitLineColorsArr = zrUtil.isArray(splitLineColors) ? splitLineColors : [splitLineColors];
+        var splitAreaColorsArr = zrUtil.isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
 
-        var splitLines = [];
-        var splitAreas = [];
+        var splitLines: (graphic.Circle | graphic.Polyline)[][] = [];
+        var splitAreas: (graphic.Ring | graphic.Polygon)[][] = [];
 
-        function getColorIndex(areaOrLine, areaOrLineColorList, idx) {
+        function getColorIndex(
+            areaOrLine: any[][],
+            areaOrLineColorList: ZRColor[],
+            idx: number
+        ) {
             var colorIndex = idx % areaOrLineColorList.length;
             areaOrLine[colorIndex] = areaOrLine[colorIndex] || [];
             return colorIndex;
@@ -96,7 +103,7 @@ export default echarts.extendComponentView({
             var cy = radar.cy;
             for (var i = 0; i < ticksRadius.length; i++) {
                 if (showSplitLine) {
-                    var colorIndex = getColorIndex(splitLines, splitLineColors, i);
+                    var colorIndex = getColorIndex(splitLines, splitLineColorsArr, i);
                     splitLines[colorIndex].push(new graphic.Circle({
                         shape: {
                             cx: cx,
@@ -106,7 +113,7 @@ export default echarts.extendComponentView({
                     }));
                 }
                 if (showSplitArea && i < ticksRadius.length - 1) {
-                    var colorIndex = getColorIndex(splitAreas, splitAreaColors, i);
+                    var colorIndex = getColorIndex(splitAreas, splitAreaColorsArr, i);
                     splitAreas[colorIndex].push(new graphic.Ring({
                         shape: {
                             cx: cx,
@@ -120,7 +127,7 @@ export default echarts.extendComponentView({
         }
         // Polyyon
         else {
-            var realSplitNumber;
+            var realSplitNumber: number;
             var axesTicksPoints = zrUtil.map(indicatorAxes, function (indicatorAxis, idx) {
                 var ticksCoords = indicatorAxis.getTicksCoords();
                 realSplitNumber = realSplitNumber == null
@@ -131,9 +138,9 @@ export default echarts.extendComponentView({
                 });
             });
 
-            var prevPoints = [];
+            var prevPoints: number[][] = [];
             for (var i = 0; i <= realSplitNumber; i++) {
-                var points = [];
+                var points: number[][] = [];
                 for (var j = 0; j < indicatorAxes.length; j++) {
                     points.push(axesTicksPoints[j][i]);
                 }
@@ -148,7 +155,7 @@ export default echarts.extendComponentView({
                 }
 
                 if (showSplitLine) {
-                    var colorIndex = getColorIndex(splitLines, splitLineColors, i);
+                    var colorIndex = getColorIndex(splitLines, splitLineColorsArr, i);
                     splitLines[colorIndex].push(new graphic.Polyline({
                         shape: {
                             points: points
@@ -156,7 +163,7 @@ export default echarts.extendComponentView({
                     }));
                 }
                 if (showSplitArea && prevPoints) {
-                    var colorIndex = getColorIndex(splitAreas, splitAreaColors, i - 1);
+                    var colorIndex = getColorIndex(splitAreas, splitAreaColorsArr, i - 1);
                     splitAreas[colorIndex].push(new graphic.Polygon({
                         shape: {
                             points: points.concat(prevPoints)
@@ -175,7 +182,7 @@ export default echarts.extendComponentView({
                 splitAreas, {
                     style: zrUtil.defaults({
                         stroke: 'none',
-                        fill: splitAreaColors[idx % splitAreaColors.length]
+                        fill: splitAreaColorsArr[idx % splitAreaColorsArr.length]
                     }, areaStyle),
                     silent: true
                 }
@@ -187,7 +194,7 @@ export default echarts.extendComponentView({
                 splitLines, {
                     style: zrUtil.defaults({
                         fill: 'none',
-                        stroke: splitLineColors[idx % splitLineColors.length]
+                        stroke: splitLineColorsArr[idx % splitLineColorsArr.length]
                     }, lineStyle),
                     silent: true
                 }
@@ -195,4 +202,6 @@ export default echarts.extendComponentView({
         }, this);
 
     }
-});
\ No newline at end of file
+}
+
+ComponentView.registerClass(RadarView);
\ No newline at end of file
diff --git a/src/coord/Axis.ts b/src/coord/Axis.ts
index 199189b..8fb7921 100644
--- a/src/coord/Axis.ts
+++ b/src/coord/Axis.ts
@@ -219,7 +219,7 @@ class Axis {
         return createAxisLabels(this).labels;
     }
 
-    getLabelModel(): Model {
+    getLabelModel(): Model<AxisBaseOption['axisLabel']> {
         return this.model.getModel('axisLabel');
     }
 
diff --git a/src/coord/axisCommonTypes.ts b/src/coord/axisCommonTypes.ts
index e32181b..046a055 100644
--- a/src/coord/axisCommonTypes.ts
+++ b/src/coord/axisCommonTypes.ts
@@ -74,12 +74,12 @@ export interface AxisBaseOption extends ComponentOption,
     // + a number
     // + 'dataMin': use the min value in data.
     // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
-    min?: OptionDataValue | 'dataMin';
+    min?: number | 'dataMin' | ((extent: {min: number, max: number}) => number);
     // Max value of the axis. can be:
     // + a number
     // + 'dataMax': use the max value in data.
     // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
-    max?: OptionDataValue | 'dataMax';
+    max?: number | 'dataMax' | ((extent: {min: number, max: number}) => number);
     // Readonly prop, specifies start value of the range when using data zoom.
     // Only for internal usage.
     rangeStart?: number;
diff --git a/src/coord/axisHelper.ts b/src/coord/axisHelper.ts
index c536824..1b2f341 100644
--- a/src/coord/axisHelper.ts
+++ b/src/coord/axisHelper.ts
@@ -17,8 +17,6 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import {__DEV__} from '../config';
 import * as zrUtil from 'zrender/src/core/util';
 import OrdinalScale from '../scale/Ordinal';
@@ -30,18 +28,23 @@ import {
     makeColumnLayout,
     retrieveColumnLayout
 } from '../layout/barGrid';
-import BoundingRect from 'zrender/src/core/BoundingRect';
+import BoundingRect, { RectLike } from 'zrender/src/core/BoundingRect';
 
-import '../scale/Log';
 import TimeScale from '../scale/Time';
-import { ComponentOption } from '../util/types';
 import Model from '../model/Model';
+import { AxisBaseModel } from './AxisBaseModel';
+import LogScale from '../scale/Log';
+import Axis from './Axis';
+import { AxisBaseOption } from './axisCommonTypes';
+import type CartesianAxisModel from './cartesian/AxisModel';
+
+type BarWidthAndOffset = ReturnType<typeof makeColumnLayout>
 
 /**
  * Get axis scale extent before niced.
  * Item of returned array can only be number (including Infinity and NaN).
  */
-export function getScaleExtent(scale, model) {
+export function getScaleExtent(scale: Scale, model: AxisBaseModel) {
     var scaleType = scale.type;
 
     var min = model.getMin();
@@ -51,27 +54,29 @@ export function getScaleExtent(scale, model) {
     var originalExtent = scale.getExtent();
 
     var axisDataLen;
-    var boundaryGap;
+    var boundaryGapInner: number[];
     var span;
     if (scaleType === 'ordinal') {
         axisDataLen = model.getCategories().length;
     }
     else {
-        boundaryGap = model.get('boundaryGap');
-        if (!zrUtil.isArray(boundaryGap)) {
-            boundaryGap = [boundaryGap || 0, boundaryGap || 0];
-        }
-        if (typeof boundaryGap[0] === 'boolean') {
+        var boundaryGap = model.get('boundaryGap');
+        var boundaryGapArr = zrUtil.isArray(boundaryGap)
+            ? boundaryGap : [boundaryGap || 0, boundaryGap || 0];
+
+        if (typeof boundaryGapArr[0] === 'boolean' || typeof boundaryGapArr[1] === 'boolean') {
             if (__DEV__) {
                 console.warn('Boolean type for boundaryGap is only '
                     + 'allowed for ordinal axis. Please use string in '
                     + 'percentage instead, e.g., "20%". Currently, '
                     + 'boundaryGap is set to be 0.');
             }
-            boundaryGap = [0, 0];
+            boundaryGapInner = [0, 0];
+        }
+        else {
+            boundaryGapInner[0] = numberUtil.parsePercent(boundaryGapArr[0], 1);
+            boundaryGapInner[1] = numberUtil.parsePercent(boundaryGapArr[1], 1);
         }
-        boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
-        boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
         span = (originalExtent[1] - originalExtent[0])
             || Math.abs(originalExtent[0]);
     }
@@ -94,12 +99,12 @@ export function getScaleExtent(scale, model) {
     if (min == null) {
         min = scaleType === 'ordinal'
             ? (axisDataLen ? 0 : NaN)
-            : originalExtent[0] - boundaryGap[0] * span;
+            : originalExtent[0] - boundaryGapInner[0] * span;
     }
     if (max == null) {
         max = scaleType === 'ordinal'
             ? (axisDataLen ? axisDataLen - 1 : NaN)
-            : originalExtent[1] + boundaryGap[1] * span;
+            : originalExtent[1] + boundaryGapInner[1] * span;
     }
 
     if (min === 'dataMin') {
@@ -128,7 +133,7 @@ export function getScaleExtent(scale, model) {
     scale.setBlank(
         zrUtil.eqNaN(min)
         || zrUtil.eqNaN(max)
-        || (scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length)
+        || ((scale instanceof OrdinalScale) && !scale.getOrdinalMeta().categories.length)
     );
 
     // Evaluate if axis needs cross zero
@@ -155,18 +160,19 @@ export function getScaleExtent(scale, model) {
     var ecModel = model.ecModel;
     if (ecModel && (scaleType === 'time' /*|| scaleType === 'interval' */)) {
         var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
-        var isBaseAxisAndHasBarSeries;
+        var isBaseAxisAndHasBarSeries = false;
 
         zrUtil.each(barSeriesModels, function (seriesModel) {
-            isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
+            isBaseAxisAndHasBarSeries = isBaseAxisAndHasBarSeries || seriesModel.getBaseAxis() === model.axis;
         });
 
         if (isBaseAxisAndHasBarSeries) {
-            // Calculate placement of bars on axis
+            // Calculate placement of bars on axis. TODO should be decoupled
+            // with barLayout
             var barWidthAndOffset = makeColumnLayout(barSeriesModels);
 
             // Adjust axis min and max to account for overflow
-            var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
+            var adjustedScale = adjustScaleForOverflow(min, max, model as CartesianAxisModel, barWidthAndOffset);
             min = adjustedScale.min;
             max = adjustedScale.max;
         }
@@ -175,7 +181,12 @@ export function getScaleExtent(scale, model) {
     return [min, max];
 }
 
-function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
+function adjustScaleForOverflow(
+    min: number,
+    max: number,
+    model: CartesianAxisModel,  // Onlhy support cartesian coord yet.
+    barWidthAndOffset: BarWidthAndOffset
+) {
 
     // Get Axis Length
     var axisExtent = model.axis.getExtent();
@@ -210,13 +221,13 @@ function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
     return {min: min, max: max};
 }
 
-export function niceScaleExtent(scale, model) {
+export function niceScaleExtent(scale: Scale, model: AxisBaseModel) {
     var extent = getScaleExtent(scale, model);
     var fixMin = model.getMin() != null;
     var fixMax = model.getMax() != null;
     var splitNumber = model.get('splitNumber');
 
-    if (scale.type === 'log') {
+    if (scale instanceof LogScale) {
         scale.base = model.get('logBase');
     }
 
@@ -239,14 +250,14 @@ export function niceScaleExtent(scale, model) {
     // FIXME
     var interval = model.get('interval');
     if (interval != null) {
-        scale.setInterval && scale.setInterval(interval);
+        (scale as IntervalScale).setInterval && (scale as IntervalScale).setInterval(interval);
     }
 }
 
 /**
  * @param axisType Default retrieve from model.type
  */
-export function createScaleByModel(model: Model<ComponentOption>, axisType?: string): Scale {
+export function createScaleByModel(model: AxisBaseModel, axisType?: string): Scale {
     axisType = axisType || model.get('type');
     if (axisType) {
         switch (axisType) {
@@ -272,7 +283,7 @@ export function createScaleByModel(model: Model<ComponentOption>, axisType?: str
 /**
  * Check if the axis corss 0
  */
-export function ifAxisCrossZero(axis) {
+export function ifAxisCrossZero(axis: Axis) {
     var dataExtent = axis.scale.getExtent();
     var min = dataExtent[0];
     var max = dataExtent[1];
@@ -280,51 +291,51 @@ export function ifAxisCrossZero(axis) {
 }
 
 /**
- * @param {module:echarts/coord/Axis} axis
- * @return {Function} Label formatter function.
+ * @param axis
+ * @return Label formatter function.
  *         param: {number} tickValue,
  *         param: {number} idx, the index in all ticks.
  *                         If category axis, this param is not requied.
  *         return: {string} label string.
  */
-export function makeLabelFormatter(axis) {
+export function makeLabelFormatter(axis: Axis) {
     var labelFormatter = axis.getLabelModel().get('formatter');
     var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
 
     if (typeof labelFormatter === 'string') {
-        labelFormatter = (function (tpl) {
-            return function (val) {
+        return (function (tpl) {
+            return function (val: number | string) {
                 // For category axis, get raw value; for numeric axis,
                 // get foramtted label like '1,333,444'.
                 val = axis.scale.getLabel(val);
                 return tpl.replace('{value}', val != null ? val : '');
             };
         })(labelFormatter);
-        // Consider empty array
-        return labelFormatter;
     }
     else if (typeof labelFormatter === 'function') {
-        return function (tickValue, idx) {
-            // The original intention of `idx` is "the index of the tick in all ticks".
-            // But the previous implementation of category axis do not consider the
-            // `axisLabel.interval`, which cause that, for example, the `interval` is
-            // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
-            // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
-            // the definition here for back compatibility.
-            if (categoryTickStart != null) {
-                idx = tickValue - categoryTickStart;
-            }
-            return labelFormatter(getAxisRawValue(axis, tickValue), idx);
-        };
+        return (function (cb) {
+            return function (tickValue: number, idx: number) {
+                // The original intention of `idx` is "the index of the tick in all ticks".
+                // But the previous implementation of category axis do not consider the
+                // `axisLabel.interval`, which cause that, for example, the `interval` is
+                // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
+                // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
+                // the definition here for back compatibility.
+                if (categoryTickStart != null) {
+                    idx = tickValue - categoryTickStart;
+                }
+                return cb(getAxisRawValue(axis, tickValue), idx);
+            };
+        })(labelFormatter);
     }
     else {
-        return function (tick) {
+        return function (tick: number) {
             return axis.scale.getLabel(tick);
         };
     }
 }
 
-export function getAxisRawValue(axis, value) {
+export function getAxisRawValue(axis: Axis, value: number | string): number | string {
     // In category axis with data zoom, tick is not the original
     // index of axis.data. So tick should not be exposed to user
     // in category axis.
@@ -332,25 +343,23 @@ export function getAxisRawValue(axis, value) {
 }
 
 /**
- * @param {module:echarts/coord/Axis} axis
- * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
+ * @param axis
+ * @return Be null/undefined if no labels.
  */
-export function estimateLabelUnionRect(axis) {
+export function estimateLabelUnionRect(axis: Axis) {
     var axisModel = axis.model;
     var scale = axis.scale;
 
-    if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
+    if (!axisModel.get(['axisLabel', 'show']) || scale.isBlank()) {
         return;
     }
 
-    var isCategory = axis.type === 'category';
-
     var realNumberScaleTicks;
     var tickCount;
     var categoryScaleExtent = scale.getExtent();
 
     // Optimize for large category data, avoid call `getTicks()`.
-    if (isCategory) {
+    if (scale instanceof OrdinalScale) {
         tickCount = scale.count();
     }
     else {
@@ -369,7 +378,7 @@ export function estimateLabelUnionRect(axis) {
     }
     for (var i = 0; i < tickCount; i += step) {
         var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
-        var label = labelFormatter(tickValue);
+        var label = labelFormatter(tickValue, i);
         var unrotatedSingleRect = axisLabelModel.getTextRect(label);
         var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
 
@@ -379,23 +388,22 @@ export function estimateLabelUnionRect(axis) {
     return rect;
 }
 
-function rotateTextRect(textRect, rotate) {
+function rotateTextRect(textRect: RectLike, rotate: number) {
     var rotateRadians = rotate * Math.PI / 180;
-    var boundingBox = textRect.plain();
-    var beforeWidth = boundingBox.width;
-    var beforeHeight = boundingBox.height;
+    var beforeWidth = textRect.width;
+    var beforeHeight = textRect.height;
     var afterWidth = beforeWidth * Math.cos(rotateRadians) + beforeHeight * Math.sin(rotateRadians);
     var afterHeight = beforeWidth * Math.sin(rotateRadians) + beforeHeight * Math.cos(rotateRadians);
-    var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
+    var rotatedRect = new BoundingRect(textRect.x, textRect.y, afterWidth, afterHeight);
 
     return rotatedRect;
 }
 
 /**
- * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
+ * @param model axisLabelModel or axisTickModel
  * @return {number|String} Can be null|'auto'|number|function
  */
-export function getOptionCategoryInterval(model) {
+export function getOptionCategoryInterval(model: Model<AxisBaseOption['axisLabel']>) {
     var interval = model.get('interval');
     return interval == null ? 'auto' : interval;
 }
@@ -406,7 +414,7 @@ export function getOptionCategoryInterval(model) {
  * @param {Object} axis axisModel.axis
  * @return {boolean}
  */
-export function shouldShowAllLabels(axis) {
+export function shouldShowAllLabels(axis: Axis) {
     return axis.type === 'category'
         && getOptionCategoryInterval(axis.getLabelModel()) === 0;
 }
diff --git a/src/coord/axisModelCommonMixin.ts b/src/coord/axisModelCommonMixin.ts
index a68cec7..4ac27d5 100644
--- a/src/coord/axisModelCommonMixin.ts
+++ b/src/coord/axisModelCommonMixin.ts
@@ -33,7 +33,7 @@ class AxisModelCommonMixin<Opt extends AxisBaseOption> {
     /**
      * @return min value or 'dataMin' or null/undefined (means auto) or NaN
      */
-    getMin(origin?: boolean): number | 'dataMin' {
+    getMin(origin?: boolean): AxisBaseOption['min'] | number {
         var option = this.option;
         var min = (!origin && option.rangeStart != null)
             ? option.rangeStart : option.min;
@@ -46,13 +46,13 @@ class AxisModelCommonMixin<Opt extends AxisBaseOption> {
         ) {
             min = this.axis.scale.parse(min);
         }
-        return min as any;
+        return min;
     }
 
     /**
      * @return max value or 'dataMax' or null/undefined (means auto) or NaN
      */
-    getMax(origin?: boolean): number | 'dataMax' {
+    getMax(origin?: boolean): AxisBaseOption['max'] | number {
         var option = this.option;
         var max = (!origin && option.rangeEnd != null)
             ? option.rangeEnd : option.max;
@@ -65,7 +65,7 @@ class AxisModelCommonMixin<Opt extends AxisBaseOption> {
         ) {
             max = this.axis.scale.parse(max);
         }
-        return max as any;
+        return max;
     }
 
     getNeedCrossZero(): boolean {
diff --git a/src/helper.ts b/src/helper.ts
index c3d454b..b71c43c 100644
--- a/src/helper.ts
+++ b/src/helper.ts
@@ -30,6 +30,7 @@ import {
     getStackedDimension
 } from './data/helper/dataStackHelper';
 import SeriesModel from './model/Series';
+import { AxisBaseModel } from './coord/AxisBaseModel';
 
 /**
  * Create a muti dimension List structure from seriesModel.
@@ -71,7 +72,7 @@ export {createSymbol} from './util/symbol';
  * @param {Object|module:echarts/Model} option If `optoin.type`
  *        is secified, it can only be `'value'` currently.
  */
-export function createScale(dataExtent: number[], option: object | Model) {
+export function createScale(dataExtent: number[], option: object | AxisBaseModel) {
     var axisModel = option;
     if (!(option instanceof Model)) {
         axisModel = new Model(option);
@@ -85,10 +86,10 @@ export function createScale(dataExtent: number[], option: object | Model) {
         // zrUtil.mixin(axisModel, AxisModelCommonMixin);
     }
 
-    var scale = axisHelper.createScaleByModel(axisModel as Model);
+    var scale = axisHelper.createScaleByModel(axisModel as AxisBaseModel);
     scale.setExtent(dataExtent[0], dataExtent[1]);
 
-    axisHelper.niceScaleExtent(scale, axisModel);
+    axisHelper.niceScaleExtent(scale, axisModel as AxisBaseModel);
     return scale;
 }
 
diff --git a/src/layout/barGrid.ts b/src/layout/barGrid.ts
index 999dfe9..691202a 100644
--- a/src/layout/barGrid.ts
+++ b/src/layout/barGrid.ts
@@ -411,10 +411,13 @@ function doCalBarWidthAndOffset(seriesInfoList: LayoutSeriesInfo[]) {
  * @param seriesModel If not provided, return all.
  * @return {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  */
-export function retrieveColumnLayout(
+function retrieveColumnLayout(barWidthAndOffset: BarWidthAndOffset, axis: Axis2D): typeof barWidthAndOffset[string]
+// eslint-disable-next-line max-len
+function retrieveColumnLayout(barWidthAndOffset: BarWidthAndOffset, axis: Axis2D, seriesModel: BarSeriesModel): typeof barWidthAndOffset[string][string]
+function retrieveColumnLayout(
     barWidthAndOffset: BarWidthAndOffset,
     axis: Axis2D,
-    seriesModel: BarSeriesModel
+    seriesModel?: BarSeriesModel
 ) {
     if (barWidthAndOffset && axis) {
         var result = barWidthAndOffset[getAxisKey(axis)];
@@ -424,6 +427,7 @@ export function retrieveColumnLayout(
         return result;
     }
 }
+export {retrieveColumnLayout};
 
 export function layout(seriesType: string, ecModel: GlobalModel) {
 
diff --git a/src/model/mixin/textStyle.ts b/src/model/mixin/textStyle.ts
index 193b820..2779c36 100644
--- a/src/model/mixin/textStyle.ts
+++ b/src/model/mixin/textStyle.ts
@@ -25,6 +25,9 @@ import { LabelOption, ColorString } from '../../util/types';
 var PATH_COLOR = ['textStyle', 'color'] as const;
 
 type LabelFontOption = Pick<LabelOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>
+type LabelRectRelatedOption = Pick<LabelOption,
+    'align' | 'verticalAlign' | 'padding' | 'lineHeight' | 'baseline' | 'rich'
+> & LabelFontOption;
 
 class TextStyleMixin {
     /**
@@ -52,7 +55,7 @@ class TextStyleMixin {
         }, this.ecModel);
     }
 
-    getTextRect(this: Model<LabelOption> & TextStyleMixin, text: string): graphicUtil.BoundingRect {
+    getTextRect(this: Model<LabelRectRelatedOption> & TextStyleMixin, text: string): graphicUtil.BoundingRect {
         return textContain.getBoundingRect(
             text,
             this.getFont(),
diff --git a/src/scale/Log.ts b/src/scale/Log.ts
index 2fd9a51..04de008 100644
--- a/src/scale/Log.ts
+++ b/src/scale/Log.ts
@@ -42,9 +42,9 @@ var mathLog = Math.log;
 
 class LogScale extends Scale {
 
-    type = 'log';
+    readonly type = 'log';
 
-    private base = 10;
+    base = 10;
 
     private _originalScale: IntervalScale = new IntervalScale();
 
diff --git a/src/scale/Ordinal.ts b/src/scale/Ordinal.ts
index 69b0261..51fdc07 100644
--- a/src/scale/Ordinal.ts
+++ b/src/scale/Ordinal.ts
@@ -30,6 +30,7 @@ import OrdinalMeta from '../data/OrdinalMeta';
 import List from '../data/List';
 import * as scaleHelper from './helper';
 import { OrdinalRawValue, OrdinalNumber, DimensionLoose } from '../util/types';
+import { AxisBaseOption } from '../coord/axisCommonTypes';
 
 
 class OrdinalScale extends Scale {
@@ -40,7 +41,7 @@ class OrdinalScale extends Scale {
 
 
     constructor(setting?: {
-        ordinalMeta?: OrdinalMeta | OrdinalRawValue[],
+        ordinalMeta?: OrdinalMeta | AxisBaseOption['data'],
         extent?: [number, number]
     }) {
         super(setting);
diff --git a/src/scale/Scale.ts b/src/scale/Scale.ts
index 9303428..84f6f05 100644
--- a/src/scale/Scale.ts
+++ b/src/scale/Scale.ts
@@ -23,7 +23,6 @@ import { Dictionary } from 'zrender/src/core/types';
 import List from '../data/List';
 import { DimensionName, ScaleDataValue, OptionDataValue } from '../util/types';
 
-
 abstract class Scale {
 
     type: string;
@@ -152,12 +151,13 @@ abstract class Scale {
      */
     abstract getLabel(tick: any): string;
 
-    abstract getTicks(expandToNicedExtent: boolean): number[];
+    abstract getTicks(expandToNicedExtent?: boolean): number[];
 
     abstract getMinorTicks(splitNumber: number): number[][];
 
     static registerClass: clazzUtil.ClassManager['registerClass'];
 
+    static getClass: clazzUtil.ClassManager['getClass'];
 }
 
 type ScaleConstructor = typeof Scale & clazzUtil.ClassManager;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org