@orbcharts/plugins-basic 3.0.0-beta.2 → 3.0.0-beta.3

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 (80) hide show
  1. package/LICENSE +200 -200
  2. package/lib/core-types.ts +7 -7
  3. package/lib/core.ts +6 -6
  4. package/lib/plugins-basic-types.ts +6 -6
  5. package/package.json +44 -44
  6. package/src/base/BaseBarStack.ts +780 -780
  7. package/src/base/BaseBars.ts +765 -765
  8. package/src/base/BaseBarsTriangle.ts +674 -674
  9. package/src/base/BaseDots.ts +515 -515
  10. package/src/base/BaseGroupAxis.ts +679 -679
  11. package/src/base/BaseLegend.ts +680 -680
  12. package/src/base/BaseLineAreas.ts +629 -629
  13. package/src/base/BaseLines.ts +706 -706
  14. package/src/base/BaseTooltip.ts +385 -385
  15. package/src/base/BaseValueAxis.ts +580 -580
  16. package/src/base/types.ts +2 -2
  17. package/src/const.ts +30 -30
  18. package/src/grid/defaults.ts +244 -244
  19. package/src/grid/gridObservables.ts +545 -545
  20. package/src/grid/index.ts +16 -16
  21. package/src/grid/plugins/BarStack.ts +64 -64
  22. package/src/grid/plugins/Bars.ts +69 -69
  23. package/src/grid/plugins/BarsPN.ts +66 -66
  24. package/src/grid/plugins/BarsTriangle.ts +73 -73
  25. package/src/grid/plugins/Dots.ts +68 -68
  26. package/src/grid/plugins/GridLegend.ts +107 -107
  27. package/src/grid/plugins/GridTooltip.ts +66 -66
  28. package/src/grid/plugins/GridZoom.ts +218 -218
  29. package/src/grid/plugins/GroupAux.ts +1098 -1098
  30. package/src/grid/plugins/GroupAxis.ts +97 -97
  31. package/src/grid/plugins/LineAreas.ts +65 -65
  32. package/src/grid/plugins/Lines.ts +59 -59
  33. package/src/grid/plugins/ValueAxis.ts +93 -93
  34. package/src/grid/plugins/ValueStackAxis.ts +95 -95
  35. package/src/index.ts +9 -9
  36. package/src/multiGrid/defaults.ts +224 -224
  37. package/src/multiGrid/index.ts +14 -14
  38. package/src/multiGrid/multiGridObservables.ts +49 -49
  39. package/src/multiGrid/plugins/MultiBarStack.ts +106 -106
  40. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  41. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  42. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  43. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  44. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  45. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  46. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  47. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  48. package/src/multiGrid/plugins/MultiValueAxis.ts +133 -133
  49. package/src/multiGrid/plugins/MultiValueStackAxis.ts +133 -133
  50. package/src/multiGrid/plugins/OverlappingValueAxes.ts +299 -299
  51. package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +298 -298
  52. package/src/noneData/defaults.ts +102 -102
  53. package/src/noneData/index.ts +3 -3
  54. package/src/noneData/plugins/Container.ts +27 -27
  55. package/src/noneData/plugins/Tooltip.ts +373 -373
  56. package/src/series/defaults.ts +206 -206
  57. package/src/series/index.ts +9 -9
  58. package/src/series/plugins/Bubbles.ts +603 -603
  59. package/src/series/plugins/Pie.ts +623 -623
  60. package/src/series/plugins/PieEventTexts.ts +283 -283
  61. package/src/series/plugins/PieLabels.ts +640 -640
  62. package/src/series/plugins/Rose.ts +516 -516
  63. package/src/series/plugins/RoseLabels.ts +600 -600
  64. package/src/series/plugins/SeriesLegend.ts +107 -107
  65. package/src/series/plugins/SeriesTooltip.ts +66 -66
  66. package/src/series/seriesObservables.ts +145 -145
  67. package/src/series/seriesUtils.ts +51 -51
  68. package/src/tree/defaults.ts +78 -78
  69. package/src/tree/index.ts +4 -4
  70. package/src/tree/plugins/TreeLegend.ts +107 -107
  71. package/src/tree/plugins/TreeMap.ts +333 -333
  72. package/src/tree/plugins/TreeTooltip.ts +66 -66
  73. package/src/utils/commonUtils.ts +21 -21
  74. package/src/utils/d3Graphics.ts +174 -174
  75. package/src/utils/d3Utils.ts +73 -73
  76. package/src/utils/observables.ts +14 -14
  77. package/src/utils/orbchartsUtils.ts +100 -100
  78. package/tsconfig.base.json +13 -13
  79. package/tsconfig.json +2 -2
  80. package/vite.config.js +22 -22
