@orbcharts/plugins-basic 3.0.5 → 3.0.7

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 (116) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +3414 -3390
  3. package/dist/orbcharts-plugins-basic.umd.js +35 -35
  4. package/lib/core-types.ts +7 -7
  5. package/lib/core.ts +6 -6
  6. package/lib/gridObservables.ts +6 -6
  7. package/lib/plugins-basic-types.ts +6 -6
  8. package/package.json +48 -48
  9. package/src/base/BaseBars.ts +765 -765
  10. package/src/base/BaseBarsTriangle.ts +676 -676
  11. package/src/base/BaseDots.ts +464 -464
  12. package/src/base/BaseGroupAxis.ts +691 -691
  13. package/src/base/BaseLegend.ts +684 -684
  14. package/src/base/BaseLineAreas.ts +629 -629
  15. package/src/base/BaseLines.ts +706 -706
  16. package/src/base/BaseOrdinalBubbles.ts +729 -729
  17. package/src/base/BaseRacingBars.ts +582 -582
  18. package/src/base/BaseRacingLabels.ts +404 -404
  19. package/src/base/BaseRacingValueLabels.ts +403 -403
  20. package/src/base/BaseStackedBars.ts +782 -782
  21. package/src/base/BaseTooltip.ts +408 -386
  22. package/src/base/BaseValueAxis.ts +600 -600
  23. package/src/base/BaseXAxis.ts +427 -427
  24. package/src/base/BaseXZoom.ts +241 -241
  25. package/src/base/BaseYAxis.ts +389 -389
  26. package/src/base/types.ts +2 -2
  27. package/src/const.ts +30 -30
  28. package/src/grid/defaults.ts +213 -213
  29. package/src/grid/gridObservables.ts +635 -635
  30. package/src/grid/index.ts +16 -16
  31. package/src/grid/plugins/Bars.ts +69 -69
  32. package/src/grid/plugins/BarsPN.ts +66 -66
  33. package/src/grid/plugins/BarsTriangle.ts +73 -73
  34. package/src/grid/plugins/Dots.ts +68 -68
  35. package/src/grid/plugins/GridLegend.ts +107 -107
  36. package/src/grid/plugins/GridTooltip.ts +66 -66
  37. package/src/grid/plugins/GroupAux.ts +1095 -1095
  38. package/src/grid/plugins/GroupAxis.ts +73 -73
  39. package/src/grid/plugins/GroupZoom.ts +218 -218
  40. package/src/grid/plugins/LineAreas.ts +65 -65
  41. package/src/grid/plugins/Lines.ts +59 -59
  42. package/src/grid/plugins/StackedBars.ts +64 -64
  43. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  44. package/src/grid/plugins/ValueAxis.ts +94 -94
  45. package/src/index.ts +6 -6
  46. package/src/multiGrid/defaults.ts +244 -244
  47. package/src/multiGrid/index.ts +14 -14
  48. package/src/multiGrid/multiGridObservables.ts +50 -50
  49. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  50. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  51. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  52. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -169
  53. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  54. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  55. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  56. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  57. package/src/multiGrid/plugins/MultiStackedBars.ts +106 -106
  58. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  59. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  60. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +300 -300
  61. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  62. package/src/multiValue/defaults.ts +523 -523
  63. package/src/multiValue/index.ts +16 -16
  64. package/src/multiValue/multiValueObservables.ts +781 -781
  65. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  66. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  67. package/src/multiValue/plugins/OrdinalAux.ts +660 -660
  68. package/src/multiValue/plugins/OrdinalAxis.ts +524 -524
  69. package/src/multiValue/plugins/OrdinalBubbles.ts +226 -226
  70. package/src/multiValue/plugins/OrdinalZoom.ts +57 -57
  71. package/src/multiValue/plugins/RacingBars.ts +375 -375
  72. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -300
  73. package/src/multiValue/plugins/RacingValueAxis.ts +114 -114
  74. package/src/multiValue/plugins/Scatter.ts +486 -486
  75. package/src/multiValue/plugins/ScatterBubbles.ts +635 -635
  76. package/src/multiValue/plugins/XAxis.ts +107 -107
  77. package/src/multiValue/plugins/XYAux.ts +683 -683
  78. package/src/multiValue/plugins/XYAxes.ts +194 -194
  79. package/src/multiValue/plugins/XYAxes_legacy.ts +683 -683
  80. package/src/multiValue/plugins/XZoom.ts +40 -40
  81. package/src/noneData/defaults.ts +102 -102
  82. package/src/noneData/index.ts +3 -3
  83. package/src/noneData/plugins/Container.ts +27 -27
  84. package/src/noneData/plugins/Tooltip.ts +373 -373
  85. package/src/relationship/defaults.ts +221 -221
  86. package/src/relationship/index.ts +5 -5
  87. package/src/relationship/plugins/ForceDirected.ts +1056 -1056
  88. package/src/relationship/plugins/ForceDirectedBubbles.ts +1294 -1294
  89. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  90. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  91. package/src/relationship/relationshipObservables.ts +49 -49
  92. package/src/series/defaults.ts +223 -222
  93. package/src/series/index.ts +9 -9
  94. package/src/series/plugins/Bubbles.ts +784 -766
  95. package/src/series/plugins/Pie.ts +622 -622
  96. package/src/series/plugins/PieEventTexts.ts +283 -283
  97. package/src/series/plugins/PieLabels.ts +639 -639
  98. package/src/series/plugins/Rose.ts +515 -515
  99. package/src/series/plugins/RoseLabels.ts +599 -599
  100. package/src/series/plugins/SeriesLegend.ts +107 -107
  101. package/src/series/plugins/SeriesTooltip.ts +66 -66
  102. package/src/series/seriesObservables.ts +168 -168
  103. package/src/series/seriesUtils.ts +51 -51
  104. package/src/tree/defaults.ts +102 -102
  105. package/src/tree/index.ts +4 -4
  106. package/src/tree/plugins/TreeLegend.ts +100 -100
  107. package/src/tree/plugins/TreeMap.ts +341 -341
  108. package/src/tree/plugins/TreeTooltip.ts +66 -66
  109. package/src/utils/commonUtils.ts +31 -31
  110. package/src/utils/d3Graphics.ts +176 -176
  111. package/src/utils/d3Utils.ts +92 -92
  112. package/src/utils/observables.ts +14 -14
  113. package/src/utils/orbchartsUtils.ts +129 -129
  114. package/tsconfig.base.json +13 -13
  115. package/tsconfig.json +2 -2
  116. package/vite.config.js +22 -22
