types.ts 35.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
 * [Notice]:
 * Consider custom bundle on demand, chart specified
 * or component specified types and constants should
 * not put here. Only common types and constants can
 * be put in this file.
 */

P
pissang 已提交
28 29
import Group from 'zrender/src/graphic/Group';
import Element, {ElementEvent, ElementTextConfig} from 'zrender/src/Element';
30 31 32 33 34 35 36
import DataFormatMixin from '../model/mixin/dataFormat';
import GlobalModel from '../model/Global';
import ExtensionAPI from '../ExtensionAPI';
import SeriesModel from '../model/Series';
import { createHashMap, HashMap } from 'zrender/src/core/util';
import { TaskPlanCallbackReturn, TaskProgressParams } from '../stream/task';
import List, {ListDimensionType} from '../data/List';
P
pissang 已提交
37
import { Dictionary, ImageLike, TextAlign, TextVerticalAlign } from 'zrender/src/core/types';
38
import { PatternObject } from 'zrender/src/graphic/Pattern';
39 40
import Source from '../data/Source';
import { TooltipMarker } from './format';
P
pissang 已提交
41
import { AnimationEasing } from 'zrender/src/animation/easing';
42 43
import { LinearGradientObject } from 'zrender/src/graphic/LinearGradient';
import { RadialGradientObject } from 'zrender/src/graphic/RadialGradient';
44
import { RectLike } from 'zrender/src/core/BoundingRect';
1
100pah 已提交
45
import { TSpanStyleProps } from 'zrender/src/graphic/TSpan';
P
pissang 已提交
46 47
import { PathStyleProps } from 'zrender/src/graphic/Path';
import { ImageStyleProps } from 'zrender/src/graphic/Image';
1
100pah 已提交
48
import ZRText, { TextStyleProps } from 'zrender/src/graphic/Text';
49 50 51 52 53 54 55



// ---------------------------
// Common types and constants
// ---------------------------

P
pissang 已提交
56 57
export {Dictionary};

58 59
export type RendererType = 'canvas' | 'svg';

1
100pah 已提交
60 61 62
export type LayoutOrient = 'vertical' | 'horizontal';
export type HorizontalAlign = 'left' | 'center' | 'right';
export type VerticalAlign = 'top' | 'middle' | 'bottom';
P
pissang 已提交
63

P
pissang 已提交
64
// Types from zrender
65
export type ColorString = string;
1
100pah 已提交
66 67
export type ZRColor = ColorString | LinearGradientObject | RadialGradientObject | PatternObject;
export type ZRLineType = 'solid' | 'dotted' | 'dashed';
68

1
100pah 已提交
69 70
export type ZRFontStyle = 'normal' | 'italic' | 'oblique';
export type ZRFontWeight = 'normal' | 'bold' | 'bolder' | 'lighter' | number;
71

P
pissang 已提交
72
export type ZREasing = AnimationEasing;
73

1
100pah 已提交
74 75
export type ZRTextAlign = TextAlign;
export type ZRTextVerticalAlign = TextVerticalAlign;
P
pissang 已提交
76

1
100pah 已提交
77
export type ZRElementEvent = ElementEvent;
78

1
100pah 已提交
79
export type ZRRectLike = RectLike;
80

1
100pah 已提交
81
export type ZRStyleProps = PathStyleProps | ImageStyleProps | TSpanStyleProps | TextStyleProps;
P
pissang 已提交
82

1
100pah 已提交
83 84 85
// ComponentFullType can be:
//     'xxx.yyy': means ComponentMainType.ComponentSubType.
//     'xxx': means ComponentMainType.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
// See `checkClassType` check the restict definition.
export type ComponentFullType = string;
export type ComponentMainType = keyof ECUnitOption & string;
export type ComponentSubType = ComponentOption['type'];
/**
 * Use `parseClassType` to parse componentType declaration to componentTypeInfo.
 * For example:
 * componentType declaration: 'xxx.yyy', get componentTypeInfo {main: 'xxx', sub: 'yyy'}.
 * componentType declaration: '', get componentTypeInfo {main: '', sub: ''}.
 */
export interface ComponentTypeInfo {
    main: ComponentMainType; // Never null/undefined. `''` represents absence.
    sub: ComponentSubType; // Never null/undefined. `''` represents absence.
}

export interface ECElement extends Element {
    useHoverLayer?: boolean;
P
pissang 已提交
103
    tooltip?: CommonTooltipOption<unknown> & {
104 105 106 107
        content?: string;
        formatterParams?: unknown;
    };
    highDownSilentOnTouch?: boolean;
108
    onStateChange?: (toState: DisplayState) => void;
109

110 111 112 113
    // 0: normal
    // 1: blur
    // 2: emphasis
    hoverState?: 0 | 1 | 2;
114
    selected?: boolean;
115

1
100pah 已提交
116
    z2EmphasisLift?: number;
117 118 119 120 121

    /**
     * Force disable animation on any condition
     */
    disableLabelAnimation?: boolean
122 123 124 125
    /**
     * Force disable overall layout
     */
    disableLabelLayout?: boolean
126 127 128 129 130 131 132 133 134 135
}

export interface DataHost {
    getData(dataType?: string): List;
}

export interface DataModel extends DataHost, DataFormatMixin {}
    // Pick<DataHost, 'getData'>,
    // Pick<DataFormatMixin, 'getDataParams' | 'formatTooltip'> {}

P
pissang 已提交
136
interface PayloadItem {
137
    excludeSeriesId?: string | string[];
138
    animation?: AnimationPayload
139 140 141 142 143 144 145 146 147
    [other: string]: any;
}

