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

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 (181) hide show
  1. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +2 -2
  2. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +2 -2
  3. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +2 -2
  4. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +2 -2
  5. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +1 -1
  6. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +3 -3
  7. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +3 -3
  8. package/dist/{src/base/BaseBarStack.d.ts → orbcharts-plugins-basic/src/base/BaseStackedBar.d.ts} +6 -6
  9. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -2
  10. package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +4 -4
  11. package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +5 -5
  12. package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +2 -2
  13. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedBar.d.ts +1 -0
  14. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedValueAxis.d.ts +1 -0
  15. package/dist/orbcharts-plugins-basic/src/index.d.ts +7 -0
  16. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/defaults.d.ts +4 -4
  17. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +3 -3
  18. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedBar.d.ts +1 -0
  19. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedValueAxis.d.ts +1 -0
  20. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +1 -0
  21. package/dist/orbcharts-plugins-basic/src/multiValue/defaults.d.ts +9 -0
  22. package/dist/orbcharts-plugins-basic/src/multiValue/index.d.ts +8 -0
  23. package/dist/orbcharts-plugins-basic/src/multiValue/multiValueObservables.d.ts +33 -0
  24. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueLegend.d.ts +1 -0
  25. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueTooltip.d.ts +1 -0
  26. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/Scatter.d.ts +3 -0
  27. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/ScatterBubbles.d.ts +3 -0
  28. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAux.d.ts +3 -0
  29. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAxes.d.ts +3 -0
  30. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYZoom.d.ts +1 -0
  31. package/dist/orbcharts-plugins-basic/src/relationship/defaults.d.ts +6 -0
  32. package/dist/orbcharts-plugins-basic/src/relationship/index.d.ts +5 -0
  33. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirected.d.ts +3 -0
  34. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirectedBubbles.d.ts +3 -0
  35. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipLegend.d.ts +1 -0
  36. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipTooltip.d.ts +1 -0
  37. package/dist/orbcharts-plugins-basic/src/relationship/relationshipObservables.d.ts +1 -0
  38. package/dist/{src → orbcharts-plugins-basic/src}/series/seriesObservables.d.ts +3 -3
  39. package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +1 -1
  40. package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +2 -2
  41. package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +1 -1
  42. package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +3 -3
  43. package/dist/orbcharts-plugins-basic.es.js +13327 -10361
  44. package/dist/orbcharts-plugins-basic.umd.js +99 -49
  45. package/dist/src/index.d.ts +1 -5
  46. package/package.json +4 -4
  47. package/src/base/BaseBars.ts +5 -5
  48. package/src/base/BaseBarsTriangle.ts +6 -4
  49. package/src/base/BaseDots.ts +3 -54
  50. package/src/base/BaseGroupAxis.ts +50 -50
  51. package/src/base/BaseLegend.ts +25 -21
  52. package/src/base/BaseLineAreas.ts +4 -4
  53. package/src/base/BaseLines.ts +3 -3
  54. package/src/base/{BaseBarStack.ts → BaseStackedBar.ts} +22 -20
  55. package/src/base/BaseTooltip.ts +5 -2
  56. package/src/base/BaseValueAxis.ts +84 -81
  57. package/src/grid/defaults.ts +15 -13
  58. package/src/grid/gridObservables.ts +56 -47
  59. package/src/grid/index.ts +2 -2
  60. package/src/grid/plugins/GridLegend.ts +2 -2
  61. package/src/grid/plugins/GridZoom.ts +20 -20
  62. package/src/grid/plugins/GroupAux.ts +216 -211
  63. package/src/grid/plugins/{BarStack.ts → StackedBar.ts} +7 -7
  64. package/src/grid/plugins/{ValueStackAxis.ts → StackedValueAxis.ts} +6 -5
  65. package/src/grid/plugins/ValueAxis.ts +1 -0
  66. package/src/index.ts +2 -5
  67. package/src/multiGrid/defaults.ts +11 -11
  68. package/src/multiGrid/index.ts +3 -3
  69. package/src/multiGrid/plugins/MultiBars.ts +1 -1
  70. package/src/multiGrid/plugins/MultiBarsTriangle.ts +1 -1
  71. package/src/multiGrid/plugins/MultiGridLegend.ts +2 -2
  72. package/src/multiGrid/plugins/MultiGroupAxis.ts +1 -1
  73. package/src/multiGrid/plugins/{MultiBarStack.ts → MultiStackedBar.ts} +8 -8
  74. package/src/multiGrid/plugins/{MultiValueStackAxis.ts → MultiStackedValueAxis.ts} +4 -3
  75. package/src/multiGrid/plugins/MultiValueAxis.ts +2 -1
  76. package/src/multiGrid/plugins/{OverlappingValueStackAxes.ts → OverlappingStackedValueAxes.ts} +9 -8
  77. package/src/multiGrid/plugins/OverlappingValueAxes.ts +4 -3
  78. package/src/multiValue/defaults.ts +167 -0
  79. package/src/multiValue/index.ts +9 -0
  80. package/src/multiValue/multiValueObservables.ts +297 -0
  81. package/src/multiValue/plugins/MultiValueLegend.ts +107 -0
  82. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -0
  83. package/src/multiValue/plugins/Scatter.ts +426 -0
  84. package/src/multiValue/plugins/ScatterBubbles.ts +554 -0
  85. package/src/multiValue/plugins/XYAux.ts +682 -0
  86. package/src/multiValue/plugins/XYAxes.ts +685 -0
  87. package/src/multiValue/plugins/XYZoom.ts +300 -0
  88. package/src/noneData/plugins/Container.ts +23 -23
  89. package/src/noneData/plugins/Tooltip.ts +365 -365
  90. package/src/relationship/defaults.ts +197 -0
  91. package/src/relationship/index.ts +5 -0
  92. package/src/relationship/plugins/ForceDirected.ts +1169 -0
  93. package/src/relationship/plugins/ForceDirectedBubbles.ts +1394 -0
  94. package/src/relationship/plugins/RelationshipLegend.ts +100 -0
  95. package/src/relationship/plugins/RelationshipTooltip.ts +66 -0
  96. package/src/relationship/relationshipObservables.ts +50 -0
  97. package/src/series/defaults.ts +13 -12
  98. package/src/series/plugins/Bubbles.ts +22 -22
  99. package/src/series/plugins/Pie.ts +2 -2
  100. package/src/series/plugins/PieEventTexts.ts +22 -21
  101. package/src/series/plugins/PieLabels.ts +2 -2
  102. package/src/series/plugins/Rose.ts +2 -2
  103. package/src/series/plugins/RoseLabels.ts +2 -2
  104. package/src/series/plugins/SeriesLegend.ts +4 -4
  105. package/src/series/seriesObservables.ts +3 -3
  106. package/src/tree/defaults.ts +3 -3
  107. package/src/tree/plugins/TreeLegend.ts +3 -10
  108. package/src/utils/commonUtils.ts +5 -5
  109. package/src/utils/d3Utils.ts +4 -3
  110. package/src/utils/observables.ts +2 -2
  111. package/src/utils/orbchartsUtils.ts +28 -12
  112. package/dist/src/grid/plugins/BarStack.d.ts +0 -1
  113. package/dist/src/grid/plugins/ValueStackAxis.d.ts +0 -1
  114. package/dist/src/multiGrid/plugins/MultiBarStack.d.ts +0 -1
  115. package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +0 -1
  116. package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +0 -1
  117. package/dist/src/multiValue/plugins/Scatter.d.ts +0 -0
  118. package/dist/src/multiValue/plugins/ScatterAxes.d.ts +0 -0
  119. package/dist/src/noneData/plugins/Container.d.ts +0 -1
  120. package/dist/src/noneData/plugins/Tooltip.d.ts +0 -3
  121. package/dist/src/relationship/index.d.ts +0 -0
  122. package/dist/src/relationship/plugins/Relationship.d.ts +0 -0
  123. package/src/base/BaseGroupArea.ts +0 -0
  124. package/src/multiValue/plugins/ScatterAxes.ts +0 -0
  125. package/src/relationship/plugins/Relationship.ts +0 -0
  126. /package/dist/{lib → orbcharts-plugins-basic/lib}/core-types.d.ts +0 -0
  127. /package/dist/{lib → orbcharts-plugins-basic/lib}/core.d.ts +0 -0
  128. /package/dist/{lib → orbcharts-plugins-basic/lib}/plugins-basic-types.d.ts +0 -0
  129. /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseTooltip.d.ts +0 -0
  130. /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
  131. /package/dist/{src → orbcharts-plugins-basic/src}/const.d.ts +0 -0
  132. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
  133. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsPN.d.ts +0 -0
  134. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
  135. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
  136. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
  137. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridTooltip.d.ts +0 -0
  138. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridZoom.d.ts +0 -0
  139. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
  140. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
  141. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
  142. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
  143. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
  144. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/multiGridObservables.d.ts +0 -0
  145. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  146. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  147. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  148. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  149. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridTooltip.d.ts +0 -0
  150. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  151. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  152. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  153. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  154. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  155. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/Ranking.d.ts +0 -0
  156. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/RankingAxis.d.ts +0 -0
  157. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
  158. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/index.d.ts +0 -0
  159. /package/dist/{src/base/BaseGroupArea.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Container.d.ts} +0 -0
  160. /package/dist/{src/multiValue/index.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Tooltip.d.ts} +0 -0
  161. /package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +0 -0
  162. /package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +0 -0
  163. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
  164. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
  165. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieEventTexts.d.ts +0 -0
  166. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
  167. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Rose.d.ts +0 -0
  168. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/RoseLabels.d.ts +0 -0
  169. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
  170. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesTooltip.d.ts +0 -0
  171. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
  172. /package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +0 -0
  173. /package/dist/{src → orbcharts-plugins-basic/src}/tree/defaults.d.ts +0 -0
  174. /package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +0 -0
  175. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
  176. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
  177. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeTooltip.d.ts +0 -0
  178. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
  179. /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
  180. /package/src/{grid → multiValue}/plugins/Ranking.ts +0 -0
  181. /package/src/{grid → multiValue}/plugins/RankingAxis.ts +0 -0
