@orbcharts/plugins-basic 3.0.0-alpha.49 → 3.0.0-alpha.51

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