export interface Payload extends PayloadItem {
    type: string;
    escapeConnect?: boolean;
    batch?: PayloadItem[];
}

148 149 150 151 152 153 154
// Payload includes override anmation info
export interface AnimationPayload {
    duration?: number
    easing?: AnimationEasing
    delay?: number
}

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
export interface ViewRootGroup extends Group {
    __ecComponentInfo?: {
        mainType: string,
        index: number
    };
}

/**
 * The echarts event type to user.
 * Also known as packedEvent.
 */
export interface ECEvent extends ECEventData{
    // event type
    type: string;
    componentType?: string;
    componentIndex?: number;
    seriesIndex?: number;
    escapeConnect?: boolean;
    event?: ElementEvent;
    batch?: ECEventData;
}
export interface ECEventData {
    [key: string]: any;
}

export interface EventQueryItem{
    [key: string]: any;
}
export interface NormalizedEventQuery {
    cptQuery: EventQueryItem;
    dataQuery: EventQueryItem;
    otherQuery: EventQueryItem;
}

export interface ActionInfo {
    // action type
    type: string;
    // If not provided, use the same string of `type`.
    event?: string;
    // update method
    update?: string;
}
export interface ActionHandler {
    (payload: Payload, ecModel: GlobalModel, api: ExtensionAPI): void | ECEventData;
}

export interface OptionPreprocessor {
    (option: ECUnitOption, isTheme: boolean): void
}

export interface PostUpdater {
    (ecModel: GlobalModel, api: ExtensionAPI): void;
}

209 210 211 212
export interface StageHandlerReset {
    (seriesModel: SeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload?: Payload):
        StageHandlerProgressExecutor | StageHandlerProgressExecutor[] | void
}
213 214 215 216
export interface StageHandlerOverallReset {
    (ecModel: GlobalModel, api: ExtensionAPI, payload?: Payload): void
}
export interface StageHandler {
217 218 219 220 221 222
    seriesType?: string;
    createOnAllSeries?: boolean;
    performRawSeries?: boolean;
    plan?: StageHandlerPlan;
    overallReset?: StageHandlerOverallReset;
    reset?: StageHandlerReset;
223
    getTargetSeries?: (ecModel: GlobalModel, api: ExtensionAPI) => HashMap<SeriesModel>;
224
}
225 226

export interface StageHandlerInternal extends StageHandler {
227
    uid: string;
P
pissang 已提交
228
    visualType?: 'layout' | 'visual';
229 230
    // modifyOutputEnd?: boolean;
    __prio: number;
231
    __raw: StageHandler | StageHandlerOverallReset;
232 233 234
    isVisual?: boolean; // PENDING: not used
    isLayout?: boolean; // PENDING: not used
}
235 236


237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
export type StageHandlerProgressParams = TaskProgressParams;
export interface StageHandlerProgressExecutor {
    dataEach?: (data: List, idx: number) => void;
    progress?: (params: StageHandlerProgressParams, data: List) => void;
}
export type StageHandlerPlanReturn = TaskPlanCallbackReturn;
export interface StageHandlerPlan {
    (seriesModel: SeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload?: Payload):
        StageHandlerPlanReturn
}

export interface LoadingEffectCreator {
    (api: ExtensionAPI, cfg: object): LoadingEffect;
}
export interface LoadingEffect extends Element {
    resize: () => void;
}

export type TooltipRenderMode = 'html' | 'richText';


// ---------------------------------
// Data and dimension related types
// ---------------------------------

// Finally the user data will be parsed and stored in `list._storage`.
// `NaN` represents "no data" (raw data `null`/`undefined`/`NaN`/`'-'`).
// `Date` will be parsed to timestamp.
// Ordinal/category data will be parsed to its index if possible, otherwise
// keep its original string in list._storage.
// Check `convertDataValue` for more details.
1
100pah 已提交
268 269
export type OrdinalRawValue = string | number;
export type OrdinalNumber = number; // The number mapped from each OrdinalRawValue.
O
Ovilia 已提交
270 271 272 273
export type OrdinalSortInfo = {
    ordinalNumber: OrdinalNumber,
    beforeSortIndex: number
};
274 275
export type ParsedValueNumeric = number | OrdinalNumber;
export type ParsedValue = ParsedValueNumeric | OrdinalRawValue;
1
100pah 已提交
276 277 278
// FIXME:TS better name?
// This is not `OptionDataPrimitive` because the "dataProvider parse"
// will not be performed. But "scale parse" will be performed.
279
export type ScaleDataValue = ParsedValue | Date;
280

P
pissang 已提交
281
// Can only be string or index, because it is used in object key in some code.
282 283 284 285 286 287 288 289 290
// Making the type alias here just intending to show the meaning clearly in code.
export type DimensionIndex = number;
// If being a number-like string but not being defined a dimension name.
// See `List.js#getDimension` for more details.
export type DimensionIndexLoose = DimensionIndex | string;
export type DimensionName = string;
export type DimensionLoose = DimensionName | DimensionIndexLoose;
export type DimensionType = ListDimensionType;

291
export const VISUAL_DIMENSIONS = createHashMap([
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    'tooltip', 'label', 'itemName', 'itemId', 'seriesName'
]);
// The key is VISUAL_DIMENSIONS
export interface DataVisualDimensions {
    // can be set as false to directly to prevent this data
    // dimension from displaying in the default tooltip.
    // see `Series.ts#formatTooltip`.
    tooltip?: DimensionIndex | false;
    label?: DimensionIndex;
    itemName?: DimensionIndex;
    itemId?: DimensionIndex;
    seriesName?: DimensionIndex;
}

