@orbcharts/plugins-basic 3.0.0-alpha.75 → 3.0.0-alpha.76

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 (81) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +3461 -3468
  3. package/dist/orbcharts-plugins-basic.umd.js +17 -17
  4. package/lib/core-types.ts +7 -7
  5. package/lib/core.ts +6 -6
  6. package/package.json +43 -43
  7. package/src/base/BaseBarStack.ts +779 -779
  8. package/src/base/BaseBars.ts +764 -764
  9. package/src/base/BaseBarsTriangle.ts +672 -672
  10. package/src/base/BaseDots.ts +513 -513
  11. package/src/base/BaseGroupAxis.ts +678 -678
  12. package/src/base/BaseLegend.ts +642 -642
  13. package/src/base/BaseLineAreas.ts +627 -627
  14. package/src/base/BaseLines.ts +704 -704
  15. package/src/base/BaseValueAxis.ts +578 -578
  16. package/src/base/types.ts +2 -2
  17. package/src/const.ts +30 -30
  18. package/src/grid/defaults.ts +128 -128
  19. package/src/grid/gridObservables.ts +545 -545
  20. package/src/grid/index.ts +15 -15
  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 +96 -96
  27. package/src/grid/plugins/GroupAux.ts +1098 -1098
  28. package/src/grid/plugins/GroupAxis.ts +97 -97
  29. package/src/grid/plugins/LineAreas.ts +65 -65
  30. package/src/grid/plugins/Lines.ts +59 -59
  31. package/src/grid/plugins/ScalingArea.ts +218 -218
  32. package/src/grid/plugins/ValueAxis.ts +93 -93
  33. package/src/grid/plugins/ValueStackAxis.ts +95 -95
  34. package/src/grid/types.ts +123 -123
  35. package/src/index.ts +9 -9
  36. package/src/multiGrid/defaults.ts +158 -158
  37. package/src/multiGrid/index.ts +13 -13
  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 +148 -148
  44. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  45. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  46. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  47. package/src/multiGrid/plugins/MultiValueAxis.ts +133 -133
  48. package/src/multiGrid/plugins/MultiValueStackAxis.ts +133 -133
  49. package/src/multiGrid/plugins/OverlappingValueAxes.ts +299 -299
  50. package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +298 -298
  51. package/src/multiGrid/types.ts +72 -72
  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/noneData/types.ts +26 -26
  57. package/src/series/defaults.ts +149 -149
  58. package/src/series/index.ts +9 -9
  59. package/src/series/plugins/Bubbles.ts +603 -603
  60. package/src/series/plugins/Pie.ts +623 -623
  61. package/src/series/plugins/PieEventTexts.ts +283 -283
  62. package/src/series/plugins/PieLabels.ts +640 -640
  63. package/src/series/plugins/Rose.ts +516 -516
  64. package/src/series/plugins/RoseLabels.ts +600 -600
  65. package/src/series/plugins/SeriesLegend.ts +96 -96
  66. package/src/series/seriesObservables.ts +145 -145
  67. package/src/series/seriesUtils.ts +51 -51
  68. package/src/series/types.ts +87 -87
  69. package/src/tree/defaults.ts +23 -23
  70. package/src/tree/index.ts +3 -3
  71. package/src/tree/plugins/TreeLegend.ts +96 -96
  72. package/src/tree/plugins/TreeMap.ts +333 -333
  73. package/src/tree/types.ts +23 -23
  74. package/src/utils/commonUtils.ts +21 -21
  75. package/src/utils/d3Graphics.ts +174 -174
  76. package/src/utils/d3Utils.ts +73 -73
  77. package/src/utils/observables.ts +14 -14
  78. package/src/utils/orbchartsUtils.ts +100 -100
  79. package/tsconfig.base.json +13 -13
  80. package/tsconfig.json +2 -2
  81. package/vite.config.js +22 -22
