2ef6a1b25f5ebd96c527a3d71604f2677bbed40ee06a78ffbdce5620c8fe65879eaa9045023e813d8a9249f99dab19ebad108fd1e1478c2bfa5b218695a517 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. * Caution: If the mechanism should be changed some day, these cases
  3. * should be considered:
  4. *
  5. * (1) In `merge option` mode, if using the same option to call `setOption`
  6. * many times, the result should be the same (try our best to ensure that).
  7. * (2) In `merge option` mode, if a component has no id/name specified, it
  8. * will be merged by index, and the result sequence of the components is
  9. * consistent to the original sequence.
  10. * (3) In `replaceMerge` mode, keep the result sequence of the components is
  11. * consistent to the original sequence, even though there might result in "hole".
  12. * (4) `reset` feature (in toolbox). Find detailed info in comments about
  13. * `mergeOption` in module:echarts/model/OptionManager.
  14. */
  15. import { HashMap } from 'zrender/lib/core/util.js';
  16. import Model from './Model.js';
  17. import ComponentModel from './Component.js';
  18. import SeriesModel from './Series.js';
  19. import { Payload, OptionPreprocessor, ECBasicOption, ECUnitOption, ComponentMainType, ComponentSubType, OptionId, OptionName } from '../util/types.js';
  20. import OptionManager from './OptionManager.js';
  21. import Scheduler from '../core/Scheduler.js';
  22. import { LocaleOption } from '../core/locale.js';
  23. import { PaletteMixin } from './mixin/palette.js';
  24. export interface GlobalModelSetOptionOpts {
  25. replaceMerge: ComponentMainType | ComponentMainType[];
  26. }
  27. export interface InnerSetOptionOpts {
  28. replaceMergeMainTypeMap: HashMap<boolean, string>;
  29. }
  30. declare class GlobalModel extends Model<ECUnitOption> {
  31. option: ECUnitOption;
  32. private _theme;
  33. private _locale;
  34. private _optionManager;
  35. private _componentsMap;
  36. /**
  37. * `_componentsMap` might have "hole" becuase of remove.
  38. * So save components count for a certain mainType here.
  39. */
  40. private _componentsCount;
  41. /**
  42. * Mapping between filtered series list and raw series list.
  43. * key: filtered series indices, value: raw series indices.
  44. * Items of `_seriesIndices` never be null/empty/-1.
  45. * If series has been removed by `replaceMerge`, those series
  46. * also won't be in `_seriesIndices`, just like be filtered.
  47. */
  48. private _seriesIndices;
  49. /**
  50. * Key: seriesIndex.
  51. * Keep consistent with `_seriesIndices`.
  52. */
  53. private _seriesIndicesMap;
  54. /**
  55. * Model for store update payload
  56. */
  57. private _payload;
  58. scheduler: Scheduler;
  59. ssr: boolean;
  60. init(option: ECBasicOption, parentModel: Model, ecModel: GlobalModel, theme: object, locale: object, optionManager: OptionManager): void;
  61. setOption(option: ECBasicOption, opts: GlobalModelSetOptionOpts, optionPreprocessorFuncs: OptionPreprocessor[]): void;
  62. /**
  63. * @param type null/undefined: reset all.
  64. * 'recreate': force recreate all.
  65. * 'timeline': only reset timeline option
  66. * 'media': only reset media query option
  67. * @return Whether option changed.
  68. */
  69. resetOption(type: 'recreate' | 'timeline' | 'media', opt?: Pick<GlobalModelSetOptionOpts, 'replaceMerge'>): boolean;
  70. private _resetOption;
  71. mergeOption(option: ECUnitOption): void;
  72. private _mergeOption;
  73. /**
  74. * Get option for output (cloned option and inner info removed)
  75. */
  76. getOption(): ECUnitOption;
  77. getTheme(): Model;
  78. getLocaleModel(): Model<LocaleOption>;
  79. setUpdatePayload(payload: Payload): void;
  80. getUpdatePayload(): Payload;
  81. /**
  82. * @param idx If not specified, return the first one.
  83. */
  84. getComponent(mainType: ComponentMainType, idx?: number): ComponentModel;
  85. /**
  86. * @return Never be null/undefined.
  87. */
  88. queryComponents(condition: QueryConditionKindB): ComponentModel[];
  89. /**
  90. * The interface is different from queryComponents,
  91. * which is convenient for inner usage.
  92. *
  93. * @usage
  94. * let result = findComponents(
  95. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  96. * );
  97. * let result = findComponents(
  98. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  99. * );
  100. * let result = findComponents(
  101. * {mainType: 'series',
  102. * filter: function (model, index) {...}}
  103. * );
  104. * // result like [component0, componnet1, ...]
  105. */
  106. findComponents(condition: QueryConditionKindA): ComponentModel[];
  107. /**
  108. * Travel components (before filtered).
  109. *
  110. * @usage
  111. * eachComponent('legend', function (legendModel, index) {
  112. * ...
  113. * });
  114. * eachComponent(function (componentType, model, index) {
  115. * // componentType does not include subType
  116. * // (componentType is 'a' but not 'a.b')
  117. * });
  118. * eachComponent(
  119. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  120. * function (model, index) {...}
  121. * );
  122. * eachComponent(
  123. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  124. * function (model, index) {...}
  125. * );
  126. */
  127. eachComponent<T>(cb: EachComponentAllCallback, context?: T): void;
  128. eachComponent<T>(mainType: string, cb: EachComponentInMainTypeCallback, context?: T): void;
  129. eachComponent<T>(mainType: QueryConditionKindA, cb: EachComponentInMainTypeCallback, context?: T): void;
  130. /**
  131. * Get series list before filtered by name.
  132. */
  133. getSeriesByName(name: OptionName): SeriesModel[];
  134. /**
  135. * Get series list before filtered by index.
  136. */
  137. getSeriesByIndex(seriesIndex: number): SeriesModel;
  138. /**
  139. * Get series list before filtered by type.
  140. * FIXME: rename to getRawSeriesByType?
  141. */
  142. getSeriesByType(subType: ComponentSubType): SeriesModel[];
  143. /**
  144. * Get all series before filtered.
  145. */
  146. getSeries(): SeriesModel[];
  147. /**
  148. * Count series before filtered.
  149. */
  150. getSeriesCount(): number;
  151. /**
  152. * After filtering, series may be different
  153. * frome raw series.
  154. */
  155. eachSeries<T>(cb: (this: T, series: SeriesModel, rawSeriesIndex: number) => void, context?: T): void;
  156. /**
  157. * Iterate raw series before filtered.
  158. *
  159. * @param {Function} cb
  160. * @param {*} context
  161. */
  162. eachRawSeries<T>(cb: (this: T, series: SeriesModel, rawSeriesIndex: number) => void, context?: T): void;
  163. /**
  164. * After filtering, series may be different.
  165. * frome raw series.
  166. */
  167. eachSeriesByType<T>(subType: ComponentSubType, cb: (this: T, series: SeriesModel, rawSeriesIndex: number) => void, context?: T): void;
  168. /**
  169. * Iterate raw series before filtered of given type.
  170. */
  171. eachRawSeriesByType<T>(subType: ComponentSubType, cb: (this: T, series: SeriesModel, rawSeriesIndex: number) => void, context?: T): void;
  172. isSeriesFiltered(seriesModel: SeriesModel): boolean;
  173. getCurrentSeriesIndices(): number[];
  174. filterSeries<T>(cb: (this: T, series: SeriesModel, rawSeriesIndex: number) => boolean, context?: T): void;
  175. restoreData(payload?: Payload): void;
  176. private static internalField;
  177. }
  178. /**
  179. * @param condition.mainType Mandatory.
  180. * @param condition.subType Optional.
  181. * @param condition.query like {xxxIndex, xxxId, xxxName},
  182. * where xxx is mainType.
  183. * If query attribute is null/undefined or has no index/id/name,
  184. * do not filtering by query conditions, which is convenient for
  185. * no-payload situations or when target of action is global.
  186. * @param condition.filter parameter: component, return boolean.
  187. */
  188. export interface QueryConditionKindA {
  189. mainType: ComponentMainType;
  190. subType?: ComponentSubType;
  191. query?: {
  192. [k: string]: number | number[] | string | string[];
  193. };
  194. filter?: (cmpt: ComponentModel) => boolean;
  195. }
  196. /**
  197. * If none of index and id and name used, return all components with mainType.
  198. * @param condition.mainType
  199. * @param condition.subType If ignore, only query by mainType
  200. * @param condition.index Either input index or id or name.
  201. * @param condition.id Either input index or id or name.
  202. * @param condition.name Either input index or id or name.
  203. */
  204. export interface QueryConditionKindB {
  205. mainType: ComponentMainType;
  206. subType?: ComponentSubType;
  207. index?: number | number[];
  208. id?: OptionId | OptionId[];
  209. name?: OptionName | OptionName[];
  210. }
  211. export interface EachComponentAllCallback {
  212. (mainType: string, model: ComponentModel, componentIndex: number): void;
  213. }
  214. interface EachComponentInMainTypeCallback {
  215. (model: ComponentModel, componentIndex: number): void;
  216. }
  217. interface GlobalModel extends PaletteMixin<ECUnitOption> {
  218. }
  219. export default GlobalModel;