@orbcharts/plugins-basic 3.0.7 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +6837 -6656
  3. package/dist/orbcharts-plugins-basic.umd.js +45 -45
  4. package/dist/src/base/BaseStackedBars.d.ts +2 -0
  5. package/dist/src/series/defaults.d.ts +2 -1
  6. package/dist/src/series/index.d.ts +1 -0
  7. package/dist/src/series/plugins/Indicator.d.ts +3 -0
  8. package/lib/core-types.ts +7 -7
  9. package/lib/core.ts +6 -6
  10. package/lib/gridObservables.ts +6 -6
  11. package/lib/plugins-basic-types.ts +6 -6
  12. package/package.json +48 -48
  13. package/src/base/BaseBars.ts +765 -765
  14. package/src/base/BaseBarsTriangle.ts +676 -676
  15. package/src/base/BaseDots.ts +464 -464
  16. package/src/base/BaseGroupAxis.ts +691 -691
  17. package/src/base/BaseLegend.ts +684 -684
  18. package/src/base/BaseLineAreas.ts +629 -629
  19. package/src/base/BaseLines.ts +706 -706
  20. package/src/base/BaseOrdinalBubbles.ts +729 -729
  21. package/src/base/BaseRacingBars.ts +582 -582
  22. package/src/base/BaseRacingLabels.ts +404 -404
  23. package/src/base/BaseRacingValueLabels.ts +403 -403
  24. package/src/base/BaseStackedBars.ts +793 -782
  25. package/src/base/BaseTooltip.ts +408 -408
  26. package/src/base/BaseValueAxis.ts +600 -600
  27. package/src/base/BaseXAxis.ts +427 -427
  28. package/src/base/BaseXZoom.ts +241 -241
  29. package/src/base/BaseYAxis.ts +389 -389
  30. package/src/base/types.ts +2 -2
  31. package/src/const.ts +30 -30
  32. package/src/grid/defaults.ts +213 -213
  33. package/src/grid/gridObservables.ts +635 -635
  34. package/src/grid/index.ts +16 -16
  35. package/src/grid/plugins/Bars.ts +69 -69
  36. package/src/grid/plugins/BarsPN.ts +66 -66
  37. package/src/grid/plugins/BarsTriangle.ts +73 -73
  38. package/src/grid/plugins/Dots.ts +68 -68
  39. package/src/grid/plugins/GridLegend.ts +107 -107
  40. package/src/grid/plugins/GridTooltip.ts +66 -66
  41. package/src/grid/plugins/GroupAux.ts +1095 -1095
  42. package/src/grid/plugins/GroupAxis.ts +73 -73
  43. package/src/grid/plugins/GroupZoom.ts +218 -218
  44. package/src/grid/plugins/LineAreas.ts +65 -65
  45. package/src/grid/plugins/Lines.ts +59 -59
  46. package/src/grid/plugins/StackedBars.ts +66 -64
  47. package/src/grid/plugins/StackedValueAxis.ts +97 -96
  48. package/src/grid/plugins/ValueAxis.ts +94 -94
  49. package/src/index.ts +6 -6
  50. package/src/multiGrid/defaults.ts +244 -244
  51. package/src/multiGrid/index.ts +14 -14
  52. package/src/multiGrid/multiGridObservables.ts +50 -50
  53. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  54. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  55. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  56. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -169
  57. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  58. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  59. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  60. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  61. package/src/multiGrid/plugins/MultiStackedBars.ts +109 -106
  62. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +135 -134
  63. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  64. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +300 -300
  65. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  66. package/src/multiValue/defaults.ts +523 -523
  67. package/src/multiValue/index.ts +16 -16
  68. package/src/multiValue/multiValueObservables.ts +781 -781
  69. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  70. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  71. package/src/multiValue/plugins/OrdinalAux.ts +660 -660
  72. package/src/multiValue/plugins/OrdinalAxis.ts +524 -524
  73. package/src/multiValue/plugins/OrdinalBubbles.ts +226 -226
  74. package/src/multiValue/plugins/OrdinalZoom.ts +57 -57
  75. package/src/multiValue/plugins/RacingBars.ts +375 -375
  76. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -300
  77. package/src/multiValue/plugins/RacingValueAxis.ts +114 -114
  78. package/src/multiValue/plugins/Scatter.ts +486 -486
  79. package/src/multiValue/plugins/ScatterBubbles.ts +635 -635
  80. package/src/multiValue/plugins/XAxis.ts +107 -107
  81. package/src/multiValue/plugins/XYAux.ts +683 -683
  82. package/src/multiValue/plugins/XYAxes.ts +194 -194
  83. package/src/multiValue/plugins/XYAxes_legacy.ts +683 -683
  84. package/src/multiValue/plugins/XZoom.ts +40 -40
  85. package/src/noneData/defaults.ts +102 -102
  86. package/src/noneData/index.ts +3 -3
  87. package/src/noneData/plugins/Container.ts +27 -27
  88. package/src/noneData/plugins/Tooltip.ts +373 -373
  89. package/src/relationship/defaults.ts +221 -221
  90. package/src/relationship/index.ts +5 -5
  91. package/src/relationship/plugins/ForceDirected.ts +1056 -1056
  92. package/src/relationship/plugins/ForceDirectedBubbles.ts +1294 -1294
  93. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  94. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  95. package/src/relationship/relationshipObservables.ts +49 -49
  96. package/src/series/defaults.ts +236 -224
  97. package/src/series/index.ts +10 -9
  98. package/src/series/plugins/Bubbles.ts +784 -784
  99. package/src/series/plugins/Indicator.ts +292 -0
  100. package/src/series/plugins/Pie.ts +622 -622
  101. package/src/series/plugins/PieEventTexts.ts +283 -283
  102. package/src/series/plugins/PieLabels.ts +639 -639
  103. package/src/series/plugins/Rose.ts +515 -515
  104. package/src/series/plugins/RoseLabels.ts +599 -599
  105. package/src/series/plugins/SeriesLegend.ts +107 -107
  106. package/src/series/plugins/SeriesTooltip.ts +66 -66
  107. package/src/series/seriesObservables.ts +168 -168
  108. package/src/series/seriesUtils.ts +51 -51
  109. package/src/tree/defaults.ts +102 -102
  110. package/src/tree/index.ts +4 -4
  111. package/src/tree/plugins/TreeLegend.ts +100 -100
  112. package/src/tree/plugins/TreeMap.ts +341 -341
  113. package/src/tree/plugins/TreeTooltip.ts +66 -66
  114. package/src/utils/commonUtils.ts +31 -31
  115. package/src/utils/d3Graphics.ts +176 -176
  116. package/src/utils/d3Utils.ts +92 -92
  117. package/src/utils/observables.ts +14 -14
  118. package/src/utils/orbchartsUtils.ts +129 -129
  119. package/tsconfig.base.json +13 -13
  120. package/tsconfig.json +2 -2
  121. package/vite.config.js +22 -22