@@ -1,333 +1,333 @@
1
- import * as d3 from 'd3'
2
- import {
3
- Subject,
4
- Observable,
5
- of,
6
- takeUntil,
7
- map,
8
- switchMap,
9
- combineLatest,
10
- debounceTime,
11
- distinctUntilChanged } from 'rxjs'
12
- import type { DefinePluginConfig } from '../../../lib/core-types'
13
- import {
14
- defineTreePlugin } from '../../../lib/core'
15
- import type { Layout, ComputedDataTree, DataFormatterTree, ChartParams } from '../../../lib/core-types'
16
- import type { TreeMapParams } from '../types'
17
- import { DEFAULT_TREE_MAP_PARAMS } from '../defaults'
18
- import { getClassName, getColor } from '../../utils/orbchartsUtils'
19
- import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
20
-
21
- const pluginName = 'TreeMap'
22
- const treeClassName = getClassName(pluginName, 'tree')
23
- const tileClassName = getClassName(pluginName, 'tile')
24
-
25
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_TREE_MAP_PARAMS> = {
26
- name: pluginName,
27
- defaultParams: DEFAULT_TREE_MAP_PARAMS,
28
- layerIndex: LAYER_INDEX_OF_GRAPHIC,
29
- validator: (params, { validateColumns }) => {
30
- const result = validateColumns(params, {
31
- paddingInner: {
32
- toBeTypes: ['number']
33
- },
34
- paddingOuter: {
35
- toBeTypes: ['number']
36
- },
37
- labelColorType: {
38
- toBeOption: 'ColorType'
39
- },
40
- squarifyRatio: {
41
- toBeTypes: ['number']
42
- },
43
- sort: {
44
- toBeTypes: ['Function']
45
- }
46
- })
47
- return result
48
- }
49
- }
50
-
51
- function renderTree ({ selection, treeData, fullParams, fullChartParams, textSizePx }: {
52
- selection: d3.Selection<any, any, any, any>
53
- treeData: d3.HierarchyRectangularNode<ComputedDataTree>[]
54
- fullParams: TreeMapParams
55
- fullChartParams: ChartParams
56
- textSizePx: number
57
- }) {
58
- const padding = textSizePx / 2
59
- const lineHeight = textSizePx // 行高
60
-
61
- const cell = selection.selectAll<SVGGElement, d3.HierarchyRectangularNode<ComputedDataTree>>(`g.${treeClassName}`)
62
- .data(treeData, d => d.data.id)
63
- .join('g')
64
- .attr('class', treeClassName)
65
-
66
- cell
67
- // .transition()
68
- // .duration(fullChartParams.transitionDuration)
69
- .attr('transform', (d) => !d.x0 || !d.y0 ? null : `translate(${d.x0},${d.y0})`)
70
- .each((d, i, nodes) => {
71
- const eachCell = d3.select(nodes[i])
72
-
73
- const tile = eachCell
74
- .selectAll<SVGRectElement, d3.HierarchyRectangularNode<ComputedDataTree>>(`rect.${tileClassName}`)
75
- .data([d], d => d.data.id)
76
- .join('rect')
77
- .attr("id", d => d.data.id)
78
- .attr("class", tileClassName)
79
- .attr('cursor', 'pointer')
80
- .attr("width", (d) => d.x1 - d.x0)
81
- .attr("height", (d) => d.y1 - d.y0)
82
- .attr('fill', d => d.data.color)
83
- .attr('data-name', d => d.data.label)
84
- .attr('data-category', d => d.data.categoryLabel)
85
- .attr('data-value', d => d.data.value)
86
-
87
- const label = eachCell
88
- .selectAll('g')
89
- .data([d])
90
- .join('g')
91
- .each((d, i, nodes) => {
92
- const eachLabel = d3.select(nodes[i])
93
- const text = eachLabel
94
- .selectAll('text')
95
- .data([d])
96
- .join('text')
97
- .text(d => d.data.label)
98
- .attr('dominant-baseline', 'hanging')
99
- .attr("x", padding)
100
- .attr("y", padding)
101
- .attr('font-size', fullChartParams.styles.textSize)
102
- .each(function(d) {
103
- // -- tspan(自動斷行) --
104
- const textElement = d3.select(this);
105
- const words = d.data.label.split(/\s+/).reverse() // 以空隔分割字串
106
- let word;
107
- let line: string[] = []
108
- const x = textElement.attr("x")
109
- let y = textElement.attr("y")
110
- let dy = 0
111
- let tspan = textElement
112
- .text(null)
113
- .append("tspan")
114
- .attr('cursor', 'pointer')
115
- .attr('fill', getColor(fullParams.labelColorType, fullChartParams))
116
- .attr('font-size', fullChartParams.styles.textSize)
117
- .attr("x", x)
118
- .attr("y", y)
119
-
120
- while (word = words.pop()) {
121
- line.push(word)
122
- tspan.text(line.join(" "))
123
- if (tspan.node().getComputedTextLength() > (d.x1 - d.x0 - padding)) {
124
- line.pop()
125
- tspan.text(line.join(" "))
126
- line = [word]
127
- dy += lineHeight
128
- tspan = textElement
129
- .append("tspan")
130
- .attr('cursor', 'pointer')
131
- .attr('fill', getColor(fullParams.labelColorType, fullChartParams))
132
- .attr('font-size', fullChartParams.styles.textSize)
133
- .attr("x", x)
134
- .attr("y", y)
135
- .attr("dy", dy + "px")
136
- .text(word)
137
- }
138
- }
139
- })
140
- })
141
-
142
- })
143
-
144
- return cell
145
- }
146
-
147
- function highlight ({ selection, ids, fullChartParams }: {
148
- selection: d3.Selection<any, d3.HierarchyRectangularNode<ComputedDataTree>, any, any>
149
- ids: string[]
150
- fullChartParams: ChartParams
151
- }) {
152
- selection.interrupt('highlight')
153
-
154
- if (!ids.length) {
155
- // remove highlight
156
- selection
157
- .transition('highlight')
158
- .duration(200)
159
- .style('opacity', 1)
160
- return
161
- }
162
-
163
- selection
164
- .each((d, i, n) => {
165
- if (ids.includes(d.data.id)) {
166
- d3.select(n[i])
167
- .style('opacity', 1)
168
- } else {
169
- d3.select(n[i])
170
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
171
- }
172
- })
173
- }
174
-
175
- export const TreeMap = defineTreePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
176
- const destroy$ = new Subject()
177
-
178
- const treeData$ = combineLatest({
179
- layout: observer.layout$,
180
- visibleComputedData: observer.visibleComputedData$,
181
- fullParams: observer.fullParams$,
182
- fullDataFormatter: observer.fullDataFormatter$,
183
- fullChartParams: observer.fullChartParams$
184
- }).pipe(
185
- takeUntil(destroy$),
186
- switchMap(async d => d),
187
- map(data => {
188
- const treemap = d3.treemap()
189
- .size([data.layout.width, data.layout.height])
190
- .paddingInner(data.fullParams.paddingInner)
191
- .paddingOuter(data.fullParams.paddingOuter)
192
- .round(true)
193
- .tile(d3.treemapSquarify.ratio(data.fullParams.squarifyRatio))
194
-
195
- const root = d3.hierarchy(data.visibleComputedData)
196
- .sum(d => d.value)
197
- .sort(data.fullParams.sort as (a: any, b: any) => number)
198
-
199
- //call treemap
200
- treemap(root)
201
-
202
- const treeData: d3.HierarchyRectangularNode<ComputedDataTree>[] = root.leaves() as any
203
-
204
- return treeData
205
- })
206
- )
207
-
208
- const cellSelection$ = combineLatest({
209
- selection: of(selection),
210
- treeData: treeData$,
211
- fullParams: observer.fullParams$,
212
- fullChartParams: observer.fullChartParams$,
213
- textSizePx: observer.textSizePx$
214
- }).pipe(
215
- takeUntil(destroy$),
216
- switchMap(async d => d),
217
- map(data => {
218
- return renderTree({
219
- selection,
220
- treeData: data.treeData,
221
- fullParams: data.fullParams,
222
- fullChartParams: data.fullChartParams,
223
- textSizePx: data.textSizePx
224
- })
225
- })
226
- )
227
-
228
- const highlightTarget$ = observer.fullChartParams$.pipe(
229
- takeUntil(destroy$),
230
- map(d => d.highlightTarget),
231
- distinctUntilChanged()
232
- )
233
-
234
- combineLatest({
235
- cellSelection: cellSelection$,
236
- computedData: observer.computedData$,
237
- treeData: treeData$,
238
- fullParams: observer.fullParams$,
239
- fullChartParams: observer.fullChartParams$,
240
- highlightTarget: highlightTarget$,
241
- CategoryDataMap: observer.CategoryDataMap$,
242
- }).pipe(
243
- takeUntil(destroy$),
244
- switchMap(async d => d)
245
- ).subscribe(data => {
246
- data.cellSelection
247
- .on('mouseover', (event, datum) => {
248
- event.stopPropagation()
249
-
250
- subject.event$.next({
251
- type: 'tree',
252
- eventName: 'mouseover',
253
- pluginName,
254
- highlightTarget: data.highlightTarget,
255
- datum: datum.data,
256
- category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
257
- categoryIndex: datum.data.categoryIndex,
258
- categoryLabel: datum.data.categoryLabel,
259
- event,
260
- data: data.computedData
261
- })
262
- })
263
- .on('mousemove', (event, datum) => {
264
- event.stopPropagation()
265
-
266
- subject.event$.next({
267
- type: 'tree',
268
- eventName: 'mousemove',
269
- pluginName,
270
- highlightTarget: data.highlightTarget,
271
- datum: datum.data,
272
- category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
273
- categoryIndex: datum.data.categoryIndex,
274
- categoryLabel: datum.data.categoryLabel,
275
- event,
276
- data: data.computedData
277
- })
278
- })
279
- .on('mouseout', (event, datum) => {
280
- event.stopPropagation()
281
-
282
- subject.event$.next({
283
- type: 'tree',
284
- eventName: 'mouseout',
285
- pluginName,
286
- highlightTarget: data.highlightTarget,
287
- datum: datum.data,
288
- category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
289
- categoryIndex: datum.data.categoryIndex,
290
- categoryLabel: datum.data.categoryLabel,
291
- event,
292
- data: data.computedData
293
- })
294
- })
295
- .on('click', (event, datum) => {
296
- event.stopPropagation()
297
-
298
- subject.event$.next({
299
- type: 'tree',
300
- eventName: 'click',
301
- pluginName,
302
- highlightTarget: data.highlightTarget,
303
- datum: datum.data,
304
- category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
305
- categoryIndex: datum.data.categoryIndex,
306
- categoryLabel: datum.data.categoryLabel,
307
- event,
308
- data: data.computedData
309
- })
310
- })
311
- })
312
-
313
- combineLatest({
314
- cellSelection: cellSelection$,
315
- highlight: observer.treeHighlight$.pipe(
316
- map(data => data.map(d => d.id))
317
- ),
318
- fullChartParams: observer.fullChartParams$
319
- }).pipe(
320
- takeUntil(destroy$),
321
- switchMap(async d => d)
322
- ).subscribe(data => {
323
- highlight({
324
- selection: data.cellSelection,
325
- ids: data.highlight,
326
- fullChartParams: data.fullChartParams
327
- })
328
- })
329
-
330
- return () => {
331
- destroy$.next(undefined)
332
- }
333
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Subject,
4
+ Observable,
5
+ of,
6
+ takeUntil,
7
+ map,
8
+ switchMap,
9
+ combineLatest,
10
+ debounceTime,
11
+ distinctUntilChanged } from 'rxjs'
12
+ import type { DefinePluginConfig } from '../../../lib/core-types'
13
+ import {
14
+ defineTreePlugin } from '../../../lib/core'
15
+ import type { Layout, ComputedDataTree, DataFormatterTree, ChartParams } from '../../../lib/core-types'
16
+ import type { TreeMapParams } from '../types'
17
+ import { DEFAULT_TREE_MAP_PARAMS } from '../defaults'
18
+ import { getClassName, getColor } from '../../utils/orbchartsUtils'
19
+ import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
20
+
21
+ const pluginName = 'TreeMap'
22
+ const treeClassName = getClassName(pluginName, 'tree')
23
+ const tileClassName = getClassName(pluginName, 'tile')
24
+
25
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_TREE_MAP_PARAMS> = {
26
+ name: pluginName,
27
+ defaultParams: DEFAULT_TREE_MAP_PARAMS,
28
+ layerIndex: LAYER_INDEX_OF_GRAPHIC,
29
+ validator: (params, { validateColumns }) => {
30
+ const result = validateColumns(params, {
31
+ paddingInner: {
32
+ toBeTypes: ['number']
33
+ },
34
+ paddingOuter: {
35
+ toBeTypes: ['number']
36
+ },
37
+ labelColorType: {
38
+ toBeOption: 'ColorType'
39
+ },
40
+ squarifyRatio: {
41
+ toBeTypes: ['number']
42
+ },
43
+ sort: {
44
+ toBeTypes: ['Function']
45
+ }
46
+ })
47
+ return result
48
+ }
49
+ }
50
+
51
+ function renderTree ({ selection, treeData, fullParams, fullChartParams, textSizePx }: {
52
+ selection: d3.Selection<any, any, any, any>
53
+ treeData: d3.HierarchyRectangularNode<ComputedDataTree>[]
54
+ fullParams: TreeMapParams
55
+ fullChartParams: ChartParams
56
+ textSizePx: number
57
+ }) {
58
+ const padding = textSizePx / 2
59
+ const lineHeight = textSizePx // 行高
60
+
61
+ const cell = selection.selectAll<SVGGElement, d3.HierarchyRectangularNode<ComputedDataTree>>(`g.${treeClassName}`)
62
+ .data(treeData, d => d.data.id)
63
+ .join('g')
64
+ .attr('class', treeClassName)
65
+
66
+ cell
67
+ // .transition()
68
+ // .duration(fullChartParams.transitionDuration)
69
+ .attr('transform', (d) => !d.x0 || !d.y0 ? null : `translate(${d.x0},${d.y0})`)
70
+ .each((d, i, nodes) => {
71
+ const eachCell = d3.select(nodes[i])
72
+
73
+ const tile = eachCell
74
+ .selectAll<SVGRectElement, d3.HierarchyRectangularNode<ComputedDataTree>>(`rect.${tileClassName}`)
75
+ .data([d], d => d.data.id)
76
+ .join('rect')
77
+ .attr("id", d => d.data.id)
78
+ .attr("class", tileClassName)
79
+ .attr('cursor', 'pointer')
80
+ .attr("width", (d) => d.x1 - d.x0)
81
+ .attr("height", (d) => d.y1 - d.y0)
82
+ .attr('fill', d => d.data.color)
83
+ .attr('data-name', d => d.data.label)
84
+ .attr('data-category', d => d.data.categoryLabel)
85
+ .attr('data-value', d => d.data.value)
86
+
87
+ const label = eachCell
88
+ .selectAll('g')
89
+ .data([d])
90
+ .join('g')
91
+ .each((d, i, nodes) => {
92
+ const eachLabel = d3.select(nodes[i])
93
+ const text = eachLabel
94
+ .selectAll('text')
95
+ .data([d])
96
+ .join('text')
97
+ .text(d => d.data.label)
98
+ .attr('dominant-baseline', 'hanging')
99
+ .attr("x", padding)
100
+ .attr("y", padding)
101
+ .attr('font-size', fullChartParams.styles.textSize)
102
+ .each(function(d) {
103
+ // -- tspan(自動斷行) --
104
+ const textElement = d3.select(this);
105
+ const words = d.data.label.split(/\s+/).reverse() // 以空隔分割字串
106
+ let word;
107
+ let line: string[] = []
108
+ const x = textElement.attr("x")
109
+ let y = textElement.attr("y")
110
+ let dy = 0
111
+ let tspan = textElement
112
+ .text(null)
113
+ .append("tspan")
114
+ .attr('cursor', 'pointer')
115
+ .attr('fill', getColor(fullParams.labelColorType, fullChartParams))
116
+ .attr('font-size', fullChartParams.styles.textSize)
117
+ .attr("x", x)
118
+ .attr("y", y)
119
+
120
+ while (word = words.pop()) {
121
+ line.push(word)
122
+ tspan.text(line.join(" "))
123
+ if (tspan.node().getComputedTextLength() > (d.x1 - d.x0 - padding)) {
124
+ line.pop()
125
+ tspan.text(line.join(" "))
126
+ line = [word]
127
+ dy += lineHeight
128
+ tspan = textElement
129
+ .append("tspan")
130
+ .attr('cursor', 'pointer')
131
+ .attr('fill', getColor(fullParams.labelColorType, fullChartParams))
132
+ .attr('font-size', fullChartParams.styles.textSize)
133
+ .attr("x", x)
134
+ .attr("y", y)
135
+ .attr("dy", dy + "px")
136
+ .text(word)
137
+ }
138
+ }
139
+ })
140
+ })
141
+
142
+ })
143
+
144
+ return cell
145
+ }
146
+
147
+ function highlight ({ selection, ids, fullChartParams }: {
148
+ selection: d3.Selection<any, d3.HierarchyRectangularNode<ComputedDataTree>, any, any>
149
+ ids: string[]
150
+ fullChartParams: ChartParams
151
+ }) {
152
+ selection.interrupt('highlight')
153
+
154
+ if (!ids.length) {
155
+ // remove highlight
156
+ selection
157
+ .transition('highlight')
158
+ .duration(200)
159
+ .style('opacity', 1)
160
+ return
161
+ }
162
+
163
+ selection
164
+ .each((d, i, n) => {
165
+ if (ids.includes(d.data.id)) {
166
+ d3.select(n[i])
167
+ .style('opacity', 1)
168
+ } else {
169
+ d3.select(n[i])
170
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
171
+ }
172
+ })
173
+ }
174
+
175
+ export const TreeMap = defineTreePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
176
+ const destroy$ = new Subject()
177
+
178
+ const treeData$ = combineLatest({
179
+ layout: observer.layout$,
180
+ visibleComputedData: observer.visibleComputedData$,
181
+ fullParams: observer.fullParams$,
182
+ fullDataFormatter: observer.fullDataFormatter$,
183
+ fullChartParams: observer.fullChartParams$
184
+ }).pipe(
185
+ takeUntil(destroy$),
186
+ switchMap(async d => d),
187
+ map(data => {
188
+ const treemap = d3.treemap()
189
+ .size([data.layout.width, data.layout.height])
190
+ .paddingInner(data.fullParams.paddingInner)
191
+ .paddingOuter(data.fullParams.paddingOuter)
192
+ .round(true)
193
+ .tile(d3.treemapSquarify.ratio(data.fullParams.squarifyRatio))
194
+
195
+ const root = d3.hierarchy(data.visibleComputedData)
196
+ .sum(d => d.value)
197
+ .sort(data.fullParams.sort as (a: any, b: any) => number)
198
+
199
+ //call treemap
200
+ treemap(root)
201
+
202
+ const treeData: d3.HierarchyRectangularNode<ComputedDataTree>[] = root.leaves() as any
203
+
204
+ return treeData
205
+ })
206
+ )
207
+
208
+ const cellSelection$ = combineLatest({
209
+ selection: of(selection),
210
+ treeData: treeData$,
211
+ fullParams: observer.fullParams$,
212
+ fullChartParams: observer.fullChartParams$,
213
+ textSizePx: observer.textSizePx$
214
+ }).pipe(
215
+ takeUntil(destroy$),
216
+ switchMap(async d => d),
217
+ map(data => {
218
+ return renderTree({
219
+ selection,
220
+ treeData: data.treeData,
221
+ fullParams: data.fullParams,
222
+ fullChartParams: data.fullChartParams,
223
+ textSizePx: data.textSizePx
224
+ })
225
+ })
226
+ )
227
+
228
+ const highlightTarget$ = observer.fullChartParams$.pipe(
229
+ takeUntil(destroy$),
230
+ map(d => d.highlightTarget),
231
+ distinctUntilChanged()
232
+ )
233
+
234
+ combineLatest({
235
+ cellSelection: cellSelection$,
236
+ computedData: observer.computedData$,
237
+ treeData: treeData$,
238
+ fullParams: observer.fullParams$,
239
+ fullChartParams: observer.fullChartParams$,
240
+ highlightTarget: highlightTarget$,
241
+ CategoryDataMap: observer.CategoryDataMap$,
242
+ }).pipe(
243
+ takeUntil(destroy$),
244
+ switchMap(async d => d)
245
+ ).subscribe(data => {
246
+ data.cellSelection
247
+ .on('mouseover', (event, datum) => {
248
+ event.stopPropagation()
249
+
250
+ subject.event$.next({
251
+ type: 'tree',
252
+ eventName: 'mouseover',
253
+ pluginName,
254
+ highlightTarget: data.highlightTarget,
255
+ datum: datum.data,
256
+ category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
257
+ categoryIndex: datum.data.categoryIndex,
258
+ categoryLabel: datum.data.categoryLabel,
259
+ event,
260
+ data: data.computedData
261
+ })
262
+ })
263
+ .on('mousemove', (event, datum) => {
264
+ event.stopPropagation()
265
+
266
+ subject.event$.next({
267
+ type: 'tree',
268
+ eventName: 'mousemove',
269
+ pluginName,
270
+ highlightTarget: data.highlightTarget,
271
+ datum: datum.data,
272
+ category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
273
+ categoryIndex: datum.data.categoryIndex,
274
+ categoryLabel: datum.data.categoryLabel,
275
+ event,
276
+ data: data.computedData
277
+ })
278
+ })
279
+ .on('mouseout', (event, datum) => {
280
+ event.stopPropagation()
281
+
282
+ subject.event$.next({
283
+ type: 'tree',
284
+ eventName: 'mouseout',
285
+ pluginName,
286
+ highlightTarget: data.highlightTarget,
287
+ datum: datum.data,
288
+ category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
289
+ categoryIndex: datum.data.categoryIndex,
290
+ categoryLabel: datum.data.categoryLabel,
291
+ event,
292
+ data: data.computedData
293
+ })
294
+ })
295
+ .on('click', (event, datum) => {
296
+ event.stopPropagation()
297
+
298
+ subject.event$.next({
299
+ type: 'tree',
300
+ eventName: 'click',
301
+ pluginName,
302
+ highlightTarget: data.highlightTarget,
303
+ datum: datum.data,
304
+ category: data.CategoryDataMap.get(datum.data.categoryLabel)!,
305
+ categoryIndex: datum.data.categoryIndex,
306
+ categoryLabel: datum.data.categoryLabel,
307
+ event,
308
+ data: data.computedData
309
+ })
310
+ })
311
+ })
312
+
313
+ combineLatest({
314
+ cellSelection: cellSelection$,
315
+ highlight: observer.treeHighlight$.pipe(
316
+ map(data => data.map(d => d.id))
317
+ ),
318
+ fullChartParams: observer.fullChartParams$
319
+ }).pipe(
320
+ takeUntil(destroy$),
321
+ switchMap(async d => d)
322
+ ).subscribe(data => {
323
+ highlight({
324
+ selection: data.cellSelection,
325
+ ids: data.highlight,
326
+ fullChartParams: data.fullChartParams
327
+ })
328
+ })
329
+
330
+ return () => {
331
+ destroy$.next(undefined)
332
+ }
333
+ })