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/02/26 12:11:29 UTC

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

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 1fb92cc  ts: add types for polar coord
1fb92cc is described below

commit 1fb92ccd728dc1d510fb9cbe576d7b5f34af9e1e
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Feb 26 20:10:57 2020 +0800

    ts: add types for polar coord
---
 src/component/tooltip/TooltipRichContent.ts |   2 +-
 src/coord/Axis.ts                           |   2 +-
 src/coord/CoordinateSystem.ts               |   8 +-
 src/coord/axisModelCreator.ts               |   2 +-
 src/coord/polar/AngleAxis.ts                |  69 +++++------
 src/coord/polar/AxisModel.ts                |  86 ++++++++-----
 src/coord/polar/Polar.ts                    | 184 +++++++++++-----------------
 src/coord/polar/PolarModel.ts               |  42 ++++---
 src/coord/polar/RadiusAxis.ts               |  49 ++++----
 src/coord/polar/polarCreator.ts             |  57 +++++----
 src/coord/polar/prepareCustom.ts            |  25 ++--
 11 files changed, 256 insertions(+), 270 deletions(-)

diff --git a/src/component/tooltip/TooltipRichContent.ts b/src/component/tooltip/TooltipRichContent.ts
index 2890625..1b3f2ac 100644
--- a/src/component/tooltip/TooltipRichContent.ts
+++ b/src/component/tooltip/TooltipRichContent.ts
@@ -22,7 +22,7 @@ import * as zrUtil from 'zrender/src/core/util';
 import Text from 'zrender/src/graphic/Text';
 import ExtensionAPI from '../../ExtensionAPI';
 import { ZRenderType } from 'zrender/src/zrender';
-import TooltipModel, { TooltipOption } from './TooltipModel';
+import { TooltipOption } from './TooltipModel';
 import * as graphic from '../../util/graphic';
 import { Dictionary } from 'zrender/src/core/types';
 import { ColorString } from '../../util/types';
