Skip to content

Commit

Permalink
fix(type): optimize types for dts bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Nov 5, 2020
1 parent 1ea68de commit f9bd8da
Show file tree
Hide file tree
Showing 71 changed files with 150 additions and 117 deletions.
14 changes: 11 additions & 3 deletions src/ExtensionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {EChartsType} from './echarts';
import {CoordinateSystemMaster} from './coord/CoordinateSystem';
import Element from 'zrender/src/Element';
import ComponentModel from './model/Component';
import ComponentView from './view/Component';
import ChartView from './view/Chart';
import SeriesModel from './model/Series';
import GlobalModel from './model/Global';

const availableMethods: (keyof EChartsType)[] = [
'getDom',
Expand All @@ -35,10 +39,10 @@ const availableMethods: (keyof EChartsType)[] = [
'off',
'getDataURL',
'getConnectedDataURL',
'getModel',
// 'getModel',
'getOption',
'getViewOfComponentModel',
'getViewOfSeriesModel',
// 'getViewOfComponentModel',
// 'getViewOfSeriesModel',
'getId',
'updateLabelLayout'
];
Expand All @@ -62,6 +66,10 @@ abstract class ExtensionAPI {
abstract leaveSelect(el: Element): void;
abstract enterBlur(el: Element): void;
abstract leaveBlur(el: Element): void;
// These methods are not planned to be exposed to outside.
abstract getViewOfComponentModel(componentModel: ComponentModel): ComponentView;
abstract getViewOfSeriesModel(seriesModel: SeriesModel): ChartView;
abstract getModel(): GlobalModel;
}

export default ExtensionAPI;
2 changes: 1 addition & 1 deletion src/chart/boxplot/boxplotLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface BoxplotItemLayout {
initBaseline: number
}

export default function (ecModel: GlobalModel) {
export default function boxplotLayout(ecModel: GlobalModel) {

const groupResult = groupSeriesByAxis(ecModel);

Expand Down
2 changes: 1 addition & 1 deletion src/chart/boxplot/boxplotVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../ExtensionAPI';
import BoxplotSeriesModel from './BoxplotSeries';

export default function (ecModel: GlobalModel, api: ExtensionAPI) {
export default function boxplotVisual(ecModel: GlobalModel, api: ExtensionAPI) {
ecModel.eachRawSeriesByType('boxplot', function (seriesModel: BoxplotSeriesModel) {
seriesModel.getData().setVisual('legendSymbol', 'roundRect');
});
Expand Down
2 changes: 1 addition & 1 deletion src/chart/boxplot/prepareBoxplotData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface PrepareBoxplotDataOpt {
* default 1.5, means Q1 - 1.5 * (Q3 - Q1).
* If 'none'/0 passed, min bound will not be used.
*/
export default function (
export default function prepareBoxplotData(
rawData: number[][],
opt: PrepareBoxplotDataOpt
): {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/candlestick/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import * as zrUtil from 'zrender/src/core/util';
import { ECUnitOption } from '../../util/types';

export default function (option: ECUnitOption) {
export default function candlestickPreprocessor(option: ECUnitOption) {
if (!option || !zrUtil.isArray(option.series)) {
return;
}
Expand Down
31 changes: 21 additions & 10 deletions src/chart/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { setDefaultStateProxy, enableHoverEmphasis } from '../util/states';
import * as labelStyleHelper from '../label/labelStyle';
import {getDefaultLabel} from './helper/labelHelper';
import createListFromArray from './helper/createListFromArray';
import {getLayoutOnAxis} from '../layout/barGrid';
import {getLayoutOnAxis, BarGridLayoutResult, BarGridLayoutOptionForCustomSeries} from '../layout/barGrid';
import DataDiffer, { DataDiffMode } from '../data/DataDiffer';
import SeriesModel from '../model/Series';
import Model from '../model/Model';
Expand Down Expand Up @@ -55,7 +55,8 @@ import {
OrdinalRawValue,
PayloadAnimationPart,
DecalObject,
InnerDecalObject
InnerDecalObject,
TextCommonOption
} from '../util/types';
import Element, { ElementProps, ElementTextConfig } from 'zrender/src/Element';
import prepareCartesian2d from '../coord/cartesian/prepareCustom';
Expand Down Expand Up @@ -93,6 +94,7 @@ import { AnimationEasing } from 'zrender/src/animation/easing';
import * as matrix from 'zrender/src/core/matrix';
import { PatternObject } from 'zrender/src/graphic/Pattern';
import { createOrUpdatePatternFromDecal } from '../util/decal';
import { ZRenderType } from 'zrender/src/zrender';


const inner = makeInner<{
Expand Down Expand Up @@ -229,8 +231,15 @@ type CustomElementOptionOnState = CustomDisplayableOptionOnState | CustomImageOp


export interface CustomSeriesRenderItemAPI extends
CustomSeriesRenderItemCoordinateSystemAPI,
Pick<ExtensionAPI, 'getWidth' | 'getHeight' | 'getZr' | 'getDevicePixelRatio'> {
CustomSeriesRenderItemCoordinateSystemAPI {

// Methods from ExtensionAPI.
// NOTE: Not using Pick<ExtensionAPI> here because we don't want to bundle ExtensionAPI into the d.ts
getWidth(): number
getHeight(): number
getZr(): ZRenderType
getDevicePixelRatio(): number

value(dim: DimensionLoose, dataIndexInside?: number): ParsedValue;
ordinalRawValue(dim: DimensionLoose, dataIndexInside?: number): ParsedValue | OrdinalRawValue;
style(userProps?: ZRStyleProps, dataIndexInside?: number): ZRStyleProps;
Expand All @@ -241,9 +250,9 @@ export interface CustomSeriesRenderItemAPI extends
): VT extends NonStyleVisualProps ? DefaultDataVisual[VT]
: VT extends StyleVisualProps ? PathStyleProps[typeof STYLE_VISUAL_TYPE[VT]]
: void;
barLayout(opt: Omit<Parameters<typeof getLayoutOnAxis>[0], 'axis'>): ReturnType<typeof getLayoutOnAxis>;
currentSeriesIndices(): ReturnType<GlobalModel['getCurrentSeriesIndices']>;
font(opt: Parameters<typeof labelStyleHelper.getFont>[0]): ReturnType<typeof labelStyleHelper.getFont>;
barLayout(opt: BarGridLayoutOptionForCustomSeries): BarGridLayoutResult;
currentSeriesIndices(): number[];
font(opt: Pick<TextCommonOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>): string;
}
interface CustomSeriesRenderItemParamsCoordSys {
type: string;
Expand All @@ -266,7 +275,7 @@ export interface CustomSeriesRenderItemParams {
seriesIndex: number;
coordSys: CustomSeriesRenderItemParamsCoordSys;
dataInsideLength: number;
encode: ReturnType<typeof wrapEncodeDef>;
encode: WrapEncodeDefRet;
}
type CustomSeriesRenderItem = (
params: CustomSeriesRenderItemParams,
Expand Down Expand Up @@ -1889,8 +1898,10 @@ function makeRenderItem(
}
}

function wrapEncodeDef(data: List<CustomSeriesModel>): Dictionary<number[]> {
const encodeDef = {} as Dictionary<number[]>;
type WrapEncodeDefRet = Dictionary<number[]>;

function wrapEncodeDef(data: List<CustomSeriesModel>): WrapEncodeDefRet {
const encodeDef = {} as WrapEncodeDefRet;
each(data.dimensions, function (dimName, dataDimIndex) {
const dimInfo = data.getDimensionInfo(dimName);
if (!dimInfo.isExtraCoord) {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/funnel/funnelLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function labelLayout(data: List) {
});
}

export default function (ecModel: GlobalModel, api: ExtensionAPI) {
export default function funnelLayout(ecModel: GlobalModel, api: ExtensionAPI) {
ecModel.eachSeriesByType('funnel', function (seriesModel: FunnelSeriesModel) {
const data = seriesModel.getData();
const valueDim = data.mapDimension('value');
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/adjustEdge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function intersectCurveCircle(
}

// Adjust edge to avoid
export default function (graph: Graph, scale: number) {
export default function adjustEdge(graph: Graph, scale: number) {
const tmp0: number[] = [];
const quadraticSubdivide = curveTool.quadraticSubdivide;
const pts: number[][] = [[], [], []];
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/categoryFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import GlobalModel from '../../model/Global';
import GraphSeriesModel, { GraphNodeItemOption } from './GraphSeries';
import type LegendModel from '../../component/legend/LegendModel';

export default function (ecModel: GlobalModel) {
export default function categoryFilter(ecModel: GlobalModel) {
const legendModels = ecModel.findComponents({
mainType: 'legend'
}) as LegendModel[];
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/categoryVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import GraphSeriesModel, { GraphNodeItemOption } from './GraphSeries';
import { Dictionary, ColorString } from '../../util/types';
import { extend } from 'zrender/src/core/util';

export default function (ecModel: GlobalModel) {
export default function categoryVisual(ecModel: GlobalModel) {

const paletteScope: Dictionary<ColorString> = {};
ecModel.eachSeriesByType('graph', function (seriesModel: GraphSeriesModel) {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/circularLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {circularLayout} from './circularLayoutHelper';
import GlobalModel from '../../model/Global';
import GraphSeriesModel from './GraphSeries';

export default function (ecModel: GlobalModel) {
export default function graphCircularLayout(ecModel: GlobalModel) {
ecModel.eachSeriesByType('graph', function (seriesModel: GraphSeriesModel) {
if (seriesModel.get('layout') === 'circular') {
circularLayout(seriesModel, 'symbolSize');
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/createView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getViewRect(seriesModel: GraphSeriesModel, api: ExtensionAPI, aspect: n
});
}

export default function (ecModel: GlobalModel, api: ExtensionAPI) {
export default function createViewCoordSys(ecModel: GlobalModel, api: ExtensionAPI) {
const viewList: View[] = [];
ecModel.eachSeriesByType('graph', function (seriesModel: GraphSeriesModel) {
const coordSysType = seriesModel.get('coordinateSystem');
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/edgeVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function normalize(a: string | number | (string | number)[]): (string | number)[
return a;
}

export default function (ecModel: GlobalModel) {
export default function graphEdgeVisual(ecModel: GlobalModel) {
ecModel.eachSeriesByType('graph', function (seriesModel: GraphSeriesModel) {
const graph = seriesModel.getGraph();
const edgeData = seriesModel.getEdgeData();
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/forceLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ForceLayoutInstance {
}


export default function (ecModel: GlobalModel) {
export default function graphForceLayout(ecModel: GlobalModel) {
ecModel.eachSeriesByType('graph', function (graphSeries: GraphSeriesModel) {
const coordSys = graphSeries.coordinateSystem;
if (coordSys && coordSys.type !== 'view') {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/graph/simpleLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../ExtensionAPI';
import GraphSeriesModel from './GraphSeries';

export default function (ecModel: GlobalModel, api: ExtensionAPI) {
export default function graphSimpleLayout(ecModel: GlobalModel, api: ExtensionAPI) {
ecModel.eachSeriesByType('graph', function (seriesModel: GraphSeriesModel) {
const layout = seriesModel.get('layout');
const coordSys = seriesModel.coordinateSystem;
Expand Down
2 changes: 1 addition & 1 deletion src/chart/helper/createGraphFromNodeEdge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import SeriesModel from '../../model/Series';
import { convertOptionIdName } from '../../util/model';

export default function (
export default function createGraphFromNodeEdge(
nodes: OptionSourceDataOriginal<OptionDataValue, OptionDataItemObject<OptionDataValue>>,
edges: OptionSourceDataOriginal<OptionDataValue, GraphEdgeItemObject<OptionDataValue>>,
seriesModel: SeriesModel,
Expand Down
2 changes: 1 addition & 1 deletion src/chart/helper/createListSimply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import SeriesModel from '../../model/Series';
* dimensionsCount: 5
* });
*/
export default function (
export default function createListSimply(
seriesModel: SeriesModel,
opt: CreateDimensionsParams | CreateDimensionsParams['coordDimensions'],
nameList?: string[]
Expand Down
2 changes: 1 addition & 1 deletion src/chart/helper/createRenderPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { StageHandlerPlanReturn } from '../../util/types';
/**
* @return {string} If large mode changed, return string 'reset';
*/
export default function () {
export default function createRenderPlanner() {
const inner = makeInner<{
large: boolean
progressiveRender: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/chart/helper/enableAriaDecalForTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SeriesModel from '../../model/Series';
import {Dictionary, DecalObject} from '../../util/types';
import { getDecalFromPalette } from '../../model/mixin/palette';

export default function (seriesModel: SeriesModel) {
export default function enableAriaDecalForTree(seriesModel: SeriesModel) {
const data = seriesModel.getData();
const tree = data.tree;
const decalPaletteScope: Dictionary<DecalObject> = {};
Expand Down
2 changes: 1 addition & 1 deletion src/chart/line/lineAnimationDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function diffData(oldData: List, newData: List) {
return diffResult;
}

export default function (
export default function lineAnimationDiff(
oldData: List, newData: List,
oldStackedOnPoints: ArrayLike<number>, newStackedOnPoints: ArrayLike<number>,
oldCoordSys: Cartesian2D | Polar, newCoordSys: Cartesian2D | Polar,
Expand Down
2 changes: 1 addition & 1 deletion src/chart/map/mapDataStatistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function dataStatistics(datas: List[], statisticType: MapValueCalculationType):
});
}

export default function (ecModel: GlobalModel): void {
export default function mapDataStatistic(ecModel: GlobalModel): void {
const seriesGroups = {} as {[key: string]: MapSeries[]};
ecModel.eachSeriesByType('map', function (seriesModel: MapSeries) {
const hostGeoModel = seriesModel.getHostGeoModel();
Expand Down
2 changes: 1 addition & 1 deletion src/chart/map/mapSymbolLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import GlobalModel from '../../model/Global';
import MapSeries from './MapSeries';
import { Dictionary } from '../../util/types';

export default function (ecModel: GlobalModel) {
export default function mapSymbolLayout(ecModel: GlobalModel) {

const processedMapType = {} as {[mapType: string]: boolean};

Expand Down
2 changes: 1 addition & 1 deletion src/chart/pie/labelLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function isPositionCenter(sectorShape: LabelLayout) {
return sectorShape.position === 'center';
}

export default function (
export default function pieLabelLayout(
seriesModel: PieSeriesModel
) {
const data = seriesModel.getData();
Expand Down
2 changes: 1 addition & 1 deletion src/chart/pie/pieLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getViewRect(seriesModel: PieSeriesModel, api: ExtensionAPI) {
);
}

export default function (
export default function pieLayout(
seriesType: 'pie',
ecModel: GlobalModel,
api: ExtensionAPI
Expand Down
2 changes: 1 addition & 1 deletion src/chart/radar/backwardCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Backward compat for radar chart in 2
import * as zrUtil from 'zrender/src/core/util';

export default function (option) {
export default function radarBackwardCompat(option) {
let polarOptArr = option.polar;
if (polarOptArr) {
if (!zrUtil.isArray(polarOptArr)) {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/radar/radarLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import RadarSeriesModel from './RadarSeries';
import Radar from '../../coord/radar/Radar';

type Point = number[];
export default function (ecModel: GlobalModel) {
export default function radarLayout(ecModel: GlobalModel) {
ecModel.eachSeriesByType('radar', function (seriesModel: RadarSeriesModel) {
const data = seriesModel.getData();
const points: Point[][] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/chart/sankey/sankeyLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { GraphNode, GraphEdge } from '../../data/Graph';
import { LayoutOrient } from '../../util/types';
import GlobalModel from '../../model/Global';

export default function (ecModel: GlobalModel, api: ExtensionAPI) {
export default function sankeyLayout(ecModel: GlobalModel, api: ExtensionAPI) {

ecModel.eachSeriesByType('sankey', function (seriesModel: SankeySeriesModel) {

Expand Down
2 changes: 1 addition & 1 deletion src/chart/sankey/sankeyVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import VisualMapping from '../../visual/VisualMapping';
import GlobalModel from '../../model/Global';
import SankeySeriesModel, { SankeyNodeItemOption } from './SankeySeries';

export default function (ecModel: GlobalModel) {
export default function sankeyVisual(ecModel: GlobalModel) {
ecModel.eachSeriesByType('sankey', function (seriesModel: SankeySeriesModel) {
const graph = seriesModel.getGraph();
const nodes = graph.nodes;
Expand Down
2 changes: 1 addition & 1 deletion src/chart/sunburst/sunburstLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { TreeNode } from '../../data/Tree';
// let PI2 = Math.PI * 2;
const RADIAN = Math.PI / 180;

export default function (
export default function sunburstLayout(
seriesType: 'sunburst',
ecModel: GlobalModel,
api: ExtensionAPI
Expand Down
2 changes: 1 addition & 1 deletion src/chart/sunburst/sunburstVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Dictionary, ColorString } from '../../util/types';
import { TreeNode } from '../../data/Tree';
import { lift } from 'zrender/src/tool/color';

export default function (ecModel: GlobalModel) {
export default function sunburstVisual(ecModel: GlobalModel) {

const paletteScope: Dictionary<ColorString> = {};

Expand Down
Loading

0 comments on commit f9bd8da

Please sign in to comment.