dd660287647751f717c636ee93b9494509815e5a9e6b907a40601aad1e81c5a45c14b5cbfeba834e751236391b9bda1f8c984e3f8847ce703aafe3f505fe0f 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * ECharts option manager
  3. */
  4. import ExtensionAPI from '../core/ExtensionAPI.js';
  5. import { OptionPreprocessor, ECUnitOption, ECBasicOption } from '../util/types.js';
  6. import GlobalModel, { InnerSetOptionOpts } from './Global.js';
  7. /**
  8. * TERM EXPLANATIONS:
  9. * See `ECOption` and `ECUnitOption` in `src/util/types.ts`.
  10. */
  11. declare class OptionManager {
  12. private _api;
  13. private _timelineOptions;
  14. private _mediaList;
  15. private _mediaDefault;
  16. /**
  17. * -1, means default.
  18. * empty means no media.
  19. */
  20. private _currentMediaIndices;
  21. private _optionBackup;
  22. private _newBaseOption;
  23. constructor(api: ExtensionAPI);
  24. setOption(rawOption: ECBasicOption, optionPreprocessorFuncs: OptionPreprocessor[], opt: InnerSetOptionOpts): void;
  25. mountOption(isRecreate: boolean): ECUnitOption;
  26. getTimelineOption(ecModel: GlobalModel): ECUnitOption;
  27. getMediaOption(ecModel: GlobalModel): ECUnitOption[];
  28. }
  29. /**
  30. * Consider case:
  31. * `chart.setOption(opt1);`
  32. * Then user do some interaction like dataZoom, dataView changing.
  33. * `chart.setOption(opt2);`
  34. * Then user press 'reset button' in toolbox.
  35. *
  36. * After doing that all of the interaction effects should be reset, the
  37. * chart should be the same as the result of invoke
  38. * `chart.setOption(opt1); chart.setOption(opt2);`.
  39. *
  40. * Although it is not able ensure that
  41. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  42. * `chart.setOption(merge(opt1, opt2));` exactly,
  43. * this might be the only simple way to implement that feature.
  44. *
  45. * MEMO: We've considered some other approaches:
  46. * 1. Each model handle its self restoration but not uniform treatment.
  47. * (Too complex in logic and error-prone)
  48. * 2. Use a shadow ecModel. (Performace expensive)
  49. *
  50. * FIXME: A possible solution:
  51. * Add a extra level of model for each component model. The inheritance chain would be:
  52. * ecModel <- componentModel <- componentActionModel <- dataItemModel
  53. * And all of the actions can only modify the `componentActionModel` rather than
  54. * `componentModel`. `setOption` will only modify the `ecModel` and `componentModel`.
  55. * When "resotre" action triggered, model from `componentActionModel` will be discarded
  56. * instead of recreating the "ecModel" from the "_optionBackup".
  57. */
  58. export default OptionManager;