export type DimensionDefinition = {
P
pissang 已提交
307 308 309
    type?: string,
    name: string,
    displayName?: string
310 311 312
};
export type DimensionDefinitionLoose = DimensionDefinition['type'] | DimensionDefinition;

313 314 315 316 317 318
export const SOURCE_FORMAT_ORIGINAL = 'original' as const;
export const SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows' as const;
export const SOURCE_FORMAT_OBJECT_ROWS = 'objectRows' as const;
export const SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns' as const;
export const SOURCE_FORMAT_TYPED_ARRAY = 'typedArray' as const;
export const SOURCE_FORMAT_UNKNOWN = 'unknown' as const;
319 320 321 322 323 324 325 326 327

export type SourceFormat =
    typeof SOURCE_FORMAT_ORIGINAL
    | typeof SOURCE_FORMAT_ARRAY_ROWS
    | typeof SOURCE_FORMAT_OBJECT_ROWS
    | typeof SOURCE_FORMAT_KEYED_COLUMNS
    | typeof SOURCE_FORMAT_TYPED_ARRAY
    | typeof SOURCE_FORMAT_UNKNOWN;

328 329
export const SERIES_LAYOUT_BY_COLUMN = 'column' as const;
export const SERIES_LAYOUT_BY_ROW = 'row' as const;
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344

export type SeriesLayoutBy = typeof SERIES_LAYOUT_BY_COLUMN | typeof SERIES_LAYOUT_BY_ROW;



// --------------------------------------------
// echarts option types (base and common part)
// --------------------------------------------

/**
 * [ECUnitOption]:
 * An object that contains definitions of components
 * and other properties. For example:
 *
 * ```ts
345
 * let option: ECUnitOption = {
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
 *
 *     // Single `title` component:
 *     title: {...},
 *
 *     // Two `visualMap` components:
 *     visualMap: [{...}, {...}],
 *
 *     // Two `series.bar` components
 *     // and one `series.pie` component:
 *     series: [
 *         {type: 'bar', data: [...]},
 *         {type: 'bar', data: [...]},
 *         {type: 'pie', data: [...]}
 *     ],
 *
 *     // A property:
 *     backgroundColor: '#421ae4'
 *
 *     // A property object:
 *     textStyle: {
 *         color: 'red',
 *         fontSize: 20
 *     }
 * };
 * ```
 */
export type ECUnitOption = {
1
100pah 已提交
373 374 375 376 377
    // Exclude these reserverd word for `ECOption` to avoid to infer to "any".
    baseOption?: never
    options?: never
    media?: never
    timeline?: ComponentOption | ComponentOption[]
378
    [key: string]: ComponentOption | ComponentOption[] | Dictionary<any> | any
1
100pah 已提交
379
} & AnimationOptionMixin;
380 381 382 383 384 385 386 387

/**
 * [ECOption]:
 * An object input to echarts.setOption(option).
 * May be an 'option: ECUnitOption',
 * or may be an object contains multi-options. For example:
 *
 * ```ts
388
 * let option: ECOption = {
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
 *     baseOption: {
 *         title: {...},
 *         legend: {...},
 *         series: [
 *             {data: [...]},
 *             {data: [...]},
 *             ...
 *         ]
 *     },
 *     timeline: {...},
 *     options: [
 *         {title: {...}, series: {data: [...]}},
 *         {title: {...}, series: {data: [...]}},
 *         ...
 *     ],
 *     media: [
 *         {
 *             query: {maxWidth: 320},
 *             option: {series: {x: 20}, visualMap: {show: false}}
 *         },
 *         {
 *             query: {minWidth: 320, maxWidth: 720},
 *             option: {series: {x: 500}, visualMap: {show: true}}
 *         },
 *         {
 *             option: {series: {x: 1200}, visualMap: {show: true}}
 *         }
 *     ]
 * };
 * ```
 */
export type ECOption = ECUnitOption | {
    baseOption?: ECUnitOption,
    timeline?: ComponentOption,
    options?: ECUnitOption[],
1
100pah 已提交
424
    media?: MediaUnit[],
425 426 427 428 429 430 431 432
};

// series.data or dataset.source
export type OptionSourceData =
    ArrayLike<OptionDataItem>
    | Dictionary<ArrayLike<OptionDataItem>>; // Only for `SOURCE_FORMAT_KEYED_COLUMNS`.
// See also `model.js#getDataItemValue`.
export type OptionDataItem =
433 434 435
    OptionDataValue
    | Dictionary<OptionDataValue>
    | ArrayLike<OptionDataValue>
436
    // FIXME: In some case (markpoint in geo (geo-map.html)), dataItem is {coord: [...]}
437 438 439 440 441 442
    | OptionDataItemObject<OptionDataValue>;
// Only for `SOURCE_FORMAT_KEYED_ORIGINAL`
export type OptionDataItemObject<T> = {
    name?: string
    value?: T[] | T
};
443
export type OptionDataValue = string | number | Date;
444

P
pissang 已提交
445 446
export type OptionDataValueNumeric = number | '-';
export type OptionDataValueCategory = string;
P
pissang 已提交
447
export type OptionDataValueDate = Date | string | number;
P
pissang 已提交
448

449
// export type ModelOption = Dictionary<any> | any[] | string | number | boolean | ((...args: any) => any);
450
export type ModelOption = any;
451 452
export type ThemeOption = Dictionary<any>;

453
export type DisplayState = 'normal' | 'emphasis' | 'blur' | 'select';
454
export type DisplayStateNonNormal = Exclude<DisplayState, 'normal'>;
455
export type DisplayStateHostOption = {
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
    emphasis?: Dictionary<any>,
    [key: string]: any
};