@@ -1,375 +1,375 @@
1
- import {
2
- takeUntil,
3
- combineLatest,
4
- of,
5
- iif,
6
- interval,
7
- map,
8
- distinctUntilChanged,
9
- shareReplay,
10
- switchMap,
11
- EMPTY,
12
- Subject,
13
- } from 'rxjs'
14
- import type { Observable } from 'rxjs'
15
- import type {
16
- DefinePluginConfig,
17
- } from '../../../lib/core-types'
18
- import type { BaseRacingLabelsParams, BaseRacingBarsParams } from '../../../lib/plugins-basic-types'
19
- import { defineMultiValuePlugin } from '../../../lib/core'
20
- import { createBaseRacingLabels } from '../../base/BaseRacingLabels'
21
- import { createBaseRacingValueLabels } from '../../base/BaseRacingValueLabels'
22
- import { createBaseRacingBars } from '../../base/BaseRacingBars'
23
- import { DEFAULT_RACING_BARS_PARAMS } from '../defaults'
24
- import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
25
- import {
26
- // visibleComputedSumDataObservable,
27
- // visibleComputedRankingByIndexDataObservable,
28
- // rankingAmountLimitObservable,
29
- computedRankingAmountObservable,
30
- rankingItemHeightObservable,
31
- rankingScaleListObservable,
32
- // computedRankingWithXYDataObservable
33
- } from '../multiValueObservables'
34
-
35
- const pluginName = 'RacingBars'
36
-
37
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_RACING_BARS_PARAMS> = {
38
- name: pluginName,
39
- defaultParams: DEFAULT_RACING_BARS_PARAMS,
40
- layerIndex: LAYER_INDEX_OF_GRAPHIC,
41
- validator: (params, { validateColumns }) => {
42
- const result = validateColumns(params, {
43
- bar: {
44
- toBeTypes: ['object']
45
- },
46
- barLabel: {
47
- toBeTypes: ['object']
48
- },
49
- valueLabel: {
50
- toBeTypes: ['object']
51
- },
52
- axisLabel: {
53
- toBeTypes: ['object']
54
- },
55
- rankingAmount: {
56
- toBe: 'number | "auto"',
57
- test: (value: any) => {
58
- return typeof value === 'number' || value === 'auto'
59
- }
60
- },
61
- autorun: {
62
- toBeTypes: ['boolean']
63
- },
64
- loop: {
65
- toBeTypes: ['boolean']
66
- },
67
- })
68
- if (params.bar) {
69
- const barResult = validateColumns(params.bar, {
70
- barWidth: {
71
- toBeTypes: ['number']
72
- },
73
- barPadding: {
74
- toBeTypes: ['number']
75
- },
76
- barRadius: {
77
- toBeTypes: ['number', 'boolean']
78
- },
79
- })
80
- if (barResult.status === 'error') {
81
- return barResult
82
- }
83
- }
84
- if (params.barLabel) {
85
- const barLabelResult = validateColumns(params.barLabel, {
86
- position: {
87
- toBe: '"inside" | "outside" | "none"',
88
- test: (value: any) => {
89
- return value === 'inside' || value === 'outside' || value === 'none'
90
- }
91
- },
92
- padding: {
93
- toBeTypes: ['number']
94
- },
95
- // rotate: {
96
- // toBeTypes: ['number']
97
- // },
98
- colorType: {
99
- toBeOption: 'ColorType',
100
- },
101
- })
102
- if (barLabelResult.status === 'error') {
103
- return barLabelResult
104
- }
105
- }
106
- if (params.valueLabel) {
107
- const valueLabelResult = validateColumns(params.valueLabel, {
108
- padding: {
109
- toBeTypes: ['number']
110
- },
111
- colorType: {
112
- toBeOption: 'ColorType',
113
- },
114
- format: {
115
- toBeTypes: ['Function']
116
- },
117
- })
118
- if (valueLabelResult.status === 'error') {
119
- return valueLabelResult
120
- }
121
- }
122
- if (params.axisLabel) {
123
- const axisLabelResult = validateColumns(params.axisLabel, {
124
- offset: {
125
- toBe: '[number, number]',
126
- test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
127
- },
128
- colorType: {
129
- toBeOption: 'ColorType',
130
- },
131
- })
132
- if (axisLabelResult.status === 'error') {
133
- return axisLabelResult
134
- }
135
- }
136
- return result
137
- }
138
- }
139
-
140
- export const RacingBars = defineMultiValuePlugin(pluginConfig)(({ selection, name, observer, subject }) => {
141
-
142
- const baseRacingBarsSelection = selection.append('g').attr('class', `${pluginName}-bars`)
143
- const baseRacingLabelsSelection = selection.append('g').attr('class', `${pluginName}-labels`)
144
- const baseRacingValueLabelsSelection = selection.append('g').attr('class', `${pluginName}-valueLabels`)
145
-
146
- const destroy$ = new Subject()
147
-
148
- // const baseRacingLabelsParams$: Observable<BaseRacingLabelsParams> = observer.fullParams$.pipe(
149
- // takeUntil(destroy$),
150
- // map(params => {
151
- // return {
152
- // ...params,
153
- // axisLabel: {
154
- // offset: [0, 0],
155
- // colorType: 'primary'
156
- // }
157
- // }
158
- // })
159
- // )
160
-
161
- // const baseRacingBarsParams$: Observable<BaseRacingBarsParams> = observer.fullParams$.pipe(
162
- // takeUntil(destroy$),
163
- // map(params => {
164
- // return {
165
- // ...params
166
- // }
167
- // })
168
- // )
169
-
170
- const baseRacingValueLabelsParams$ = observer.fullParams$.pipe(
171
- takeUntil(destroy$),
172
- map(params => {
173
- return params.valueLabel
174
- })
175
- )
176
-
177
- const rankingAmount$ = observer.fullParams$.pipe(
178
- takeUntil(destroy$),
179
- map(p => p.rankingAmount),
180
- distinctUntilChanged(),
181
- )
182
-
183
- const computedRankingAmount$ = computedRankingAmountObservable({
184
- containerSize$: observer.containerSize$,
185
- visibleComputedData$: observer.visibleComputedData$,
186
- textSizePx$: observer.textSizePx$,
187
- rankingAmount$
188
- }).pipe(
189
- takeUntil(destroy$),
190
- shareReplay(1)
191
- )
192
-
193
- const rankingItemHeight$ = rankingItemHeightObservable({
194
- containerSize$: observer.containerSize$,
195
- // visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
196
- textSizePx$: observer.textSizePx$,
197
- computedRankingAmount$
198
- }).pipe(
199
- takeUntil(destroy$),
200
- shareReplay(1)
201
- )
202
-
203
- const rankingScaleList$ = rankingScaleListObservable({
204
- visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
205
- rankingItemHeight$
206
- }).pipe(
207
- takeUntil(destroy$),
208
- shareReplay(1)
209
- )
210
-
211
- // const computedRankingWithXYData$ = computedRankingWithXYDataObservable({
212
- // visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
213
- // rankingScaleList$
214
- // }).pipe(
215
- // takeUntil(destroy$),
216
- // )
217
-
218
- // const xScale$ = combineLatest({
219
- // xScale: observer.xScale$,
220
- // layout: observer.layout$,
221
- // containerSize: observer.containerSize$,
222
- // }).pipe(
223
- // takeUntil(destroy$),
224
- // switchMap(async d => d),
225
- // map(data => {
226
- // // 原本的 xScale 是根據 layout 計算的,現在要根據 containerSize 重新計算
227
- // const containerWidthScale = data.containerSize.width / data.layout.width
228
-
229
- // return (n: number) => {
230
- // const originWidth = data.xScale(n)
231
- // if (originWidth == null) {
232
- // return 0
233
- // }
234
- // return data.xScale(n) * containerWidthScale
235
- // }
236
- // }),
237
- // shareReplay(1)
238
- // )
239
-
240
- const unsubscribeBaseRacingLabels = createBaseRacingLabels(`${pluginName}-labels`, {
241
- selection: baseRacingLabelsSelection,
242
- computedData$: observer.computedData$,
243
- visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
244
- rankingScaleList$,
245
- xScale$: observer.xScale$,
246
- fullParams$: observer.fullParams$,
247
- fullDataFormatter$: observer.fullDataFormatter$,
248
- fullChartParams$: observer.fullChartParams$,
249
- transitionEase$: of('easeLinear'),
250
- // layout$: observer.layout$,
251
- containerPosition$: observer.containerPosition$,
252
- containerSize$: observer.containerSize$,
253
- isCategorySeprate$: observer.isCategorySeprate$,
254
- // xyValueIndex$: observer.xyValueIndex$,
255
- })
256
-
257
- const unsubscribeBaseRacingValueLabels = createBaseRacingValueLabels(`${pluginName}-valueLabels`, {
258
- selection: baseRacingValueLabelsSelection,
259
- computedData$: observer.computedData$,
260
- visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
261
- rankingScaleList$,
262
- xScale$: observer.xScale$,
263
- computedRankingAmount$,
264
- fullParams$: baseRacingValueLabelsParams$,
265
- // fullDataFormatter$: observer.fullDataFormatter$,
266
- fullChartParams$: observer.fullChartParams$,
267
- // layout$: observer.layout$,
268
- containerPosition$: observer.containerPosition$,
269
- containerSize$: observer.containerSize$,
270
- isCategorySeprate$: observer.isCategorySeprate$,
271
- // xyValueIndex$: observer.xyValueIndex$,
272
- })
273
-
274
- const unsubscribeBaseRacingBars = createBaseRacingBars(`${pluginName}-bars`, {
275
- selection: baseRacingBarsSelection,
276
- computedData$: observer.computedData$,
277
- visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
278
- // xyValueIndex$: observer.xyValueIndex$,
279
- CategoryDataMap$: observer.CategoryDataMap$,
280
- fullParams$: observer.fullParams$,
281
- fullDataFormatter$: observer.fullDataFormatter$,
282
- fullChartParams$: observer.fullChartParams$,
283
- highlight$: observer.highlight$,
284
- rankingItemHeight$,
285
- rankingScaleList$,
286
- xScale$: observer.xScale$,
287
- containerPosition$: observer.containerPosition$,
288
- containerSize$: observer.containerSize$,
289
- // layout$: observer.layout$,
290
- isCategorySeprate$: observer.isCategorySeprate$,
291
- event$: subject.event$,
292
- })
293
-
294
- const valueAmount$ = observer.visibleComputedRankingByIndexData$.pipe(
295
- takeUntil(destroy$),
296
- map(d => (d[0] && d[0][0] && d[0][0].value.length) ?? 0),
297
- distinctUntilChanged()
298
- )
299
-
300
- const autorun$ = observer.fullParams$.pipe(
301
- takeUntil(destroy$),
302
- map(p => p.autorun),
303
- distinctUntilChanged()
304
- )
305
-
306
- const loop$ = observer.fullParams$.pipe(
307
- takeUntil(destroy$),
308
- map(p => p.loop),
309
- distinctUntilChanged()
310
- )
311
-
312
- const tickDurationPeriod$ = observer.fullChartParams$.pipe(
313
- takeUntil(destroy$),
314
- map(p => p.transitionDuration),
315
- distinctUntilChanged()
316
- )
317
-
318
- // -- autorun --
319
- let toggle = true
320
-
321
- combineLatest({
322
- autorun: autorun$,
323
- loop: loop$,
324
- valueAmount: valueAmount$,
325
- tickDurationPeriod: tickDurationPeriod$,
326
- // xyValueIndex: observer.xyValueIndex$,
327
- fullDataFormatter: observer.fullDataFormatter$,
328
- }).pipe(
329
- takeUntil(destroy$),
330
- switchMap(async d => d)
331
- ).subscribe(({ autorun, loop, valueAmount, tickDurationPeriod, fullDataFormatter }) => {
332
- if (toggle == false) {
333
- return
334
- }
335
- if (autorun) {
336
- const nextIndex = fullDataFormatter.xAxis.valueIndex + 1
337
- if (nextIndex < valueAmount) {
338
- toggle = false // timer 執行期間不可再次執行
339
-
340
- setTimeout(() => {
341
- subject.dataFormatter$.next({
342
- ...fullDataFormatter,
343
- xAxis: {
344
- ...fullDataFormatter.xAxis,
345
- valueIndex: nextIndex
346
- }
347
- })
348
-
349
- toggle = true
350
- }, tickDurationPeriod)
351
- } else if (nextIndex >= valueAmount && loop) {
352
- toggle = false // timer 執行期間不可再次執行
353
-
354
- setTimeout(() => {
355
- subject.dataFormatter$.next({
356
- ...fullDataFormatter,
357
- xAxis: {
358
- ...fullDataFormatter.xAxis,
359
- valueIndex: 0
360
- }
361
- })
362
-
363
- toggle = true
364
- }, tickDurationPeriod)
365
- }
366
- }
367
- })
368
-
369
- return () => {
370
- destroy$.next(undefined)
371
- unsubscribeBaseRacingLabels()
372
- unsubscribeBaseRacingValueLabels()
373
- unsubscribeBaseRacingBars()
374
- }
375
- })
1
+ import {
2
+ takeUntil,
3
+ combineLatest,
4
+ of,
5
+ iif,
6
+ interval,
7
+ map,
8
+ distinctUntilChanged,
9
+ shareReplay,
10
+ switchMap,
11
+ EMPTY,
12
+ Subject,
13
+ } from 'rxjs'
14
+ import type { Observable } from 'rxjs'
15
+ import type {
16
+ DefinePluginConfig,
17
+ } from '../../../lib/core-types'
18
+ import type { BaseRacingLabelsParams, BaseRacingBarsParams } from '../../../lib/plugins-basic-types'
19
+ import { defineMultiValuePlugin } from '../../../lib/core'
20
+ import { createBaseRacingLabels } from '../../base/BaseRacingLabels'
21
+ import { createBaseRacingValueLabels } from '../../base/BaseRacingValueLabels'
22
+ import { createBaseRacingBars } from '../../base/BaseRacingBars'
23
+ import { DEFAULT_RACING_BARS_PARAMS } from '../defaults'
24
+ import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
25
+ import {
26
+ // visibleComputedSumDataObservable,
27
+ // visibleComputedRankingByIndexDataObservable,
28
+ // rankingAmountLimitObservable,
29
+ computedRankingAmountObservable,
30
+ rankingItemHeightObservable,
31
+ rankingScaleListObservable,
32
+ // computedRankingWithXYDataObservable
33
+ } from '../multiValueObservables'
34
+
35
+ const pluginName = 'RacingBars'
36
+
37
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_RACING_BARS_PARAMS> = {
38
+ name: pluginName,
39
+ defaultParams: DEFAULT_RACING_BARS_PARAMS,
40
+ layerIndex: LAYER_INDEX_OF_GRAPHIC,
41
+ validator: (params, { validateColumns }) => {
42
+ const result = validateColumns(params, {
43
+ bar: {
44
+ toBeTypes: ['object']
45
+ },
46
+ barLabel: {
47
+ toBeTypes: ['object']
48
+ },
49
+ valueLabel: {
50
+ toBeTypes: ['object']
51
+ },
52
+ axisLabel: {
53
+ toBeTypes: ['object']
54
+ },
55
+ rankingAmount: {
56
+ toBe: 'number | "auto"',
57
+ test: (value: any) => {
58
+ return typeof value === 'number' || value === 'auto'
59
+ }
60
+ },
61
+ autorun: {
62
+ toBeTypes: ['boolean']
63
+ },
64
+ loop: {
65
+ toBeTypes: ['boolean']
66
+ },
67
+ })
68
+ if (params.bar) {
69
+ const barResult = validateColumns(params.bar, {
70
+ barWidth: {
71
+ toBeTypes: ['number']
72
+ },
73
+ barPadding: {
74
+ toBeTypes: ['number']
75
+ },
76
+ barRadius: {
77
+ toBeTypes: ['number', 'boolean']
78
+ },
79
+ })
80
+ if (barResult.status === 'error') {
81
+ return barResult
82
+ }
83
+ }
84
+ if (params.barLabel) {
85
+ const barLabelResult = validateColumns(params.barLabel, {
86
+ position: {
87
+ toBe: '"inside" | "outside" | "none"',
88
+ test: (value: any) => {
89
+ return value === 'inside' || value === 'outside' || value === 'none'
90
+ }
91
+ },
92
+ padding: {
93
+ toBeTypes: ['number']
94
+ },
95
+ // rotate: {
96
+ // toBeTypes: ['number']
97
+ // },
98
+ colorType: {
99
+ toBeOption: 'ColorType',
100
+ },
101
+ })
102
+ if (barLabelResult.status === 'error') {
103
+ return barLabelResult
104
+ }
105
+ }
106
+ if (params.valueLabel) {
107
+ const valueLabelResult = validateColumns(params.valueLabel, {
108
+ padding: {
109
+ toBeTypes: ['number']
110
+ },
111
+ colorType: {
112
+ toBeOption: 'ColorType',
113
+ },
114
+ format: {
115
+ toBeTypes: ['Function']
116
+ },
117
+ })
118
+ if (valueLabelResult.status === 'error') {
119
+ return valueLabelResult
120
+ }
121
+ }
122
+ if (params.axisLabel) {
123
+ const axisLabelResult = validateColumns(params.axisLabel, {
124
+ offset: {
125
+ toBe: '[number, number]',
126
+ test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
127
+ },
128
+ colorType: {
129
+ toBeOption: 'ColorType',
130
+ },
131
+ })
132
+ if (axisLabelResult.status === 'error') {
133
+ return axisLabelResult
134
+ }
135
+ }
136
+ return result
137
+ }
138
+ }
139
+
140
+ export const RacingBars = defineMultiValuePlugin(pluginConfig)(({ selection, name, observer, subject }) => {
141
+
142
+ const baseRacingBarsSelection = selection.append('g').attr('class', `${pluginName}-bars`)
143
+ const baseRacingLabelsSelection = selection.append('g').attr('class', `${pluginName}-labels`)
144
+ const baseRacingValueLabelsSelection = selection.append('g').attr('class', `${pluginName}-valueLabels`)
145
+
146
+ const destroy$ = new Subject()
147
+
148
+ // const baseRacingLabelsParams$: Observable<BaseRacingLabelsParams> = observer.fullParams$.pipe(
149
+ // takeUntil(destroy$),
150
+ // map(params => {
151
+ // return {
152
+ // ...params,
153
+ // axisLabel: {
154
+ // offset: [0, 0],
155
+ // colorType: 'primary'
156
+ // }
157
+ // }
158
+ // })
159
+ // )
160
+
161
+ // const baseRacingBarsParams$: Observable<BaseRacingBarsParams> = observer.fullParams$.pipe(
162
+ // takeUntil(destroy$),
163
+ // map(params => {
164
+ // return {
165
+ // ...params
166
+ // }
167
+ // })
168
+ // )
169
+
170
+ const baseRacingValueLabelsParams$ = observer.fullParams$.pipe(
171
+ takeUntil(destroy$),
172
+ map(params => {
173
+ return params.valueLabel
174
+ })
175
+ )
176
+
177
+ const rankingAmount$ = observer.fullParams$.pipe(
178
+ takeUntil(destroy$),
179
+ map(p => p.rankingAmount),
180
+ distinctUntilChanged(),
181
+ )
182
+
183
+ const computedRankingAmount$ = computedRankingAmountObservable({
184
+ containerSize$: observer.containerSize$,
185
+ visibleComputedData$: observer.visibleComputedData$,
186
+ textSizePx$: observer.textSizePx$,
187
+ rankingAmount$
188
+ }).pipe(
189
+ takeUntil(destroy$),
190
+ shareReplay(1)
191
+ )
192
+
193
+ const rankingItemHeight$ = rankingItemHeightObservable({
194
+ containerSize$: observer.containerSize$,
195
+ // visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
196
+ textSizePx$: observer.textSizePx$,
197
+ computedRankingAmount$
198
+ }).pipe(
199
+ takeUntil(destroy$),
200
+ shareReplay(1)
201
+ )
202
+
203
+ const rankingScaleList$ = rankingScaleListObservable({
204
+ visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
205
+ rankingItemHeight$
206
+ }).pipe(
207
+ takeUntil(destroy$),
208
+ shareReplay(1)
209
+ )
210
+
211
+ // const computedRankingWithXYData$ = computedRankingWithXYDataObservable({
212
+ // visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
213
+ // rankingScaleList$
214
+ // }).pipe(
215
+ // takeUntil(destroy$),
216
+ // )
217
+
218
+ // const xScale$ = combineLatest({
219
+ // xScale: observer.xScale$,
220
+ // layout: observer.layout$,
221
+ // containerSize: observer.containerSize$,
222
+ // }).pipe(
223
+ // takeUntil(destroy$),
224
+ // switchMap(async d => d),
225
+ // map(data => {
226
+ // // 原本的 xScale 是根據 layout 計算的,現在要根據 containerSize 重新計算
227
+ // const containerWidthScale = data.containerSize.width / data.layout.width
228
+
229
+ // return (n: number) => {
230
+ // const originWidth = data.xScale(n)
231
+ // if (originWidth == null) {
232
+ // return 0
233
+ // }
234
+ // return data.xScale(n) * containerWidthScale
235
+ // }
236
+ // }),
237
+ // shareReplay(1)
238
+ // )
239
+
240
+ const unsubscribeBaseRacingLabels = createBaseRacingLabels(`${pluginName}-labels`, {
241
+ selection: baseRacingLabelsSelection,
242
+ computedData$: observer.computedData$,
243
+ visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
244
+ rankingScaleList$,
245
+ xScale$: observer.xScale$,
246
+ fullParams$: observer.fullParams$,
247
+ fullDataFormatter$: observer.fullDataFormatter$,
248
+ fullChartParams$: observer.fullChartParams$,
249
+ transitionEase$: of('easeLinear'),
250
+ // layout$: observer.layout$,
251
+ containerPosition$: observer.containerPosition$,
252
+ containerSize$: observer.containerSize$,
253
+ isCategorySeprate$: observer.isCategorySeprate$,
254
+ // xyValueIndex$: observer.xyValueIndex$,
255
+ })
256
+
257
+ const unsubscribeBaseRacingValueLabels = createBaseRacingValueLabels(`${pluginName}-valueLabels`, {
258
+ selection: baseRacingValueLabelsSelection,
259
+ computedData$: observer.computedData$,
260
+ visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
261
+ rankingScaleList$,
262
+ xScale$: observer.xScale$,
263
+ computedRankingAmount$,
264
+ fullParams$: baseRacingValueLabelsParams$,
265
+ // fullDataFormatter$: observer.fullDataFormatter$,
266
+ fullChartParams$: observer.fullChartParams$,
267
+ // layout$: observer.layout$,
268
+ containerPosition$: observer.containerPosition$,
269
+ containerSize$: observer.containerSize$,
270
+ isCategorySeprate$: observer.isCategorySeprate$,
271
+ // xyValueIndex$: observer.xyValueIndex$,
272
+ })
273
+
274
+ const unsubscribeBaseRacingBars = createBaseRacingBars(`${pluginName}-bars`, {
275
+ selection: baseRacingBarsSelection,
276
+ computedData$: observer.computedData$,
277
+ visibleComputedRankingData$: observer.visibleComputedRankingByIndexData$,
278
+ // xyValueIndex$: observer.xyValueIndex$,
279
+ CategoryDataMap$: observer.CategoryDataMap$,
280
+ fullParams$: observer.fullParams$,
281
+ fullDataFormatter$: observer.fullDataFormatter$,
282
+ fullChartParams$: observer.fullChartParams$,
283
+ highlight$: observer.highlight$,
284
+ rankingItemHeight$,
285
+ rankingScaleList$,
286
+ xScale$: observer.xScale$,
287
+ containerPosition$: observer.containerPosition$,
288
+ containerSize$: observer.containerSize$,
289
+ // layout$: observer.layout$,
290
+ isCategorySeprate$: observer.isCategorySeprate$,
291
+ event$: subject.event$,
292
+ })
293
+
294
+ const valueAmount$ = observer.visibleComputedRankingByIndexData$.pipe(
295
+ takeUntil(destroy$),
296
+ map(d => (d[0] && d[0][0] && d[0][0].value.length) ?? 0),
297
+ distinctUntilChanged()
298
+ )
299
+
300
+ const autorun$ = observer.fullParams$.pipe(
301
+ takeUntil(destroy$),
302
+ map(p => p.autorun),
303
+ distinctUntilChanged()
304
+ )
305
+
306
+ const loop$ = observer.fullParams$.pipe(
307
+ takeUntil(destroy$),
308
+ map(p => p.loop),
309
+ distinctUntilChanged()
310
+ )
311
+
312
+ const tickDurationPeriod$ = observer.fullChartParams$.pipe(
313
+ takeUntil(destroy$),
314
+ map(p => p.transitionDuration),
315
+ distinctUntilChanged()
316
+ )
317
+
318
+ // -- autorun --
319
+ let toggle = true
320
+
321
+ combineLatest({
322
+ autorun: autorun$,
323
+ loop: loop$,
324
+ valueAmount: valueAmount$,
325
+ tickDurationPeriod: tickDurationPeriod$,
326
+ // xyValueIndex: observer.xyValueIndex$,
327
+ fullDataFormatter: observer.fullDataFormatter$,
328
+ }).pipe(
329
+ takeUntil(destroy$),
330
+ switchMap(async d => d)
331
+ ).subscribe(({ autorun, loop, valueAmount, tickDurationPeriod, fullDataFormatter }) => {
332
+ if (toggle == false) {
333
+ return
334
+ }
335
+ if (autorun) {
336
+ const nextIndex = fullDataFormatter.xAxis.valueIndex + 1
337
+ if (nextIndex < valueAmount) {
338
+ toggle = false // timer 執行期間不可再次執行
339
+
340
+ setTimeout(() => {
341
+ subject.dataFormatter$.next({
342
+ ...fullDataFormatter,
343
+ xAxis: {
344
+ ...fullDataFormatter.xAxis,
345
+ valueIndex: nextIndex
346
+ }
347
+ })
348
+
349
+ toggle = true
350
+ }, tickDurationPeriod)
351
+ } else if (nextIndex >= valueAmount && loop) {
352
+ toggle = false // timer 執行期間不可再次執行
353
+
354
+ setTimeout(() => {
355
+ subject.dataFormatter$.next({
356
+ ...fullDataFormatter,
357
+ xAxis: {
358
+ ...fullDataFormatter.xAxis,
359
+ valueIndex: 0
360
+ }
361
+ })
362
+
363
+ toggle = true
364
+ }, tickDurationPeriod)
365
+ }
366
+ }
367
+ })
368
+
369
+ return () => {
370
+ destroy$.next(undefined)
371
+ unsubscribeBaseRacingLabels()
372
+ unsubscribeBaseRacingValueLabels()
373
+ unsubscribeBaseRacingBars()
374
+ }
375
+ })