@@ -1,675 +1,675 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- switchMap,
6
- takeUntil,
7
- distinctUntilChanged,
8
- shareReplay,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import type { BasePluginFn } from './types'
12
- import type {
13
- ComputedDatumGrid,
14
- ComputedDataGrid,
15
- ComputedLayoutDatumGrid,
16
- ComputedLayoutDataGrid,
17
- DataFormatterTypeMap,
18
- EventGrid,
19
- ChartParams,
20
- GridContainerPosition,
21
- Layout,
22
- TransformData
23
- } from '../../lib/core-types'
24
- import type { BaseBarsTriangleParams } from '../../lib/plugins-basic-types'
25
- import { getD3TransitionEase } from '../utils/d3Utils'
26
- import { getClassName, getUniID } from '../utils/orbchartsUtils'
27
- import { gridSelectionsObservable } from '../grid/gridObservables'
28
-
29
- // export interface BaseBarsTriangleParams {
30
- // barWidth: number
31
- // barPadding: number
32
- // barGroupPadding: number // 群組和群組間的間隔
33
- // linearGradientOpacity: [number, number]
34
- // }
35
-
36
- interface BaseBarsContext {
37
- selection: d3.Selection<any, unknown, any, unknown>
38
- computedData$: Observable<ComputedDataGrid>
39
- computedLayoutData$: Observable<ComputedLayoutDataGrid>
40
- visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
- visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
42
- fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
43
- seriesLabels$: Observable<string[]>
44
- SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
- GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
46
- fullParams$: Observable<BaseBarsTriangleParams>
47
- fullChartParams$: Observable<ChartParams>
48
- gridAxesTransform$: Observable<TransformData>
49
- gridGraphicTransform$: Observable<TransformData>
50
- gridAxesSize$: Observable<{
51
- width: number;
52
- height: number;
53
- }>
54
- gridHighlight$: Observable<ComputedDatumGrid[]>
55
- gridContainerPosition$: Observable<GridContainerPosition[]>
56
- isSeriesSeprate$: Observable<boolean>
57
- event$: Subject<EventGrid>
58
- }
59
-
60
-
61
- interface RenderBarParams {
62
- graphicGSelection: d3.Selection<SVGGElement, unknown, any, any>
63
- pathGClassName: string
64
- pathClassName: string
65
- visibleComputedLayoutData: ComputedLayoutDataGrid
66
- linearGradientIds: string[]
67
- zeroYArr: number[]
68
- groupLabels: string[]
69
- barScale: d3.ScalePoint<string>
70
- params: BaseBarsTriangleParams
71
- chartParams: ChartParams
72
- barWidth: number
73
- delayGroup: number
74
- transitionItem: number
75
- isSeriesSeprate: boolean
76
- }
77
-
78
- // interface BarDatumGrid extends ComputedDatumGrid {
79
- // linearGradientId: string
80
- // }
81
-
82
- type ClipPathDatum = {
83
- id: string;
84
- // x: number;
85
- // y: number;
86
- width: number;
87
- height: number;
88
- }
89
-
90
- // const pluginName = 'BaseBarsTriangle'
91
- // const pathGClassName = getClassName(pluginName, 'pathG')
92
- // const pathClassName = getClassName(pluginName, 'path')
93
- // group的delay在動畫中的佔比(剩餘部份的時間為圖形本身的動畫時間,因為delay時間和最後一個group的動畫時間加總為1)
94
- const groupDelayProportionOfDuration = 0.3
95
-
96
- function calcBarWidth ({ axisWidth, groupAmount, barAmountOfGroup, barPadding = 0, barGroupPadding = 0 }: {
97
- axisWidth: number
98
- groupAmount: number
99
- barAmountOfGroup: number
100
- barPadding: number
101
- barGroupPadding: number
102
- }) {
103
- const eachGroupWidth = axisWidth / (groupAmount - 1)
104
- const width = (eachGroupWidth - barGroupPadding) / barAmountOfGroup - barPadding
105
- return width > 1 ? width : 1
106
- }
107
-
108
- function makeBarScale (barWidth: number, seriesLabels: string[], params: BaseBarsTriangleParams) {
109
- const barHalfWidth = barWidth! / 2
110
- const barGroupWidth = barWidth * seriesLabels.length + params.barPadding! * seriesLabels.length
111
- return d3.scalePoint()
112
- .domain(seriesLabels)
113
- .range([-barGroupWidth / 2 + barHalfWidth, barGroupWidth / 2 - barHalfWidth])
114
- }
115
-
116
- function calcDelayGroup (barGroupAmount: number, totalDuration: number) {
117
- if (barGroupAmount <= 1) {
118
- // 一筆內計算會出錯所以不算
119
- return 0
120
- }
121
- return totalDuration / (barGroupAmount - 1) * groupDelayProportionOfDuration // 依group數量計算
122
- }
123
-
124
- function calctransitionItem (barGroupAmount: number, totalDuration: number) {
125
- if (barGroupAmount <= 1) {
126
- // 一筆內不會有delay
127
- return totalDuration
128
- }
129
- return totalDuration * (1 - groupDelayProportionOfDuration) // delay後剩餘的時間
130
- }
131
-
132
- function renderTriangleBars ({ graphicGSelection, pathGClassName, pathClassName, visibleComputedLayoutData, linearGradientIds, zeroYArr, groupLabels, barScale, params, chartParams, barWidth, delayGroup, transitionItem, isSeriesSeprate }: RenderBarParams) {
133
-
134
- const barHalfWidth = barWidth! / 2
135
-
136
- graphicGSelection
137
- .each((d, seriesIndex, g) => {
138
- // g
139
- const gSelection = d3.select(g[seriesIndex])
140
- .selectAll<SVGGElement, ComputedDatumGrid>(`g.${pathGClassName}`)
141
- .data(visibleComputedLayoutData[seriesIndex] ?? [])
142
- .join(
143
- enter => {
144
- const enterSelection = enter
145
- .append('g')
146
- .classed(pathGClassName, true)
147
- .attr('cursor', 'pointer')
148
- enterSelection
149
- .append('path')
150
- .classed(pathClassName, true)
151
- .style('vector-effect', 'non-scaling-stroke')
152
- .attr('d', (d) => {
153
- const x = -barHalfWidth
154
- const y1 = zeroYArr[seriesIndex]
155
- const y2 = zeroYArr[seriesIndex]
156
- return `M${x},${y1} L${x + (barWidth! / 2)},${y2} ${x + barWidth!},${y1}`
157
- })
158
- return enterSelection
159
- },
160
- update => update,
161
- exit => exit.remove()
162
- )
163
- .attr('transform', d => `translate(${isSeriesSeprate ? 0 : barScale(d.seriesLabel)!}, 0)`)
164
-
165
- // path
166
- gSelection.select(`path.${pathClassName}`)
167
- .attr('height', d => Math.abs(d.axisYFromZero))
168
- .attr('y', d => d.axisY < zeroYArr[seriesIndex] ? d.axisY : zeroYArr[seriesIndex])
169
- .attr('x', d => isSeriesSeprate ? 0 : barScale(d.seriesLabel)!)
170
- // .style('fill', d => `url(#${d.linearGradientId})`)
171
- .style('fill', d => `url(#${linearGradientIds[d.seriesIndex]})`)
172
- .attr('stroke', d => d.color)
173
- .attr('transform', d => `translate(${(d ? d.axisX : 0)}, ${0})`)
174
- .transition()
175
- .duration(transitionItem)
176
- .ease(getD3TransitionEase(chartParams.transitionEase))
177
- .delay((d, i) => d.groupIndex * delayGroup)
178
- // .attr('transform', `translate(${-barHalfWidth}, 0)`)
179
- // .attr('x', d => itemScale(d.itemLabel)!)
180
- // .attr('y', d => -d.y)
181
- .attr('d', (d) => {
182
- const x = -barHalfWidth
183
- const y1 = zeroYArr[seriesIndex]
184
- const y2 = d.axisY
185
- return `M${x},${y1} L${x + (barWidth! / 2)},${y2} ${x + barWidth!},${y1}`
186
- })
187
- })
188
-
189
- const graphicBarSelection: d3.Selection<SVGPathElement, ComputedDatumGrid, any, any> = graphicGSelection.selectAll(`path.${pathClassName}`)
190
-
191
- return graphicBarSelection
192
- }
193
-
194
- function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
195
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
196
- computedData: ComputedDataGrid
197
- linearGradientIds: string[]
198
- params: BaseBarsTriangleParams
199
- }) {
200
- defsSelection!
201
- .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
202
- .data(computedData ?? [])
203
- .join(
204
- enter => {
205
- return enter
206
- .append('linearGradient')
207
- .attr('x1', '0%')
208
- .attr('x2', '0%')
209
- .attr('y1', '100%')
210
- .attr('y2', '0%')
211
- .attr('spreadMethod', 'pad')
212
- },
213
- update => update,
214
- exit => exit.remove()
215
- )
216
- .attr('id', (d, i) => {
217
- return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
218
- })
219
- .html((d, i) => {
220
- const color = d[0] ? d[0].color : ''
221
- return `
222
- <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
223
- <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
224
- `
225
- })
226
-
227
- }
228
-
229
-
230
- function renderClipPath ({ defsSelection, clipPathData }: {
231
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
232
- clipPathData: ClipPathDatum[]
233
- }) {
234
- const clipPath = defsSelection
235
- .selectAll<SVGClipPathElement, Layout>('clipPath')
236
- .data(clipPathData)
237
- .join(
238
- enter => {
239
- return enter
240
- .append('clipPath')
241
- },
242
- update => update,
243
- exit => exit.remove()
244
- )
245
- .attr('id', d => d.id)
246
- .each((d, i, g) => {
247
- const rect = d3.select(g[i])
248
- .selectAll<SVGRectElement, typeof d>('rect')
249
- .data([d])
250
- .join(
251
- enter => {
252
- return enter
253
- .append('rect')
254
- },
255
- update => update,
256
- exit => exit.remove()
257
- )
258
- .attr('x', 0)
259
- .attr('y', 0)
260
- .attr('width', _d => _d.width)
261
- .attr('height', _d => _d.height)
262
- })
263
- }
264
-
265
- function highlight ({ selection, ids, fullChartParams }: {
266
- selection: d3.Selection<SVGPathElement, ComputedDatumGrid, any, any>
267
- ids: string[]
268
- fullChartParams: ChartParams
269
- }) {
270
- selection.interrupt('highlight')
271
-
272
- const removeHighlight = () => {
273
- selection
274
- .transition('highlight')
275
- .duration(200)
276
- .style('opacity', 1)
277
- }
278
-
279
- if (!ids.length) {
280
- removeHighlight()
281
- return
282
- }
283
-
284
- selection
285
- .each((d, i, n) => {
286
- if (ids.includes(d.id)) {
287
- d3.select(n[i])
288
- .style('opacity', 1)
289
- } else {
290
- d3.select(n[i])
291
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
292
- }
293
- })
294
- }
295
-
296
-
297
- export const createBaseBarsTriangle: BasePluginFn<BaseBarsContext> = (pluginName: string, {
298
- selection,
299
- computedData$,
300
- computedLayoutData$,
301
- visibleComputedData$,
302
- visibleComputedLayoutData$,
303
- fullDataFormatter$,
304
- seriesLabels$,
305
- SeriesDataMap$,
306
- GroupDataMap$,
307
- fullParams$,
308
- fullChartParams$,
309
- gridAxesTransform$,
310
- gridGraphicTransform$,
311
- gridAxesSize$,
312
- gridHighlight$,
313
- gridContainerPosition$,
314
- isSeriesSeprate$,
315
- event$
316
- }) => {
317
- const destroy$ = new Subject()
318
-
319
- const clipPathID = getUniID(pluginName, 'clipPath-box')
320
- const pathGClassName = getClassName(pluginName, 'pathG')
321
- const pathClassName = getClassName(pluginName, 'path')
322
-
323
- const {
324
- seriesSelection$,
325
- axesSelection$,
326
- defsSelection$,
327
- graphicGSelection$
328
- } = gridSelectionsObservable({
329
- selection,
330
- pluginName,
331
- clipPathID,
332
- seriesLabels$,
333
- gridContainerPosition$,
334
- gridAxesTransform$,
335
- gridGraphicTransform$
336
- })
337
-
338
- // valueAxis 的起始座標
339
- const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
340
- takeUntil(destroy$),
341
- map(data => {
342
- // 抵消掉外層的變型
343
- return - data.translate[1] / data.scale[1]
344
- })
345
- )
346
-
347
- const zeroYArr$ = visibleComputedLayoutData$.pipe(
348
- // map(d => d[0] && d[0][0]
349
- // ? d[0][0].axisY - d[0][0].axisYFromZero
350
- // : 0),
351
- map(data => {
352
- return data.map(d => {
353
- return d[0] ? d[0].axisY - d[0].axisYFromZero : 0
354
- })
355
- }),
356
- distinctUntilChanged()
357
- )
358
-
359
- const barWidth$ = combineLatest({
360
- computedData: computedData$,
361
- visibleComputedData: visibleComputedData$,
362
- params: fullParams$,
363
- gridAxesSize: gridAxesSize$,
364
- isSeriesSeprate: isSeriesSeprate$
365
- }).pipe(
366
- takeUntil(destroy$),
367
- switchMap(async d => d),
368
- map(data => {
369
- if (data.params.barWidth) {
370
- return data.params.barWidth
371
- } else if (data.isSeriesSeprate) {
372
- return calcBarWidth({
373
- axisWidth: data.gridAxesSize.width,
374
- groupAmount: data.computedData[0] ? data.computedData[0].length : 0,
375
- barAmountOfGroup: 1,
376
- barPadding: data.params.barPadding,
377
- barGroupPadding: data.params.barGroupPadding
378
- })
379
- } else {
380
- return calcBarWidth({
381
- axisWidth: data.gridAxesSize.width,
382
- groupAmount: data.computedData[0] ? data.computedData[0].length : 0,
383
- barAmountOfGroup: data.visibleComputedData.length,
384
- barPadding: data.params.barPadding,
385
- barGroupPadding: data.params.barGroupPadding
386
- })
387
- }
388
- })
389
- )
390
-
391
- // const seriesLabels$ = visibleComputedData$.pipe(
392
- // takeUntil(destroy$),
393
- // map(data => {
394
- // const SeriesLabelSet: Set<string> = new Set()
395
- // data.forEach(d => {
396
- // d.forEach(_d => {
397
- // SeriesLabelSet.add(_d.seriesLabel)
398
- // })
399
- // })
400
- // return Array.from(SeriesLabelSet)
401
- // })
402
- // )
403
-
404
- const groupLabels$ = visibleComputedData$.pipe(
405
- takeUntil(destroy$),
406
- map(data => {
407
- const GroupLabelSet: Set<string> = new Set()
408
- data.forEach(d => {
409
- d.forEach(_d => {
410
- GroupLabelSet.add(_d.groupLabel)
411
- })
412
- })
413
- return Array.from(GroupLabelSet)
414
- })
415
- )
416
-
417
- const barScale$: Observable<d3.ScalePoint<string>> = new Observable(subscriber => {
418
- combineLatest({
419
- seriesLabels: seriesLabels$,
420
- barWidth: barWidth$,
421
- params: fullParams$,
422
- }).pipe(
423
- takeUntil(destroy$),
424
- switchMap(async d => d)
425
- ).subscribe(data => {
426
- const barScale = makeBarScale(data.barWidth, data.seriesLabels, data.params)
427
- subscriber.next(barScale)
428
- })
429
- })
430
-
431
- const transitionDuration$ = fullChartParams$.pipe(
432
- takeUntil(destroy$),
433
- map(d => d.transitionDuration),
434
- distinctUntilChanged()
435
- )
436
-
437
- const delayGroup$ = new Observable<number>(subscriber => {
438
- combineLatest({
439
- groupLabels: groupLabels$,
440
- transitionDuration: transitionDuration$,
441
- }).pipe(
442
- switchMap(async d => d)
443
- ).subscribe(data => {
444
- const delay = calcDelayGroup(data.groupLabels.length, data.transitionDuration)
445
- subscriber.next(delay)
446
- })
447
- }).pipe(
448
- takeUntil(destroy$),
449
- distinctUntilChanged()
450
- )
451
-
452
- const transitionItem$ = new Observable<number>(subscriber => {
453
- combineLatest({
454
- groupLabels: groupLabels$,
455
- transitionDuration: transitionDuration$
456
- }).pipe(
457
- switchMap(async d => d)
458
- ).subscribe(data => {
459
- const transition = calctransitionItem(data.groupLabels.length, data.transitionDuration)
460
- subscriber.next(transition)
461
- })
462
- }).pipe(
463
- takeUntil(destroy$),
464
- distinctUntilChanged()
465
- )
466
-
467
- //
468
-
469
- combineLatest({
470
- defsSelection: defsSelection$,
471
- gridAxesSize: gridAxesSize$,
472
- }).pipe(
473
- takeUntil(destroy$),
474
- switchMap(async d => d)
475
- ).subscribe(data => {
476
- const clipPathData = [{
477
- id: clipPathID,
478
- width: data.gridAxesSize.width,
479
- height: data.gridAxesSize.height
480
- }]
481
- renderClipPath({
482
- defsSelection: data.defsSelection,
483
- clipPathData
484
- })
485
- })
486
-
487
-
488
- const highlightTarget$ = fullChartParams$.pipe(
489
- takeUntil(destroy$),
490
- map(d => d.highlightTarget),
491
- distinctUntilChanged()
492
- )
493
-
494
- const linearGradientIds$ = seriesLabels$.pipe(
495
- takeUntil(destroy$),
496
- map(d => d.map((d, i) => {
497
- return getUniID(pluginName, `lineargradient-${d}`)
498
- }))
499
- )
500
-
501
- // const barData$ = combineLatest({
502
- // linearGradientIds: linearGradientIds$,
503
- // computedData: computedData$
504
- // }).pipe(
505
- // takeUntil(destroy$),
506
- // switchMap(async d => d),
507
- // map(data => {
508
- // return data.computedData.map((series, seriesIndex) => {
509
- // return series.map((_d, _i) => {
510
- // return <BarDatumGrid>{
511
- // linearGradientId: data.linearGradientIds[seriesIndex],
512
- // ..._d
513
- // }
514
- // })
515
- // })
516
- // })
517
- // )
518
-
519
- const barSelection$ = combineLatest({
520
- graphicGSelection: graphicGSelection$,
521
- defsSelection: defsSelection$,
522
- computedData: computedData$,
523
- visibleComputedLayoutData: visibleComputedLayoutData$,
524
- linearGradientIds: linearGradientIds$,
525
- zeroYArr: zeroYArr$,
526
- groupLabels: groupLabels$,
527
- barScale: barScale$,
528
- params: fullParams$,
529
- chartParams: fullChartParams$,
530
- barWidth: barWidth$,
531
- delayGroup: delayGroup$,
532
- transitionItem: transitionItem$,
533
- isSeriesSeprate: isSeriesSeprate$
534
- }).pipe(
535
- takeUntil(destroy$),
536
- switchMap(async (d) => d),
537
- map(data => {
538
- renderLinearGradient({
539
- defsSelection: data.defsSelection,
540
- computedData: data.computedData,
541
- linearGradientIds: data.linearGradientIds,
542
- params: data.params
543
- })
544
-
545
- return renderTriangleBars({
546
- graphicGSelection: data.graphicGSelection,
547
- pathGClassName,
548
- pathClassName,
549
- visibleComputedLayoutData: data.visibleComputedLayoutData,
550
- linearGradientIds: data.linearGradientIds,
551
- zeroYArr: data.zeroYArr,
552
- groupLabels: data.groupLabels,
553
- barScale: data.barScale,
554
- params: data.params,
555
- chartParams: data.chartParams,
556
- barWidth: data.barWidth,
557
- delayGroup: data.delayGroup,
558
- transitionItem: data.transitionItem,
559
- isSeriesSeprate: data.isSeriesSeprate
560
- })
561
- })
562
- )
563
-
564
- combineLatest({
565
- barSelection: barSelection$,
566
- computedData: computedData$,
567
- highlightTarget: highlightTarget$,
568
- SeriesDataMap: SeriesDataMap$,
569
- GroupDataMap: GroupDataMap$,
570
- }).subscribe(data => {
571
-
572
- data.barSelection!
573
- .on('mouseover', (event, datum) => {
574
- event.stopPropagation()
575
-
576
- event$.next({
577
- type: 'grid',
578
- eventName: 'mouseover',
579
- pluginName,
580
- highlightTarget: data.highlightTarget,
581
- datum,
582
- gridIndex: datum.gridIndex,
583
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
584
- seriesIndex: datum.seriesIndex,
585
- seriesLabel: datum.seriesLabel,
586
- groups: data.GroupDataMap.get(datum.groupLabel)!,
587
- groupIndex: datum.groupIndex,
588
- groupLabel: datum.groupLabel,
589
- event,
590
- data: data.computedData
591
- })
592
- })
593
- .on('mousemove', (event, datum) => {
594
- event.stopPropagation()
595
-
596
- event$.next({
597
- type: 'grid',
598
- eventName: 'mousemove',
599
- pluginName,
600
- highlightTarget: data.highlightTarget,
601
- datum,
602
- gridIndex: datum.gridIndex,
603
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
604
- seriesIndex: datum.seriesIndex,
605
- seriesLabel: datum.seriesLabel,
606
- groups: data.GroupDataMap.get(datum.groupLabel)!,
607
- groupIndex: datum.groupIndex,
608
- groupLabel: datum.groupLabel,
609
- event,
610
- data: data.computedData
611
- })
612
- })
613
- .on('mouseout', (event, datum) => {
614
- event.stopPropagation()
615
-
616
- event$.next({
617
- type: 'grid',
618
- eventName: 'mouseout',
619
- pluginName,
620
- highlightTarget: data.highlightTarget,
621
- datum,
622
- gridIndex: datum.gridIndex,
623
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
624
- seriesIndex: datum.seriesIndex,
625
- seriesLabel: datum.seriesLabel,
626
- groups: data.GroupDataMap.get(datum.groupLabel)!,
627
- groupIndex: datum.groupIndex,
628
- groupLabel: datum.groupLabel,
629
- event,
630
- data: data.computedData
631
- })
632
- })
633
- .on('click', (event, datum) => {
634
- event.stopPropagation()
635
-
636
- event$.next({
637
- type: 'grid',
638
- eventName: 'click',
639
- pluginName,
640
- highlightTarget: data.highlightTarget,
641
- datum,
642
- gridIndex: datum.gridIndex,
643
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
644
- seriesIndex: datum.seriesIndex,
645
- seriesLabel: datum.seriesLabel,
646
- groups: data.GroupDataMap.get(datum.groupLabel)!,
647
- groupIndex: datum.groupIndex,
648
- groupLabel: datum.groupLabel,
649
- event,
650
- data: data.computedData
651
- })
652
- })
653
- })
654
-
655
- combineLatest({
656
- barSelection: barSelection$,
657
- highlight: gridHighlight$.pipe(
658
- map(data => data.map(d => d.id))
659
- ),
660
- fullChartParams: fullChartParams$
661
- }).pipe(
662
- takeUntil(destroy$),
663
- switchMap(async d => d)
664
- ).subscribe(data => {
665
- highlight({
666
- selection: data.barSelection,
667
- ids: data.highlight,
668
- fullChartParams: data.fullChartParams
669
- })
670
- })
671
-
672
- return () => {
673
- destroy$.next(undefined)
674
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ switchMap,
6
+ takeUntil,
7
+ distinctUntilChanged,
8
+ shareReplay,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import type { BasePluginFn } from './types'
12
+ import type {
13
+ ComputedDatumGrid,
14
+ ComputedDataGrid,
15
+ ComputedLayoutDatumGrid,
16
+ ComputedLayoutDataGrid,
17
+ DataFormatterTypeMap,
18
+ EventGrid,
19
+ ChartParams,
20
+ GridContainerPosition,
21
+ Layout,
22
+ TransformData
23
+ } from '../../lib/core-types'
24
+ import type { BaseBarsTriangleParams } from '../../lib/plugins-basic-types'
25
+ import { getD3TransitionEase } from '../utils/d3Utils'
26
+ import { getClassName, getUniID } from '../utils/orbchartsUtils'
27
+ import { gridSelectionsObservable } from '../grid/gridObservables'
28
+
29
+ // export interface BaseBarsTriangleParams {
30
+ // barWidth: number
31
+ // barPadding: number
32
+ // barGroupPadding: number // 群組和群組間的間隔
33
+ // linearGradientOpacity: [number, number]
34
+ // }
35
+
36
+ interface BaseBarsContext {
37
+ selection: d3.Selection<any, unknown, any, unknown>
38
+ computedData$: Observable<ComputedDataGrid>
39
+ computedLayoutData$: Observable<ComputedLayoutDataGrid>
40
+ visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
+ visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
42
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
43
+ seriesLabels$: Observable<string[]>
44
+ SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
+ GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
46
+ fullParams$: Observable<BaseBarsTriangleParams>
47
+ fullChartParams$: Observable<ChartParams>
48
+ gridAxesTransform$: Observable<TransformData>
49
+ gridGraphicTransform$: Observable<TransformData>
50
+ gridAxesSize$: Observable<{
51
+ width: number;
52
+ height: number;
53
+ }>
54
+ gridHighlight$: Observable<ComputedDatumGrid[]>
55
+ gridContainerPosition$: Observable<GridContainerPosition[]>
56
+ isSeriesSeprate$: Observable<boolean>
57
+ event$: Subject<EventGrid>
58
+ }
59
+
60
+
61
+ interface RenderBarParams {
62
+ graphicGSelection: d3.Selection<SVGGElement, unknown, any, any>
63
+ pathGClassName: string
64
+ pathClassName: string
65
+ visibleComputedLayoutData: ComputedLayoutDataGrid
66
+ linearGradientIds: string[]
67
+ zeroYArr: number[]
68
+ groupLabels: string[]
69
+ barScale: d3.ScalePoint<string>
70
+ params: BaseBarsTriangleParams
71
+ chartParams: ChartParams
72
+ barWidth: number
73
+ delayGroup: number
74
+ transitionItem: number
75
+ isSeriesSeprate: boolean
76
+ }
77
+
78
+ // interface BarDatumGrid extends ComputedDatumGrid {
79
+ // linearGradientId: string
80
+ // }
81
+
82
+ type ClipPathDatum = {
83
+ id: string;
84
+ // x: number;
85
+ // y: number;
86
+ width: number;
87
+ height: number;
88
+ }
89
+
90
+ // const pluginName = 'BaseBarsTriangle'
91
+ // const pathGClassName = getClassName(pluginName, 'pathG')
92
+ // const pathClassName = getClassName(pluginName, 'path')
93
+ // group的delay在動畫中的佔比(剩餘部份的時間為圖形本身的動畫時間,因為delay時間和最後一個group的動畫時間加總為1)
94
+ const groupDelayProportionOfDuration = 0.3
95
+
96
+ function calcBarWidth ({ axisWidth, groupAmount, barAmountOfGroup, barPadding = 0, barGroupPadding = 0 }: {
97
+ axisWidth: number
98
+ groupAmount: number
99
+ barAmountOfGroup: number
100
+ barPadding: number
101
+ barGroupPadding: number
102
+ }) {
103
+ const eachGroupWidth = axisWidth / (groupAmount - 1)
104
+ const width = (eachGroupWidth - barGroupPadding) / barAmountOfGroup - barPadding
105
+ return width > 1 ? width : 1
106
+ }
107
+
108
+ function makeBarScale (barWidth: number, seriesLabels: string[], params: BaseBarsTriangleParams) {
109
+ const barHalfWidth = barWidth! / 2
110
+ const barGroupWidth = barWidth * seriesLabels.length + params.barPadding! * seriesLabels.length
111
+ return d3.scalePoint()
112
+ .domain(seriesLabels)
113
+ .range([-barGroupWidth / 2 + barHalfWidth, barGroupWidth / 2 - barHalfWidth])
114
+ }
115
+
116
+ function calcDelayGroup (barGroupAmount: number, totalDuration: number) {
117
+ if (barGroupAmount <= 1) {
118
+ // 一筆內計算會出錯所以不算
119
+ return 0
120
+ }
121
+ return totalDuration / (barGroupAmount - 1) * groupDelayProportionOfDuration // 依group數量計算
122
+ }
123
+
124
+ function calctransitionItem (barGroupAmount: number, totalDuration: number) {
125
+ if (barGroupAmount <= 1) {
126
+ // 一筆內不會有delay
127
+ return totalDuration
128
+ }
129
+ return totalDuration * (1 - groupDelayProportionOfDuration) // delay後剩餘的時間
130
+ }
131
+
132
+ function renderTriangleBars ({ graphicGSelection, pathGClassName, pathClassName, visibleComputedLayoutData, linearGradientIds, zeroYArr, groupLabels, barScale, params, chartParams, barWidth, delayGroup, transitionItem, isSeriesSeprate }: RenderBarParams) {
133
+
134
+ const barHalfWidth = barWidth! / 2
135
+
136
+ graphicGSelection
137
+ .each((d, seriesIndex, g) => {
138
+ // g
139
+ const gSelection = d3.select(g[seriesIndex])
140
+ .selectAll<SVGGElement, ComputedDatumGrid>(`g.${pathGClassName}`)
141
+ .data(visibleComputedLayoutData[seriesIndex] ?? [])
142
+ .join(
143
+ enter => {
144
+ const enterSelection = enter
145
+ .append('g')
146
+ .classed(pathGClassName, true)
147
+ .attr('cursor', 'pointer')
148
+ enterSelection
149
+ .append('path')
150
+ .classed(pathClassName, true)
151
+ .style('vector-effect', 'non-scaling-stroke')
152
+ .attr('d', (d) => {
153
+ const x = -barHalfWidth
154
+ const y1 = zeroYArr[seriesIndex]
155
+ const y2 = zeroYArr[seriesIndex]
156
+ return `M${x},${y1} L${x + (barWidth! / 2)},${y2} ${x + barWidth!},${y1}`
157
+ })
158
+ return enterSelection
159
+ },
160
+ update => update,
161
+ exit => exit.remove()
162
+ )
163
+ .attr('transform', d => `translate(${isSeriesSeprate ? 0 : barScale(d.seriesLabel)!}, 0)`)
164
+
165
+ // path
166
+ gSelection.select(`path.${pathClassName}`)
167
+ .attr('height', d => Math.abs(d.axisYFromZero))
168
+ .attr('y', d => d.axisY < zeroYArr[seriesIndex] ? d.axisY : zeroYArr[seriesIndex])
169
+ .attr('x', d => isSeriesSeprate ? 0 : barScale(d.seriesLabel)!)
170
+ // .style('fill', d => `url(#${d.linearGradientId})`)
171
+ .style('fill', d => `url(#${linearGradientIds[d.seriesIndex]})`)
172
+ .attr('stroke', d => d.color)
173
+ .attr('transform', d => `translate(${(d ? d.axisX : 0)}, ${0})`)
174
+ .transition()
175
+ .duration(transitionItem)
176
+ .ease(getD3TransitionEase(chartParams.transitionEase))
177
+ .delay((d, i) => d.groupIndex * delayGroup)
178
+ // .attr('transform', `translate(${-barHalfWidth}, 0)`)
179
+ // .attr('x', d => itemScale(d.itemLabel)!)
180
+ // .attr('y', d => -d.y)
181
+ .attr('d', (d) => {
182
+ const x = -barHalfWidth
183
+ const y1 = zeroYArr[seriesIndex]
184
+ const y2 = d.axisY
185
+ return `M${x},${y1} L${x + (barWidth! / 2)},${y2} ${x + barWidth!},${y1}`
186
+ })
187
+ })
188
+
189
+ const graphicBarSelection: d3.Selection<SVGPathElement, ComputedDatumGrid, any, any> = graphicGSelection.selectAll(`path.${pathClassName}`)
190
+
191
+ return graphicBarSelection
192
+ }
193
+
194
+ function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
195
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
196
+ computedData: ComputedDataGrid
197
+ linearGradientIds: string[]
198
+ params: BaseBarsTriangleParams
199
+ }) {
200
+ defsSelection!
201
+ .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
202
+ .data(computedData ?? [])
203
+ .join(
204
+ enter => {
205
+ return enter
206
+ .append('linearGradient')
207
+ .attr('x1', '0%')
208
+ .attr('x2', '0%')
209
+ .attr('y1', '100%')
210
+ .attr('y2', '0%')
211
+ .attr('spreadMethod', 'pad')
212
+ },
213
+ update => update,
214
+ exit => exit.remove()
215
+ )
216
+ .attr('id', (d, i) => {
217
+ return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
218
+ })
219
+ .html((d, i) => {
220
+ const color = d[0] ? d[0].color : ''
221
+ return `
222
+ <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
223
+ <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
224
+ `
225
+ })
226
+
227
+ }
228
+
229
+
230
+ function renderClipPath ({ defsSelection, clipPathData }: {
231
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
232
+ clipPathData: ClipPathDatum[]
233
+ }) {
234
+ const clipPath = defsSelection
235
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
236
+ .data(clipPathData)
237
+ .join(
238
+ enter => {
239
+ return enter
240
+ .append('clipPath')
241
+ },
242
+ update => update,
243
+ exit => exit.remove()
244
+ )
245
+ .attr('id', d => d.id)
246
+ .each((d, i, g) => {
247
+ const rect = d3.select(g[i])
248
+ .selectAll<SVGRectElement, typeof d>('rect')
249
+ .data([d])
250
+ .join(
251
+ enter => {
252
+ return enter
253
+ .append('rect')
254
+ },
255
+ update => update,
256
+ exit => exit.remove()
257
+ )
258
+ .attr('x', 0)
259
+ .attr('y', 0)
260
+ .attr('width', _d => _d.width)
261
+ .attr('height', _d => _d.height)
262
+ })
263
+ }
264
+
265
+ function highlight ({ selection, ids, fullChartParams }: {
266
+ selection: d3.Selection<SVGPathElement, ComputedDatumGrid, any, any>
267
+ ids: string[]
268
+ fullChartParams: ChartParams
269
+ }) {
270
+ selection.interrupt('highlight')
271
+
272
+ const removeHighlight = () => {
273
+ selection
274
+ .transition('highlight')
275
+ .duration(200)
276
+ .style('opacity', 1)
277
+ }
278
+
279
+ if (!ids.length) {
280
+ removeHighlight()
281
+ return
282
+ }
283
+
284
+ selection
285
+ .each((d, i, n) => {
286
+ if (ids.includes(d.id)) {
287
+ d3.select(n[i])
288
+ .style('opacity', 1)
289
+ } else {
290
+ d3.select(n[i])
291
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
292
+ }
293
+ })
294
+ }
295
+
296
+
297
+ export const createBaseBarsTriangle: BasePluginFn<BaseBarsContext> = (pluginName: string, {
298
+ selection,
299
+ computedData$,
300
+ computedLayoutData$,
301
+ visibleComputedData$,
302
+ visibleComputedLayoutData$,
303
+ fullDataFormatter$,
304
+ seriesLabels$,
305
+ SeriesDataMap$,
306
+ GroupDataMap$,
307
+ fullParams$,
308
+ fullChartParams$,
309
+ gridAxesTransform$,
310
+ gridGraphicTransform$,
311
+ gridAxesSize$,
312
+ gridHighlight$,
313
+ gridContainerPosition$,
314
+ isSeriesSeprate$,
315
+ event$
316
+ }) => {
317
+ const destroy$ = new Subject()
318
+
319
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
320
+ const pathGClassName = getClassName(pluginName, 'pathG')
321
+ const pathClassName = getClassName(pluginName, 'path')
322
+
323
+ const {
324
+ seriesSelection$,
325
+ axesSelection$,
326
+ defsSelection$,
327
+ graphicGSelection$
328
+ } = gridSelectionsObservable({
329
+ selection,
330
+ pluginName,
331
+ clipPathID,
332
+ seriesLabels$,
333
+ gridContainerPosition$,
334
+ gridAxesTransform$,
335
+ gridGraphicTransform$
336
+ })
337
+
338
+ // valueAxis 的起始座標
339
+ const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
340
+ takeUntil(destroy$),
341
+ map(data => {
342
+ // 抵消掉外層的變型
343
+ return - data.translate[1] / data.scale[1]
344
+ })
345
+ )
346
+
347
+ const zeroYArr$ = visibleComputedLayoutData$.pipe(
348
+ // map(d => d[0] && d[0][0]
349
+ // ? d[0][0].axisY - d[0][0].axisYFromZero
350
+ // : 0),
351
+ map(data => {
352
+ return data.map(d => {
353
+ return d[0] ? d[0].axisY - d[0].axisYFromZero : 0
354
+ })
355
+ }),
356
+ distinctUntilChanged()
357
+ )
358
+
359
+ const barWidth$ = combineLatest({
360
+ computedData: computedData$,
361
+ visibleComputedData: visibleComputedData$,
362
+ params: fullParams$,
363
+ gridAxesSize: gridAxesSize$,
364
+ isSeriesSeprate: isSeriesSeprate$
365
+ }).pipe(
366
+ takeUntil(destroy$),
367
+ switchMap(async d => d),
368
+ map(data => {
369
+ if (data.params.barWidth) {
370
+ return data.params.barWidth
371
+ } else if (data.isSeriesSeprate) {
372
+ return calcBarWidth({
373
+ axisWidth: data.gridAxesSize.width,
374
+ groupAmount: data.computedData[0] ? data.computedData[0].length : 0,
375
+ barAmountOfGroup: 1,
376
+ barPadding: data.params.barPadding,
377
+ barGroupPadding: data.params.barGroupPadding
378
+ })
379
+ } else {
380
+ return calcBarWidth({
381
+ axisWidth: data.gridAxesSize.width,
382
+ groupAmount: data.computedData[0] ? data.computedData[0].length : 0,
383
+ barAmountOfGroup: data.visibleComputedData.length,
384
+ barPadding: data.params.barPadding,
385
+ barGroupPadding: data.params.barGroupPadding
386
+ })
387
+ }
388
+ })
389
+ )
390
+
391
+ // const seriesLabels$ = visibleComputedData$.pipe(
392
+ // takeUntil(destroy$),
393
+ // map(data => {
394
+ // const SeriesLabelSet: Set<string> = new Set()
395
+ // data.forEach(d => {
396
+ // d.forEach(_d => {
397
+ // SeriesLabelSet.add(_d.seriesLabel)
398
+ // })
399
+ // })
400
+ // return Array.from(SeriesLabelSet)
401
+ // })
402
+ // )
403
+
404
+ const groupLabels$ = visibleComputedData$.pipe(
405
+ takeUntil(destroy$),
406
+ map(data => {
407
+ const GroupLabelSet: Set<string> = new Set()
408
+ data.forEach(d => {
409
+ d.forEach(_d => {
410
+ GroupLabelSet.add(_d.groupLabel)
411
+ })
412
+ })
413
+ return Array.from(GroupLabelSet)
414
+ })
415
+ )
416
+
417
+ const barScale$: Observable<d3.ScalePoint<string>> = new Observable(subscriber => {
418
+ combineLatest({
419
+ seriesLabels: seriesLabels$,
420
+ barWidth: barWidth$,
421
+ params: fullParams$,
422
+ }).pipe(
423
+ takeUntil(destroy$),
424
+ switchMap(async d => d)
425
+ ).subscribe(data => {
426
+ const barScale = makeBarScale(data.barWidth, data.seriesLabels, data.params)
427
+ subscriber.next(barScale)
428
+ })
429
+ })
430
+
431
+ const transitionDuration$ = fullChartParams$.pipe(
432
+ takeUntil(destroy$),
433
+ map(d => d.transitionDuration),
434
+ distinctUntilChanged()
435
+ )
436
+
437
+ const delayGroup$ = new Observable<number>(subscriber => {
438
+ combineLatest({
439
+ groupLabels: groupLabels$,
440
+ transitionDuration: transitionDuration$,
441
+ }).pipe(
442
+ switchMap(async d => d)
443
+ ).subscribe(data => {
444
+ const delay = calcDelayGroup(data.groupLabels.length, data.transitionDuration)
445
+ subscriber.next(delay)
446
+ })
447
+ }).pipe(
448
+ takeUntil(destroy$),
449
+ distinctUntilChanged()
450
+ )
451
+
452
+ const transitionItem$ = new Observable<number>(subscriber => {
453
+ combineLatest({
454
+ groupLabels: groupLabels$,
455
+ transitionDuration: transitionDuration$
456
+ }).pipe(
457
+ switchMap(async d => d)
458
+ ).subscribe(data => {
459
+ const transition = calctransitionItem(data.groupLabels.length, data.transitionDuration)
460
+ subscriber.next(transition)
461
+ })
462
+ }).pipe(
463
+ takeUntil(destroy$),
464
+ distinctUntilChanged()
465
+ )
466
+
467
+ //
468
+
469
+ combineLatest({
470
+ defsSelection: defsSelection$,
471
+ gridAxesSize: gridAxesSize$,
472
+ }).pipe(
473
+ takeUntil(destroy$),
474
+ switchMap(async d => d)
475
+ ).subscribe(data => {
476
+ const clipPathData = [{
477
+ id: clipPathID,
478
+ width: data.gridAxesSize.width,
479
+ height: data.gridAxesSize.height
480
+ }]
481
+ renderClipPath({
482
+ defsSelection: data.defsSelection,
483
+ clipPathData
484
+ })
485
+ })
486
+
487
+
488
+ const highlightTarget$ = fullChartParams$.pipe(
489
+ takeUntil(destroy$),
490
+ map(d => d.highlightTarget),
491
+ distinctUntilChanged()
492
+ )
493
+
494
+ const linearGradientIds$ = seriesLabels$.pipe(
495
+ takeUntil(destroy$),
496
+ map(d => d.map((d, i) => {
497
+ return getUniID(pluginName, `lineargradient-${d}`)
498
+ }))
499
+ )
500
+
501
+ // const barData$ = combineLatest({
502
+ // linearGradientIds: linearGradientIds$,
503
+ // computedData: computedData$
504
+ // }).pipe(
505
+ // takeUntil(destroy$),
506
+ // switchMap(async d => d),
507
+ // map(data => {
508
+ // return data.computedData.map((series, seriesIndex) => {
509
+ // return series.map((_d, _i) => {
510
+ // return <BarDatumGrid>{
511
+ // linearGradientId: data.linearGradientIds[seriesIndex],
512
+ // ..._d
513
+ // }
514
+ // })
515
+ // })
516
+ // })
517
+ // )
518
+
519
+ const barSelection$ = combineLatest({
520
+ graphicGSelection: graphicGSelection$,
521
+ defsSelection: defsSelection$,
522
+ computedData: computedData$,
523
+ visibleComputedLayoutData: visibleComputedLayoutData$,
524
+ linearGradientIds: linearGradientIds$,
525
+ zeroYArr: zeroYArr$,
526
+ groupLabels: groupLabels$,
527
+ barScale: barScale$,
528
+ params: fullParams$,
529
+ chartParams: fullChartParams$,
530
+ barWidth: barWidth$,
531
+ delayGroup: delayGroup$,
532
+ transitionItem: transitionItem$,
533
+ isSeriesSeprate: isSeriesSeprate$
534
+ }).pipe(
535
+ takeUntil(destroy$),
536
+ switchMap(async (d) => d),
537
+ map(data => {
538
+ renderLinearGradient({
539
+ defsSelection: data.defsSelection,
540
+ computedData: data.computedData,
541
+ linearGradientIds: data.linearGradientIds,
542
+ params: data.params
543
+ })
544
+
545
+ return renderTriangleBars({
546
+ graphicGSelection: data.graphicGSelection,
547
+ pathGClassName,
548
+ pathClassName,
549
+ visibleComputedLayoutData: data.visibleComputedLayoutData,
550
+ linearGradientIds: data.linearGradientIds,
551
+ zeroYArr: data.zeroYArr,
552
+ groupLabels: data.groupLabels,
553
+ barScale: data.barScale,
554
+ params: data.params,
555
+ chartParams: data.chartParams,
556
+ barWidth: data.barWidth,
557
+ delayGroup: data.delayGroup,
558
+ transitionItem: data.transitionItem,
559
+ isSeriesSeprate: data.isSeriesSeprate
560
+ })
561
+ })
562
+ )
563
+
564
+ combineLatest({
565
+ barSelection: barSelection$,
566
+ computedData: computedData$,
567
+ highlightTarget: highlightTarget$,
568
+ SeriesDataMap: SeriesDataMap$,
569
+ GroupDataMap: GroupDataMap$,
570
+ }).subscribe(data => {
571
+
572
+ data.barSelection!
573
+ .on('mouseover', (event, datum) => {
574
+ event.stopPropagation()
575
+
576
+ event$.next({
577
+ type: 'grid',
578
+ eventName: 'mouseover',
579
+ pluginName,
580
+ highlightTarget: data.highlightTarget,
581
+ datum,
582
+ gridIndex: datum.gridIndex,
583
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
584
+ seriesIndex: datum.seriesIndex,
585
+ seriesLabel: datum.seriesLabel,
586
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
587
+ groupIndex: datum.groupIndex,
588
+ groupLabel: datum.groupLabel,
589
+ event,
590
+ data: data.computedData
591
+ })
592
+ })
593
+ .on('mousemove', (event, datum) => {
594
+ event.stopPropagation()
595
+
596
+ event$.next({
597
+ type: 'grid',
598
+ eventName: 'mousemove',
599
+ pluginName,
600
+ highlightTarget: data.highlightTarget,
601
+ datum,
602
+ gridIndex: datum.gridIndex,
603
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
604
+ seriesIndex: datum.seriesIndex,
605
+ seriesLabel: datum.seriesLabel,
606
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
607
+ groupIndex: datum.groupIndex,
608
+ groupLabel: datum.groupLabel,
609
+ event,
610
+ data: data.computedData
611
+ })
612
+ })
613
+ .on('mouseout', (event, datum) => {
614
+ event.stopPropagation()
615
+
616
+ event$.next({
617
+ type: 'grid',
618
+ eventName: 'mouseout',
619
+ pluginName,
620
+ highlightTarget: data.highlightTarget,
621
+ datum,
622
+ gridIndex: datum.gridIndex,
623
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
624
+ seriesIndex: datum.seriesIndex,
625
+ seriesLabel: datum.seriesLabel,
626
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
627
+ groupIndex: datum.groupIndex,
628
+ groupLabel: datum.groupLabel,
629
+ event,
630
+ data: data.computedData
631
+ })
632
+ })
633
+ .on('click', (event, datum) => {
634
+ event.stopPropagation()
635
+
636
+ event$.next({
637
+ type: 'grid',
638
+ eventName: 'click',
639
+ pluginName,
640
+ highlightTarget: data.highlightTarget,
641
+ datum,
642
+ gridIndex: datum.gridIndex,
643
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
644
+ seriesIndex: datum.seriesIndex,
645
+ seriesLabel: datum.seriesLabel,
646
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
647
+ groupIndex: datum.groupIndex,
648
+ groupLabel: datum.groupLabel,
649
+ event,
650
+ data: data.computedData
651
+ })
652
+ })
653
+ })
654
+
655
+ combineLatest({
656
+ barSelection: barSelection$,
657
+ highlight: gridHighlight$.pipe(
658
+ map(data => data.map(d => d.id))
659
+ ),
660
+ fullChartParams: fullChartParams$
661
+ }).pipe(
662
+ takeUntil(destroy$),
663
+ switchMap(async d => d)
664
+ ).subscribe(data => {
665
+ highlight({
666
+ selection: data.barSelection,
667
+ ids: data.highlight,
668
+ fullChartParams: data.fullChartParams
669
+ })
670
+ })
671
+
672
+ return () => {
673
+ destroy$.next(undefined)
674
+ }
675
675
  }