// The key is VISUAL_DIMENSIONS
export interface OptionEncodeVisualDimensions {
    tooltip?: OptionEncodeValue;
    label?: OptionEncodeValue;
    itemName?: OptionEncodeValue;
    itemId?: OptionEncodeValue;
    seriesName?: OptionEncodeValue;
    // Notice: `value` is coordDim, not nonCoordDim.
}
export interface OptionEncode extends OptionEncodeVisualDimensions {
    [coordDim: string]: OptionEncodeValue
}
export type OptionEncodeValue = DimensionIndex[] | DimensionIndex | DimensionName[] | DimensionName;
473 474
export type EncodeDefaulter = (source: Source, dimCount: number) => OptionEncode;

P
pissang 已提交
475
// TODO: TYPE Different callback param for different series
476
export interface CallbackDataParams {
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
    // component main type
    componentType: string;
    // component sub type
    componentSubType: string;
    componentIndex: number;
    // series component sub type
    seriesType?: string;
    // series component index (the alias of `componentIndex` for series)
    seriesIndex?: number;
    seriesId?: string;
    seriesName?: string;
    name: string;
    dataIndex: number;
    data: any;
    dataType?: string;
    value: any;
1
100pah 已提交
493
    color?: ZRColor;
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    borderColor?: string;
    dimensionNames?: DimensionName[];
    encode?: DimensionUserOuputEncode;
    marker?: TooltipMarker;
    status?: DisplayState;
    dimensionIndex?: number;
    percent?: number; // Only for chart like 'pie'

    // Param name list for mapping `a`, `b`, `c`, `d`, `e`
    $vars: string[];
}
export type DimensionUserOuputEncode = {
    [coordOrVisualDimName: string]:
        // index: coordDimIndex, value: dataDimIndex
        DimensionIndex[]
};
export type DimensionUserOuput = {
    // The same as `data.dimensions`
    dimensionNames: DimensionName[]
    encode: DimensionUserOuputEncode
};
515 516 517 518 519 520 521 522 523 524 525 526 527 528

export interface MediaQuery {
    minWidth?: number;
    maxWidth?: number;
    minHeight?: number;
    maxHeight?: number;
    minAspectRatio?: number;
    maxAspectRatio?: number;
};
export type MediaUnit = {
    query: MediaQuery,
    option: ECUnitOption
};

529 530 531
export type ComponentLayoutMode = {
    // Only support 'box' now.
    type: 'box',
P
pissang 已提交
532
    ignoreSize?: boolean | boolean[]
533
};
P
pissang 已提交
534
/******************* Mixins for Common Option Properties   ********************** */
535 536 537 538 539
export interface ColorPaletteOptionMixin {
    color?: ZRColor | ZRColor[]
    colorLayer?: ZRColor[][]
}

P
pissang 已提交
540 541 542
/**
 * Mixin of option set to control the box layout of each component.
 */
P
pissang 已提交
543 544 545 546 547 548 549
export interface BoxLayoutOptionMixin {
    width?: number | string;
    height?: number | string;
    top?: number | string;
    right?: number | string;
    bottom?: number | string;
    left?: number | string;
550 551
}

552 553 554 555 556 557 558 559
export interface CircleLayoutOptionMixin {
    // Can be percent
    center?: (number | string)[]
    // Can specify [innerRadius, outerRadius]
    radius?: (number | string)[] | number | string
}

export interface ShadowOptionMixin {
P
pissang 已提交
560
    shadowBlur?: number
1
100pah 已提交
561
    shadowColor?: ColorString
P
pissang 已提交
562 563 564 565
    shadowOffsetX?: number
    shadowOffsetY?: number
}

P
pissang 已提交
566 567 568 569 570 571
export interface BorderOptionMixin {
    borderColor?: string
    borderWidth?: number
    borderType?: ZRLineType
}

P
pissang 已提交
572 573 574
export type AnimationDelayCallbackParam = {
    count: number
    index: number
1
100pah 已提交
575
};
P
pissang 已提交
576 577 578
export type AnimationDurationCallback = (idx: number) => number;
export type AnimationDelayCallback = (idx: number, params?: AnimationDelayCallbackParam) => number;

579 580 581 582 583
export interface AnimationOption {
    duration?: number
    easing?: AnimationEasing
    delay?: number
}
P
pissang 已提交
584 585 586
/**
 * Mixin of option set to control the animation of series.
 */
587
export interface AnimationOptionMixin {
P
pissang 已提交
588 589 590
    /**
     * If enable animation
     */
P
pissang 已提交
591
    animation?: boolean
P
pissang 已提交
592 593 594
    /**
     * Disable animation when the number of elements exceeds the threshold
     */
P
pissang 已提交
595 596
    animationThreshold?: number
    // For init animation
P
pissang 已提交
597 598 599 600
    /**
     * Duration of initialize animation.
     * Can be a callback to specify duration of each element
     */
P
pissang 已提交
601
    animationDuration?: number | AnimationDurationCallback
P
pissang 已提交
602 603 604
    /**
     * Easing of initialize animation
     */
P
pissang 已提交
605
    animationEasing?: AnimationEasing
P
pissang 已提交
606 607 608 609
    /**
     * Delay of initialize animation
     * Can be a callback to specify duration of each element
     */
P
pissang 已提交
610 611
    animationDelay?: AnimationDelayCallback
    // For update animation
P
pissang 已提交
612 613 614 615
    /**
     * Delay of data update animation.
     * Can be a callback to specify duration of each element
     */
P
pissang 已提交
616
    animationDurationUpdate?: number | AnimationDurationCallback
P
pissang 已提交
617 618 619
    /**
     * Easing of data update animation.
     */
P
pissang 已提交
620
    animationEasingUpdate?: AnimationEasing
P
pissang 已提交
621 622 623 624
    /**
     * Delay of data update animation.
     * Can be a callback to specify duration of each element
     */
P
pissang 已提交
625 626 627
    animationDelayUpdate?: number | AnimationDelayCallback
}

