(registers: EChartsExtensionInstallRegisters)
| 721 | } |
| 722 | |
| 723 | export function installUniversalTransition(registers: EChartsExtensionInstallRegisters) { |
| 724 | |
| 725 | registers.registerUpdateLifecycle('series:beforeupdate', (ecMOdel, api, params) => { |
| 726 | each(normalizeToArray(params.seriesTransition), transOpt => { |
| 727 | each(normalizeToArray(transOpt.to), (finder) => { |
| 728 | const series = params.updatedSeries; |
| 729 | for (let i = 0; i < series.length; i++) { |
| 730 | if (finder.seriesIndex != null && finder.seriesIndex === series[i].seriesIndex |
| 731 | || finder.seriesId != null && finder.seriesId === series[i].id) { |
| 732 | series[i][SERIES_UNIVERSAL_TRANSITION_PROP] = true; |
| 733 | } |
| 734 | } |
| 735 | }); |
| 736 | }); |
| 737 | }); |
| 738 | registers.registerUpdateLifecycle('series:transition', (ecModel, api, params) => { |
| 739 | // TODO api provide an namespace that can save stuff per instance |
| 740 | const globalStore = getUniversalTransitionGlobalStore(api); |
| 741 | |
| 742 | // TODO multiple to multiple series. |
| 743 | if (globalStore.oldSeries && params.updatedSeries && params.optionChanged) { |
| 744 | // TODO transitionOpt was used in an old implementation and can be removed now |
| 745 | // Use give transition config if its' give; |
| 746 | const transitionOpt = params.seriesTransition; |
| 747 | if (transitionOpt) { |
| 748 | each(normalizeToArray(transitionOpt), opt => { |
| 749 | transitionSeriesFromOpt(opt, globalStore, params, api); |
| 750 | }); |
| 751 | } |
| 752 | else { // Else guess from series based on transition series key. |
| 753 | const updateBatches = findTransitionSeriesBatches(globalStore, params); |
| 754 | each(updateBatches.keys(), key => { |
| 755 | const batch = updateBatches.get(key); |
| 756 | transitionBetween(batch.oldSeries, batch.newSeries, api); |
| 757 | }); |
| 758 | } |
| 759 | |
| 760 | // Reset |
| 761 | each(params.updatedSeries, series => { |
| 762 | // Reset; |
| 763 | if (series[SERIES_UNIVERSAL_TRANSITION_PROP]) { |
| 764 | series[SERIES_UNIVERSAL_TRANSITION_PROP] = false; |
| 765 | } |
| 766 | }); |
| 767 | } |
| 768 | |
| 769 | // Save all series of current update. Not only the updated one. |
| 770 | const allSeries = ecModel.getSeries(); |
| 771 | const savedSeries: SeriesModel[] = globalStore.oldSeries = []; |
| 772 | const savedDataGroupIds: string[] = globalStore.oldDataGroupIds = []; |
| 773 | const savedData: SeriesData[] = globalStore.oldData = []; |
| 774 | for (let i = 0; i < allSeries.length; i++) { |
| 775 | const data = allSeries[i].getData(); |
| 776 | // Only save the data that can have transition. |
| 777 | // Avoid large data costing too much extra memory |
| 778 | if (data.count() < DATA_COUNT_THRESHOLD) { |
| 779 | savedSeries.push(allSeries[i]); |
| 780 | savedDataGroupIds.push(allSeries[i].get('dataGroupId') as string); |
nothing calls this directly
no test coverage detected
searching dependent graphs…