@@ -1,168 +1,168 @@
1
- import * as d3 from 'd3'
2
- import {
3
- Observable,
4
- Subject,
5
- of,
6
- takeUntil,
7
- filter,
8
- first,
9
- map,
10
- switchMap,
11
- combineLatest,
12
- merge,
13
- shareReplay,
14
- distinctUntilChanged
15
- } from 'rxjs'
16
- import type {
17
- ContainerPosition,
18
- ComputedDatumSeries } from '../../lib/core-types'
19
- import { getClassName, getUniID } from '../utils/orbchartsUtils'
20
-
21
- function createSeriesSelection ({ selection, pluginName, visibleComputedSortedData$ }: {
22
- selection: d3.Selection<any, unknown, any, unknown>
23
- pluginName: string
24
- // separateSeries$: Observable<boolean>
25
- // separateLabel$: Observable<boolean>
26
- // seriesLabels$: Observable<string[]>
27
- // datumLabels$: Observable<string[]>
28
- visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
29
- }) {
30
- const seriesClassName = getClassName(pluginName, 'series')
31
-
32
- return visibleComputedSortedData$.pipe(
33
- map(data => data.map(series => series[0] ? `${series[0].seriesLabel}_${series[0].label}` : '')),
34
- distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
35
- map(data => {
36
- return selection
37
- .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
38
- .data(data, d => d)
39
- .join(
40
- enter => {
41
- return enter
42
- .append('g')
43
- .classed(seriesClassName, true)
44
- },
45
- update => update,
46
- exit => exit.remove()
47
- )
48
- }),
49
- shareReplay(1)
50
- )
51
-
52
-
53
- // return combineLatest({
54
- // seriesLabels: seriesLabels$,
55
- // separateSeries: separateSeries$
56
- // }).pipe(
57
- // switchMap(async d => d),
58
- // map((data, i) => {
59
- // const selectionData = data.separateSeries ? data.seriesLabels : [data.seriesLabels.join('')]
60
- // return selection
61
- // .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
62
- // .data(selectionData, d => d)
63
- // .join(
64
- // enter => {
65
- // return enter
66
- // .append('g')
67
- // .classed(seriesClassName, true)
68
- // },
69
- // update => update,
70
- // exit => exit.remove()
71
- // )
72
- // }),
73
- // shareReplay(1)
74
- // )
75
- }
76
-
77
- // series選取器,以起始座標位置為基準
78
- export const seriesStartSelectionObservable = ({ selection, pluginName, visibleComputedSortedData$, seriesContainerPosition$ }: {
79
- selection: d3.Selection<any, unknown, any, unknown>
80
- pluginName: string
81
- visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
82
- seriesContainerPosition$: Observable<ContainerPosition[]>
83
- }) => {
84
-
85
- const seriesStartSelection$ = createSeriesSelection({ selection, pluginName, visibleComputedSortedData$ })
86
-
87
- combineLatest({
88
- seriesStartSelection: seriesStartSelection$,
89
- seriesContainerPosition: seriesContainerPosition$
90
- }).pipe(
91
- switchMap(async d => d),
92
- // selection數量不同的時候才執行
93
- distinctUntilChanged((a, b) => a.seriesContainerPosition.length === b.seriesContainerPosition.length)
94
- ).subscribe(data => {
95
- // 無transition動畫
96
- data.seriesStartSelection
97
- .attr('transform', (d, i) => {
98
- const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
99
- return `translate(${seriesContainerPosition.startX}, ${seriesContainerPosition.startY})`
100
- })
101
- })
102
-
103
- combineLatest({
104
- seriesStartSelection: seriesStartSelection$,
105
- seriesContainerPosition: seriesContainerPosition$
106
- }).pipe(
107
- switchMap(async d => d),
108
- ).subscribe(data => {
109
- // 有transition動畫
110
- data.seriesStartSelection
111
- .transition()
112
- .attr('transform', (d, i) => {
113
- const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
114
- return `translate(${seriesContainerPosition.startX}, ${seriesContainerPosition.startY})`
115
- })
116
- })
117
-
118
- return {
119
- seriesStartSelection$
120
- }
121
- }
122
-
123
- // series選取器,以中心座標位置為基準
124
- export const seriesCenterSelectionObservable = ({ selection, pluginName, visibleComputedSortedData$, seriesContainerPosition$ }: {
125
- selection: d3.Selection<any, unknown, any, unknown>
126
- pluginName: string
127
- visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
128
- seriesContainerPosition$: Observable<ContainerPosition[]>
129
- }) => {
130
-
131
- const seriesCenterSelection$ = createSeriesSelection({ selection, pluginName, visibleComputedSortedData$ })
132
-
133
- combineLatest({
134
- seriesCenterSelection: seriesCenterSelection$,
135
- seriesContainerPosition: seriesContainerPosition$
136
- }).pipe(
137
- switchMap(async d => d),
138
- // selection數量相同的時候才執行
139
- distinctUntilChanged((a, b) => a.seriesContainerPosition.length === b.seriesContainerPosition.length)
140
- ).subscribe(data => {
141
- // 無transition動畫
142
- data.seriesCenterSelection
143
- .attr('transform', (d, i) => {
144
- const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
145
- return `translate(${seriesContainerPosition.centerX}, ${seriesContainerPosition.centerY})`
146
- })
147
- })
148
-
149
- combineLatest({
150
- seriesCenterSelection: seriesCenterSelection$,
151
- seriesContainerPosition: seriesContainerPosition$
152
- }).pipe(
153
- switchMap(async d => d),
154
- ).subscribe(data => {
155
- // 有transition動畫
156
- data.seriesCenterSelection
157
- .transition()
158
- .attr('transform', (d, i) => {
159
- const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
160
- return `translate(${seriesContainerPosition.centerX}, ${seriesContainerPosition.centerY})`
161
- })
162
- })
163
-
164
- return {
165
- seriesCenterSelection$,
166
- }
167
- }
168
-
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Observable,
4
+ Subject,
5
+ of,
6
+ takeUntil,
7
+ filter,
8
+ first,
9
+ map,
10
+ switchMap,
11
+ combineLatest,
12
+ merge,
13
+ shareReplay,
14
+ distinctUntilChanged
15
+ } from 'rxjs'
16
+ import type {
17
+ ContainerPosition,
18
+ ComputedDatumSeries } from '../../lib/core-types'
19
+ import { getClassName, getUniID } from '../utils/orbchartsUtils'
20
+
21
+ function createSeriesSelection ({ selection, pluginName, visibleComputedSortedData$ }: {
22
+ selection: d3.Selection<any, unknown, any, unknown>
23
+ pluginName: string
24
+ // separateSeries$: Observable<boolean>
25
+ // separateLabel$: Observable<boolean>
26
+ // seriesLabels$: Observable<string[]>
27
+ // datumLabels$: Observable<string[]>
28
+ visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
29
+ }) {
30
+ const seriesClassName = getClassName(pluginName, 'series')
31
+
32
+ return visibleComputedSortedData$.pipe(
33
+ map(data => data.map(series => series[0] ? `${series[0].seriesLabel}_${series[0].label}` : '')),
34
+ distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
35
+ map(data => {
36
+ return selection
37
+ .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
38
+ .data(data, d => d)
39
+ .join(
40
+ enter => {
41
+ return enter
42
+ .append('g')
43
+ .classed(seriesClassName, true)
44
+ },
45
+ update => update,
46
+ exit => exit.remove()
47
+ )
48
+ }),
49
+ shareReplay(1)
50
+ )
51
+
52
+
53
+ // return combineLatest({
54
+ // seriesLabels: seriesLabels$,
55
+ // separateSeries: separateSeries$
56
+ // }).pipe(
57
+ // switchMap(async d => d),
58
+ // map((data, i) => {
59
+ // const selectionData = data.separateSeries ? data.seriesLabels : [data.seriesLabels.join('')]
60
+ // return selection
61
+ // .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
62
+ // .data(selectionData, d => d)
63
+ // .join(
64
+ // enter => {
65
+ // return enter
66
+ // .append('g')
67
+ // .classed(seriesClassName, true)
68
+ // },
69
+ // update => update,
70
+ // exit => exit.remove()
71
+ // )
72
+ // }),
73
+ // shareReplay(1)
74
+ // )
75
+ }
76
+
77
+ // series選取器,以起始座標位置為基準
78
+ export const seriesStartSelectionObservable = ({ selection, pluginName, visibleComputedSortedData$, seriesContainerPosition$ }: {
79
+ selection: d3.Selection<any, unknown, any, unknown>
80
+ pluginName: string
81
+ visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
82
+ seriesContainerPosition$: Observable<ContainerPosition[]>
83
+ }) => {
84
+
85
+ const seriesStartSelection$ = createSeriesSelection({ selection, pluginName, visibleComputedSortedData$ })
86
+
87
+ combineLatest({
88
+ seriesStartSelection: seriesStartSelection$,
89
+ seriesContainerPosition: seriesContainerPosition$
90
+ }).pipe(
91
+ switchMap(async d => d),
92
+ // selection數量不同的時候才執行
93
+ distinctUntilChanged((a, b) => a.seriesContainerPosition.length === b.seriesContainerPosition.length)
94
+ ).subscribe(data => {
95
+ // 無transition動畫
96
+ data.seriesStartSelection
97
+ .attr('transform', (d, i) => {
98
+ const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
99
+ return `translate(${seriesContainerPosition.startX}, ${seriesContainerPosition.startY})`
100
+ })
101
+ })
102
+
103
+ combineLatest({
104
+ seriesStartSelection: seriesStartSelection$,
105
+ seriesContainerPosition: seriesContainerPosition$
106
+ }).pipe(
107
+ switchMap(async d => d),
108
+ ).subscribe(data => {
109
+ // 有transition動畫
110
+ data.seriesStartSelection
111
+ .transition()
112
+ .attr('transform', (d, i) => {
113
+ const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
114
+ return `translate(${seriesContainerPosition.startX}, ${seriesContainerPosition.startY})`
115
+ })
116
+ })
117
+
118
+ return {
119
+ seriesStartSelection$
120
+ }
121
+ }
122
+
123
+ // series選取器,以中心座標位置為基準
124
+ export const seriesCenterSelectionObservable = ({ selection, pluginName, visibleComputedSortedData$, seriesContainerPosition$ }: {
125
+ selection: d3.Selection<any, unknown, any, unknown>
126
+ pluginName: string
127
+ visibleComputedSortedData$: Observable<ComputedDatumSeries[][]>
128
+ seriesContainerPosition$: Observable<ContainerPosition[]>
129
+ }) => {
130
+
131
+ const seriesCenterSelection$ = createSeriesSelection({ selection, pluginName, visibleComputedSortedData$ })
132
+
133
+ combineLatest({
134
+ seriesCenterSelection: seriesCenterSelection$,
135
+ seriesContainerPosition: seriesContainerPosition$
136
+ }).pipe(
137
+ switchMap(async d => d),
138
+ // selection數量相同的時候才執行
139
+ distinctUntilChanged((a, b) => a.seriesContainerPosition.length === b.seriesContainerPosition.length)
140
+ ).subscribe(data => {
141
+ // 無transition動畫
142
+ data.seriesCenterSelection
143
+ .attr('transform', (d, i) => {
144
+ const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
145
+ return `translate(${seriesContainerPosition.centerX}, ${seriesContainerPosition.centerY})`
146
+ })
147
+ })
148
+
149
+ combineLatest({
150
+ seriesCenterSelection: seriesCenterSelection$,
151
+ seriesContainerPosition: seriesContainerPosition$
152
+ }).pipe(
153
+ switchMap(async d => d),
154
+ ).subscribe(data => {
155
+ // 有transition動畫
156
+ data.seriesCenterSelection
157
+ .transition()
158
+ .attr('transform', (d, i) => {
159
+ const seriesContainerPosition = data.seriesContainerPosition[i] ?? data.seriesContainerPosition[0]
160
+ return `translate(${seriesContainerPosition.centerX}, ${seriesContainerPosition.centerY})`
161
+ })
162
+ })
163
+
164
+ return {
165
+ seriesCenterSelection$,
166
+ }
167
+ }
168
+
@@ -1,52 +1,52 @@
1
- import * as d3 from 'd3'
2
- import type { ComputedDataSeries, ComputedDatumSeries, EventName, EventSeries, HighlightTarget } from '../../lib/core-types'
3
- // import type { D3PieDatum, PieDatum } from '../types'
4
-
5
- // 由d3.pie()建出來的資料格式
6
- export interface D3PieDatum {
7
- data: any
8
- index: number,
9
- value: number,
10
- startAngle: number,
11
- endAngle: number,
12
- padAngle: number,
13
- }
14
-
15
- export interface PieDatum extends D3PieDatum {
16
- data: ComputedDatumSeries
17
- id: string
18
- }
19
-
20
- export function makePieData ({ data, startAngle, endAngle }: {
21
- data: ComputedDatumSeries[]
22
- startAngle: number
23
- endAngle: number
24
- // itemLabels: string[]
25
- // arcLabels: string[]
26
- }): PieDatum[] {
27
- let pie = d3.pie<any, any>()
28
- .startAngle(startAngle)
29
- // .endAngle(startAngle + (endAngle - startAngle) * t)
30
- .endAngle(endAngle)
31
- .value(d => d.value)
32
- // .value((d) => d.visible == false ? 0 : d.value)
33
- // .sort(null) // 不要排序
34
- .sort((a, b) => a.seq - b.seq)
35
- // .sort((a: any, b: any) => {
36
- // return b.value - a.value
37
- // })
38
- // .sort(d3.ascending)
39
- const pieData = pie(data)
40
- return pieData.map((d: D3PieDatum, i: number) => {
41
- // const itemLabel = d.data.itemLabel
42
- let _d: any = d
43
- _d.id = d.data.id
44
- return _d
45
- // return {
46
- // ...d,
47
- // itemIndex: itemLabels.indexOf(itemLabel),
48
- // itemLabel,
49
- // id: d.data.id,
50
- // }
51
- })
1
+ import * as d3 from 'd3'
2
+ import type { ComputedDataSeries, ComputedDatumSeries, EventName, EventSeries, HighlightTarget } from '../../lib/core-types'
3
+ // import type { D3PieDatum, PieDatum } from '../types'
4
+
5
+ // 由d3.pie()建出來的資料格式
6
+ export interface D3PieDatum {
7
+ data: any
8
+ index: number,
9
+ value: number,
10
+ startAngle: number,
11
+ endAngle: number,
12
+ padAngle: number,
13
+ }
14
+
15
+ export interface PieDatum extends D3PieDatum {
16
+ data: ComputedDatumSeries
17
+ id: string
18
+ }
19
+
20
+ export function makePieData ({ data, startAngle, endAngle }: {
21
+ data: ComputedDatumSeries[]
22
+ startAngle: number
23
+ endAngle: number
24
+ // itemLabels: string[]
25
+ // arcLabels: string[]
26
+ }): PieDatum[] {
27
+ let pie = d3.pie<any, any>()
28
+ .startAngle(startAngle)
29
+ // .endAngle(startAngle + (endAngle - startAngle) * t)
30
+ .endAngle(endAngle)
31
+ .value(d => d.value)
32
+ // .value((d) => d.visible == false ? 0 : d.value)
33
+ // .sort(null) // 不要排序
34
+ .sort((a, b) => a.seq - b.seq)
35
+ // .sort((a: any, b: any) => {
36
+ // return b.value - a.value
37
+ // })
38
+ // .sort(d3.ascending)
39
+ const pieData = pie(data)
40
+ return pieData.map((d: D3PieDatum, i: number) => {
41
+ // const itemLabel = d.data.itemLabel
42
+ let _d: any = d
43
+ _d.id = d.data.id
44
+ return _d
45
+ // return {
46
+ // ...d,
47
+ // itemIndex: itemLabels.indexOf(itemLabel),
48
+ // itemLabel,
49
+ // id: d.data.id,
50
+ // }
51
+ })
52
52
  }
@@ -1,103 +1,103 @@
1
- import type { TreeMapParams, TreeLegendParams, TreeTooltipParams } from '../../lib/plugins-basic-types'
2
-
3
- export const DEFAULT_TREE_MAP_PARAMS: TreeMapParams = {
4
- paddingInner: 2,
5
- paddingOuter: 2,
6
- labelColorType: 'labelContrast',
7
- squarifyRatio: 1.618034, // 黃金比例
8
- sort: (a, b) => b.value - a.value
9
- }
10
- DEFAULT_TREE_MAP_PARAMS.sort.toString = () => `(a, b) => b.value - a.value`
11
-
12
- export const DEFAULT_TREE_LEGEND_PARAMS: TreeLegendParams = {
13
- // position: 'right',
14
- // justify: 'end',
15
- placement: 'right-end',
16
- padding: 28,
17
- backgroundFill: 'none',
18
- backgroundStroke: 'none',
19
- gap: 10,
20
- listRectWidth: 14,
21
- listRectHeight: 14,
22
- listRectRadius: 0,
23
- textColorType: 'primary'
24
- }
25
-
26
- export const DEFAULT_TREE_TOOLTIP_PARAMS: TreeTooltipParams = {
27
- backgroundColorType: 'background',
28
- strokeColorType: 'primary',
29
- backgroundOpacity: 0.8,
30
- textColorType: 'primary',
31
- offset: [20, 5],
32
- padding: 10,
33
- renderFn: (eventData, { styles, utils }) => {
34
- const hasCategoryLabel = eventData.categoryLabel ? true : false
35
- const hasDatumLabel = eventData.datum.label ? true : false
36
- const valueText = utils.toCurrency(eventData.datum.value)
37
- const bulletWidth = styles.textSizePx * 0.7
38
- const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
39
- const categorySvg = hasCategoryLabel
40
- ? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.datum.color}"></rect>
41
- <text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
42
- <tspan>${eventData.categoryLabel}</tspan>
43
- </text>`
44
- : ''
45
- const datumLabelSvg = hasDatumLabel
46
- ? `<tspan>${eventData.datum.label}</tspan> `
47
- : ''
48
- const categoryLabelTextWidth = hasCategoryLabel
49
- ? utils.measureTextWidth(`${eventData.categoryLabel}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
50
- : 0
51
- const datumLabelTextWidth = hasDatumLabel
52
- ? utils.measureTextWidth(`${eventData.datum.label}${valueText}`, styles.textSizePx)
53
- : 0
54
- const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
55
- const lineEndX = hasDatumLabel
56
- ? maxTextWidth + styles.textSizePx * 0.5
57
- : 0
58
- const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
59
- const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
60
- ${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
61
- </text>`
62
-
63
- return `${categorySvg}
64
- <g ${hasCategoryLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
65
- ${datumSvg}
66
- </g>`
67
- },
68
- }
69
- DEFAULT_TREE_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, utils }) => {
70
- const hasCategoryLabel = eventData.categoryLabel ? true : false
71
- const hasDatumLabel = eventData.datum.label ? true : false
72
- const valueText = utils.toCurrency(eventData.datum.value)
73
- const bulletWidth = styles.textSizePx * 0.7
74
- const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
75
- const categorySvg = hasCategoryLabel
76
- ? \`<rect width="\${bulletWidth}" height="\${bulletWidth}" x="\${offset}" y="\${offset - 1}" rx="\${bulletWidth / 2}" fill="\${eventData.datum.color}"></rect>
77
- <text x="\${styles.textSizePx * 1.5}" font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
78
- <tspan>\${eventData.categoryLabel}</tspan>
79
- </text>\`
80
- : ''
81
- const datumLabelSvg = hasDatumLabel
82
- ? \`<tspan>\${eventData.datum.label}</tspan> \`
83
- : ''
84
- const categoryLabelTextWidth = hasCategoryLabel
85
- ? utils.measureTextWidth(\`\${eventData.categoryLabel}\${valueText}\`, styles.textSizePx) + styles.textSizePx * 1.5
86
- : 0
87
- const datumLabelTextWidth = hasDatumLabel
88
- ? utils.measureTextWidth(\`\${eventData.datum.label}\${valueText}\`, styles.textSizePx)
89
- : 0
90
- const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
91
- const lineEndX = hasDatumLabel
92
- ? maxTextWidth + styles.textSizePx * 0.5
93
- : 0
94
- const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
95
- const datumSvg = \`<text font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
96
- \${datumLabelSvg}<tspan font-weight="bold" text-anchor="\${valueTextAnchor}" x="\${lineEndX}">\${valueText}</tspan>
97
- </text>\`
98
-
99
- return \`\${categorySvg}
100
- <g \${hasCategoryLabel ? \`transform="translate(0, \${styles.textSizePx * 2})"\` : ''}>
101
- \${datumSvg}
102
- </g>\`
1
+ import type { TreeMapParams, TreeLegendParams, TreeTooltipParams } from '../../lib/plugins-basic-types'
2
+
3
+ export const DEFAULT_TREE_MAP_PARAMS: TreeMapParams = {
4
+ paddingInner: 2,
5
+ paddingOuter: 2,
6
+ labelColorType: 'labelContrast',
7
+ squarifyRatio: 1.618034, // 黃金比例
8
+ sort: (a, b) => b.value - a.value
9
+ }
10
+ DEFAULT_TREE_MAP_PARAMS.sort.toString = () => `(a, b) => b.value - a.value`
11
+
12
+ export const DEFAULT_TREE_LEGEND_PARAMS: TreeLegendParams = {
13
+ // position: 'right',
14
+ // justify: 'end',
15
+ placement: 'right-end',
16
+ padding: 28,
17
+ backgroundFill: 'none',
18
+ backgroundStroke: 'none',
19
+ gap: 10,
20
+ listRectWidth: 14,
21
+ listRectHeight: 14,
22
+ listRectRadius: 0,
23
+ textColorType: 'primary'
24
+ }
25
+
26
+ export const DEFAULT_TREE_TOOLTIP_PARAMS: TreeTooltipParams = {
27
+ backgroundColorType: 'background',
28
+ strokeColorType: 'primary',
29
+ backgroundOpacity: 0.8,
30
+ textColorType: 'primary',
31
+ offset: [20, 5],
32
+ padding: 10,
33
+ renderFn: (eventData, { styles, utils }) => {
34
+ const hasCategoryLabel = eventData.categoryLabel ? true : false
35
+ const hasDatumLabel = eventData.datum.label ? true : false
36
+ const valueText = utils.toCurrency(eventData.datum.value)
37
+ const bulletWidth = styles.textSizePx * 0.7
38
+ const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
39
+ const categorySvg = hasCategoryLabel
40
+ ? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.datum.color}"></rect>
41
+ <text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
42
+ <tspan>${eventData.categoryLabel}</tspan>
43
+ </text>`
44
+ : ''
45
+ const datumLabelSvg = hasDatumLabel
46
+ ? `<tspan>${eventData.datum.label}</tspan> `
47
+ : ''
48
+ const categoryLabelTextWidth = hasCategoryLabel
49
+ ? utils.measureTextWidth(`${eventData.categoryLabel}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
50
+ : 0
51
+ const datumLabelTextWidth = hasDatumLabel
52
+ ? utils.measureTextWidth(`${eventData.datum.label}${valueText}`, styles.textSizePx)
53
+ : 0
54
+ const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
55
+ const lineEndX = hasDatumLabel
56
+ ? maxTextWidth + styles.textSizePx * 0.5
57
+ : 0
58
+ const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
59
+ const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
60
+ ${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
61
+ </text>`
62
+
63
+ return `${categorySvg}
64
+ <g ${hasCategoryLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
65
+ ${datumSvg}
66
+ </g>`
67
+ },
68
+ }
69
+ DEFAULT_TREE_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, utils }) => {
70
+ const hasCategoryLabel = eventData.categoryLabel ? true : false
71
+ const hasDatumLabel = eventData.datum.label ? true : false
72
+ const valueText = utils.toCurrency(eventData.datum.value)
73
+ const bulletWidth = styles.textSizePx * 0.7
74
+ const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
75
+ const categorySvg = hasCategoryLabel
76
+ ? \`<rect width="\${bulletWidth}" height="\${bulletWidth}" x="\${offset}" y="\${offset - 1}" rx="\${bulletWidth / 2}" fill="\${eventData.datum.color}"></rect>
77
+ <text x="\${styles.textSizePx * 1.5}" font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
78
+ <tspan>\${eventData.categoryLabel}</tspan>
79
+ </text>\`
80
+ : ''
81
+ const datumLabelSvg = hasDatumLabel
82
+ ? \`<tspan>\${eventData.datum.label}</tspan> \`
83
+ : ''
84
+ const categoryLabelTextWidth = hasCategoryLabel
85
+ ? utils.measureTextWidth(\`\${eventData.categoryLabel}\${valueText}\`, styles.textSizePx) + styles.textSizePx * 1.5
86
+ : 0
87
+ const datumLabelTextWidth = hasDatumLabel
88
+ ? utils.measureTextWidth(\`\${eventData.datum.label}\${valueText}\`, styles.textSizePx)
89
+ : 0
90
+ const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
91
+ const lineEndX = hasDatumLabel
92
+ ? maxTextWidth + styles.textSizePx * 0.5
93
+ : 0
94
+ const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
95
+ const datumSvg = \`<text font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
96
+ \${datumLabelSvg}<tspan font-weight="bold" text-anchor="\${valueTextAnchor}" x="\${lineEndX}">\${valueText}</tspan>
97
+ </text>\`
98
+
99
+ return \`\${categorySvg}
100
+ <g \${hasCategoryLabel ? \`transform="translate(0, \${styles.textSizePx * 2})"\` : ''}>
101
+ \${datumSvg}
102
+ </g>\`
103
103
  }`
package/src/tree/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './defaults'
2
- // export * from './types'
3
- export { TreeLegend } from './plugins/TreeLegend'
4
- export { TreeMap } from './plugins/TreeMap'
1
+ export * from './defaults'
2
+ // export * from './types'
3
+ export { TreeLegend } from './plugins/TreeLegend'
4
+ export { TreeMap } from './plugins/TreeMap'
5
5
  export { TreeTooltip } from './plugins/TreeTooltip'