P
pissang 已提交
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
export interface RoamOptionMixin {
    /**
     * If enable roam. can be specified 'scale' or 'move'
     */
    roam?: boolean | 'pan' | 'move' | 'zoom' | 'scale'
    /**
     * Current center position.
     */
    center?: number[]
    /**
     * Current zoom level. Default is 1
     */
    zoom?: number

    scaleLimit?: {
        min?: number
        max?: number
    }
}

P
pissang 已提交
648
// TODO: TYPE value type?
1
100pah 已提交
649 650
export type SymbolSizeCallback<T> = (rawValue: any, params: T) => number | number[];
export type SymbolCallback<T> = (rawValue: any, params: T) => string;
651
export type SymbolRotateCallback<T> = (rawValue: any, params: T) => number;
P
pissang 已提交
652 653 654 655
/**
 * Mixin of option set to control the element symbol.
 * Include type of symbol, and size of symbol.
 */
P
pissang 已提交
656
export interface SymbolOptionMixin<T = unknown> {
P
pissang 已提交
657 658 659
    /**
     * type of symbol, like `cirlce`, `rect`, or custom path and image.
     */
P
pissang 已提交
660
    symbol?: string | (unknown extends T ? never : SymbolCallback<T>)
P
pissang 已提交
661 662 663
    /**
     * Size of symbol.
     */
P
pissang 已提交
664 665
    symbolSize?: number | number[] | (unknown extends T ? never : SymbolSizeCallback<T>)

666 667
    symbolRotate?: number | (unknown extends T ? never : SymbolRotateCallback<T>)

P
pissang 已提交
668
    symbolKeepAspect?: boolean
P
pissang 已提交
669 670

    symbolOffset?: number[]
P
pissang 已提交
671 672 673 674 675 676
}

/**
 * ItemStyleOption is a most common used set to config element styles.
 * It includes both fill and stroke style.
 */
P
pissang 已提交
677
export interface ItemStyleOption extends ShadowOptionMixin, BorderOptionMixin {
678
    color?: ZRColor
P
pissang 已提交
679 680 681
    opacity?: number
}

P
pissang 已提交
682 683 684 685 686
/**
 * ItemStyleOption is a option set to control styles on lines.
 * Used in the components or series like `line`, `axis`
 * It includes stroke style.
 */
687
export interface LineStyleOption<Clr = ZRColor> extends ShadowOptionMixin {
688
    width?: number
1
100pah 已提交
689
    color?: Clr
690 691 692 693
    opacity?: number
    type?: ZRLineType
}

P
pissang 已提交
694 695 696 697
/**
 * ItemStyleOption is a option set to control styles on an area, like polygon, rectangle.
 * It only include fill style.
 */
1
100pah 已提交
698 699
export interface AreaStyleOption<Clr = ZRColor> extends ShadowOptionMixin {
    color?: Clr
P
pissang 已提交
700
    opacity?: number
701 702
}

1
100pah 已提交
703 704
type Arrayable<T extends Dictionary<any>> = { [key in keyof T]: T[key] | T[key][] };
type Dictionaryable<T extends Dictionary<any>> = { [key in keyof T]: T[key] | Dictionary<T[key]>};
P
pissang 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

export interface VisualOptionUnit {
    symbol?: string
    // TODO Support [number, number]?
    symbolSize?: number
    color?: ColorString
    colorAlpha?: number
    opacity?: number
    colorLightness?: number
    colorSaturation?: number
    colorHue?: number

    // Not exposed?
    liftZ?: number
}
export type VisualOptionFixed = VisualOptionUnit;
/**
 * Option about visual properties used in piecewise mapping
 * Used in each piece.
 */
1
100pah 已提交
725
export type VisualOptionPiecewise = VisualOptionUnit;
P
pissang 已提交
726 727 728
/**
 * Option about visual properties used in linear mapping
 */
1
100pah 已提交
729
export type VisualOptionLinear = Arrayable<VisualOptionUnit>;
P
pissang 已提交
730 731 732 733 734 735 736

/**
 * Option about visual properties can be encoded from ordinal categories.
 * Each value can either be a dictonary to lookup with category name, or
 * be an array to lookup with category index. In this case the array length should
 * be same with categories
 */
1
100pah 已提交
737
export type VisualOptionCategory = Arrayable<VisualOptionUnit> | Dictionaryable<VisualOptionUnit>;
P
pissang 已提交
738 739 740 741 742 743

/**
 * All visual properties can be encoded.
 */
export type BuiltinVisualProperty = keyof VisualOptionUnit;

1
100pah 已提交
744
export interface TextCommonOption extends ShadowOptionMixin {
745 746 747
    color?: string
    fontStyle?: ZRFontStyle
    fontWeight?: ZRFontWeight
P
pissang 已提交
748 749
    fontFamily?: string
    fontSize?: number
P
pissang 已提交
750 751
    align?: HorizontalAlign
    verticalAlign?: VerticalAlign
P
pissang 已提交
752
    // @deprecated
P
pissang 已提交
753
    baseline?: VerticalAlign
P
pissang 已提交
754

P
pissang 已提交
755 756
    opacity?: number

P
pissang 已提交
757
    lineHeight?: number
758
    backgroundColor?: ColorString | {
P
pissang 已提交
759 760 761 762
        image: ImageLike
    }
    borderColor?: string
    borderWidth?: number
P
pissang 已提交
763
    borderRadius?: number | number[]
764
    padding?: number | number[]
P
pissang 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777