diff --git a/src/coord/Axis.ts b/src/coord/Axis.ts
index a551889..99e8a98 100644
--- a/src/coord/Axis.ts
+++ b/src/coord/Axis.ts
@@ -47,7 +47,7 @@ class Axis {
     readonly dim: DimensionName;
 
     // Axis scale
-    readonly scale: Scale;
+    scale: Scale;
 
     private _extent: [number, number];
 
diff --git a/src/coord/CoordinateSystem.ts b/src/coord/CoordinateSystem.ts
index 632f1e2..327e0a9 100644
--- a/src/coord/CoordinateSystem.ts
+++ b/src/coord/CoordinateSystem.ts
@@ -83,8 +83,8 @@ export interface CoordinateSystemMaster {
 }
 
 /**
- * For example: cartesian is CoordinateSystemExecutive.
- * series.coordinateSystem is CoordinateSystemExecutive.
+ * For example: cartesian is CoordinateSystem.
+ * series.coordinateSystem is CoordinateSystem.
  */
 export interface CoordinateSystem {
 
@@ -128,7 +128,9 @@ export interface CoordinateSystem {
 
     getRoamTransform?: () => MatrixArray;
 
-    getArea?: () => BoundingRect;
+    getArea?: () => {
+        contain(x: number, y: number): boolean
+    };
 
     // Only `coord/View.js` implements `getBoundingRect`.
     // But if other coord sys implement it, should follow this signature.
diff --git a/src/coord/axisModelCreator.ts b/src/coord/axisModelCreator.ts
index fa62412..a2c161c 100644
--- a/src/coord/axisModelCreator.ts
+++ b/src/coord/axisModelCreator.ts
@@ -40,7 +40,7 @@ type Constructor<T> = new (...args: any[]) => T;
 export default function <
     AxisOptionT extends AxisBaseOption,
     AxisModelCtor extends Constructor<ComponentModel<AxisOptionT>>
->(
+> (
     axisName: DimensionName,
     BaseAxisModelClass: AxisModelCtor,
     extraDefaultOption?: AxisOptionT
diff --git a/src/coord/polar/AngleAxis.ts b/src/coord/polar/AngleAxis.ts
index 69d025b..cbcffcc 100644
--- a/src/coord/polar/AngleAxis.ts
+++ b/src/coord/polar/AngleAxis.ts
@@ -17,46 +17,38 @@
 * under the License.
 */
 
-// @ts-nocheck
-
-import * as zrUtil from 'zrender/src/core/util';
 import * as textContain from 'zrender/src/contain/text';
 import Axis from '../Axis';
 import {makeInner} from '../../util/model';
-
-var inner = makeInner();
-
-function AngleAxis(scale, angleExtent) {
-
-    angleExtent = angleExtent || [0, 360];
-
-    Axis.call(this, 'angle', scale, angleExtent);
-
-    /**
-     * Axis type
-     *  - 'category'
-     *  - 'value'
-     *  - 'time'
-     *  - 'log'
-     * @type {string}
-     */
-    this.type = 'category';
+import { OptionAxisType } from '../axisCommonTypes';
+import Scale from '../../scale/Scale';
+import OrdinalScale from '../../scale/Ordinal';
+import Polar from './Polar';
+import { AngleAxisModel } from './AxisModel';
+
+var inner = makeInner<{
+    lastAutoInterval: number
+    lastTickCount: number
+}>();
+
+interface AngleAxis {
+    dataToAngle: Axis['dataToCoord']
+    angleToData: Axis['coordToData']
 }
+class AngleAxis extends Axis {
+    type: OptionAxisType
 
-AngleAxis.prototype = {
+    polar: Polar
 
-    constructor: AngleAxis,
+    model: AngleAxisModel
 
-    /**
-     * @override
-     */
-    pointToData: function (point, clamp) {
-        return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
-    },
-
-    dataToAngle: Axis.prototype.dataToCoord,
+    constructor(scale?: Scale, angleExtent?: [number, number]) {
+        super('angle', scale, angleExtent || [0, 360]);
+    }
 
-    angleToData: Axis.prototype.coordToData,
+    pointToData(point: number[], clamp?: boolean) {
+        return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
+    }
 
     /**
      * Only be called in category axis.
@@ -65,11 +57,11 @@ AngleAxis.prototype = {
      * @override
      * @return {number} Auto interval for cateogry axis tick and label
      */
-    calculateCategoryInterval: function () {
+    calculateCategoryInterval() {
         var axis = this;
         var labelModel = axis.getLabelModel();
 
-        var ordinalScale = axis.scale;
+        var ordinalScale = axis.scale as OrdinalScale;
         var ordinalExtent = ordinalScale.getExtent();
         // Providing this method is for optimization:
         // avoid generating a long array by `getTicks`
@@ -87,7 +79,7 @@ AngleAxis.prototype = {
         // Not precise, just use height as text width
         // and each distance from axis line yet.
         var rect = textContain.getBoundingRect(
-            tickValue, labelModel.getFont(), 'center', 'top'
+            tickValue + '', labelModel.getFont(), 'center', 'top'
         );
         var maxH = Math.max(rect.height, 7);
 
@@ -122,8 +114,11 @@ AngleAxis.prototype = {
 
         return interval;
     }
-};
+}
+
+AngleAxis.prototype.dataToAngle = Axis.prototype.dataToCoord;
+
+AngleAxis.prototype.angleToData = Axis.prototype.coordToData;
 
-zrUtil.inherits(AngleAxis, Axis);
 
 export default AngleAxis;
\ No newline at end of file
diff --git a/src/coord/polar/AxisModel.ts b/src/coord/polar/AxisModel.ts
index 7169112..244f7e6 100644
--- a/src/coord/polar/AxisModel.ts
+++ b/src/coord/polar/AxisModel.ts
@@ -17,59 +17,89 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import * as zrUtil from 'zrender/src/core/util';
 import ComponentModel from '../../model/Component';
 import axisModelCreator from '../axisModelCreator';
 import {AxisModelCommonMixin} from '../axisModelCommonMixin';
+import { AxisBaseOption } from '../axisCommonTypes';
+import AngleAxis from './AngleAxis';
+import RadiusAxis from './RadiusAxis';
 
-var PolarAxisModel = ComponentModel.extend({
+export interface AngleAxisOption extends AxisBaseOption {
+    /**
+     * Index of host polar component
+     */
+    polarIndex?: number
+    /**
+     * Id of host polar component
+     */
+    polarId?: string
 
-    type: 'polarAxis',
+    startAngle?: number
+    clockwise?: boolean
 
+    splitNumber?: number
+
+    axisLabel?: Omit<AxisBaseOption['axisLabel'], 'rotate'> & {
+        rotate?: AxisBaseOption['axisLabel']['rotate'] | false
+    }
+}
+
+export interface RadiusAxisOption extends AxisBaseOption {
     /**
-     * @type {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
+     * Index of host polar component
      */
-    axis: null,
-
+    polarIndex?: number
     /**
-     * @override
+     * Id of host polar component
      */
-    getCoordSysModel: function () {
+    polarId?: string
+}
+
+type PolarAxisOption = AngleAxisOption | RadiusAxisOption;
+
+class PolarAxisModel<T extends PolarAxisOption = PolarAxisOption> extends ComponentModel<T> {
+    static type = 'polarAxis'
+
+    getCoordSysModel(): ComponentModel {
         return this.ecModel.queryComponents({
             mainType: 'polar',
             index: this.option.polarIndex,
             id: this.option.polarId
         })[0];
     }
+}
 
-});
-
+interface PolarAxisModel<T extends PolarAxisOption = PolarAxisOption> extends AxisModelCommonMixin<T> {}
 zrUtil.mixin(PolarAxisModel, AxisModelCommonMixin);
 
-var polarAxisDefaultExtendedOption = {
-    angle: {
-        // polarIndex: 0,
-        // polarId: '',
+export {PolarAxisModel};
 
-        startAngle: 90,
+export class AngleAxisModel extends PolarAxisModel<AngleAxisOption> {
+    axis: AngleAxis
+}
+export class RadiusAxisModel extends PolarAxisModel<RadiusAxisOption> {
+    axis: RadiusAxis
+}
 
-        clockwise: true,
+ComponentModel.registerClass(PolarAxisModel);
 
-        splitNumber: 12,
+const angleAxisExtraOption: AngleAxisOption = {
+    startAngle: 90,
 
-        axisLabel: {
-            rotate: false
-        }
-    },
-    radius: {
-        // polarIndex: 0,
-        // polarId: '',
+    clockwise: true,
 
-        splitNumber: 5
+    splitNumber: 12,
+
+    axisLabel: {
+        rotate: false
     }
 };
 
-axisModelCreator('angle', PolarAxisModel, polarAxisDefaultExtendedOption.angle);
-axisModelCreator('radius', PolarAxisModel, polarAxisDefaultExtendedOption.radius);
+const radiusAxisExtraOption: RadiusAxisOption = {
+    splitNumber: 5
+};
+
+
+axisModelCreator('angle', AngleAxisModel, angleAxisExtraOption);
+axisModelCreator('radius', RadiusAxisModel, radiusAxisExtraOption);
diff --git a/src/coord/polar/Polar.ts b/src/coord/polar/Polar.ts
index ebf1024..cf1fa87 100644
--- a/src/coord/polar/Polar.ts
+++ b/src/coord/polar/Polar.ts
@@ -17,115 +17,84 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 /**
  * @module echarts/coord/polar/Polar
  */
 
 import RadiusAxis from './RadiusAxis';
 import AngleAxis from './AngleAxis';
+import PolarModel from './PolarModel';
+import { CoordinateSystem, CoordinateSystemMaster } from '../CoordinateSystem';
+import GlobalModel from '../../model/Global';
+import { ParsedModelFinder } from '../../util/model';
+import { ScaleDataValue } from '../../util/types';
+import ExtensionAPI from '../../ExtensionAPI';
 
-/**
- * @alias {module:echarts/coord/polar/Polar}
- * @constructor
- * @param {string} name
- */
-var Polar = function (name) {
+interface Polar {
+    update(ecModel: GlobalModel, api: ExtensionAPI): void
+}
+class Polar implements CoordinateSystem, CoordinateSystemMaster {
 
-    /**
-     * @type {string}
-     */
-    this.name = name || '';
+    readonly name: string;
 
-    /**
-     * x of polar center
-     * @type {number}
-     */
-    this.cx = 0;
+    readonly dimensions = ['radius', 'angle']
 
-    /**
-     * y of polar center
-     * @type {number}
-     */
-    this.cy = 0;
+    readonly type = 'polar'
 
     /**
-     * @type {module:echarts/coord/polar/RadiusAxis}
-     * @private
+     * x of polar center
      */
-    this._radiusAxis = new RadiusAxis();
+    cx = 0;
 
     /**
-     * @type {module:echarts/coord/polar/AngleAxis}
-     * @private
+     * y of polar center
      */
-    this._angleAxis = new AngleAxis();
-
-    this._radiusAxis.polar = this._angleAxis.polar = this;
-};
+    cy = 0;
 
-Polar.prototype = {
+    private _radiusAxis = new RadiusAxis();
 
-    type: 'polar',
+    private _angleAxis = new AngleAxis();
 
-    axisPointerEnabled: true,
+    axisPointerEnabled = true
 
-    constructor: Polar,
+    model: PolarModel
 
-    /**
-     * @param {Array.<string>}
-     * @readOnly
-     */
-    dimensions: ['radius', 'angle'],
+    constructor(name: string) {
+        this.name = name || '';
 
-    /**
-     * @type {module:echarts/coord/PolarModel}
-     */
-    model: null,
+        this._radiusAxis.polar = this._angleAxis.polar = this;
+    }
 
     /**
      * If contain coord
-     * @param {Array.<number>} point
-     * @return {boolean}
      */
-    containPoint: function (point) {
+    containPoint(point: number[]) {
         var coord = this.pointToCoord(point);
         return this._radiusAxis.contain(coord[0])
             && this._angleAxis.contain(coord[1]);
-    },
+    }
 
     /**
      * If contain data
-     * @param {Array.<number>} data
-     * @return {boolean}
      */
-    containData: function (data) {
+    containData(data: number[]) {
         return this._radiusAxis.containData(data[0])
             && this._angleAxis.containData(data[1]);
-    },
+    }
 
-    /**
-     * @param {string} dim
-     * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
-     */
-    getAxis: function (dim) {
-        return this['_' + dim + 'Axis'];
-    },
+    getAxis(dim: 'radius' | 'angle') {
+        const key = ('_' + dim + 'Axis') as '_radiusAxis' | '_angleAxis';
+        return this[key];
+    }
 
-    /**
-     * @return {Array.<module:echarts/coord/Axis>}
-     */
-    getAxes: function () {
+    getAxes() {
         return [this._radiusAxis, this._angleAxis];
-    },
+    }
 
     /**
      * Get axes by type of scale
-     * @param {string} scaleType
-     * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
      */
-    getAxesByScale: function (scaleType) {
+    getAxesByScale(scaleType: 'ordinal' | 'interval' | 'time' | 'log') {
         var axes = [];
         var angleAxis = this._angleAxis;
         var radiusAxis = this._radiusAxis;
@@ -133,89 +102,66 @@ Polar.prototype = {
         radiusAxis.scale.type === scaleType && axes.push(radiusAxis);
 
         return axes;
-    },
+    }
 
-    /**
-     * @return {module:echarts/coord/polar/AngleAxis}
-     */
-    getAngleAxis: function () {
+    getAngleAxis() {
         return this._angleAxis;
-    },
+    }
 
-    /**
-     * @return {module:echarts/coord/polar/RadiusAxis}
-     */
-    getRadiusAxis: function () {
+    getRadiusAxis() {
         return this._radiusAxis;
-    },
+    }
 
-    /**
-     * @param {module:echarts/coord/polar/Axis}
-     * @return {module:echarts/coord/polar/Axis}
-     */
-    getOtherAxis: function (axis) {
+    getOtherAxis(axis: AngleAxis | RadiusAxis): AngleAxis | RadiusAxis {
         var angleAxis = this._angleAxis;
         return axis === angleAxis ? this._radiusAxis : angleAxis;
-    },
+    }
 
     /**
      * Base axis will be used on stacking.
      *
-     * @return {module:echarts/coord/polar/Axis}
      */
-    getBaseAxis: function () {
+    getBaseAxis() {
         return this.getAxesByScale('ordinal')[0]
             || this.getAxesByScale('time')[0]
             || this.getAngleAxis();
-    },
+    }
 
-    /**
-     * @param {string} [dim] 'radius' or 'angle' or 'auto' or null/undefined
-     * @return {Object} {baseAxes: [], otherAxes: []}
-     */
-    getTooltipAxes: function (dim) {
+    getTooltipAxes(dim: 'radius' | 'angle' | 'auto') {
         var baseAxis = (dim != null && dim !== 'auto')
             ? this.getAxis(dim) : this.getBaseAxis();
         return {
             baseAxes: [baseAxis],
             otherAxes: [this.getOtherAxis(baseAxis)]
         };
-    },
+    }
 
     /**
      * Convert a single data item to (x, y) point.
      * Parameter data is an array which the first element is radius and the second is angle
-     * @param {Array.<number>} data
-     * @param {boolean} [clamp=false]
-     * @return {Array.<number>}
      */
-    dataToPoint: function (data, clamp) {
+    dataToPoint(data: ScaleDataValue[], clamp?: boolean) {
         return this.coordToPoint([
             this._radiusAxis.dataToRadius(data[0], clamp),
             this._angleAxis.dataToAngle(data[1], clamp)
         ]);
-    },
+    }
 
     /**
      * Convert a (x, y) point to data
-     * @param {Array.<number>} point
-     * @param {boolean} [clamp=false]
-     * @return {Array.<number>}
      */
-    pointToData: function (point, clamp) {
+    pointToData(point: number[], clamp?: boolean) {
         var coord = this.pointToCoord(point);
         return [
             this._radiusAxis.radiusToData(coord[0], clamp),
             this._angleAxis.angleToData(coord[1], clamp)
         ];
-    },
+    }
 
     /**
      * Convert a (x, y) point to (radius, angle) coord
-     * @param {Array.<number>} point
-     * @return {Array.<number>}
      */
-    pointToCoord: function (point) {
+    pointToCoord(point: number[]) {
         var dx = point[0] - this.cx;
         var dy = point[1] - this.cy;
         var angleAxis = this.getAngleAxis();
@@ -241,14 +187,12 @@ Polar.prototype = {
         }
 
         return [radius, radian];
-    },
+    }
 
     /**
      * Convert a (radius, angle) coord to (x, y) point
-     * @param {Array.<number>} coord
-     * @return {Array.<number>}
      */
-    coordToPoint: function (coord) {
+    coordToPoint(coord: number[]) {
         var radius = coord[0];
         var radian = coord[1] / 180 * Math.PI;
         var x = Math.cos(radian) * radius + this.cx;
@@ -256,14 +200,13 @@ Polar.prototype = {
         var y = -Math.sin(radian) * radius + this.cy;
 
         return [x, y];
-    },
+    }
 
     /**
      * Get ring area of cartesian.
      * Area will have a contain function to determine if a point is in the coordinate system.
-     * @return {Ring}
      */
-    getArea: function () {
+    getArea() {
 
         var angleAxis = this.getAngleAxis();
         var radiusAxis = this.getRadiusAxis();
@@ -282,7 +225,7 @@ Polar.prototype = {
             startAngle: -angleExtent[0] * RADIAN,
             endAngle: -angleExtent[1] * RADIAN,
             clockwise: angleAxis.inverse,
-            contain: function (x, y) {
+            contain(x: number, y: number) {
                 // It's a ring shape.
                 // Start angle and end angle don't matter
                 var dx = x - this.cx;
@@ -296,6 +239,17 @@ Polar.prototype = {
         };
     }
 
-};
+    convertToPixel(ecModel: GlobalModel, finder: ParsedModelFinder, value: ScaleDataValue[]) {
+        const seriesModel = finder.seriesModel;
+        const coordSys = seriesModel ? seriesModel.coordinateSystem : null;
+        return coordSys === this ? this.dataToPoint(value) : null;
+    }
+
+    convertFromPixel(ecModel: GlobalModel, finder: ParsedModelFinder, pixel: number[]) {
+        const seriesModel = finder.seriesModel;
+        const coordSys = seriesModel ? seriesModel.coordinateSystem : null;
+        return coordSys === this ? this.pointToData(pixel) : null;
+    }
+}
 
 export default Polar;
\ No newline at end of file
diff --git a/src/coord/polar/PolarModel.ts b/src/coord/polar/PolarModel.ts
index aded158..368e58c 100644
--- a/src/coord/polar/PolarModel.ts
+++ b/src/coord/polar/PolarModel.ts
@@ -17,39 +17,37 @@
 * under the License.
 */
 
-// @ts-nocheck
+import { ComponentOption, CircleLayoutOptionMixin } from '../../util/types';
+import ComponentModel from '../../model/Component';
+import Polar from './Polar';
+import { AngleAxisModel, RadiusAxisModel } from './AxisModel';
 
-import * as echarts from '../../echarts';
-import './AxisModel';
+export interface PolarOption extends ComponentOption, CircleLayoutOptionMixin {
+}
 
-export default echarts.extendComponentModel({
+class PolarModel extends ComponentModel<PolarOption> {
+    static type = 'polar' as const
+    type = PolarModel.type
 
-    type: 'polar',
+    static dependencies = ['radiusAxis', 'angleAxis']
 
-    dependencies: ['polarAxis', 'angleAxis'],
+    coordinateSystem: Polar
 
-    /**
-     * @type {module:echarts/coord/polar/Polar}
-     */
-    coordinateSystem: null,
-
-    /**
-     * @param {string} axisType
-     * @return {module:echarts/coord/polar/AxisModel}
-     */
-    findAxisModel: function (axisType) {
+    findAxisModel(axisType: 'angleAxis'): AngleAxisModel
+    findAxisModel(axisType: 'radiusAxis'): RadiusAxisModel
+    findAxisModel(axisType: 'angleAxis' | 'radiusAxis'): AngleAxisModel | RadiusAxisModel {
         var foundAxisModel;
         var ecModel = this.ecModel;
 
-        ecModel.eachComponent(axisType, function (axisModel) {
+        ecModel.eachComponent(axisType, function (this: PolarModel, axisModel: AngleAxisModel | RadiusAxisModel) {
             if (axisModel.getCoordSysModel() === this) {
                 foundAxisModel = axisModel;
             }
         }, this);
         return foundAxisModel;
-    },
+    }
 
-    defaultOption: {
+    static defaultOption: PolarOption = {
 
         zlevel: 0,
 
@@ -59,4 +57,8 @@ export default echarts.extendComponentModel({
 
         radius: '80%'
     }
-});
\ No newline at end of file
+}
+
+ComponentModel.registerClass(PolarModel);
+
+export default PolarModel;
\ No newline at end of file
diff --git a/src/coord/polar/RadiusAxis.ts b/src/coord/polar/RadiusAxis.ts
index 2068a7a..0784816 100644
--- a/src/coord/polar/RadiusAxis.ts
+++ b/src/coord/polar/RadiusAxis.ts
@@ -17,42 +17,35 @@
 * under the License.
 */
 
-// @ts-nocheck
-
-import * as zrUtil from 'zrender/src/core/util';
 import Axis from '../Axis';
+import { OptionAxisType } from '../axisCommonTypes';
+import Scale from '../../scale/Scale';
+import Polar from './Polar';
+import { RadiusAxisModel } from './AxisModel';
+
+interface RadiusAxis {
+    dataToRadius: Axis['dataToCoord']
+    radiusToData: Axis['coordToData']
+}
 
-function RadiusAxis(scale, radiusExtent) {
-
-    Axis.call(this, 'radius', scale, radiusExtent);
+class RadiusAxis extends Axis {
+    type: OptionAxisType
 
-    /**
-     * Axis type
-     *  - 'category'
-     *  - 'value'
-     *  - 'time'
-     *  - 'log'
-     * @type {string}
-     */
-    this.type = 'category';
-}
+    polar: Polar
 
-RadiusAxis.prototype = {
+    model: RadiusAxisModel
 
-    constructor: RadiusAxis,
+    constructor(scale?: Scale, radiusExtent?: [number, number]) {
+        super('radius', scale, radiusExtent);
+    }
 
-    /**
-     * @override
-     */
-    pointToData: function (point, clamp) {
+    pointToData(point: number[], clamp?: boolean) {
         return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
-    },
-
-    dataToRadius: Axis.prototype.dataToCoord,
+    }
+}
 
-    radiusToData: Axis.prototype.coordToData
-};
+RadiusAxis.prototype.dataToRadius = Axis.prototype.dataToCoord;
 
-zrUtil.inherits(RadiusAxis, Axis);
+RadiusAxis.prototype.radiusToData = Axis.prototype.coordToData;
 
 export default RadiusAxis;
\ No newline at end of file
diff --git a/src/coord/polar/polarCreator.ts b/src/coord/polar/polarCreator.ts
index 012972d..4286de4 100644
--- a/src/coord/polar/polarCreator.ts
+++ b/src/coord/polar/polarCreator.ts
@@ -17,8 +17,6 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 // TODO Axis scale
 
 import {__DEV__} from '../../config';
@@ -32,14 +30,20 @@ import {
 import CoordinateSystem from '../../CoordinateSystem';
 import {getStackedDimension} from '../../data/helper/dataStackHelper';
 
-import './PolarModel';
+import PolarModel from './PolarModel';
+import ExtensionAPI from '../../ExtensionAPI';
+import GlobalModel from '../../model/Global';
+import OrdinalScale from '../../scale/Ordinal';
+import RadiusAxis from './RadiusAxis';
+import AngleAxis from './AngleAxis';
+import { PolarAxisModel, AngleAxisModel, RadiusAxisModel } from './AxisModel';
+import SeriesModel from '../../model/Series';
+import { SeriesOption } from '../../util/types';
 
 /**
  * Resize method bound to the polar
- * @param {module:echarts/coord/polar/PolarModel} polarModel
- * @param {module:echarts/ExtensionAPI} api
  */
-function resizePolar(polar, polarModel, api) {
+function resizePolar(polar: Polar, polarModel: PolarModel, api: ExtensionAPI) {
     var center = polarModel.get('center');
     var width = api.getWidth();
     var height = api.getHeight();
@@ -58,20 +62,20 @@ function resizePolar(polar, polarModel, api) {
         // r0 = 0
         radius = [0, radius];
     }
-    radius = [
+    const parsedRadius = [
         parsePercent(radius[0], size),
         parsePercent(radius[1], size)
     ];
 
     radiusAxis.inverse
-        ? radiusAxis.setExtent(radius[1], radius[0])
-        : radiusAxis.setExtent(radius[0], radius[1]);
+        ? radiusAxis.setExtent(parsedRadius[1], parsedRadius[0])
+        : radiusAxis.setExtent(parsedRadius[0], parsedRadius[1]);
 }
 
 /**
  * Update polar
  */
-function updatePolarScale(ecModel, api) {
+function updatePolarScale(this: Polar, ecModel: GlobalModel, api: ExtensionAPI) {
     var polar = this;
     var angleAxis = polar.getAngleAxis();
     var radiusAxis = polar.getRadiusAxis();
@@ -101,33 +105,33 @@ function updatePolarScale(ecModel, api) {
     // Fix extent of category angle axis
     if (angleAxis.type === 'category' && !angleAxis.onBand) {
         var extent = angleAxis.getExtent();
-        var diff = 360 / angleAxis.scale.count();
+        var diff = 360 / (angleAxis.scale as OrdinalScale).count();
         angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
         angleAxis.setExtent(extent[0], extent[1]);
     }
 }
 
+function isAngleAxisModel(axisModel: AngleAxisModel | PolarAxisModel): axisModel is AngleAxisModel {
+    return axisModel.mainType === 'angleAxis';
+}
 /**
  * Set common axis properties
- * @param {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
- * @param {module:echarts/coord/polar/AxisModel}
- * @inner
  */
-function setAxis(axis, axisModel) {
+function setAxis(axis: RadiusAxis | AngleAxis, axisModel: PolarAxisModel) {
     axis.type = axisModel.get('type');
     axis.scale = createScaleByModel(axisModel);
     axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
     axis.inverse = axisModel.get('inverse');
 
-    if (axisModel.mainType === 'angleAxis') {
-        axis.inverse ^= axisModel.get('clockwise');
+    if (isAngleAxisModel(axisModel)) {
+        axis.inverse = axis.inverse !== axisModel.get('clockwise');
         var startAngle = axisModel.get('startAngle');
         axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
     }
 
     // Inject axis instance
     axisModel.axis = axis;
-    axis.model = axisModel;
+    axis.model = axisModel as AngleAxisModel | RadiusAxisModel;
 }
 
 
@@ -135,10 +139,10 @@ var polarCreator = {
 
     dimensions: Polar.prototype.dimensions,
 
-    create: function (ecModel, api) {
-        var polarList = [];
-        ecModel.eachComponent('polar', function (polarModel, idx) {
-            var polar = new Polar(idx);
+    create: function (ecModel: GlobalModel, api: ExtensionAPI) {
+        var polarList: Polar[] = [];
+        ecModel.eachComponent('polar', function (polarModel: PolarModel, idx: number) {
+            var polar = new Polar(idx + '');
             // Inject resize and update method
             polar.update = updatePolarScale;
 
@@ -159,18 +163,21 @@ var polarCreator = {
             polar.model = polarModel;
         });
         // Inject coordinateSystem to series
-        ecModel.eachSeries(function (seriesModel) {
+        ecModel.eachSeries(function (seriesModel: SeriesModel<SeriesOption & {
+            polarIndex?: number
+            polarId?: string
+        }>) {
             if (seriesModel.get('coordinateSystem') === 'polar') {
                 var polarModel = ecModel.queryComponents({
                     mainType: 'polar',
                     index: seriesModel.get('polarIndex'),
                     id: seriesModel.get('polarId')
-                })[0];
+                })[0] as PolarModel;
 
                 if (__DEV__) {
                     if (!polarModel) {
                         throw new Error(
-                            'Polar "' + zrUtil.retrieve(
+                            'Polar "' + zrUtil.retrieve<number | string>(
                                 seriesModel.get('polarIndex'),
                                 seriesModel.get('polarId'),
                                 0
diff --git a/src/coord/polar/prepareCustom.ts b/src/coord/polar/prepareCustom.ts
index 16d02b4..01c2a4d 100644
--- a/src/coord/polar/prepareCustom.ts
+++ b/src/coord/polar/prepareCustom.ts
@@ -17,21 +17,24 @@
 * under the License.
 */
 
-// @ts-nocheck
-
 import * as zrUtil from 'zrender/src/core/util';
+import Polar from './Polar';
+import RadiusAxis from './RadiusAxis';
+import AngleAxis from './AngleAxis';
 
-function dataToCoordSize(dataSize, dataItem) {
+function dataToCoordSize(this: Polar, dataSize: number[], dataItem: number[]) {
     // dataItem is necessary in log axis.
     return zrUtil.map(['Radius', 'Angle'], function (dim, dimIdx) {
-        var axis = this['get' + dim + 'Axis']();
-        var val = dataItem[dimIdx];
-        var halfSize = dataSize[dimIdx] / 2;
-        var method = 'dataTo' + dim;
+        const getterName = 'get' + dim + 'Axis' as 'getAngleAxis'| 'getRadiusAxis';
+        // TODO: TYPE Check Angle Axis
+        const axis = this[getterName]() as RadiusAxis;
+        const val = dataItem[dimIdx];
+        const halfSize = dataSize[dimIdx] / 2;
+        const converterName = 'dataTo' + dim as 'dataToRadius';
 
         var result = axis.type === 'category'
             ? axis.getBandWidth()
-            : Math.abs(axis[method](val - halfSize) - axis[method](val + halfSize));
+            : Math.abs(axis[converterName](val - halfSize) - axis[converterName](val + halfSize));
 
         if (dim === 'Angle') {
             result = result * Math.PI / 180;
@@ -42,7 +45,7 @@ function dataToCoordSize(dataSize, dataItem) {
     }, this);
 }
 
-export default function (coordSys) {
+export default function (coordSys: Polar) {
     var radiusAxis = coordSys.getRadiusAxis();
     var angleAxis = coordSys.getAngleAxis();
     var radius = radiusAxis.getExtent();
@@ -57,13 +60,13 @@ export default function (coordSys) {
             r0: radius[0]
         },
         api: {
-            coord: zrUtil.bind(function (data) {
+            coord: function (data: number[]) {
                 var radius = radiusAxis.dataToRadius(data[0]);
                 var angle = angleAxis.dataToAngle(data[1]);
                 var coord = coordSys.coordToPoint([radius, angle]);
                 coord.push(radius, angle * Math.PI / 180);
                 return coord;
-            }),
+            },
             size: zrUtil.bind(dataToCoordSize, coordSys)
         }
     };


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