@@ -0,0 +1,297 @@
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Observable,
4
+ Subject,
5
+ debounceTime,
6
+ of,
7
+ takeUntil,
8
+ filter,
9
+ map,
10
+ switchMap,
11
+ combineLatest,
12
+ merge,
13
+ shareReplay,
14
+ distinctUntilChanged
15
+ } from 'rxjs'
16
+ import type {
17
+ ChartParams,
18
+ HighlightTarget,
19
+ DataFormatterMultiValue,
20
+ ComputedDataMultiValue,
21
+ ComputedDatumMultiValue,
22
+ ComputedLayoutDatumMultiValue,
23
+ TransformData,
24
+ ContainerPositionScaled,
25
+ Layout,
26
+ } from '../../lib/core-types'
27
+ import { createAxisToLabelIndexScale, createAxisToValueScale } from '../../lib/core'
28
+ import { getClassName, getUniID } from '../utils/orbchartsUtils'
29
+ import { d3EventObservable } from '../utils/observables'
30
+
31
+ // 建立 multiValue 主要的 selection
32
+ export const multiValueSelectionsObservable = ({ selection, pluginName, clipPathID, categoryLabels$, multiValueContainerPosition$, multiValueGraphicTransform$ }: {
33
+ selection: d3.Selection<any, unknown, any, unknown>
34
+ pluginName: string
35
+ clipPathID: string
36
+ // computedData$: Observable<ComputedDataMultiValue>
37
+ categoryLabels$: Observable<string[]>
38
+ multiValueContainerPosition$: Observable<ContainerPositionScaled[]>
39
+ // multiValueAxesTransform$: Observable<TransformData>
40
+ multiValueGraphicTransform$: Observable<TransformData>
41
+ }) => {
42
+ const categoryClassName = getClassName(pluginName, 'category')
43
+ const axesClassName = getClassName(pluginName, 'axes')
44
+ const graphicClassName = getClassName(pluginName, 'graphic')
45
+
46
+ // <g> category selection(container排放位置)
47
+ // <g> axes selection(圖軸)
48
+ // <defs> clipPath selection
49
+ // <g> graphic selection(圖形 scale 範圍的變形)
50
+ const categorySelection$ = categoryLabels$.pipe(
51
+ map((categoryLabels, i) => {
52
+ return selection
53
+ .selectAll<SVGGElement, string>(`g.${categoryClassName}`)
54
+ .data(categoryLabels, d => d)
55
+ .join(
56
+ enter => {
57
+ return enter
58
+ .append('g')
59
+ .classed(categoryClassName, true)
60
+ .each((d, i, g) => {
61
+ const axesSelection = d3.select(g[i])
62
+ .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${axesClassName}`)
63
+ .data([i])
64
+ .join(
65
+ enter => {
66
+ return enter
67
+ .append('g')
68
+ .classed(axesClassName, true)
69
+ .attr('clip-path', `url(#${clipPathID})`)
70
+ .each((d, i, g) => {
71
+ const defsSelection = d3.select(g[i])
72
+ .selectAll<SVGDefsElement, any>('defs')
73
+ .data([i])
74
+ .join('defs')
75
+
76
+ const graphicGSelection = d3.select(g[i])
77
+ .selectAll<SVGGElement, any>('g')
78
+ .data([i])
79
+ .join('g')
80
+ .classed(graphicClassName, true)
81
+ })
82
+ },
83
+ update => update,
84
+ exit => exit.remove()
85
+ )
86
+ })
87
+ },
88
+ update => update,
89
+ exit => exit.remove()
90
+ )
91
+ }),
92
+ shareReplay(1)
93
+ )
94
+
95
+ // <g> category selection
96
+ combineLatest({
97
+ categorySelection: categorySelection$,
98
+ multiValueContainerPosition: multiValueContainerPosition$
99
+ }).pipe(
100
+ switchMap(async d => d)
101
+ ).subscribe(data => {
102
+ data.categorySelection
103
+ .transition()
104
+ .attr('transform', (d, i) => {
105
+ const multiValueContainerPosition = data.multiValueContainerPosition[i] ?? data.multiValueContainerPosition[0]
106
+ const translate = multiValueContainerPosition.translate
107
+ const scale = multiValueContainerPosition.scale
108
+ return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
109
+ })
110
+ })
111
+
112
+ // <g> axes selection
113
+ const axesSelection$ = categorySelection$.pipe(
114
+ map(categorySelection => {
115
+ return categorySelection
116
+ .select<SVGGElement>(`g.${axesClassName}`)
117
+ }),
118
+ shareReplay(1)
119
+ )
120
+
121
+ // <defs> clipPath selection
122
+ const defsSelection$ = axesSelection$.pipe(
123
+ map(axesSelection => {
124
+ return axesSelection.select<SVGDefsElement>('defs')
125
+ }),
126
+ shareReplay(1)
127
+ )
128
+
129
+ // <g> graphic selection
130
+ const graphicGSelection$ = combineLatest({
131
+ axesSelection: axesSelection$,
132
+ multiValueGraphicTransform: multiValueGraphicTransform$
133
+ }).pipe(
134
+ switchMap(async d => d),
135
+ map(data => {
136
+ const graphicGSelection = data.axesSelection
137
+ .select<SVGGElement>(`g.${graphicClassName}`)
138
+ graphicGSelection
139
+ .transition()
140
+ .duration(50)
141
+ .style('transform', data.multiValueGraphicTransform.value)
142
+ return graphicGSelection
143
+ }),
144
+ shareReplay(1)
145
+ )
146
+
147
+ return {
148
+ categorySelection$,
149
+ axesSelection$,
150
+ defsSelection$,
151
+ graphicGSelection$
152
+ }
153
+ }
154
+
155
+
156
+ export const multiValueXYPositionObservable = ({ rootSelection, fullDataFormatter$, filteredMinMaxXYData$, multiValueContainerPosition$, layout$ }: {
157
+ rootSelection: d3.Selection<any, unknown, any, unknown>
158
+ fullDataFormatter$: Observable<DataFormatterMultiValue>
159
+ // computedData$: Observable<ComputedDataMultiValue>
160
+ // minMaxXY$: Observable<{ minX: number, maxX: number, minY: number, maxY: number }>
161
+ filteredMinMaxXYData$: Observable<{
162
+ minXDatum: ComputedLayoutDatumMultiValue
163
+ maxXDatum: ComputedLayoutDatumMultiValue
164
+ minYDatum: ComputedLayoutDatumMultiValue
165
+ maxYDatum: ComputedLayoutDatumMultiValue
166
+ }>
167
+ multiValueContainerPosition$: Observable<ContainerPositionScaled[]>
168
+ layout$: Observable<Layout>
169
+ }) => {
170
+ const rootMousemove$ = d3EventObservable(rootSelection, 'mousemove').pipe(
171
+ debounceTime(2) // 避免過度頻繁觸發,實測時沒加電腦容易卡頓
172
+ )
173
+
174
+ const columnAmount$ = multiValueContainerPosition$.pipe(
175
+ map(multiValueContainerPosition => {
176
+ const maxColumnIndex = multiValueContainerPosition.reduce((acc, current) => {
177
+ return current.columnIndex > acc ? current.columnIndex : acc
178
+ }, 0)
179
+ return maxColumnIndex + 1
180
+ }),
181
+ distinctUntilChanged(),
182
+ shareReplay(1)
183
+ )
184
+
185
+ const rowAmount$ = multiValueContainerPosition$.pipe(
186
+ map(multiValueContainerPosition => {
187
+ const maxRowIndex = multiValueContainerPosition.reduce((acc, current) => {
188
+ return current.rowIndex > acc ? current.rowIndex : acc
189
+ }, 0)
190
+ return maxRowIndex + 1
191
+ }),
192
+ distinctUntilChanged(),
193
+ shareReplay(1)
194
+ )
195
+
196
+ // const xyScale$ = combineLatest({
197
+ // layout: layout$,
198
+ // filteredMinMaxXYData: filteredMinMaxXYData$,
199
+ // fullDataFormatter: fullDataFormatter$,
200
+ // columnAmount: columnAmount$,
201
+ // rowAmount: rowAmount$
202
+ // }).pipe(
203
+ // switchMap(async d => d),
204
+ // map(data => {
205
+ // const xScale = createAxisToValueScale({
206
+ // maxValue: data.filteredMinMaxXYData.maxXDatum.value[0],
207
+ // minValue: data.filteredMinMaxXYData.minXDatum.value[0],
208
+ // axisWidth: data.layout.width,
209
+ // scaleDomain: data.fullDataFormatter.xAxis.scaleDomain,
210
+ // scaleRange: data.fullDataFormatter.xAxis.scaleRange,
211
+ // })
212
+ // const yScale = createAxisToValueScale({
213
+ // maxValue: data.filteredMinMaxXYData.maxYDatum.value[1],
214
+ // minValue: data.filteredMinMaxXYData.minYDatum.value[1],
215
+ // axisWidth: data.layout.height,
216
+ // scaleDomain: data.fullDataFormatter.yAxis.scaleDomain,
217
+ // scaleRange: data.fullDataFormatter.yAxis.scaleRange,
218
+ // reverse: true
219
+ // })
220
+ // return { xScale, yScale }
221
+ // })
222
+ // )
223
+
224
+ const xyScale$: Observable<{
225
+ xScale: d3.ScaleLinear<number, number, never>;
226
+ yScale: d3.ScaleLinear<number, number, never>;
227
+ }> = new Observable(subscriber => {
228
+ combineLatest({
229
+ layout: layout$,
230
+ filteredMinMaxXYData: filteredMinMaxXYData$,
231
+ fullDataFormatter: fullDataFormatter$,
232
+ columnAmount: columnAmount$,
233
+ rowAmount: rowAmount$
234
+ }).pipe(
235
+ switchMap(async d => d),
236
+ ).subscribe(data => {
237
+ if (!data.filteredMinMaxXYData.minXDatum || !data.filteredMinMaxXYData.maxXDatum
238
+ || data.filteredMinMaxXYData.minXDatum.value[0] == null || data.filteredMinMaxXYData.maxXDatum.value[0] == null
239
+ || !data.filteredMinMaxXYData.minYDatum || !data.filteredMinMaxXYData.maxYDatum
240
+ || data.filteredMinMaxXYData.minYDatum.value[1] == null || data.filteredMinMaxXYData.maxYDatum.value[1] == null
241
+ ) {
242
+ return
243
+ }
244
+ const xScale = createAxisToValueScale({
245
+ maxValue: data.filteredMinMaxXYData.maxXDatum.value[0],
246
+ minValue: data.filteredMinMaxXYData.minXDatum.value[0],
247
+ axisWidth: data.layout.width,
248
+ scaleDomain: data.fullDataFormatter.xAxis.scaleDomain,
249
+ scaleRange: data.fullDataFormatter.xAxis.scaleRange,
250
+ })
251
+ const yScale = createAxisToValueScale({
252
+ maxValue: data.filteredMinMaxXYData.maxYDatum.value[1],
253
+ minValue: data.filteredMinMaxXYData.minYDatum.value[1],
254
+ axisWidth: data.layout.height,
255
+ scaleDomain: data.fullDataFormatter.yAxis.scaleDomain,
256
+ scaleRange: data.fullDataFormatter.yAxis.scaleRange,
257
+ reverse: true
258
+ })
259
+ subscriber.next({ xScale, yScale })
260
+ })
261
+ })
262
+
263
+ const axisValue$ = combineLatest({
264
+ fullDataFormatter: fullDataFormatter$,
265
+ rootMousemove: rootMousemove$,
266
+ columnAmount: columnAmount$,
267
+ rowAmount: rowAmount$,
268
+ layout: layout$,
269
+ multiValueContainerPosition: multiValueContainerPosition$
270
+ }).pipe(
271
+ switchMap(async d => d),
272
+ map(data => {
273
+ // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
274
+ return {
275
+ x: ((data.rootMousemove.offsetX - data.layout.left) / data.multiValueContainerPosition[0].scale[0])
276
+ % (data.layout.rootWidth / data.columnAmount / data.multiValueContainerPosition[0].scale[0]),
277
+ y: ((data.rootMousemove.offsetY - data.layout.top) / data.multiValueContainerPosition[0].scale[1])
278
+ % (data.layout.rootHeight / data.rowAmount / data.multiValueContainerPosition[0].scale[1])
279
+ }
280
+ })
281
+ )
282
+
283
+ return combineLatest({
284
+ xyScale: xyScale$,
285
+ axisValue: axisValue$
286
+ }).pipe(
287
+ switchMap(async d => d),
288
+ map(data => {
289
+ return {
290
+ x: data.axisValue.x,
291
+ y: data.axisValue.y,
292
+ xValue: data.xyScale.xScale(data.axisValue.x),
293
+ yValue: data.xyScale.yScale(data.axisValue.y)
294
+ }
295
+ })
296
+ )
297
+ }
@@ -0,0 +1,107 @@
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ switchMap,
6
+ takeUntil,
7
+ Observable,
8
+ Subject } from 'rxjs'
9
+ import type { DefinePluginConfig } from '../../../lib/core-types'
10
+ import {
11
+ defineMultiValuePlugin } from '../../../lib/core'
12
+ import { DEFAULT_MULTI_VALUE_LEGEND_PARAMS } from '../defaults'
13
+ import { createBaseLegend } from '../../base/BaseLegend'
14
+ import { LAYER_INDEX_OF_INFO } from '../../const'
15
+
16
+ const pluginName = 'MultiValueLegend'
17
+
18
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_MULTI_VALUE_LEGEND_PARAMS> = {
19
+ name: pluginName,
20
+ defaultParams: DEFAULT_MULTI_VALUE_LEGEND_PARAMS,
21
+ layerIndex: LAYER_INDEX_OF_INFO,
22
+ validator: (params, { validateColumns }) => {
23
+ const result = validateColumns(params, {
24
+ placement: {
25
+ toBe: '"top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end" | "right" | "right-start" | "right-end"',
26
+ test: (value) => {
27
+ return [
28
+ 'top', 'top-start', 'top-end',
29
+ 'bottom', 'bottom-start', 'bottom-end',
30
+ 'left', 'left-start', 'left-end',
31
+ 'right', 'right-start', 'right-end'
32
+ ].includes(value)
33
+ }
34
+ },
35
+ padding: {
36
+ toBeTypes: ['number']
37
+ },
38
+ backgroundFill: {
39
+ toBeOption: 'ColorType',
40
+ },
41
+ backgroundStroke: {
42
+ toBeOption: 'ColorType',
43
+ },
44
+ gap: {
45
+ toBeTypes: ['number']
46
+ },
47
+ listRectWidth: {
48
+ toBeTypes: ['number']
49
+ },
50
+ listRectHeight: {
51
+ toBeTypes: ['number']
52
+ },
53
+ listRectRadius: {
54
+ toBeTypes: ['number']
55
+ },
56
+ textColorType: {
57
+ toBeOption: 'ColorType',
58
+ }
59
+ })
60
+ return result
61
+ }
62
+ }
63
+
64
+ export const MultiValueLegend = defineMultiValuePlugin(pluginConfig)(({ selection, rootSelection, observer, subject }) => {
65
+
66
+ const destroy$ = new Subject()
67
+
68
+ const categoryLabels$: Observable<string[]> = observer.CategoryDataMap$.pipe(
69
+ takeUntil(destroy$),
70
+ map(data => {
71
+ return Array.from(data.keys())
72
+ })
73
+ )
74
+
75
+ // 全部列點矩型使用相同樣式參數
76
+ const fullParams$ = observer.fullParams$.pipe(
77
+ takeUntil(destroy$),
78
+ map(d => {
79
+ const labelList = [
80
+ {
81
+ listRectWidth: d.listRectWidth,
82
+ listRectHeight: d.listRectHeight,
83
+ listRectRadius: d.listRectRadius,
84
+ }
85
+ ]
86
+ return {
87
+ ...d,
88
+ labelList
89
+ }
90
+ })
91
+ )
92
+
93
+ const unsubscribeBaseLegend = createBaseLegend(pluginName, {
94
+ rootSelection,
95
+ legendLabels$: categoryLabels$,
96
+ fullParams$,
97
+ layout$: observer.layout$,
98
+ fullChartParams$: observer.fullChartParams$,
99
+ textSizePx$: observer.textSizePx$
100
+ })
101
+
102
+ return () => {
103
+ destroy$.next(undefined)
104
+ unsubscribeBaseLegend()
105
+ }
106
+ })
107
+
@@ -0,0 +1,66 @@
1
+ import {
2
+ Subject,
3
+ } from 'rxjs'
4
+ import type { DefinePluginConfig } from '../../../lib/core-types'
5
+ import {
6
+ defineMultiValuePlugin } from '../../../lib/core'
7
+ import { DEFAULT_MULTI_VALUE_TOOLTIP_PARAMS } from '../defaults'
8
+ import { LAYER_INDEX_OF_TOOLTIP } from '../../const'
9
+ import { createBaseTooltip } from '../../base/BaseTooltip'
10
+
11
+ const pluginName = 'MultiValueTooltip'
12
+
13
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_MULTI_VALUE_TOOLTIP_PARAMS> = {
14
+ name: pluginName,
15
+ defaultParams: DEFAULT_MULTI_VALUE_TOOLTIP_PARAMS,
16
+ layerIndex: LAYER_INDEX_OF_TOOLTIP,
17
+ validator: (params, { validateColumns }) => {
18
+ const result = validateColumns(params, {
19
+ backgroundColorType: {
20
+ toBeOption: 'ColorType',
21
+ },
22
+ backgroundOpacity: {
23
+ toBeTypes: ['number']
24
+ },
25
+ strokeColorType: {
26
+ toBeOption: 'ColorType',
27
+ },
28
+ offset: {
29
+ toBe: '[number, number]',
30
+ test: (value: any) => {
31
+ return Array.isArray(value)
32
+ && value.length === 2
33
+ && typeof value[0] === 'number'
34
+ && typeof value[1] === 'number'
35
+ }
36
+ },
37
+ padding: {
38
+ toBeTypes: ['number']
39
+ },
40
+ textColorType: {
41
+ toBeOption: 'ColorType',
42
+ },
43
+ renderFn: {
44
+ toBeTypes: ['Function']
45
+ },
46
+ })
47
+ return result
48
+ }
49
+ }
50
+
51
+ export const MultiValueTooltip = defineMultiValuePlugin(pluginConfig)(({ selection, rootSelection, name, subject, observer }) => {
52
+ const destroy$ = new Subject()
53
+
54
+ const unsubscribeTooltip = createBaseTooltip(pluginName, {
55
+ rootSelection,
56
+ fullParams$: observer.fullParams$,
57
+ fullChartParams$: observer.fullChartParams$,
58
+ layout$: observer.layout$,
59
+ event$: subject.event$,
60
+ })
61
+
62
+ return () => {
63
+ destroy$.next(undefined)
64
+ unsubscribeTooltip()
65
+ }
66
+ })