    width?: number | string// Percent
    height?: number
    textBorderColor?: string
    textBorderWidth?: number

    textShadowBlur?: number
    textShadowColor?: string
    textShadowOffsetX?: number
    textShadowOffsetY?: number

    tag?: string
}
P
pissang 已提交
778 779 780 781

export interface LabelFormatterCallback<T = CallbackDataParams> {
    (params: T): string
}
P
pissang 已提交
782 783 784 785
/**
 * LabelOption is an option set to control the style of labels.
 * Include color, background, shadow, truncate, rotation, distance, etc..
 */
786
export interface LabelOption extends TextCommonOption {
P
pissang 已提交
787 788 789
    /**
     * If show label
     */
P
pissang 已提交
790 791
    show?: boolean
    // TODO: TYPE More specified 'inside', 'insideTop'....
P
pissang 已提交
792
    // x, y can be both percent string or number px.
P
pissang 已提交
793
    position?: ElementTextConfig['position']
P
pissang 已提交
794
    distance?: number
P
pissang 已提交
795
    rotate?: number
P
pissang 已提交
796
    offset?: number[]
P
pissang 已提交
797

798 799 800 801 802 803
    /**
     * Min margin between labels. Used when label has layout.
     */
    // It's minMargin instead of margin is for not breaking the previous code using margin.
    minMargin?: number

1
100pah 已提交
804
    overflow?: TextStyleProps['overflow']
1
100pah 已提交
805
    silent?: boolean
806
    precision?: number | 'auto'
O
Ovilia 已提交
807
    valueAnimation?: boolean
P
pissang 已提交
808

P
pissang 已提交
809 810
    // TODO: TYPE not all label support formatter
    // formatter?: string | ((params: CallbackDataParams) => string)
P
pissang 已提交
811 812

    rich?: Dictionary<TextCommonOption>
813 814
}

P
pissang 已提交
815 816 817
/**
 * Option for labels on line, like markLine, lines
 */
P
pissang 已提交
818
export interface LineLabelOption extends Omit<LabelOption, 'distance' | 'position'> {
819 820 821
    position?: 'start'
        | 'middle'
        | 'end'
P
pissang 已提交
822
        | 'insideStart'
823 824
        | 'insideStartTop'
        | 'insideStartBottom'
P
pissang 已提交
825
        | 'insideMiddle'
826 827
        | 'insideMiddleTop'
        | 'insideMiddleBottom'
P
pissang 已提交
828
        | 'insideEnd'
829 830 831
        | 'insideEndTop'
        | 'insideEndBottom'
        | 'insideMiddleBottom'
P
pissang 已提交
832 833 834 835 836 837 838
    /**
     * Distance can be an array.
     * Which will specify horizontal and vertical distance respectively
     */
    distance?: number | number[]
}

P
pissang 已提交
839
export interface LabelLineOption {
840 841 842
    show?: boolean
    length?: number
    length2?: number
843
    smooth?: boolean | number
P
pissang 已提交
844
    minTurnAngle?: number,
845 846 847
    lineStyle?: LineStyleOption
}

848 849 850

export interface LabelLayoutOptionCallbackParams {
    dataIndex: number,
P
pissang 已提交
851
    dataType: string,
852 853 854 855 856 857
    seriesIndex: number,
    text: string
    align: ZRTextAlign
    verticalAlign: ZRTextVerticalAlign
    rect: RectLike
    labelRect: RectLike
858 859
    // Points of label line in pie/funnel
    labelLinePoints?: number[][]
860 861
    // x: number
    // y: number
862 863 864
};

export interface LabelLayoutOption {
865
    /**
866 867
     * If move the overlapped label. If label is still overlapped after moved.
     * It will determine if to hide this label with `hideOverlap` policy.
868 869 870
     *
     * shift-x/y will keep the order on x/y
     * shuffle-x/y will move the label around the original position randomly.
871
     */
872 873 874 875
    moveOverlap?: 'shift-x'
        | 'shift-y'
        | 'shuffle-x'
        | 'shuffle-y'
876 877 878 879 880
    /**
     * If hide the overlapped label. It will be handled after move.
     * @default 'none'
     */
    hideOverlap?: boolean
P
pissang 已提交
881 882 883 884
    /**
     * If label is draggable.
     */
    draggable?: boolean
885 886 887 888 889 890 891 892 893 894 895 896 897
    /**
     * Can be absolute px number or percent string.
     */
    x?: number | string
    y?: number | string
    /**
     * offset on x based on the original position.
     */
    dx?: number
    /**
     * offset on y based on the original position.
     */
    dy?: number
898
    rotate?: number
899

900 901 902 903
    align?: ZRTextAlign
    verticalAlign?: ZRTextVerticalAlign
    width?: number
    height?: number
904
    fontSize?: number
905 906

    labelLinePoints?: number[][]
907 908 909 910 911
}

export type LabelLayoutOptionCallback = (params: LabelLayoutOptionCallbackParams) => LabelLayoutOption;


P
pissang 已提交
912
interface TooltipFormatterCallback<T> {
913 914 915 916
    /**
     * For sync callback
     * params will be an array on axis trigger.
     */
P
pissang 已提交
917
    (params: T, asyncTicket: string): string
918 919 920 921
    /**
     * For async callback.
     * Returned html string will be a placeholder when callback is not invoked.
     */
P
pissang 已提交
922
    (params: T, asyncTicket: string, callback: (cbTicket: string, html: string) => void): string
923 924
}

