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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +2863 -2860
  3. package/dist/orbcharts-plugins-basic.umd.js +46 -46
  4. package/lib/core-types.ts +7 -7
  5. package/lib/core.ts +6 -6
  6. package/lib/plugins-basic-types.ts +6 -6
  7. package/package.json +44 -44
  8. package/src/base/BaseBarStack.ts +780 -780
  9. package/src/base/BaseBars.ts +765 -765
  10. package/src/base/BaseBarsTriangle.ts +674 -674
  11. package/src/base/BaseDots.ts +515 -515
  12. package/src/base/BaseGroupAxis.ts +679 -679
  13. package/src/base/BaseLegend.ts +680 -680
  14. package/src/base/BaseLineAreas.ts +629 -629
  15. package/src/base/BaseLines.ts +706 -706
  16. package/src/base/BaseTooltip.ts +385 -382
  17. package/src/base/BaseValueAxis.ts +580 -580
  18. package/src/base/types.ts +2 -2
  19. package/src/const.ts +30 -30
  20. package/src/grid/defaults.ts +244 -244
  21. package/src/grid/gridObservables.ts +545 -545
  22. package/src/grid/index.ts +16 -16
  23. package/src/grid/plugins/BarStack.ts +64 -64
  24. package/src/grid/plugins/Bars.ts +69 -69
  25. package/src/grid/plugins/BarsPN.ts +66 -66
  26. package/src/grid/plugins/BarsTriangle.ts +73 -73
  27. package/src/grid/plugins/Dots.ts +68 -68
  28. package/src/grid/plugins/GridLegend.ts +107 -107
  29. package/src/grid/plugins/GridTooltip.ts +66 -66
  30. package/src/grid/plugins/GridZoom.ts +218 -218
  31. package/src/grid/plugins/GroupAux.ts +1098 -1098
  32. package/src/grid/plugins/GroupAxis.ts +97 -97
  33. package/src/grid/plugins/LineAreas.ts +65 -65
  34. package/src/grid/plugins/Lines.ts +59 -59
  35. package/src/grid/plugins/ValueAxis.ts +93 -93
  36. package/src/grid/plugins/ValueStackAxis.ts +95 -95
  37. package/src/index.ts +9 -9
  38. package/src/multiGrid/defaults.ts +224 -224
  39. package/src/multiGrid/index.ts +14 -14
  40. package/src/multiGrid/multiGridObservables.ts +49 -49
  41. package/src/multiGrid/plugins/MultiBarStack.ts +106 -106
  42. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  43. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  44. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  45. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  46. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  47. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  48. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  49. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  50. package/src/multiGrid/plugins/MultiValueAxis.ts +133 -133
  51. package/src/multiGrid/plugins/MultiValueStackAxis.ts +133 -133
  52. package/src/multiGrid/plugins/OverlappingValueAxes.ts +299 -299
  53. package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +298 -298
  54. package/src/noneData/defaults.ts +102 -102
  55. package/src/noneData/index.ts +3 -3
  56. package/src/noneData/plugins/Container.ts +27 -27
  57. package/src/noneData/plugins/Tooltip.ts +373 -373
  58. package/src/series/defaults.ts +206 -206
  59. package/src/series/index.ts +9 -9
  60. package/src/series/plugins/Bubbles.ts +603 -603
  61. package/src/series/plugins/Pie.ts +623 -623
  62. package/src/series/plugins/PieEventTexts.ts +283 -283
  63. package/src/series/plugins/PieLabels.ts +640 -640
  64. package/src/series/plugins/Rose.ts +516 -516
  65. package/src/series/plugins/RoseLabels.ts +600 -600
  66. package/src/series/plugins/SeriesLegend.ts +107 -107
  67. package/src/series/plugins/SeriesTooltip.ts +66 -66
  68. package/src/series/seriesObservables.ts +145 -145
  69. package/src/series/seriesUtils.ts +51 -51
  70. package/src/tree/defaults.ts +78 -78
  71. package/src/tree/index.ts +4 -4
  72. package/src/tree/plugins/TreeLegend.ts +107 -107
  73. package/src/tree/plugins/TreeMap.ts +333 -333
  74. package/src/tree/plugins/TreeTooltip.ts +66 -66
  75. package/src/utils/commonUtils.ts +21 -21
  76. package/src/utils/d3Graphics.ts +174 -174
  77. package/src/utils/d3Utils.ts +73 -73
  78. package/src/utils/observables.ts +14 -14
  79. package/src/utils/orbchartsUtils.ts +100 -100
  80. package/tsconfig.base.json +13 -13
  81. package/tsconfig.json +2 -2
  82. 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 '../../../lib/plugins-basic-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 '../../../lib/plugins-basic-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
+ })