5ee2520e0538f944016338b9afeb5177bdaf80dfe18b715a6e38614d96b284083d584b7b10f077cda0097e5db8710b4dde5463f01acc9852687c5801ff7247 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import { HashMap } from 'zrender/lib/core/util.js';
  2. import GlobalModel from '../model/Global.js';
  3. import ComponentModel, { ComponentModelConstructor } from '../model/Component.js';
  4. import SeriesData from '../data/SeriesData.js';
  5. import { ComponentOption, ComponentMainType, ComponentSubType, DisplayStateHostOption, OptionDataItem, OptionDataValue, TooltipRenderMode, Payload, OptionId, InterpolatableValue } from './types.js';
  6. import SeriesModel from '../model/Series.js';
  7. import CartesianAxisModel from '../coord/cartesian/AxisModel.js';
  8. import GridModel from '../coord/cartesian/GridModel.js';
  9. /**
  10. * If value is not array, then translate it to array.
  11. * @param {*} value
  12. * @return {Array} [value] or value
  13. */
  14. export declare function normalizeToArray<T>(value?: T | T[]): T[];
  15. /**
  16. * Sync default option between normal and emphasis like `position` and `show`
  17. * In case some one will write code like
  18. * label: {
  19. * show: false,
  20. * position: 'outside',
  21. * fontSize: 18
  22. * },
  23. * emphasis: {
  24. * label: { show: true }
  25. * }
  26. */
  27. export declare function defaultEmphasis(opt: DisplayStateHostOption, key: string, subOpts: string[]): void;
  28. export declare const TEXT_STYLE_OPTIONS: readonly ["fontStyle", "fontWeight", "fontSize", "fontFamily", "rich", "tag", "color", "textBorderColor", "textBorderWidth", "width", "height", "lineHeight", "align", "verticalAlign", "baseline", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "textShadowColor", "textShadowBlur", "textShadowOffsetX", "textShadowOffsetY", "backgroundColor", "borderColor", "borderWidth", "borderRadius", "padding"];
  29. /**
  30. * The method do not ensure performance.
  31. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  32. * This helper method retieves value from data.
  33. */
  34. export declare function getDataItemValue(dataItem: OptionDataItem): OptionDataValue | OptionDataValue[];
  35. /**
  36. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  37. * This helper method determine if dataItem has extra option besides value
  38. */
  39. export declare function isDataItemOption(dataItem: OptionDataItem): boolean;
  40. export interface MappingExistingItem {
  41. id?: OptionId;
  42. name?: string;
  43. }
  44. /**
  45. * The array `MappingResult<T>[]` exactly represents the content of the result
  46. * components array after merge.
  47. * The indices are the same as the `existings`.
  48. * Items will not be `null`/`undefined` even if the corresponding `existings` will be removed.
  49. */
  50. declare type MappingResult<T> = MappingResultItem<T>[];
  51. interface MappingResultItem<T extends MappingExistingItem = MappingExistingItem> {
  52. existing: T;
  53. newOption: ComponentOption;
  54. brandNew: boolean;
  55. keyInfo: {
  56. name: string;
  57. id: string;
  58. mainType: ComponentMainType;
  59. subType: ComponentSubType;
  60. };
  61. }
  62. declare type MappingToExistsMode = 'normalMerge' | 'replaceMerge' | 'replaceAll';
  63. /**
  64. * Mapping to existings for merge.
  65. *
  66. * Mode "normalMege":
  67. * The mapping result (merge result) will keep the order of the existing
  68. * component, rather than the order of new option. Because we should ensure
  69. * some specified index reference (like xAxisIndex) keep work.
  70. * And in most cases, "merge option" is used to update partial option but not
  71. * be expected to change the order.
  72. *
  73. * Mode "replaceMege":
  74. * (1) Only the id mapped components will be merged.
  75. * (2) Other existing components (except internal compoonets) will be removed.
  76. * (3) Other new options will be used to create new component.
  77. * (4) The index of the existing compoents will not be modified.
  78. * That means their might be "hole" after the removal.
  79. * The new components are created first at those available index.
  80. *
  81. * Mode "replaceAll":
  82. * This mode try to support that reproduce an echarts instance from another
  83. * echarts instance (via `getOption`) in some simple cases.
  84. * In this senario, the `result` index are exactly the consistent with the `newCmptOptions`,
  85. * which ensures the compoennt index referring (like `xAxisIndex: ?`) corrent. That is,
  86. * the "hole" in `newCmptOptions` will also be kept.
  87. * On the contrary, other modes try best to eliminate holes.
  88. * PENDING: This is an experimental mode yet.
  89. *
  90. * @return See the comment of <MappingResult>.
  91. */
  92. export declare function mappingToExists<T extends MappingExistingItem>(existings: T[], newCmptOptions: ComponentOption[], mode: MappingToExistsMode): MappingResult<T>;
  93. export declare function convertOptionIdName(idOrName: unknown, defaultValue: string): string;
  94. export declare function isNameSpecified(componentModel: ComponentModel): boolean;
  95. /**
  96. * @public
  97. * @param {Object} cmptOption
  98. * @return {boolean}
  99. */
  100. export declare function isComponentIdInternal(cmptOption: {
  101. id?: MappingExistingItem['id'];
  102. }): boolean;
  103. export declare function makeInternalComponentId(idSuffix: string): string;
  104. export declare function setComponentTypeToKeyInfo(mappingResult: MappingResult<MappingExistingItem & {
  105. subType?: ComponentSubType;
  106. }>, mainType: ComponentMainType, componentModelCtor: ComponentModelConstructor): void;
  107. declare type BatchItem = {
  108. seriesId: OptionId;
  109. dataIndex: number | number[];
  110. };
  111. /**
  112. * A helper for removing duplicate items between batchA and batchB,
  113. * and in themselves, and categorize by series.
  114. *
  115. * @param batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  116. * @param batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  117. * @return result: [resultBatchA, resultBatchB]
  118. */
  119. export declare function compressBatches(batchA: BatchItem[], batchB: BatchItem[]): [BatchItem[], BatchItem[]];
  120. /**
  121. * @param payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  122. * each of which can be Array or primary type.
  123. * @return dataIndex If not found, return undefined/null.
  124. */
  125. export declare function queryDataIndex(data: SeriesData, payload: Payload & {
  126. dataIndexInside?: number | number[];
  127. dataIndex?: number | number[];
  128. name?: string | string[];
  129. }): number | number[];
  130. /**
  131. * Enable property storage to any host object.
  132. * Notice: Serialization is not supported.
  133. *
  134. * For example:
  135. * let inner = zrUitl.makeInner();
  136. *
  137. * function some1(hostObj) {
  138. * inner(hostObj).someProperty = 1212;
  139. * ...
  140. * }
  141. * function some2() {
  142. * let fields = inner(this);
  143. * fields.someProperty1 = 1212;
  144. * fields.someProperty2 = 'xx';
  145. * ...
  146. * }
  147. *
  148. * @return {Function}
  149. */
  150. export declare function makeInner<T, Host extends object>(): (hostObj: Host) => T;
  151. /**
  152. * If string, e.g., 'geo', means {geoIndex: 0}.
  153. * If Object, could contain some of these properties below:
  154. * {
  155. * seriesIndex, seriesId, seriesName,
  156. * geoIndex, geoId, geoName,
  157. * bmapIndex, bmapId, bmapName,
  158. * xAxisIndex, xAxisId, xAxisName,
  159. * yAxisIndex, yAxisId, yAxisName,
  160. * gridIndex, gridId, gridName,
  161. * ... (can be extended)
  162. * }
  163. * Each properties can be number|string|Array.<number>|Array.<string>
  164. * For example, a finder could be
  165. * {
  166. * seriesIndex: 3,
  167. * geoId: ['aa', 'cc'],
  168. * gridName: ['xx', 'rr']
  169. * }
  170. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  171. * If nothing or null/undefined specified, return nothing.
  172. * If both `abcIndex`, `abcId`, `abcName` specified, only one work.
  173. * The priority is: index > id > name, the same with `ecModel.queryComponents`.
  174. */
  175. export declare type ModelFinderIndexQuery = number | number[] | 'all' | 'none' | false;
  176. export declare type ModelFinderIdQuery = OptionId | OptionId[];
  177. export declare type ModelFinderNameQuery = OptionId | OptionId[];
  178. export declare type ModelFinder = string | ModelFinderObject;
  179. export declare type ModelFinderObject = {
  180. seriesIndex?: ModelFinderIndexQuery;
  181. seriesId?: ModelFinderIdQuery;
  182. seriesName?: ModelFinderNameQuery;
  183. geoIndex?: ModelFinderIndexQuery;
  184. geoId?: ModelFinderIdQuery;
  185. geoName?: ModelFinderNameQuery;
  186. bmapIndex?: ModelFinderIndexQuery;
  187. bmapId?: ModelFinderIdQuery;
  188. bmapName?: ModelFinderNameQuery;
  189. xAxisIndex?: ModelFinderIndexQuery;
  190. xAxisId?: ModelFinderIdQuery;
  191. xAxisName?: ModelFinderNameQuery;
  192. yAxisIndex?: ModelFinderIndexQuery;
  193. yAxisId?: ModelFinderIdQuery;
  194. yAxisName?: ModelFinderNameQuery;
  195. gridIndex?: ModelFinderIndexQuery;
  196. gridId?: ModelFinderIdQuery;
  197. gridName?: ModelFinderNameQuery;
  198. dataIndex?: number;
  199. dataIndexInside?: number;
  200. };
  201. /**
  202. * {
  203. * seriesModels: [seriesModel1, seriesModel2],
  204. * seriesModel: seriesModel1, // The first model
  205. * geoModels: [geoModel1, geoModel2],
  206. * geoModel: geoModel1, // The first model
  207. * ...
  208. * }
  209. */
  210. export declare type ParsedModelFinder = {
  211. [key: string]: ComponentModel | ComponentModel[] | undefined;
  212. };
  213. export declare type ParsedModelFinderKnown = ParsedModelFinder & {
  214. seriesModels?: SeriesModel[];
  215. seriesModel?: SeriesModel;
  216. xAxisModels?: CartesianAxisModel[];
  217. xAxisModel?: CartesianAxisModel;
  218. yAxisModels?: CartesianAxisModel[];
  219. yAxisModel?: CartesianAxisModel;
  220. gridModels?: GridModel[];
  221. gridModel?: GridModel;
  222. dataIndex?: number;
  223. dataIndexInside?: number;
  224. };
  225. /**
  226. * The same behavior as `component.getReferringComponents`.
  227. */
  228. export declare function parseFinder(ecModel: GlobalModel, finderInput: ModelFinder, opt?: {
  229. defaultMainType?: ComponentMainType;
  230. includeMainTypes?: ComponentMainType[];
  231. enableAll?: boolean;
  232. enableNone?: boolean;
  233. }): ParsedModelFinder;
  234. export declare function preParseFinder(finderInput: ModelFinder, opt?: {
  235. includeMainTypes?: ComponentMainType[];
  236. }): {
  237. mainTypeSpecified: boolean;
  238. queryOptionMap: HashMap<QueryReferringUserOption, ComponentMainType>;
  239. others: Partial<Pick<ParsedModelFinderKnown, 'dataIndex' | 'dataIndexInside'>>;
  240. };
  241. export declare type QueryReferringUserOption = {
  242. index?: ModelFinderIndexQuery;
  243. id?: ModelFinderIdQuery;
  244. name?: ModelFinderNameQuery;
  245. };
  246. export declare const SINGLE_REFERRING: QueryReferringOpt;
  247. export declare const MULTIPLE_REFERRING: QueryReferringOpt;
  248. export declare type QueryReferringOpt = {
  249. useDefault?: boolean;
  250. enableAll?: boolean;
  251. enableNone?: boolean;
  252. };
  253. export declare function queryReferringComponents(ecModel: GlobalModel, mainType: ComponentMainType, userOption: QueryReferringUserOption, opt?: QueryReferringOpt): {
  254. models: ComponentModel[];
  255. specified: boolean;
  256. };
  257. export declare function setAttribute(dom: HTMLElement, key: string, value: any): void;
  258. export declare function getAttribute(dom: HTMLElement, key: string): any;
  259. export declare function getTooltipRenderMode(renderModeOption: TooltipRenderMode | 'auto'): TooltipRenderMode;
  260. /**
  261. * Group a list by key.
  262. */
  263. export declare function groupData<T, R extends string | number>(array: T[], getKey: (item: T) => R): {
  264. keys: R[];
  265. buckets: HashMap<T[], R>;
  266. };
  267. /**
  268. * Interpolate raw values of a series with percent
  269. *
  270. * @param data data
  271. * @param labelModel label model of the text element
  272. * @param sourceValue start value. May be null/undefined when init.
  273. * @param targetValue end value
  274. * @param percent 0~1 percentage; 0 uses start value while 1 uses end value
  275. * @return interpolated values
  276. * If `sourceValue` and `targetValue` are `number`, return `number`.
  277. * If `sourceValue` and `targetValue` are `string`, return `string`.
  278. * If `sourceValue` and `targetValue` are `(string | number)[]`, return `(string | number)[]`.
  279. * Other cases do not supported.
  280. */
  281. export declare function interpolateRawValues(data: SeriesData, precision: number | 'auto', sourceValue: InterpolatableValue, targetValue: InterpolatableValue, percent: number): InterpolatableValue;
  282. export {};