1
100pah 已提交
925
type TooltipBuiltinPosition = 'inside' | 'top' | 'left' | 'right' | 'bottom';
926 927
type TooltipBoxLayoutOption = Pick<
    BoxLayoutOptionMixin, 'top' | 'left' | 'right' | 'bottom'
1
100pah 已提交
928
>;
929 930 931 932 933 934 935 936 937 938 939 940 941 942
/**
 * Position relative to the hoverred element. Only available when trigger is item.
 */
interface PositionCallback {
    (
        point: [number, number],
        /**
         * params will be an array on axis trigger.
         */
        params: CallbackDataParams | CallbackDataParams[],
        /**
         * Will be HTMLDivElement when renderMode is html
         * Otherwise it's graphic.Text
         */
1
100pah 已提交
943
        el: HTMLDivElement | ZRText | null,
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
        /**
         * Rect of hover elements. Will be null if not hovered
         */
        rect: RectLike | null,
        size: {
            /**
             * Size of popup content
             */
            contentSize: [number, number]
            /**
             * Size of the chart view
             */
            viewSize: [number, number]
        }
    ): number[] | string[] | TooltipBuiltinPosition | TooltipBoxLayoutOption
}
/**
 * Common tooltip option
P
pissang 已提交
962
 * Can be configured on series, graphic elements
963
 */
P
pissang 已提交
964
export interface CommonTooltipOption<FormatterParams> {
965 966 967 968 969 970 971 972 973 974 975 976

    show?: boolean

    /**
     * When to trigger
     */
    triggerOn?: 'mousemove' | 'click' | 'none' | 'mousemove|click'
    /**
     * Whether to not hide popup content automatically
     */
    alwaysShowContent?: boolean

P
pissang 已提交
977
    formatter?: string | TooltipFormatterCallback<FormatterParams>
978 979 980 981 982 983 984
    /**
     * Absolution pixel [x, y] array. Or relative percent string [x, y] array.
     * If trigger is 'item'. position can be set to 'inside' / 'top' / 'left' / 'right' / 'bottom',
     * which is relative to the hovered element.
     *
     * Support to be a callback
     */
985
    position?: (number | string)[] | TooltipBuiltinPosition | PositionCallback | TooltipBoxLayoutOption
986 987 988 989 990 991

    confine?: boolean

    /**
     * Consider triggered from axisPointer handle, verticalAlign should be 'middle'
     */
P
pissang 已提交
992
    align?: HorizontalAlign
993

P
pissang 已提交
994
    verticalAlign?: VerticalAlign
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    /**
     * Delay of show. milesecond.
     */
    showDelay?: number

    /**
     * Delay of hide. milesecond.
     */
    hideDelay?: number

    transitionDuration?: number
    /**
     * Whether mouse is allowed to enter the floating layer of tooltip
     * If you need to interact in the tooltip like with links or buttons, it can be set as true.
     */
    enterable?: boolean

    backgroundColor?: ColorString
    borderColor?: ColorString
    borderRadius?: number
    borderWidth?: number

    /**
     * Padding between tooltip content and tooltip border.
     */
    padding?: number | number[]

    /**
     * Available when renderMode is 'html'
     */
    extraCssText?: string

    textStyle?: Pick<LabelOption,
        'color' | 'fontStyle' | 'fontWeight' | 'fontFamily' | 'fontSize' |
        'lineHeight' | 'width' | 'height' | 'textBorderColor' | 'textBorderWidth' |
        'textShadowColor' | 'textShadowBlur' | 'textShadowOffsetX' | 'textShadowOffsetY'
        | 'align'> & {

        // Available when renderMode is html
        decoration?: string
    }
}

/**
 * Tooltip option configured on each series
 */
P
pissang 已提交
1041 1042
export type SeriesTooltipOption = CommonTooltipOption<CallbackDataParams> & {
    trigger?: 'item' | 'axis' | boolean | 'none'
1
100pah 已提交
1043
};
P
pissang 已提交
1044 1045 1046 1047 1048 1049

type LabelFormatterParams = {
    value: ScaleDataValue
    axisDimension: string
    axisIndex: number
    seriesData: CallbackDataParams[]
1
100pah 已提交
1050
};
P
pissang 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
/**
 * Common axis option. can be configured on each axis
 */
export interface CommonAxisPointerOption {
    show?: boolean | 'auto'

    z?: number;
    zlevel?: number;

    triggerOn?: 'click' | 'mousemove' | 'none' | 'mousemove|click'

    type?: 'line' | 'shadow' | 'none'

    snap?: boolean

    triggerTooltip?: boolean

    /**
     * current value. When using axisPointer.handle, value can be set to define the initail position of axisPointer.
     */
1071
    value?: ScaleDataValue
P
pissang 已提交
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

    status?: 'show' | 'hide'

    // [group0, group1, ...]
    // Each group can be: {
    //      mapper: function () {},
    //      singleTooltip: 'multiple',  // 'multiple' or 'single'
    //      xAxisId: ...,
    //      yAxisName: ...,
    //      angleAxisIndex: ...
    // }
    // mapper: can be ignored.
    //      input: {axisInfo, value}
    //      output: {axisInfo, value}

    label?: LabelOption & {
        precision?: 'auto' | number
        margin?: number
        /**
         * String template include variable {value} or callback function
         */
        formatter?: string | ((params: LabelFormatterParams) => string)
    }
    animation?: boolean | 'auto'
    animationDurationUpdate?: number
    animationEasingUpdate?: ZREasing

    /**
     * Available when type is 'line'
     */
    lineStyle?: LineStyleOption
    /**
     * Available when type is 'shadow'
     */
    shadowStyle?: AreaStyleOption

