@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,630 +1,630 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- filter,
6
- switchMap,
7
- takeUntil,
8
- distinctUntilChanged,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import type { BasePluginFn } from './types'
12
- import type {
13
- ComputedDatumGrid,
14
- ComputedDataGrid,
15
- ComputedLayoutDatumGrid,
16
- ComputedAxesDataGrid,
17
- DataFormatterGrid,
18
- EventGrid,
19
- ContainerPositionScaled,
20
- ChartParams,
21
- Layout,
22
- TransformData
23
- } from '../../lib/core-types'
24
- import type { BaseLineAreasParams } from '../../lib/plugins-basic-types'
25
- import { getD3TransitionEase } from '../utils/d3Utils'
26
- import { getClassName, getUniID, getMinMaxValue } from '../utils/orbchartsUtils'
27
- import { gridGroupPositionFnObservable } from '../grid/gridObservables'
28
- import { gridSelectionsObservable } from '../grid/gridObservables'
29
-
30
- // export interface BaseLineAreasParams {
31
- // lineCurve: string
32
- // // lineWidth: number
33
- // linearGradientOpacity: [number, number]
34
- // }
35
-
36
- interface BaseLineAreasContext {
37
- selection: d3.Selection<any, unknown, any, unknown>
38
- computedData$: Observable<ComputedDataGrid>
39
- computedAxesData$: Observable<ComputedAxesDataGrid>
40
- visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
- visibleComputedAxesData$: Observable<ComputedAxesDataGrid>
42
- seriesLabels$: Observable<string[]>
43
- SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
44
- GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
- fullDataFormatter$: Observable<DataFormatterGrid>
46
- fullParams$: Observable<BaseLineAreasParams>
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<ContainerPositionScaled[]>
56
- allContainerPosition$: Observable<ContainerPositionScaled[]>
57
- layout$: Observable<Layout>
58
- event$: Subject<EventGrid>
59
- }
60
-
61
- type ClipPathDatum = {
62
- id: string;
63
- // x: number;
64
- // y: number;
65
- width: number;
66
- height: number;
67
- }
68
-
69
- // const pluginName = 'Lines'
70
- // const pathClassName = getClassName(pluginName, 'path')
71
-
72
-
73
- function createAreaPath (lineCurve: string = 'curveLinear', valueAxisStart: number): d3.Line<ComputedLayoutDatumGrid> {
74
- return d3.area<ComputedLayoutDatumGrid>()
75
- .x((d) => d.axisX)
76
- .y0(d => valueAxisStart)
77
- .y1((d) => d.axisY)
78
- .curve((d3 as any)[lineCurve])
79
-
80
- }
81
-
82
- // 依無值的資料分段
83
- function makeSegmentData (data: ComputedLayoutDatumGrid[]): ComputedLayoutDatumGrid[][] {
84
- let segmentData: ComputedLayoutDatumGrid[][] = [[]]
85
-
86
- let currentIndex = 0
87
- for (let i in data) {
88
- if (data[i].visible == false || data[i].value === undefined || data[i].value === null) {
89
- // 換下一段的 index
90
- if (segmentData[currentIndex].length) {
91
- currentIndex ++
92
- segmentData[currentIndex] = []
93
- }
94
- continue
95
- }
96
- segmentData[currentIndex].push(data[i])
97
- }
98
-
99
- return segmentData
100
- }
101
-
102
-
103
- function renderLineAreas ({ selection, pathClassName, segmentData, areaPath, linearGradientIds, params }: {
104
- selection: d3.Selection<SVGGElement, unknown, any, unknown>
105
- pathClassName: string
106
- segmentData: ComputedLayoutDatumGrid[][]
107
- areaPath: d3.Line<ComputedLayoutDatumGrid>
108
- linearGradientIds: string[]
109
- params: BaseLineAreasParams
110
- }): d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any> {
111
- // if (!data[0]) {
112
- // return undefined
113
- // }
114
-
115
- const lineAreas = selection
116
- .selectAll<SVGPathElement, ComputedLayoutDatumGrid[]>('path')
117
- .data(segmentData, (d, i) => d.length ? `${d[0].id}_${d[d.length - 1].id}` : i) // 以線段起迄id結合為線段id
118
- .join(
119
- enter => {
120
- return enter
121
- .append<SVGPathElement>('path')
122
- .classed(pathClassName, true)
123
- .attr("fill","none")
124
- // .attr('pointer-events', 'visibleStroke') // 只對線條產生事件
125
- .style('vector-effect', 'non-scaling-stroke')
126
- .style('cursor', 'pointer')
127
- },
128
- update => update,
129
- exit => exit.remove()
130
- )
131
- // .attr("stroke-width", params.lineWidth)
132
- // .attr("stroke", (d, i) => d[0] && d[0].color)
133
- .attr("fill", (d, i) => d[0] ? `url(#${linearGradientIds[d[0].seriesIndex]})` : '')
134
- .attr("d", (d) => {
135
- return areaPath(d)
136
- })
137
-
138
- return lineAreas
139
- }
140
-
141
- function highlightLineAreas ({ selection, seriesLabel, fullChartParams }: {
142
- selection: d3.Selection<any, string, any, any>
143
- seriesLabel: string | null
144
- fullChartParams: ChartParams
145
- }) {
146
- selection.interrupt('highlight')
147
- if (!seriesLabel) {
148
- // remove highlight
149
- selection
150
- .transition('highlight')
151
- .duration(200)
152
- .style('opacity', 1)
153
- return
154
- }
155
-
156
- selection
157
- .each((currentSeriesLabel, i, n) => {
158
- // const currentSeriesLabel = d[0] ? d[0].seriesLabel : ''
159
-
160
- if (currentSeriesLabel === seriesLabel) {
161
- d3.select(n[i])
162
- .style('opacity', 1)
163
- } else {
164
- d3.select(n[i])
165
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
166
- }
167
- })
168
- }
169
-
170
- function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
171
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
172
- computedData: ComputedDataGrid
173
- linearGradientIds: string[]
174
- params: BaseLineAreasParams
175
- }) {
176
- defsSelection!
177
- .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
178
- .data(computedData ?? [])
179
- .join(
180
- enter => {
181
- return enter
182
- .append('linearGradient')
183
- .attr('x1', '0%')
184
- .attr('x2', '0%')
185
- .attr('y1', '100%')
186
- .attr('y2', '0%')
187
- .attr('spreadMethod', 'pad')
188
- },
189
- update => update,
190
- exit => exit.remove()
191
- )
192
- .attr('id', (d, i) => {
193
- return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
194
- })
195
- .html((d, i) => {
196
- const color = d[0] ? d[0].color : ''
197
- return `
198
- <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
199
- <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
200
- `
201
- })
202
-
203
- }
204
-
205
- function renderClipPath ({ defsSelection, clipPathData, transitionDuration, transitionEase }: {
206
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
207
- clipPathData: ClipPathDatum[]
208
- transitionDuration: number
209
- transitionEase: string
210
- }) {
211
- const clipPath = defsSelection
212
- .selectAll<SVGClipPathElement, Layout>('clipPath')
213
- .data(clipPathData)
214
- .join(
215
- enter => {
216
- return enter
217
- .append('clipPath')
218
- },
219
- update => update,
220
- exit => exit.remove()
221
- )
222
- .attr('id', d => d.id)
223
- .each((d, i, g) => {
224
- const rect = d3.select(g[i])
225
- .selectAll<SVGRectElement, typeof d>('rect')
226
- .data([d])
227
- .join(
228
- enter => {
229
- const enterSelection = enter
230
- .append('rect')
231
- enterSelection
232
- .transition()
233
- .duration(transitionDuration)
234
- .ease(getD3TransitionEase(transitionEase))
235
- // .delay(100) // @Q@ 不知為何如果沒加 delay位置會有點跑掉
236
- .tween('tween', (_d, _i, _g) => {
237
- return (t) => {
238
- const transitionWidth = _d.width * t
239
-
240
- enterSelection
241
- .attr('x', 0)
242
- .attr('y', 0)
243
- .attr('width', _d => transitionWidth)
244
- .attr('height', _d => _d.height)
245
- }
246
- })
247
- return enterSelection
248
- },
249
- update => {
250
- return update
251
- .attr('x', 0)
252
- .attr('y', 0)
253
- .attr('width', _d => _d.width)
254
- .attr('height', _d => _d.height)
255
- },
256
- exit => exit.remove()
257
- )
258
- })
259
-
260
- }
261
-
262
- export const createBaseLineAreas: BasePluginFn<BaseLineAreasContext> = (pluginName: string, {
263
- selection,
264
- computedData$,
265
- computedAxesData$,
266
- visibleComputedData$,
267
- visibleComputedAxesData$,
268
- seriesLabels$,
269
- SeriesDataMap$,
270
- GroupDataMap$,
271
- fullParams$,
272
- fullDataFormatter$,
273
- fullChartParams$,
274
- gridAxesTransform$,
275
- gridGraphicTransform$,
276
- gridAxesSize$,
277
- gridHighlight$,
278
- gridContainerPosition$,
279
- layout$,
280
- event$
281
- }) => {
282
-
283
- const destroy$ = new Subject()
284
-
285
- const clipPathID = getUniID(pluginName, 'clipPath-box')
286
- const pathClassName = getClassName(pluginName, 'path')
287
-
288
- const {
289
- seriesSelection$,
290
- axesSelection$,
291
- defsSelection$,
292
- graphicGSelection$
293
- } = gridSelectionsObservable({
294
- selection,
295
- pluginName,
296
- clipPathID,
297
- seriesLabels$,
298
- gridContainerPosition$,
299
- gridAxesTransform$,
300
- gridGraphicTransform$
301
- })
302
-
303
- // valueAxis 的起始座標
304
- const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
305
- takeUntil(destroy$),
306
- map(data => {
307
- // 抵消掉外層的變型
308
- return - data.translate[1] / data.scale[1]
309
- })
310
- )
311
-
312
- const areaPath$: Observable<d3.Line<ComputedLayoutDatumGrid>> = new Observable(subscriber => {
313
- const paramsSubscription = combineLatest({
314
- fullParams: fullParams$,
315
- valueAxisStart: valueAxisStart$
316
- }).pipe(
317
- takeUntil(destroy$)
318
- )
319
- .subscribe(d => {
320
- const areaPath = createAreaPath(d.fullParams.lineCurve, d.valueAxisStart)
321
- subscriber.next(areaPath)
322
- })
323
- return () => {
324
- paramsSubscription.unsubscribe()
325
- }
326
- })
327
-
328
- // // 顯示範圍內的series labels
329
- // const seriesLabels$: Observable<string[]> = new Observable(subscriber => {
330
- // computedData$.pipe(
331
- // takeUntil(destroy$),
332
- // switchMap(async (d) => d),
333
- // ).subscribe(data => {
334
- // const labels = data[0] && data[0][0]
335
- // ? data.map(d => d[0].seriesLabel)
336
- // : []
337
- // subscriber.next(labels)
338
- // })
339
- // })
340
-
341
- // const axisSize$ = gridAxisSizeObservable({
342
- // fullDataFormatter$,
343
- // computedLayout$
344
- // })
345
-
346
- const transitionDuration$ = fullChartParams$
347
- .pipe(
348
- map(d => d.transitionDuration),
349
- distinctUntilChanged()
350
- )
351
-
352
- const transitionEase$ = fullChartParams$
353
- .pipe(
354
- map(d => d.transitionEase),
355
- distinctUntilChanged()
356
- )
357
-
358
- const clipPathSubscription = combineLatest({
359
- defsSelection: defsSelection$,
360
- seriesLabels: seriesLabels$,
361
- axisSize: gridAxesSize$,
362
- transitionDuration: transitionDuration$,
363
- transitionEase: transitionEase$
364
- }).pipe(
365
- takeUntil(destroy$),
366
- switchMap(async (d) => d),
367
- ).subscribe(data => {
368
- // 外層的遮罩
369
- const clipPathBox = [{
370
- id: clipPathID,
371
- width: data.axisSize.width,
372
- height: data.axisSize.height
373
- }]
374
- // 各別線條的遮罩(各別動畫)
375
- const clipPathData = clipPathBox.concat(
376
- data.seriesLabels.map(d => {
377
- return {
378
- id: `orbcharts__clipPath_${d}`,
379
- width: data.axisSize.width,
380
- height: data.axisSize.height
381
- }
382
- })
383
- )
384
- renderClipPath({
385
- defsSelection: data.defsSelection,
386
- clipPathData,
387
- transitionDuration: data.transitionDuration,
388
- transitionEase: data.transitionEase
389
- })
390
- })
391
-
392
- // const SeriesDataMap$ = computedData$.pipe(
393
- // map(d => makeGridSeriesDataMap(d))
394
- // )
395
-
396
- // const GroupDataMap$ = computedData$.pipe(
397
- // map(d => makeGridGroupDataMap(d))
398
- // )
399
-
400
- const DataMap$ = computedData$.pipe(
401
- map(d => {
402
- const DataMap: Map<string, ComputedDatumGrid> = new Map()
403
- d.flat().forEach(_d => DataMap.set(_d.id, _d))
404
- return DataMap
405
- })
406
- )
407
-
408
- // 取得事件座標的group資料
409
- const gridGroupPositionFn$ = gridGroupPositionFnObservable({
410
- fullDataFormatter$,
411
- gridAxesSize$: gridAxesSize$,
412
- computedData$: computedData$,
413
- fullChartParams$: fullChartParams$,
414
- gridContainerPosition$: gridContainerPosition$,
415
- layout$: layout$
416
- })
417
-
418
- const highlightTarget$ = fullChartParams$.pipe(
419
- takeUntil(destroy$),
420
- map(d => d.highlightTarget),
421
- distinctUntilChanged()
422
- )
423
-
424
- const linearGradientIds$ = seriesLabels$.pipe(
425
- takeUntil(destroy$),
426
- map(d => d.map((d, i) => {
427
- return getUniID(pluginName, `lineargradient-${d}`)
428
- }))
429
- )
430
-
431
- const pathSelectionArr$ = combineLatest({
432
- graphicGSelection: graphicGSelection$,
433
- defsSelection: defsSelection$,
434
- visibleComputedAxesData: visibleComputedAxesData$,
435
- linearGradientIds: linearGradientIds$,
436
- areaPath: areaPath$,
437
- params: fullParams$,
438
- }).pipe(
439
- takeUntil(destroy$),
440
- switchMap(async (d) => d),
441
- map(data => {
442
- // const updateGraphic = data.graphicGSelection
443
- // .selectAll<SVGGElement, number>('g')
444
- // .data(data.seriesLabels, (d, i) => d)
445
- // const enterGraphic = updateGraphic.enter()
446
- // .append('g')
447
- // .classed(graphicClassName, true)
448
- // updateGraphic.exit().remove()
449
- // const graphicSelection = updateGraphic.merge(enterGraphic)
450
- // .attr('clip-path', (d, i) => `url(#orbcharts__clipPath_${d})`)
451
- let pathSelectionArr: d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any>[] = []
452
-
453
- // 繪圖
454
- data.graphicGSelection.each((d, i, all) => {
455
- // 將資料分段
456
- const segmentData = makeSegmentData(data.visibleComputedAxesData[i] ?? [])
457
-
458
- pathSelectionArr[i] = renderLineAreas({
459
- selection: d3.select(all[i]),
460
- pathClassName,
461
- areaPath: data.areaPath,
462
- segmentData: segmentData,
463
- linearGradientIds: data.linearGradientIds,
464
- params: data.params
465
- })
466
- renderLinearGradient({
467
- defsSelection: data.defsSelection,
468
- computedData: data.visibleComputedAxesData,
469
- linearGradientIds: data.linearGradientIds,
470
- params: data.params
471
- })
472
- })
473
-
474
- return pathSelectionArr
475
- })
476
- )
477
-
478
- combineLatest({
479
- pathSelectionArr: pathSelectionArr$,
480
- computedData: computedData$,
481
- SeriesDataMap: SeriesDataMap$,
482
- GroupDataMap: GroupDataMap$,
483
- highlightTarget: highlightTarget$,
484
- gridGroupPositionFn: gridGroupPositionFn$,
485
- }).pipe(
486
- takeUntil(destroy$),
487
- switchMap(async (d) => d),
488
- ).subscribe(data => {
489
- data.pathSelectionArr.forEach(pathSelection => {
490
- pathSelection
491
- .on('mouseover', (event, datum) => {
492
- // event.stopPropagation()
493
-
494
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
495
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
496
- const groupData = data.GroupDataMap.get(groupLabel)!
497
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
498
- const _datum = targetDatum ?? datum[0]
499
-
500
- event$.next({
501
- type: 'grid',
502
- eventName: 'mouseover',
503
- pluginName,
504
- highlightTarget: data.highlightTarget,
505
- datum: _datum,
506
- gridIndex: _datum.gridIndex,
507
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
508
- seriesIndex: _datum.seriesIndex,
509
- seriesLabel: _datum.seriesLabel,
510
- group: data.GroupDataMap.get(_datum.groupLabel)!,
511
- groupIndex: _datum.groupIndex,
512
- groupLabel: _datum.groupLabel,
513
- event,
514
- data: data.computedData
515
- })
516
- })
517
- .on('mousemove', (event, datum) => {
518
- // event.stopPropagation()
519
-
520
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
521
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
522
- const groupData = data.GroupDataMap.get(groupLabel)!
523
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
524
- const _datum = targetDatum ?? datum[0]
525
-
526
- event$.next({
527
- type: 'grid',
528
- eventName: 'mousemove',
529
- pluginName,
530
- highlightTarget: data.highlightTarget,
531
- datum: _datum,
532
- gridIndex: _datum.gridIndex,
533
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
534
- seriesIndex: _datum.seriesIndex,
535
- seriesLabel: _datum.seriesLabel,
536
- group: data.GroupDataMap.get(_datum.groupLabel)!,
537
- groupIndex: _datum.groupIndex,
538
- groupLabel: _datum.groupLabel,
539
- event,
540
- data: data.computedData
541
- })
542
- })
543
- .on('mouseout', (event, datum) => {
544
- // event.stopPropagation()
545
-
546
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
547
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
548
- const groupData = data.GroupDataMap.get(groupLabel)!
549
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
550
- const _datum = targetDatum ?? datum[0]
551
-
552
- event$.next({
553
- type: 'grid',
554
- eventName: 'mouseout',
555
- pluginName,
556
- highlightTarget: data.highlightTarget,
557
- datum: _datum,
558
- gridIndex: _datum.gridIndex,
559
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
560
- seriesIndex: _datum.seriesIndex,
561
- seriesLabel: _datum.seriesLabel,
562
- group: data.GroupDataMap.get(_datum.groupLabel)!,
563
- groupIndex: _datum.groupIndex,
564
- groupLabel: _datum.groupLabel,
565
- event,
566
- data: data.computedData
567
- })
568
- })
569
- .on('click', (event, datum) => {
570
- // event.stopPropagation()
571
-
572
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
573
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
574
- const groupData = data.GroupDataMap.get(groupLabel)!
575
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
576
- const _datum = targetDatum ?? datum[0]
577
-
578
- event$.next({
579
- type: 'grid',
580
- eventName: 'click',
581
- pluginName,
582
- highlightTarget: data.highlightTarget,
583
- datum: _datum,
584
- gridIndex: _datum.gridIndex,
585
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
586
- seriesIndex: _datum.seriesIndex,
587
- seriesLabel: _datum.seriesLabel,
588
- group: data.GroupDataMap.get(_datum.groupLabel)!,
589
- groupIndex: _datum.groupIndex,
590
- groupLabel: _datum.groupLabel,
591
- event,
592
- data: data.computedData
593
- })
594
- })
595
- })
596
- })
597
-
598
- // const datumList$ = computedData$.pipe(
599
- // takeUntil(destroy$),
600
- // map(d => d.flat())
601
- // )
602
- // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
603
- // const highlightSubscription = gridHighlight$.subscribe()
604
-
605
- fullChartParams$.pipe(
606
- takeUntil(destroy$),
607
- filter(d => d.highlightTarget === 'series'),
608
- switchMap(d => combineLatest({
609
- graphicGSelection: graphicGSelection$,
610
- gridHighlight: gridHighlight$,
611
- DataMap: DataMap$,
612
- fullChartParams: fullChartParams$
613
- }).pipe(
614
- takeUntil(destroy$),
615
- switchMap(async d => d)
616
- ))
617
- ).subscribe(data => {
618
- const seriesLabel = data.gridHighlight[0] ? data.gridHighlight[0].seriesLabel : null
619
- highlightLineAreas({
620
- selection: data.graphicGSelection,
621
- seriesLabel,
622
- fullChartParams: data.fullChartParams
623
- })
624
- })
625
-
626
- return () => {
627
- destroy$.next(undefined)
628
- // highlightSubscription.unsubscribe()
629
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ filter,
6
+ switchMap,
7
+ takeUntil,
8
+ distinctUntilChanged,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import type { BasePluginFn } from './types'
12
+ import type {
13
+ ComputedDatumGrid,
14
+ ComputedDataGrid,
15
+ ComputedLayoutDatumGrid,
16
+ ComputedAxesDataGrid,
17
+ DataFormatterGrid,
18
+ EventGrid,
19
+ ContainerPositionScaled,
20
+ ChartParams,
21
+ Layout,
22
+ TransformData
23
+ } from '../../lib/core-types'
24
+ import type { BaseLineAreasParams } from '../../lib/plugins-basic-types'
25
+ import { getD3TransitionEase } from '../utils/d3Utils'
26
+ import { getClassName, getUniID, getMinMaxValue } from '../utils/orbchartsUtils'
27
+ import { gridGroupPositionFnObservable } from '../grid/gridObservables'
28
+ import { gridSelectionsObservable } from '../grid/gridObservables'
29
+
30
+ // export interface BaseLineAreasParams {
31
+ // lineCurve: string
32
+ // // lineWidth: number
33
+ // linearGradientOpacity: [number, number]
34
+ // }
35
+
36
+ interface BaseLineAreasContext {
37
+ selection: d3.Selection<any, unknown, any, unknown>
38
+ computedData$: Observable<ComputedDataGrid>
39
+ computedAxesData$: Observable<ComputedAxesDataGrid>
40
+ visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
+ visibleComputedAxesData$: Observable<ComputedAxesDataGrid>
42
+ seriesLabels$: Observable<string[]>
43
+ SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
44
+ GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
+ fullDataFormatter$: Observable<DataFormatterGrid>
46
+ fullParams$: Observable<BaseLineAreasParams>
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<ContainerPositionScaled[]>
56
+ allContainerPosition$: Observable<ContainerPositionScaled[]>
57
+ layout$: Observable<Layout>
58
+ event$: Subject<EventGrid>
59
+ }
60
+
61
+ type ClipPathDatum = {
62
+ id: string;
63
+ // x: number;
64
+ // y: number;
65
+ width: number;
66
+ height: number;
67
+ }
68
+
69
+ // const pluginName = 'Lines'
70
+ // const pathClassName = getClassName(pluginName, 'path')
71
+
72
+
73
+ function createAreaPath (lineCurve: string = 'curveLinear', valueAxisStart: number): d3.Line<ComputedLayoutDatumGrid> {
74
+ return d3.area<ComputedLayoutDatumGrid>()
75
+ .x((d) => d.axisX)
76
+ .y0(d => valueAxisStart)
77
+ .y1((d) => d.axisY)
78
+ .curve((d3 as any)[lineCurve])
79
+
80
+ }
81
+
82
+ // 依無值的資料分段
83
+ function makeSegmentData (data: ComputedLayoutDatumGrid[]): ComputedLayoutDatumGrid[][] {
84
+ let segmentData: ComputedLayoutDatumGrid[][] = [[]]
85
+
86
+ let currentIndex = 0
87
+ for (let i in data) {
88
+ if (data[i].visible == false || data[i].value === undefined || data[i].value === null) {
89
+ // 換下一段的 index
90
+ if (segmentData[currentIndex].length) {
91
+ currentIndex ++
92
+ segmentData[currentIndex] = []
93
+ }
94
+ continue
95
+ }
96
+ segmentData[currentIndex].push(data[i])
97
+ }
98
+
99
+ return segmentData
100
+ }
101
+
102
+
103
+ function renderLineAreas ({ selection, pathClassName, segmentData, areaPath, linearGradientIds, params }: {
104
+ selection: d3.Selection<SVGGElement, unknown, any, unknown>
105
+ pathClassName: string
106
+ segmentData: ComputedLayoutDatumGrid[][]
107
+ areaPath: d3.Line<ComputedLayoutDatumGrid>
108
+ linearGradientIds: string[]
109
+ params: BaseLineAreasParams
110
+ }): d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any> {
111
+ // if (!data[0]) {
112
+ // return undefined
113
+ // }
114
+
115
+ const lineAreas = selection
116
+ .selectAll<SVGPathElement, ComputedLayoutDatumGrid[]>('path')
117
+ .data(segmentData, (d, i) => d.length ? `${d[0].id}_${d[d.length - 1].id}` : i) // 以線段起迄id結合為線段id
118
+ .join(
119
+ enter => {
120
+ return enter
121
+ .append<SVGPathElement>('path')
122
+ .classed(pathClassName, true)
123
+ .attr("fill","none")
124
+ // .attr('pointer-events', 'visibleStroke') // 只對線條產生事件
125
+ .style('vector-effect', 'non-scaling-stroke')
126
+ .style('cursor', 'pointer')
127
+ },
128
+ update => update,
129
+ exit => exit.remove()
130
+ )
131
+ // .attr("stroke-width", params.lineWidth)
132
+ // .attr("stroke", (d, i) => d[0] && d[0].color)
133
+ .attr("fill", (d, i) => d[0] ? `url(#${linearGradientIds[d[0].seriesIndex]})` : '')
134
+ .attr("d", (d) => {
135
+ return areaPath(d)
136
+ })
137
+
138
+ return lineAreas
139
+ }
140
+
141
+ function highlightLineAreas ({ selection, seriesLabel, fullChartParams }: {
142
+ selection: d3.Selection<any, string, any, any>
143
+ seriesLabel: string | null
144
+ fullChartParams: ChartParams
145
+ }) {
146
+ selection.interrupt('highlight')
147
+ if (!seriesLabel) {
148
+ // remove highlight
149
+ selection
150
+ .transition('highlight')
151
+ .duration(200)
152
+ .style('opacity', 1)
153
+ return
154
+ }
155
+
156
+ selection
157
+ .each((currentSeriesLabel, i, n) => {
158
+ // const currentSeriesLabel = d[0] ? d[0].seriesLabel : ''
159
+
160
+ if (currentSeriesLabel === seriesLabel) {
161
+ d3.select(n[i])
162
+ .style('opacity', 1)
163
+ } else {
164
+ d3.select(n[i])
165
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
166
+ }
167
+ })
168
+ }
169
+
170
+ function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
171
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
172
+ computedData: ComputedDataGrid
173
+ linearGradientIds: string[]
174
+ params: BaseLineAreasParams
175
+ }) {
176
+ defsSelection!
177
+ .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
178
+ .data(computedData ?? [])
179
+ .join(
180
+ enter => {
181
+ return enter
182
+ .append('linearGradient')
183
+ .attr('x1', '0%')
184
+ .attr('x2', '0%')
185
+ .attr('y1', '100%')
186
+ .attr('y2', '0%')
187
+ .attr('spreadMethod', 'pad')
188
+ },
189
+ update => update,
190
+ exit => exit.remove()
191
+ )
192
+ .attr('id', (d, i) => {
193
+ return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
194
+ })
195
+ .html((d, i) => {
196
+ const color = d[0] ? d[0].color : ''
197
+ return `
198
+ <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
199
+ <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
200
+ `
201
+ })
202
+
203
+ }
204
+
205
+ function renderClipPath ({ defsSelection, clipPathData, transitionDuration, transitionEase }: {
206
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
207
+ clipPathData: ClipPathDatum[]
208
+ transitionDuration: number
209
+ transitionEase: string
210
+ }) {
211
+ const clipPath = defsSelection
212
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
213
+ .data(clipPathData)
214
+ .join(
215
+ enter => {
216
+ return enter
217
+ .append('clipPath')
218
+ },
219
+ update => update,
220
+ exit => exit.remove()
221
+ )
222
+ .attr('id', d => d.id)
223
+ .each((d, i, g) => {
224
+ const rect = d3.select(g[i])
225
+ .selectAll<SVGRectElement, typeof d>('rect')
226
+ .data([d])
227
+ .join(
228
+ enter => {
229
+ const enterSelection = enter
230
+ .append('rect')
231
+ enterSelection
232
+ .transition()
233
+ .duration(transitionDuration)
234
+ .ease(getD3TransitionEase(transitionEase))
235
+ // .delay(100) // @Q@ 不知為何如果沒加 delay位置會有點跑掉
236
+ .tween('tween', (_d, _i, _g) => {
237
+ return (t) => {
238
+ const transitionWidth = _d.width * t
239
+
240
+ enterSelection
241
+ .attr('x', 0)
242
+ .attr('y', 0)
243
+ .attr('width', _d => transitionWidth)
244
+ .attr('height', _d => _d.height)
245
+ }
246
+ })
247
+ return enterSelection
248
+ },
249
+ update => {
250
+ return update
251
+ .attr('x', 0)
252
+ .attr('y', 0)
253
+ .attr('width', _d => _d.width)
254
+ .attr('height', _d => _d.height)
255
+ },
256
+ exit => exit.remove()
257
+ )
258
+ })
259
+
260
+ }
261
+
262
+ export const createBaseLineAreas: BasePluginFn<BaseLineAreasContext> = (pluginName: string, {
263
+ selection,
264
+ computedData$,
265
+ computedAxesData$,
266
+ visibleComputedData$,
267
+ visibleComputedAxesData$,
268
+ seriesLabels$,
269
+ SeriesDataMap$,
270
+ GroupDataMap$,
271
+ fullParams$,
272
+ fullDataFormatter$,
273
+ fullChartParams$,
274
+ gridAxesTransform$,
275
+ gridGraphicTransform$,
276
+ gridAxesSize$,
277
+ gridHighlight$,
278
+ gridContainerPosition$,
279
+ layout$,
280
+ event$
281
+ }) => {
282
+
283
+ const destroy$ = new Subject()
284
+
285
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
286
+ const pathClassName = getClassName(pluginName, 'path')
287
+
288
+ const {
289
+ seriesSelection$,
290
+ axesSelection$,
291
+ defsSelection$,
292
+ graphicGSelection$
293
+ } = gridSelectionsObservable({
294
+ selection,
295
+ pluginName,
296
+ clipPathID,
297
+ seriesLabels$,
298
+ gridContainerPosition$,
299
+ gridAxesTransform$,
300
+ gridGraphicTransform$
301
+ })
302
+
303
+ // valueAxis 的起始座標
304
+ const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
305
+ takeUntil(destroy$),
306
+ map(data => {
307
+ // 抵消掉外層的變型
308
+ return - data.translate[1] / data.scale[1]
309
+ })
310
+ )
311
+
312
+ const areaPath$: Observable<d3.Line<ComputedLayoutDatumGrid>> = new Observable(subscriber => {
313
+ const paramsSubscription = combineLatest({
314
+ fullParams: fullParams$,
315
+ valueAxisStart: valueAxisStart$
316
+ }).pipe(
317
+ takeUntil(destroy$)
318
+ )
319
+ .subscribe(d => {
320
+ const areaPath = createAreaPath(d.fullParams.lineCurve, d.valueAxisStart)
321
+ subscriber.next(areaPath)
322
+ })
323
+ return () => {
324
+ paramsSubscription.unsubscribe()
325
+ }
326
+ })
327
+
328
+ // // 顯示範圍內的series labels
329
+ // const seriesLabels$: Observable<string[]> = new Observable(subscriber => {
330
+ // computedData$.pipe(
331
+ // takeUntil(destroy$),
332
+ // switchMap(async (d) => d),
333
+ // ).subscribe(data => {
334
+ // const labels = data[0] && data[0][0]
335
+ // ? data.map(d => d[0].seriesLabel)
336
+ // : []
337
+ // subscriber.next(labels)
338
+ // })
339
+ // })
340
+
341
+ // const axisSize$ = gridAxisSizeObservable({
342
+ // fullDataFormatter$,
343
+ // computedLayout$
344
+ // })
345
+
346
+ const transitionDuration$ = fullChartParams$
347
+ .pipe(
348
+ map(d => d.transitionDuration),
349
+ distinctUntilChanged()
350
+ )
351
+
352
+ const transitionEase$ = fullChartParams$
353
+ .pipe(
354
+ map(d => d.transitionEase),
355
+ distinctUntilChanged()
356
+ )
357
+
358
+ const clipPathSubscription = combineLatest({
359
+ defsSelection: defsSelection$,
360
+ seriesLabels: seriesLabels$,
361
+ axisSize: gridAxesSize$,
362
+ transitionDuration: transitionDuration$,
363
+ transitionEase: transitionEase$
364
+ }).pipe(
365
+ takeUntil(destroy$),
366
+ switchMap(async (d) => d),
367
+ ).subscribe(data => {
368
+ // 外層的遮罩
369
+ const clipPathBox = [{
370
+ id: clipPathID,
371
+ width: data.axisSize.width,
372
+ height: data.axisSize.height
373
+ }]
374
+ // 各別線條的遮罩(各別動畫)
375
+ const clipPathData = clipPathBox.concat(
376
+ data.seriesLabels.map(d => {
377
+ return {
378
+ id: `orbcharts__clipPath_${d}`,
379
+ width: data.axisSize.width,
380
+ height: data.axisSize.height
381
+ }
382
+ })
383
+ )
384
+ renderClipPath({
385
+ defsSelection: data.defsSelection,
386
+ clipPathData,
387
+ transitionDuration: data.transitionDuration,
388
+ transitionEase: data.transitionEase
389
+ })
390
+ })
391
+
392
+ // const SeriesDataMap$ = computedData$.pipe(
393
+ // map(d => makeGridSeriesDataMap(d))
394
+ // )
395
+
396
+ // const GroupDataMap$ = computedData$.pipe(
397
+ // map(d => makeGridGroupDataMap(d))
398
+ // )
399
+
400
+ const DataMap$ = computedData$.pipe(
401
+ map(d => {
402
+ const DataMap: Map<string, ComputedDatumGrid> = new Map()
403
+ d.flat().forEach(_d => DataMap.set(_d.id, _d))
404
+ return DataMap
405
+ })
406
+ )
407
+
408
+ // 取得事件座標的group資料
409
+ const gridGroupPositionFn$ = gridGroupPositionFnObservable({
410
+ fullDataFormatter$,
411
+ gridAxesSize$: gridAxesSize$,
412
+ computedData$: computedData$,
413
+ fullChartParams$: fullChartParams$,
414
+ gridContainerPosition$: gridContainerPosition$,
415
+ layout$: layout$
416
+ })
417
+
418
+ const highlightTarget$ = fullChartParams$.pipe(
419
+ takeUntil(destroy$),
420
+ map(d => d.highlightTarget),
421
+ distinctUntilChanged()
422
+ )
423
+
424
+ const linearGradientIds$ = seriesLabels$.pipe(
425
+ takeUntil(destroy$),
426
+ map(d => d.map((d, i) => {
427
+ return getUniID(pluginName, `lineargradient-${d}`)
428
+ }))
429
+ )
430
+
431
+ const pathSelectionArr$ = combineLatest({
432
+ graphicGSelection: graphicGSelection$,
433
+ defsSelection: defsSelection$,
434
+ visibleComputedAxesData: visibleComputedAxesData$,
435
+ linearGradientIds: linearGradientIds$,
436
+ areaPath: areaPath$,
437
+ params: fullParams$,
438
+ }).pipe(
439
+ takeUntil(destroy$),
440
+ switchMap(async (d) => d),
441
+ map(data => {
442
+ // const updateGraphic = data.graphicGSelection
443
+ // .selectAll<SVGGElement, number>('g')
444
+ // .data(data.seriesLabels, (d, i) => d)
445
+ // const enterGraphic = updateGraphic.enter()
446
+ // .append('g')
447
+ // .classed(graphicClassName, true)
448
+ // updateGraphic.exit().remove()
449
+ // const graphicSelection = updateGraphic.merge(enterGraphic)
450
+ // .attr('clip-path', (d, i) => `url(#orbcharts__clipPath_${d})`)
451
+ let pathSelectionArr: d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any>[] = []
452
+
453
+ // 繪圖
454
+ data.graphicGSelection.each((d, i, all) => {
455
+ // 將資料分段
456
+ const segmentData = makeSegmentData(data.visibleComputedAxesData[i] ?? [])
457
+
458
+ pathSelectionArr[i] = renderLineAreas({
459
+ selection: d3.select(all[i]),
460
+ pathClassName,
461
+ areaPath: data.areaPath,
462
+ segmentData: segmentData,
463
+ linearGradientIds: data.linearGradientIds,
464
+ params: data.params
465
+ })
466
+ renderLinearGradient({
467
+ defsSelection: data.defsSelection,
468
+ computedData: data.visibleComputedAxesData,
469
+ linearGradientIds: data.linearGradientIds,
470
+ params: data.params
471
+ })
472
+ })
473
+
474
+ return pathSelectionArr
475
+ })
476
+ )
477
+
478
+ combineLatest({
479
+ pathSelectionArr: pathSelectionArr$,
480
+ computedData: computedData$,
481
+ SeriesDataMap: SeriesDataMap$,
482
+ GroupDataMap: GroupDataMap$,
483
+ highlightTarget: highlightTarget$,
484
+ gridGroupPositionFn: gridGroupPositionFn$,
485
+ }).pipe(
486
+ takeUntil(destroy$),
487
+ switchMap(async (d) => d),
488
+ ).subscribe(data => {
489
+ data.pathSelectionArr.forEach(pathSelection => {
490
+ pathSelection
491
+ .on('mouseover', (event, datum) => {
492
+ // event.stopPropagation()
493
+
494
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
495
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
496
+ const groupData = data.GroupDataMap.get(groupLabel)!
497
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
498
+ const _datum = targetDatum ?? datum[0]
499
+
500
+ event$.next({
501
+ type: 'grid',
502
+ eventName: 'mouseover',
503
+ pluginName,
504
+ highlightTarget: data.highlightTarget,
505
+ datum: _datum,
506
+ gridIndex: _datum.gridIndex,
507
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
508
+ seriesIndex: _datum.seriesIndex,
509
+ seriesLabel: _datum.seriesLabel,
510
+ group: data.GroupDataMap.get(_datum.groupLabel)!,
511
+ groupIndex: _datum.groupIndex,
512
+ groupLabel: _datum.groupLabel,
513
+ event,
514
+ data: data.computedData
515
+ })
516
+ })
517
+ .on('mousemove', (event, datum) => {
518
+ // event.stopPropagation()
519
+
520
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
521
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
522
+ const groupData = data.GroupDataMap.get(groupLabel)!
523
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
524
+ const _datum = targetDatum ?? datum[0]
525
+
526
+ event$.next({
527
+ type: 'grid',
528
+ eventName: 'mousemove',
529
+ pluginName,
530
+ highlightTarget: data.highlightTarget,
531
+ datum: _datum,
532
+ gridIndex: _datum.gridIndex,
533
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
534
+ seriesIndex: _datum.seriesIndex,
535
+ seriesLabel: _datum.seriesLabel,
536
+ group: data.GroupDataMap.get(_datum.groupLabel)!,
537
+ groupIndex: _datum.groupIndex,
538
+ groupLabel: _datum.groupLabel,
539
+ event,
540
+ data: data.computedData
541
+ })
542
+ })
543
+ .on('mouseout', (event, datum) => {
544
+ // event.stopPropagation()
545
+
546
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
547
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
548
+ const groupData = data.GroupDataMap.get(groupLabel)!
549
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
550
+ const _datum = targetDatum ?? datum[0]
551
+
552
+ event$.next({
553
+ type: 'grid',
554
+ eventName: 'mouseout',
555
+ pluginName,
556
+ highlightTarget: data.highlightTarget,
557
+ datum: _datum,
558
+ gridIndex: _datum.gridIndex,
559
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
560
+ seriesIndex: _datum.seriesIndex,
561
+ seriesLabel: _datum.seriesLabel,
562
+ group: data.GroupDataMap.get(_datum.groupLabel)!,
563
+ groupIndex: _datum.groupIndex,
564
+ groupLabel: _datum.groupLabel,
565
+ event,
566
+ data: data.computedData
567
+ })
568
+ })
569
+ .on('click', (event, datum) => {
570
+ // event.stopPropagation()
571
+
572
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
573
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
574
+ const groupData = data.GroupDataMap.get(groupLabel)!
575
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
576
+ const _datum = targetDatum ?? datum[0]
577
+
578
+ event$.next({
579
+ type: 'grid',
580
+ eventName: 'click',
581
+ pluginName,
582
+ highlightTarget: data.highlightTarget,
583
+ datum: _datum,
584
+ gridIndex: _datum.gridIndex,
585
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
586
+ seriesIndex: _datum.seriesIndex,
587
+ seriesLabel: _datum.seriesLabel,
588
+ group: data.GroupDataMap.get(_datum.groupLabel)!,
589
+ groupIndex: _datum.groupIndex,
590
+ groupLabel: _datum.groupLabel,
591
+ event,
592
+ data: data.computedData
593
+ })
594
+ })
595
+ })
596
+ })
597
+
598
+ // const datumList$ = computedData$.pipe(
599
+ // takeUntil(destroy$),
600
+ // map(d => d.flat())
601
+ // )
602
+ // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
603
+ // const highlightSubscription = gridHighlight$.subscribe()
604
+
605
+ fullChartParams$.pipe(
606
+ takeUntil(destroy$),
607
+ filter(d => d.highlightTarget === 'series'),
608
+ switchMap(d => combineLatest({
609
+ graphicGSelection: graphicGSelection$,
610
+ gridHighlight: gridHighlight$,
611
+ DataMap: DataMap$,
612
+ fullChartParams: fullChartParams$
613
+ }).pipe(
614
+ takeUntil(destroy$),
615
+ switchMap(async d => d)
616
+ ))
617
+ ).subscribe(data => {
618
+ const seriesLabel = data.gridHighlight[0] ? data.gridHighlight[0].seriesLabel : null
619
+ highlightLineAreas({
620
+ selection: data.graphicGSelection,
621
+ seriesLabel,
622
+ fullChartParams: data.fullChartParams
623
+ })
624
+ })
625
+
626
+ return () => {
627
+ destroy$.next(undefined)
628
+ // highlightSubscription.unsubscribe()
629
+ }
630
630
  }