    handle?: {
        show?: boolean
        icon?: string
        /**
         * The size of the handle
         */
        size?: number | number[]
        /**
         * Distance from handle center to axis.
         */
        margin?: number

        color?: ColorString

        /**
         * Throttle for mobile performance
         */
        throttle?: number
    } & ShadowOptionMixin


    seriesDataIndices?: {
        seriesIndex: number
        dataIndex: number
        dataIndexInside: number
    }[]

}
1136

1137 1138
export interface ComponentOption {
    type?: string;
P
pissang 已提交
1139

1140 1141 1142 1143 1144
    id?: string;
    name?: string;

    z?: number;
    zlevel?: number;
1145 1146 1147
    // FIXME:TS more
}

1148 1149
export type BlurScope = 'coordinateSystem' | 'series' | 'global';

1150 1151
/**
 * can be array of data indices.
1152
 * Or may be an dictionary if have different types of data like in graph.
1153
 */
1154
export type InnerFocus = string | ArrayLike<number> | Dictionary<ArrayLike<number>>;
1155

1156 1157 1158 1159 1160
export interface StatesOptionMixin<StateOption = unknown, ExtraStateOpts extends {
    emphasis?: any
    select?: any
    blur?: any
} = unknown> {
1161 1162 1163 1164 1165 1166 1167 1168
    /**
     * Emphasis states
     */
    emphasis?: StateOption & {
        /**
         * self: Focus self and blur all others.
         * series: Focus series and blur all other series.
         */
1169
        focus?: 'none' | 'self' | 'series' |
P
pissang 已提交
1170 1171
            (unknown extends ExtraStateOpts['emphasis']['focus']
                ? never : ExtraStateOpts['emphasis']['focus'])
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

        /**
         * Scope of blurred element when focus.
         *
         * coordinateSystem: blur others in the same coordinateSystem
         * series: blur others in the same series
         * global: blur all others
         *
         * Default to be coordinate system.
         */
        blurScope?: BlurScope
1183
    } & Omit<ExtraStateOpts['emphasis'], 'focus'>
1184 1185 1186
    /**
     * Select states
     */
1187
    select?: StateOption & ExtraStateOpts['select']
1188 1189 1190
    /**
     * Blur states.
     */
1191
    blur?: StateOption & ExtraStateOpts['blur']
1192 1193
}

1194 1195 1196 1197 1198
export interface SeriesOption<StateOption=any, ExtraStateOpts extends {
    emphasis?: any
    select?: any
    blur?: any
} = unknown> extends
1199 1200
    ComponentOption,
    AnimationOptionMixin,
1201
    ColorPaletteOptionMixin,
1202
    StatesOptionMixin<StateOption, ExtraStateOpts>
1203
{
P
pissang 已提交
1204 1205
    name?: string

1206 1207 1208 1209
    silent?: boolean

    blendMode?: string

1210 1211 1212 1213 1214
    /**
     * Cursor when mouse on the elements
     */
    cursor?: string

1215
    // Needs to be override
1216
    data?: any
1217 1218 1219

    legendHoverLink?: boolean

1220 1221 1222
    /**
     * Configurations about progressive rendering
     */
1223 1224 1225
    progressive?: number | false
    progressiveThreshold?: number
    progressiveChunkMode?: 'mod'
1226 1227 1228
    /**
     * Not available on every series
     */
1
100pah 已提交
1229 1230
    coordinateSystem?: string

P
pissang 已提交
1231
    hoverLayerThreshold?: number
1232
    // FIXME:TS more
P
pissang 已提交
1233 1234 1235 1236 1237 1238 1239

    /**
     * When dataset is used, seriesLayoutBy specifies whether the column or the row of dataset is mapped to the series
     * namely, the series is "layout" on columns or rows
     * @default 'column'
     */
    seriesLayoutBy?: 'column' | 'row'
1240

P
pissang 已提交
1241
    labelLine?: LabelLineOption
1242

1243
    /**
1244
     * Overall label layout option in label layout stage.
1245 1246
     */
    labelLayout?: LabelLayoutOption | LabelLayoutOptionCallback
1247 1248 1249 1250 1251

    /**
     * Animation config for state transition.
     */
    stateAnimation?: AnimationOption
1252
}
P
pissang 已提交
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272

export interface SeriesOnCartesianOptionMixin {
    xAxisIndex?: number
    yAxisIndex?: number

    xAxisId?: string
    yAxisId?: string
}

export interface SeriesOnPolarOptionMixin {
    radiusAxisIndex?: number
    angleAxisIndex?: number

    radiusAxisId?: string
    angleAxisId?: string
}

export interface SeriesOnSingleOptionMixin {
    singleAxisIndex?: number
    singleAxisId?: string
1273 1274 1275 1276
}

export interface SeriesOnGeoOptionMixin {
    geoIndex?: number;
P
pissang 已提交
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
    geoId?: string
}

export interface SeriesOnCalendarOptionMixin {
    calendarIndex?: number
    calendarId?: string
}

export interface SeriesLargeOptionMixin {
    large?: boolean
    largeThreshold?: number
}
export interface SeriesStackOptionMixin {
    stack?: string
}
1292

1
100pah 已提交
1293
type SamplingFunc = (frame: ArrayLike<number>) => number;
1294 1295 1296 1297 1298

export interface SeriesSamplingOptionMixin {
    sampling?: 'none' | 'average' | 'min' | 'max' | 'sum' | SamplingFunc
}

1299 1300 1301
export interface SeriesEncodeOptionMixin {
    datasetIndex?: number;
    seriesLayoutBy?: SeriesLayoutBy;
1
100pah 已提交
1302
    dimensions?: DimensionName[];
1303 1304
    encode?: OptionEncode
}