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

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 (212) hide show
  1. package/LICENSE +200 -200
  2. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +2 -2
  3. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +2 -2
  4. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +2 -2
  5. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +2 -2
  6. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +1 -1
  7. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +3 -3
  8. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +3 -3
  9. package/dist/{src/base/BaseBarStack.d.ts → orbcharts-plugins-basic/src/base/BaseStackedBar.d.ts} +6 -6
  10. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -2
  11. package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +4 -4
  12. package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +5 -5
  13. package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +2 -2
  14. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedBar.d.ts +1 -0
  15. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedValueAxis.d.ts +1 -0
  16. package/dist/orbcharts-plugins-basic/src/index.d.ts +7 -0
  17. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/defaults.d.ts +4 -4
  18. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +3 -3
  19. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedBar.d.ts +1 -0
  20. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedValueAxis.d.ts +1 -0
  21. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +1 -0
  22. package/dist/orbcharts-plugins-basic/src/multiValue/defaults.d.ts +9 -0
  23. package/dist/orbcharts-plugins-basic/src/multiValue/index.d.ts +8 -0
  24. package/dist/orbcharts-plugins-basic/src/multiValue/multiValueObservables.d.ts +33 -0
  25. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueLegend.d.ts +1 -0
  26. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueTooltip.d.ts +1 -0
  27. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/Scatter.d.ts +3 -0
  28. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/ScatterBubbles.d.ts +3 -0
  29. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAux.d.ts +3 -0
  30. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAxes.d.ts +3 -0
  31. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYZoom.d.ts +1 -0
  32. package/dist/orbcharts-plugins-basic/src/relationship/defaults.d.ts +6 -0
  33. package/dist/orbcharts-plugins-basic/src/relationship/index.d.ts +5 -0
  34. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirected.d.ts +3 -0
  35. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirectedBubbles.d.ts +3 -0
  36. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipLegend.d.ts +1 -0
  37. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipTooltip.d.ts +1 -0
  38. package/dist/orbcharts-plugins-basic/src/relationship/relationshipObservables.d.ts +1 -0
  39. package/dist/{src → orbcharts-plugins-basic/src}/series/seriesObservables.d.ts +3 -3
  40. package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +1 -1
  41. package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +2 -2
  42. package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +1 -1
  43. package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +3 -3
  44. package/dist/orbcharts-plugins-basic.es.js +13264 -10298
  45. package/dist/orbcharts-plugins-basic.umd.js +105 -55
  46. package/dist/src/index.d.ts +1 -5
  47. package/lib/core-types.ts +7 -7
  48. package/lib/core.ts +6 -6
  49. package/lib/plugins-basic-types.ts +6 -6
  50. package/package.json +44 -44
  51. package/src/base/BaseBars.ts +765 -765
  52. package/src/base/BaseBarsTriangle.ts +676 -674
  53. package/src/base/BaseDots.ts +464 -515
  54. package/src/base/BaseGroupAxis.ts +679 -679
  55. package/src/base/BaseLegend.ts +684 -680
  56. package/src/base/BaseLineAreas.ts +629 -629
  57. package/src/base/BaseLines.ts +706 -706
  58. package/src/base/{BaseBarStack.ts → BaseStackedBar.ts} +782 -780
  59. package/src/base/BaseTooltip.ts +385 -382
  60. package/src/base/BaseValueAxis.ts +583 -580
  61. package/src/base/types.ts +2 -2
  62. package/src/const.ts +30 -30
  63. package/src/grid/defaults.ts +246 -244
  64. package/src/grid/gridObservables.ts +554 -545
  65. package/src/grid/index.ts +16 -16
  66. package/src/grid/plugins/Bars.ts +69 -69
  67. package/src/grid/plugins/BarsPN.ts +66 -66
  68. package/src/grid/plugins/BarsTriangle.ts +73 -73
  69. package/src/grid/plugins/Dots.ts +68 -68
  70. package/src/grid/plugins/GridLegend.ts +107 -107
  71. package/src/grid/plugins/GridTooltip.ts +66 -66
  72. package/src/grid/plugins/GridZoom.ts +218 -218
  73. package/src/grid/plugins/GroupAux.ts +1103 -1098
  74. package/src/grid/plugins/GroupAxis.ts +97 -97
  75. package/src/grid/plugins/LineAreas.ts +65 -65
  76. package/src/grid/plugins/Lines.ts +59 -59
  77. package/src/grid/plugins/{BarStack.ts → StackedBar.ts} +64 -64
  78. package/src/grid/plugins/{ValueStackAxis.ts → StackedValueAxis.ts} +96 -95
  79. package/src/grid/plugins/ValueAxis.ts +94 -93
  80. package/src/index.ts +6 -9
  81. package/src/multiGrid/defaults.ts +224 -224
  82. package/src/multiGrid/index.ts +15 -15
  83. package/src/multiGrid/multiGridObservables.ts +49 -49
  84. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  85. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  86. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  87. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  88. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  89. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  90. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  91. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  92. package/src/multiGrid/plugins/{MultiBarStack.ts → MultiStackedBar.ts} +106 -106
  93. package/src/multiGrid/plugins/{MultiValueStackAxis.ts → MultiStackedValueAxis.ts} +134 -133
  94. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -133
  95. package/src/multiGrid/plugins/{OverlappingValueStackAxes.ts → OverlappingStackedValueAxes.ts} +299 -298
  96. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -299
  97. package/src/multiValue/defaults.ts +167 -0
  98. package/src/multiValue/index.ts +9 -0
  99. package/src/multiValue/multiValueObservables.ts +297 -0
  100. package/src/multiValue/plugins/MultiValueLegend.ts +107 -0
  101. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -0
  102. package/src/multiValue/plugins/Scatter.ts +426 -0
  103. package/src/multiValue/plugins/ScatterBubbles.ts +554 -0
  104. package/src/multiValue/plugins/XYAux.ts +682 -0
  105. package/src/multiValue/plugins/XYAxes.ts +685 -0
  106. package/src/multiValue/plugins/XYZoom.ts +300 -0
  107. package/src/noneData/defaults.ts +102 -102
  108. package/src/noneData/index.ts +3 -3
  109. package/src/noneData/plugins/Container.ts +28 -28
  110. package/src/noneData/plugins/Tooltip.ts +374 -374
  111. package/src/relationship/defaults.ts +196 -0
  112. package/src/relationship/index.ts +5 -0
  113. package/src/relationship/plugins/ForceDirected.ts +1167 -0
  114. package/src/relationship/plugins/ForceDirectedBubbles.ts +1391 -0
  115. package/src/relationship/plugins/RelationshipLegend.ts +100 -0
  116. package/src/relationship/plugins/RelationshipTooltip.ts +66 -0
  117. package/src/relationship/relationshipObservables.ts +50 -0
  118. package/src/series/defaults.ts +206 -206
  119. package/src/series/index.ts +9 -9
  120. package/src/series/plugins/Bubbles.ts +606 -603
  121. package/src/series/plugins/Pie.ts +623 -623
  122. package/src/series/plugins/PieEventTexts.ts +284 -283
  123. package/src/series/plugins/PieLabels.ts +640 -640
  124. package/src/series/plugins/Rose.ts +516 -516
  125. package/src/series/plugins/RoseLabels.ts +600 -600
  126. package/src/series/plugins/SeriesLegend.ts +107 -107
  127. package/src/series/plugins/SeriesTooltip.ts +66 -66
  128. package/src/series/seriesObservables.ts +145 -145
  129. package/src/series/seriesUtils.ts +51 -51
  130. package/src/tree/defaults.ts +78 -78
  131. package/src/tree/index.ts +4 -4
  132. package/src/tree/plugins/TreeLegend.ts +100 -107
  133. package/src/tree/plugins/TreeMap.ts +333 -333
  134. package/src/tree/plugins/TreeTooltip.ts +66 -66
  135. package/src/utils/commonUtils.ts +21 -21
  136. package/src/utils/d3Graphics.ts +174 -174
  137. package/src/utils/d3Utils.ts +74 -73
  138. package/src/utils/observables.ts +14 -14
  139. package/src/utils/orbchartsUtils.ts +116 -100
  140. package/tsconfig.base.json +13 -13
  141. package/tsconfig.json +2 -2
  142. package/vite.config.js +22 -22
  143. package/dist/src/grid/plugins/BarStack.d.ts +0 -1
  144. package/dist/src/grid/plugins/ValueStackAxis.d.ts +0 -1
  145. package/dist/src/multiGrid/plugins/MultiBarStack.d.ts +0 -1
  146. package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +0 -1
  147. package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +0 -1
  148. package/dist/src/multiValue/plugins/Scatter.d.ts +0 -0
  149. package/dist/src/multiValue/plugins/ScatterAxes.d.ts +0 -0
  150. package/dist/src/noneData/plugins/Container.d.ts +0 -1
  151. package/dist/src/noneData/plugins/Tooltip.d.ts +0 -3
  152. package/dist/src/relationship/index.d.ts +0 -0
  153. package/dist/src/relationship/plugins/Relationship.d.ts +0 -0
  154. package/src/base/BaseGroupArea.ts +0 -0
  155. package/src/multiValue/plugins/ScatterAxes.ts +0 -0
  156. package/src/relationship/plugins/Relationship.ts +0 -0
  157. /package/dist/{lib → orbcharts-plugins-basic/lib}/core-types.d.ts +0 -0
  158. /package/dist/{lib → orbcharts-plugins-basic/lib}/core.d.ts +0 -0
  159. /package/dist/{lib → orbcharts-plugins-basic/lib}/plugins-basic-types.d.ts +0 -0
  160. /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseTooltip.d.ts +0 -0
  161. /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
  162. /package/dist/{src → orbcharts-plugins-basic/src}/const.d.ts +0 -0
  163. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
  164. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsPN.d.ts +0 -0
  165. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
  166. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
  167. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
  168. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridTooltip.d.ts +0 -0
  169. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridZoom.d.ts +0 -0
  170. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
  171. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
  172. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
  173. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
  174. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
  175. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/multiGridObservables.d.ts +0 -0
  176. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  177. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  178. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  179. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  180. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridTooltip.d.ts +0 -0
  181. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  182. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  183. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  184. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  185. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  186. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/Ranking.d.ts +0 -0
  187. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/RankingAxis.d.ts +0 -0
  188. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
  189. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/index.d.ts +0 -0
  190. /package/dist/{src/base/BaseGroupArea.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Container.d.ts} +0 -0
  191. /package/dist/{src/multiValue/index.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Tooltip.d.ts} +0 -0
  192. /package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +0 -0
  193. /package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +0 -0
  194. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
  195. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
  196. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieEventTexts.d.ts +0 -0
  197. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
  198. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Rose.d.ts +0 -0
  199. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/RoseLabels.d.ts +0 -0
  200. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
  201. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesTooltip.d.ts +0 -0
  202. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
  203. /package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +0 -0
  204. /package/dist/{src → orbcharts-plugins-basic/src}/tree/defaults.d.ts +0 -0
  205. /package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +0 -0
  206. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
  207. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
  208. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeTooltip.d.ts +0 -0
  209. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
  210. /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
  211. /package/src/{grid → multiValue}/plugins/Ranking.ts +0 -0
  212. /package/src/{grid → multiValue}/plugins/RankingAxis.ts +0 -0
@@ -1,546 +1,555 @@
1
- import * as d3 from 'd3'
2
- import {
3
- Observable,
4
- Subject,
5
- of,
6
- takeUntil,
7
- filter,
8
- map,
9
- switchMap,
10
- combineLatest,
11
- merge,
12
- shareReplay,
13
- distinctUntilChanged
14
- } from 'rxjs'
15
- import type {
16
- ChartParams,
17
- HighlightTarget,
18
- DataFormatterGrid,
19
- ComputedDataGrid,
20
- ComputedDatumGrid,
21
- TransformData,
22
- GridContainerPosition,
23
- Layout } from '../../lib/core-types'
24
- import { createAxisQuantizeScale } from '../../lib/core'
25
- import { getClassName, getUniID } from '../utils/orbchartsUtils'
26
- import { d3EventObservable } from '../utils/observables'
27
-
28
- // grid選取器
29
- export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
30
- selection: d3.Selection<any, unknown, any, unknown>
31
- pluginName: string
32
- clipPathID: string
33
- // computedData$: Observable<ComputedDataGrid>
34
- seriesLabels$: Observable<string[]>
35
- gridContainerPosition$: Observable<GridContainerPosition[]>
36
- gridAxesTransform$: Observable<TransformData>
37
- gridGraphicTransform$: Observable<TransformData>
38
- }) => {
39
- const seriesClassName = getClassName(pluginName, 'series')
40
- const axesClassName = getClassName(pluginName, 'axes')
41
- const graphicClassName = getClassName(pluginName, 'graphic')
42
-
43
- const seriesSelection$ = seriesLabels$.pipe(
44
- map((existSeriesLabels, i) => {
45
- return selection
46
- .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
47
- .data(existSeriesLabels, d => d)
48
- .join(
49
- enter => {
50
- return enter
51
- .append('g')
52
- .classed(seriesClassName, true)
53
- .each((d, i, g) => {
54
- const axesSelection = d3.select(g[i])
55
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
56
- .data([i])
57
- .join(
58
- enter => {
59
- return enter
60
- .append('g')
61
- .classed(axesClassName, true)
62
- .attr('clip-path', `url(#${clipPathID})`)
63
- .each((d, i, g) => {
64
- const defsSelection = d3.select(g[i])
65
- .selectAll<SVGDefsElement, any>('defs')
66
- .data([i])
67
- .join('defs')
68
-
69
- const graphicGSelection = d3.select(g[i])
70
- .selectAll<SVGGElement, any>('g')
71
- .data([i])
72
- .join('g')
73
- .classed(graphicClassName, true)
74
- })
75
- },
76
- update => update,
77
- exit => exit.remove()
78
- )
79
- })
80
- },
81
- update => update,
82
- exit => exit.remove()
83
- )
84
- }),
85
- shareReplay(1)
86
- )
87
-
88
- combineLatest({
89
- seriesSelection: seriesSelection$,
90
- gridContainerPosition: gridContainerPosition$
91
- }).pipe(
92
- switchMap(async d => d)
93
- ).subscribe(data => {
94
- data.seriesSelection
95
- .transition()
96
- .attr('transform', (d, i) => {
97
- const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
98
- const translate = gridContainerPosition.translate
99
- const scale = gridContainerPosition.scale
100
- return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
101
- })
102
- })
103
-
104
- const axesSelection$ = combineLatest({
105
- seriesSelection: seriesSelection$,
106
- gridAxesTransform: gridAxesTransform$
107
- }).pipe(
108
- switchMap(async d => d),
109
- map(data => {
110
- return data.seriesSelection
111
- .select<SVGGElement>(`g.${axesClassName}`)
112
- .style('transform', data.gridAxesTransform.value)
113
- }),
114
- shareReplay(1)
115
- )
116
- const defsSelection$ = axesSelection$.pipe(
117
- map(axesSelection => {
118
- return axesSelection.select<SVGDefsElement>('defs')
119
- }),
120
- shareReplay(1)
121
- )
122
- const graphicGSelection$ = combineLatest({
123
- axesSelection: axesSelection$,
124
- gridGraphicTransform: gridGraphicTransform$
125
- }).pipe(
126
- switchMap(async d => d),
127
- map(data => {
128
- const graphicGSelection = data.axesSelection
129
- .select<SVGGElement>(`g.${graphicClassName}`)
130
- graphicGSelection
131
- .transition()
132
- .duration(50)
133
- .style('transform', data.gridGraphicTransform.value)
134
- return graphicGSelection
135
- }),
136
- shareReplay(1)
137
- )
138
-
139
- return {
140
- seriesSelection$,
141
- axesSelection$,
142
- defsSelection$,
143
- graphicGSelection$
144
- }
145
- }
146
-
147
- // 由事件取得group data的function
148
- // @Q@ 之後重構改用 gridGroupPosition
149
- export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
150
- fullDataFormatter$: Observable<DataFormatterGrid>
151
- gridAxesSize$: Observable<{
152
- width: number;
153
- height: number;
154
- }>
155
- computedData$: Observable<ComputedDataGrid>
156
- // GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
157
- fullChartParams$: Observable<ChartParams>
158
- gridContainerPosition$: Observable<GridContainerPosition[]>
159
- layout$: Observable<Layout>
160
- }): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
161
- const destroy$ = new Subject()
162
-
163
- // 顯示範圍內的group labels
164
- // const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
165
- // combineLatest({
166
- // dataFormatter: fullDataFormatter$,
167
- // computedData: computedData$
168
- // }).pipe(
169
- // takeUntil(destroy$),
170
- // switchMap(async (d) => d),
171
- // ).subscribe(data => {
172
- // const groupMin = 0
173
- // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
174
- // const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
175
- // ? groupMin - data.dataFormatter.grid.groupAxis.scalePadding
176
- // : data.dataFormatter.grid.groupAxis.scaleDomain[0] as number - data.dataFormatter.grid.groupAxis.scalePadding
177
- // const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
178
- // ? groupMax + data.dataFormatter.grid.groupAxis.scalePadding
179
- // : data.dataFormatter.grid.groupAxis.scaleDomain[1] as number + data.dataFormatter.grid.groupAxis.scalePadding
180
-
181
- // // const groupingAmount = data.computedData[0]
182
- // // ? data.computedData[0].length
183
- // // : 0
184
-
185
- // let _labels = data.dataFormatter.grid.seriesDirection === 'row'
186
- // ? (data.computedData[0] ?? []).map(d => d.groupLabel)
187
- // : data.computedData.map(d => d[0].groupLabel)
188
-
189
- // const _axisLabels =
190
- // // new Array(groupingAmount).fill(0)
191
- // // .map((d, i) => {
192
- // // return _labels[i] != null
193
- // // ? _labels[i]
194
- // // : String(i) // 沒有label則用序列號填充
195
- // // })
196
- // _labels
197
- // .filter((d, i) => {
198
- // return i >= groupScaleDomainMin && i <= groupScaleDomainMax
199
- // })
200
- // subscriber.next(_axisLabels)
201
- // })
202
- // })
203
- const groupScaleDomain$ = combineLatest({
204
- fullDataFormatter: fullDataFormatter$,
205
- gridAxesSize: gridAxesSize$,
206
- computedData: computedData$
207
- }).pipe(
208
- switchMap(async (d) => d),
209
- map(data => {
210
- const groupMin = 0
211
- const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
212
- // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
213
- // ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
214
- // : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
215
- const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
216
- const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
217
- ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
218
- : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
219
-
220
- return [groupScaleDomainMin, groupScaleDomainMax]
221
- }),
222
- shareReplay(1)
223
- )
224
-
225
- const groupLabels$ = combineLatest({
226
- fullDataFormatter: fullDataFormatter$,
227
- computedData: computedData$
228
- }).pipe(
229
- switchMap(async d => d),
230
- map(data => {
231
- return data.fullDataFormatter.grid.seriesDirection === 'row'
232
- ? (data.computedData[0] ?? []).map(d => d.groupLabel)
233
- : data.computedData.map(d => d[0].groupLabel)
234
- })
235
- )
236
-
237
- // 顯示範圍內的group labels
238
- const scaleRangeGroupLabels$ = combineLatest({
239
- groupScaleDomain: groupScaleDomain$,
240
- groupLabels: groupLabels$
241
- }).pipe(
242
- switchMap(async d => d),
243
- map(data => {
244
- return data.groupLabels
245
- .filter((d, i) => {
246
- return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
247
- })
248
- })
249
- )
250
-
251
- const columnAmount$ = gridContainerPosition$.pipe(
252
- map(gridContainerPosition => {
253
- const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
254
- return current.columnIndex > acc ? current.columnIndex : acc
255
- }, 0)
256
- return maxColumnIndex + 1
257
- }),
258
- distinctUntilChanged()
259
- )
260
-
261
- const rowAmount$ = gridContainerPosition$.pipe(
262
- map(gridContainerPosition => {
263
- const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
264
- return current.rowIndex > acc ? current.rowIndex : acc
265
- }, 0)
266
- return maxRowIndex + 1
267
- }),
268
- distinctUntilChanged()
269
- )
270
-
271
- return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
272
- combineLatest({
273
- dataFormatter: fullDataFormatter$,
274
- axisSize: gridAxesSize$,
275
- fullChartParams: fullChartParams$,
276
- scaleRangeGroupLabels: scaleRangeGroupLabels$,
277
- groupLabels: groupLabels$,
278
- groupScaleDomain: groupScaleDomain$,
279
- columnAmount: columnAmount$,
280
- rowAmount: rowAmount$,
281
- layout: layout$
282
- }).pipe(
283
- takeUntil(destroy$),
284
- switchMap(async (d) => d),
285
- ).subscribe(data => {
286
-
287
- const reverse = data.dataFormatter.grid.valueAxis.position === 'right'
288
- || data.dataFormatter.grid.valueAxis.position === 'bottom'
289
- ? true : false
290
-
291
- // 比例尺座標對應非連續資料索引
292
- const xIndexScale = createAxisQuantizeScale({
293
- axisLabels: data.scaleRangeGroupLabels,
294
- axisWidth: data.axisSize.width,
295
- padding: data.dataFormatter.grid.groupAxis.scalePadding,
296
- reverse
297
- })
298
-
299
- // 依比例尺位置計算座標
300
- const axisValuePredicate = (event: any) => {
301
- return data.dataFormatter.grid.groupAxis.position === 'bottom'
302
- || data.dataFormatter.grid.groupAxis.position === 'top'
303
- ? event.offsetX - data.fullChartParams.padding.left
304
- : event.offsetY - data.fullChartParams.padding.top
305
- }
306
-
307
- // 比例尺座標取得groupData的function
308
- const createEventGroupData: (event: any) => { groupIndex: number; groupLabel: string } = (event: any) => {
309
- // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
310
- const eventData = {
311
- offsetX: event.offsetX * data.columnAmount % data.layout.rootWidth,
312
- offsetY: event.offsetY * data.rowAmount % data.layout.rootHeight
313
- }
314
- // console.log('data.columnAmount', data.columnAmount, 'data.rowAmount', data.rowAmount, 'data.layout.rootWidth', data.layout.rootWidth, 'data.layout.rootHeight', data.layout.rootHeight)
315
- const axisValue = axisValuePredicate(eventData)
316
- const xIndex = xIndexScale(axisValue)
317
- const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
318
- const groupIndex = xIndex + currentxIndexStart
319
-
320
- return {
321
- groupIndex,
322
- groupLabel: data.groupLabels[groupIndex] ?? ''
323
- }
324
- }
325
-
326
- subscriber.next(createEventGroupData)
327
-
328
- return function unsubscribe () {
329
- destroy$.next(undefined)
330
- }
331
- })
332
- })
333
- }
334
-
335
- export const gridGroupPosition = ({ rootSelection, fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
336
- rootSelection: d3.Selection<any, unknown, any, unknown>
337
- fullDataFormatter$: Observable<DataFormatterGrid>
338
- gridAxesSize$: Observable<{
339
- width: number;
340
- height: number;
341
- }>
342
- computedData$: Observable<ComputedDataGrid>
343
- fullChartParams$: Observable<ChartParams>
344
- gridContainerPosition$: Observable<GridContainerPosition[]>
345
- layout$: Observable<Layout>
346
- }) => {
347
- const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove')
348
-
349
- const groupScaleDomain$ = combineLatest({
350
- fullDataFormatter: fullDataFormatter$,
351
- gridAxesSize: gridAxesSize$,
352
- computedData: computedData$
353
- }).pipe(
354
- switchMap(async (d) => d),
355
- map(data => {
356
- const groupMin = 0
357
- const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
358
- // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
359
- // ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
360
- // : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
361
- const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
362
- const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
363
- ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
364
- : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
365
-
366
- return [groupScaleDomainMin, groupScaleDomainMax]
367
- }),
368
- shareReplay(1)
369
- )
370
-
371
- const groupLabels$ = combineLatest({
372
- fullDataFormatter: fullDataFormatter$,
373
- computedData: computedData$
374
- }).pipe(
375
- switchMap(async d => d),
376
- map(data => {
377
- return data.fullDataFormatter.grid.seriesDirection === 'row'
378
- ? (data.computedData[0] ?? []).map(d => d.groupLabel)
379
- : data.computedData.map(d => d[0].groupLabel)
380
- })
381
- )
382
-
383
- const scaleRangeGroupLabels$ = combineLatest({
384
- groupScaleDomain: groupScaleDomain$,
385
- groupLabels: groupLabels$
386
- }).pipe(
387
- switchMap(async d => d),
388
- map(data => {
389
- return data.groupLabels
390
- .filter((d, i) => {
391
- return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
392
- })
393
- })
394
- )
395
-
396
- const reverse$ = fullDataFormatter$.pipe(
397
- map(d => {
398
- return d.grid.valueAxis.position === 'right' || d.grid.valueAxis.position === 'bottom'
399
- ? true
400
- : false
401
- })
402
- )
403
-
404
- // 比例尺座標對應非連續資料索引
405
- const xIndexScale$ = combineLatest({
406
- reverse: reverse$,
407
- gridAxesSize: gridAxesSize$,
408
- scaleRangeGroupLabels: scaleRangeGroupLabels$,
409
- fullDataFormatter: fullDataFormatter$
410
- }).pipe(
411
- switchMap(async d => d),
412
- map(data => {
413
- return createAxisQuantizeScale({
414
- axisLabels: data.scaleRangeGroupLabels,
415
- axisWidth: data.gridAxesSize.width,
416
- padding: data.fullDataFormatter.grid.groupAxis.scalePadding,
417
- reverse: data.reverse
418
- })
419
- })
420
- )
421
-
422
- const columnAmount$ = gridContainerPosition$.pipe(
423
- map(gridContainerPosition => {
424
- const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
425
- return current.columnIndex > acc ? current.columnIndex : acc
426
- }, 0)
427
- return maxColumnIndex + 1
428
- }),
429
- distinctUntilChanged()
430
- )
431
-
432
- const rowAmount$ = gridContainerPosition$.pipe(
433
- map(gridContainerPosition => {
434
- const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
435
- return current.rowIndex > acc ? current.rowIndex : acc
436
- }, 0)
437
- return maxRowIndex + 1
438
- }),
439
- distinctUntilChanged()
440
- )
441
-
442
- const axisValue$ = combineLatest({
443
- fullDataFormatter: fullDataFormatter$,
444
- fullChartParams: fullChartParams$,
445
- rootMousemove: rootMousemove$,
446
- columnAmount: columnAmount$,
447
- rowAmount: rowAmount$,
448
- layout: layout$
449
- }).pipe(
450
- switchMap(async d => d),
451
- map(data => {
452
- // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
453
- const eventData = {
454
- offsetX: data.rootMousemove.offsetX * data.columnAmount % data.layout.rootWidth,
455
- offsetY: data.rootMousemove.offsetY * data.rowAmount % data.layout.rootHeight
456
- }
457
- return data.fullDataFormatter.grid.groupAxis.position === 'bottom'
458
- || data.fullDataFormatter.grid.groupAxis.position === 'top'
459
- ? eventData.offsetX - data.fullChartParams.padding.left
460
- : eventData.offsetY - data.fullChartParams.padding.top
461
- })
462
- )
463
-
464
- const groupIndex$ = combineLatest({
465
- xIndexScale: xIndexScale$,
466
- axisValue: axisValue$,
467
- groupScaleDomain: groupScaleDomain$
468
- }).pipe(
469
- switchMap(async d => d),
470
- map(data => {
471
- const xIndex = data.xIndexScale(data.axisValue)
472
- const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
473
- return xIndex + currentxIndexStart
474
- })
475
- )
476
-
477
- const groupLabel$ = combineLatest({
478
- groupIndex: groupIndex$,
479
- groupLabels: groupLabels$
480
- }).pipe(
481
- switchMap(async d => d),
482
- map(data => {
483
- return data.groupLabels[data.groupIndex] ?? ''
484
- })
485
- )
486
-
487
- return combineLatest({
488
- groupIndex: groupIndex$,
489
- groupLabel: groupLabel$
490
- }).pipe(
491
- switchMap(async d => d),
492
- map(data => {
493
- return {
494
- groupIndex: data.groupIndex,
495
- groupLabel: data.groupLabel
496
- }
497
- })
498
- )
499
- }
500
-
501
- // const gridContainerEventData$ = ({ eventData$, gridContainerPosition$, layout$ }: {
502
- // eventData$: Observable<any>
503
- // gridContainerPosition$: Observable<GridContainerPosition[]>
504
- // layout$: Observable<Layout>
505
- // }): Observable<{
506
- // offsetX: number;
507
- // offsetY: number;
508
- // }> => {
509
- // const columnAmount$ = gridContainerPosition$.pipe(
510
- // map(gridContainerPosition => {
511
- // const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
512
- // return current.columnIndex > acc ? current.columnIndex : acc
513
- // }, 0)
514
- // return maxColumnIndex + 1
515
- // }),
516
- // distinctUntilChanged()
517
- // )
518
-
519
- // const rowAmount$ = gridContainerPosition$.pipe(
520
- // map(gridContainerPosition => {
521
- // const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
522
- // return current.rowIndex > acc ? current.rowIndex : acc
523
- // }, 0)
524
- // return maxRowIndex + 1
525
- // }),
526
- // distinctUntilChanged()
527
- // )
528
-
529
- // return combineLatest({
530
- // eventData: eventData$,
531
- // gridContainerPosition: gridContainerPosition$,
532
- // layout: layout$,
533
- // columnAmount: columnAmount$,
534
- // rowAmount: rowAmount$
535
- // }).pipe(
536
- // switchMap(async d => d),
537
- // map(data => {
538
- // // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
539
- // const eventData = {
540
- // offsetX: data.eventData.offsetX * data.columnAmount % data.layout.rootWidth,
541
- // offsetY: data.eventData.offsetY * data.rowAmount % data.layout.rootHeight
542
- // }
543
- // return eventData
544
- // })
545
- // )
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Observable,
4
+ Subject,
5
+ of,
6
+ takeUntil,
7
+ filter,
8
+ map,
9
+ switchMap,
10
+ combineLatest,
11
+ merge,
12
+ shareReplay,
13
+ distinctUntilChanged
14
+ } from 'rxjs'
15
+ import type {
16
+ ChartParams,
17
+ HighlightTarget,
18
+ DataFormatterGrid,
19
+ ComputedDataGrid,
20
+ ComputedDatumGrid,
21
+ TransformData,
22
+ ContainerPositionScaled,
23
+ Layout } from '../../lib/core-types'
24
+ import { createAxisToLabelIndexScale } from '../../lib/core'
25
+ import { getClassName, getUniID } from '../utils/orbchartsUtils'
26
+ import { d3EventObservable } from '../utils/observables'
27
+
28
+ // 建立 grid 主要的 selection
29
+ export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
30
+ selection: d3.Selection<any, unknown, any, unknown>
31
+ pluginName: string
32
+ clipPathID: string
33
+ // computedData$: Observable<ComputedDataGrid>
34
+ seriesLabels$: Observable<string[]>
35
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
36
+ gridAxesTransform$: Observable<TransformData>
37
+ gridGraphicTransform$: Observable<TransformData>
38
+ }) => {
39
+ const seriesClassName = getClassName(pluginName, 'series')
40
+ const axesClassName = getClassName(pluginName, 'axes')
41
+ const graphicClassName = getClassName(pluginName, 'graphic')
42
+
43
+ // <g> series selection(container排放位置)
44
+ // <g> axes selection(旋轉圖軸方向)
45
+ // <defs> clipPath selection
46
+ // <g> graphic selection(圖形 scale 範圍的變形)
47
+ const seriesSelection$ = seriesLabels$.pipe(
48
+ map((seriesLabels, i) => {
49
+ return selection
50
+ .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
51
+ .data(seriesLabels, d => d)
52
+ .join(
53
+ enter => {
54
+ return enter
55
+ .append('g')
56
+ .classed(seriesClassName, true)
57
+ .each((d, i, g) => {
58
+ const axesSelection = d3.select(g[i])
59
+ .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
60
+ .data([i])
61
+ .join(
62
+ enter => {
63
+ return enter
64
+ .append('g')
65
+ .classed(axesClassName, true)
66
+ .attr('clip-path', `url(#${clipPathID})`)
67
+ .each((d, i, g) => {
68
+ const defsSelection = d3.select(g[i])
69
+ .selectAll<SVGDefsElement, any>('defs')
70
+ .data([i])
71
+ .join('defs')
72
+
73
+ const graphicGSelection = d3.select(g[i])
74
+ .selectAll<SVGGElement, any>('g')
75
+ .data([i])
76
+ .join('g')
77
+ .classed(graphicClassName, true)
78
+ })
79
+ },
80
+ update => update,
81
+ exit => exit.remove()
82
+ )
83
+ })
84
+ },
85
+ update => update,
86
+ exit => exit.remove()
87
+ )
88
+ }),
89
+ shareReplay(1)
90
+ )
91
+
92
+ // <g> series selection
93
+ combineLatest({
94
+ seriesSelection: seriesSelection$,
95
+ gridContainerPosition: gridContainerPosition$
96
+ }).pipe(
97
+ switchMap(async d => d)
98
+ ).subscribe(data => {
99
+ data.seriesSelection
100
+ .transition()
101
+ .attr('transform', (d, i) => {
102
+ const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
103
+ const translate = gridContainerPosition.translate
104
+ const scale = gridContainerPosition.scale
105
+ return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
106
+ })
107
+ })
108
+
109
+ // <g> axes selection
110
+ const axesSelection$ = combineLatest({
111
+ seriesSelection: seriesSelection$,
112
+ gridAxesTransform: gridAxesTransform$
113
+ }).pipe(
114
+ switchMap(async d => d),
115
+ map(data => {
116
+ return data.seriesSelection
117
+ .select<SVGGElement>(`g.${axesClassName}`)
118
+ .style('transform', data.gridAxesTransform.value)
119
+ }),
120
+ shareReplay(1)
121
+ )
122
+
123
+ // <defs> clipPath selection
124
+ const defsSelection$ = axesSelection$.pipe(
125
+ map(axesSelection => {
126
+ return axesSelection.select<SVGDefsElement>('defs')
127
+ }),
128
+ shareReplay(1)
129
+ )
130
+
131
+ // <g> graphic selection
132
+ const graphicGSelection$ = combineLatest({
133
+ axesSelection: axesSelection$,
134
+ gridGraphicTransform: gridGraphicTransform$
135
+ }).pipe(
136
+ switchMap(async d => d),
137
+ map(data => {
138
+ const graphicGSelection = data.axesSelection
139
+ .select<SVGGElement>(`g.${graphicClassName}`)
140
+ graphicGSelection
141
+ .transition()
142
+ .duration(50)
143
+ .style('transform', data.gridGraphicTransform.value)
144
+ return graphicGSelection
145
+ }),
146
+ shareReplay(1)
147
+ )
148
+
149
+ return {
150
+ seriesSelection$,
151
+ axesSelection$,
152
+ defsSelection$,
153
+ graphicGSelection$
154
+ }
155
+ }
156
+
157
+ // 由事件取得group data的function
158
+ export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
159
+ fullDataFormatter$: Observable<DataFormatterGrid>
160
+ gridAxesSize$: Observable<{
161
+ width: number;
162
+ height: number;
163
+ }>
164
+ computedData$: Observable<ComputedDataGrid>
165
+ // GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
166
+ fullChartParams$: Observable<ChartParams>
167
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
168
+ layout$: Observable<Layout>
169
+ }): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
170
+ const destroy$ = new Subject()
171
+
172
+ // 顯示範圍內的group labels
173
+ // const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
174
+ // combineLatest({
175
+ // dataFormatter: fullDataFormatter$,
176
+ // computedData: computedData$
177
+ // }).pipe(
178
+ // takeUntil(destroy$),
179
+ // switchMap(async (d) => d),
180
+ // ).subscribe(data => {
181
+ // const groupMin = 0
182
+ // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
183
+ // const groupScaleDomainMin = data.dataFormatter.groupAxis.scaleDomain[0] === 'auto'
184
+ // ? groupMin - data.dataFormatter.groupAxis.scalePadding
185
+ // : data.dataFormatter.groupAxis.scaleDomain[0] as number - data.dataFormatter.groupAxis.scalePadding
186
+ // const groupScaleDomainMax = data.dataFormatter.groupAxis.scaleDomain[1] === 'auto'
187
+ // ? groupMax + data.dataFormatter.groupAxis.scalePadding
188
+ // : data.dataFormatter.groupAxis.scaleDomain[1] as number + data.dataFormatter.groupAxis.scalePadding
189
+
190
+ // // const groupingAmount = data.computedData[0]
191
+ // // ? data.computedData[0].length
192
+ // // : 0
193
+
194
+ // let _labels = data.dataFormatter.seriesDirection === 'row'
195
+ // ? (data.computedData[0] ?? []).map(d => d.groupLabel)
196
+ // : data.computedData.map(d => d[0].groupLabel)
197
+
198
+ // const _axisLabels =
199
+ // // new Array(groupingAmount).fill(0)
200
+ // // .map((d, i) => {
201
+ // // return _labels[i] != null
202
+ // // ? _labels[i]
203
+ // // : String(i) // 沒有label則用序列號填充
204
+ // // })
205
+ // _labels
206
+ // .filter((d, i) => {
207
+ // return i >= groupScaleDomainMin && i <= groupScaleDomainMax
208
+ // })
209
+ // subscriber.next(_axisLabels)
210
+ // })
211
+ // })
212
+ const groupScaleDomain$ = combineLatest({
213
+ fullDataFormatter: fullDataFormatter$,
214
+ gridAxesSize: gridAxesSize$,
215
+ computedData: computedData$
216
+ }).pipe(
217
+ switchMap(async (d) => d),
218
+ map(data => {
219
+ const groupMin = 0
220
+ const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
221
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
222
+ // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
223
+ // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
224
+ const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
225
+ const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
226
+ ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
227
+ : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
228
+
229
+ return [groupScaleDomainMin, groupScaleDomainMax]
230
+ }),
231
+ shareReplay(1)
232
+ )
233
+
234
+ const groupLabels$ = combineLatest({
235
+ fullDataFormatter: fullDataFormatter$,
236
+ computedData: computedData$
237
+ }).pipe(
238
+ switchMap(async d => d),
239
+ map(data => {
240
+ return data.fullDataFormatter.seriesDirection === 'row'
241
+ ? (data.computedData[0] ?? []).map(d => d.groupLabel)
242
+ : data.computedData.map(d => d[0].groupLabel)
243
+ })
244
+ )
245
+
246
+ // 顯示範圍內的group labels
247
+ const scaleRangeGroupLabels$ = combineLatest({
248
+ groupScaleDomain: groupScaleDomain$,
249
+ groupLabels: groupLabels$
250
+ }).pipe(
251
+ switchMap(async d => d),
252
+ map(data => {
253
+ return data.groupLabels
254
+ .filter((d, i) => {
255
+ return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
256
+ })
257
+ })
258
+ )
259
+
260
+ const columnAmount$ = gridContainerPosition$.pipe(
261
+ map(gridContainerPosition => {
262
+ const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
263
+ return current.columnIndex > acc ? current.columnIndex : acc
264
+ }, 0)
265
+ return maxColumnIndex + 1
266
+ }),
267
+ distinctUntilChanged()
268
+ )
269
+
270
+ const rowAmount$ = gridContainerPosition$.pipe(
271
+ map(gridContainerPosition => {
272
+ const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
273
+ return current.rowIndex > acc ? current.rowIndex : acc
274
+ }, 0)
275
+ return maxRowIndex + 1
276
+ }),
277
+ distinctUntilChanged()
278
+ )
279
+
280
+ return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
281
+ combineLatest({
282
+ dataFormatter: fullDataFormatter$,
283
+ axisSize: gridAxesSize$,
284
+ fullChartParams: fullChartParams$,
285
+ scaleRangeGroupLabels: scaleRangeGroupLabels$,
286
+ groupLabels: groupLabels$,
287
+ groupScaleDomain: groupScaleDomain$,
288
+ columnAmount: columnAmount$,
289
+ rowAmount: rowAmount$,
290
+ layout: layout$
291
+ }).pipe(
292
+ takeUntil(destroy$),
293
+ switchMap(async (d) => d),
294
+ ).subscribe(data => {
295
+
296
+ const reverse = data.dataFormatter.valueAxis.position === 'right'
297
+ || data.dataFormatter.valueAxis.position === 'bottom'
298
+ ? true : false
299
+
300
+ // 比例尺座標對應非連續資料索引
301
+ const xIndexScale = createAxisToLabelIndexScale({
302
+ axisLabels: data.scaleRangeGroupLabels,
303
+ axisWidth: data.axisSize.width,
304
+ padding: data.dataFormatter.groupAxis.scalePadding,
305
+ reverse
306
+ })
307
+
308
+ // 依比例尺位置計算座標
309
+ const axisValuePredicate = (event: any) => {
310
+ return data.dataFormatter.groupAxis.position === 'bottom'
311
+ || data.dataFormatter.groupAxis.position === 'top'
312
+ ? event.offsetX - data.fullChartParams.padding.left
313
+ : event.offsetY - data.fullChartParams.padding.top
314
+ }
315
+
316
+ // 比例尺座標取得groupData的function
317
+ const createEventGroupData: (event: MouseEvent) => { groupIndex: number; groupLabel: string } = (event: any) => {
318
+ // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
319
+ const eventData = {
320
+ offsetX: event.offsetX * data.columnAmount % data.layout.rootWidth,
321
+ offsetY: event.offsetY * data.rowAmount % data.layout.rootHeight
322
+ }
323
+ // console.log('data.columnAmount', data.columnAmount, 'data.rowAmount', data.rowAmount, 'data.layout.rootWidth', data.layout.rootWidth, 'data.layout.rootHeight', data.layout.rootHeight)
324
+ const axisValue = axisValuePredicate(eventData)
325
+ const xIndex = xIndexScale(axisValue)
326
+ const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
327
+ const groupIndex = xIndex + currentxIndexStart
328
+
329
+ return {
330
+ groupIndex,
331
+ groupLabel: data.groupLabels[groupIndex] ?? ''
332
+ }
333
+ }
334
+
335
+ subscriber.next(createEventGroupData)
336
+
337
+ return function unsubscribe () {
338
+ destroy$.next(undefined)
339
+ }
340
+ })
341
+ })
342
+ }
343
+
344
+ export const gridGroupPositionObservable = ({ rootSelection, fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
345
+ rootSelection: d3.Selection<any, unknown, any, unknown>
346
+ fullDataFormatter$: Observable<DataFormatterGrid>
347
+ gridAxesSize$: Observable<{
348
+ width: number;
349
+ height: number;
350
+ }>
351
+ computedData$: Observable<ComputedDataGrid>
352
+ fullChartParams$: Observable<ChartParams>
353
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
354
+ layout$: Observable<Layout>
355
+ }) => {
356
+ const rootMousemove$ = d3EventObservable(rootSelection, 'mousemove')
357
+
358
+ const groupScaleDomain$ = combineLatest({
359
+ fullDataFormatter: fullDataFormatter$,
360
+ gridAxesSize: gridAxesSize$,
361
+ computedData: computedData$
362
+ }).pipe(
363
+ switchMap(async (d) => d),
364
+ map(data => {
365
+ const groupMin = 0
366
+ const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
367
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
368
+ // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
369
+ // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
370
+ const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
371
+ const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
372
+ ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
373
+ : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
374
+
375
+ return [groupScaleDomainMin, groupScaleDomainMax]
376
+ }),
377
+ shareReplay(1)
378
+ )
379
+
380
+ const groupLabels$ = combineLatest({
381
+ fullDataFormatter: fullDataFormatter$,
382
+ computedData: computedData$
383
+ }).pipe(
384
+ switchMap(async d => d),
385
+ map(data => {
386
+ return data.fullDataFormatter.seriesDirection === 'row'
387
+ ? (data.computedData[0] ?? []).map(d => d.groupLabel)
388
+ : data.computedData.map(d => d[0].groupLabel)
389
+ })
390
+ )
391
+
392
+ const scaleRangeGroupLabels$ = combineLatest({
393
+ groupScaleDomain: groupScaleDomain$,
394
+ groupLabels: groupLabels$
395
+ }).pipe(
396
+ switchMap(async d => d),
397
+ map(data => {
398
+ return data.groupLabels
399
+ .filter((d, i) => {
400
+ return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
401
+ })
402
+ })
403
+ )
404
+
405
+ const reverse$ = fullDataFormatter$.pipe(
406
+ map(d => {
407
+ return d.valueAxis.position === 'right' || d.valueAxis.position === 'bottom'
408
+ ? true
409
+ : false
410
+ })
411
+ )
412
+
413
+ // 比例尺座標對應非連續資料索引
414
+ const xIndexScale$ = combineLatest({
415
+ reverse: reverse$,
416
+ gridAxesSize: gridAxesSize$,
417
+ scaleRangeGroupLabels: scaleRangeGroupLabels$,
418
+ fullDataFormatter: fullDataFormatter$
419
+ }).pipe(
420
+ switchMap(async d => d),
421
+ map(data => {
422
+ return createAxisToLabelIndexScale({
423
+ axisLabels: data.scaleRangeGroupLabels,
424
+ axisWidth: data.gridAxesSize.width,
425
+ padding: data.fullDataFormatter.groupAxis.scalePadding,
426
+ reverse: data.reverse
427
+ })
428
+ })
429
+ )
430
+
431
+ const columnAmount$ = gridContainerPosition$.pipe(
432
+ map(gridContainerPosition => {
433
+ const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
434
+ return current.columnIndex > acc ? current.columnIndex : acc
435
+ }, 0)
436
+ return maxColumnIndex + 1
437
+ }),
438
+ distinctUntilChanged()
439
+ )
440
+
441
+ const rowAmount$ = gridContainerPosition$.pipe(
442
+ map(gridContainerPosition => {
443
+ const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
444
+ return current.rowIndex > acc ? current.rowIndex : acc
445
+ }, 0)
446
+ return maxRowIndex + 1
447
+ }),
448
+ distinctUntilChanged()
449
+ )
450
+
451
+ const axisValue$ = combineLatest({
452
+ fullDataFormatter: fullDataFormatter$,
453
+ fullChartParams: fullChartParams$,
454
+ rootMousemove: rootMousemove$,
455
+ columnAmount: columnAmount$,
456
+ rowAmount: rowAmount$,
457
+ layout: layout$
458
+ }).pipe(
459
+ switchMap(async d => d),
460
+ map(data => {
461
+ // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
462
+ const eventData = {
463
+ offsetX: data.rootMousemove.offsetX * data.columnAmount % data.layout.rootWidth,
464
+ offsetY: data.rootMousemove.offsetY * data.rowAmount % data.layout.rootHeight
465
+ }
466
+ return data.fullDataFormatter.groupAxis.position === 'bottom'
467
+ || data.fullDataFormatter.groupAxis.position === 'top'
468
+ ? eventData.offsetX - data.fullChartParams.padding.left
469
+ : eventData.offsetY - data.fullChartParams.padding.top
470
+ })
471
+ )
472
+
473
+ const groupIndex$ = combineLatest({
474
+ xIndexScale: xIndexScale$,
475
+ axisValue: axisValue$,
476
+ groupScaleDomain: groupScaleDomain$
477
+ }).pipe(
478
+ switchMap(async d => d),
479
+ map(data => {
480
+ const xIndex = data.xIndexScale(data.axisValue)
481
+ const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
482
+ return xIndex + currentxIndexStart
483
+ })
484
+ )
485
+
486
+ const groupLabel$ = combineLatest({
487
+ groupIndex: groupIndex$,
488
+ groupLabels: groupLabels$
489
+ }).pipe(
490
+ switchMap(async d => d),
491
+ map(data => {
492
+ return data.groupLabels[data.groupIndex] ?? ''
493
+ })
494
+ )
495
+
496
+ return combineLatest({
497
+ groupIndex: groupIndex$,
498
+ groupLabel: groupLabel$
499
+ }).pipe(
500
+ switchMap(async d => d),
501
+ map(data => {
502
+ return {
503
+ groupIndex: data.groupIndex,
504
+ groupLabel: data.groupLabel
505
+ }
506
+ })
507
+ )
508
+ }
509
+
510
+ // const gridContainerEventData$ = ({ eventData$, gridContainerPosition$, layout$ }: {
511
+ // eventData$: Observable<any>
512
+ // gridContainerPosition$: Observable<ContainerPositionScaled[]>
513
+ // layout$: Observable<Layout>
514
+ // }): Observable<{
515
+ // offsetX: number;
516
+ // offsetY: number;
517
+ // }> => {
518
+ // const columnAmount$ = gridContainerPosition$.pipe(
519
+ // map(gridContainerPosition => {
520
+ // const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
521
+ // return current.columnIndex > acc ? current.columnIndex : acc
522
+ // }, 0)
523
+ // return maxColumnIndex + 1
524
+ // }),
525
+ // distinctUntilChanged()
526
+ // )
527
+
528
+ // const rowAmount$ = gridContainerPosition$.pipe(
529
+ // map(gridContainerPosition => {
530
+ // const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
531
+ // return current.rowIndex > acc ? current.rowIndex : acc
532
+ // }, 0)
533
+ // return maxRowIndex + 1
534
+ // }),
535
+ // distinctUntilChanged()
536
+ // )
537
+
538
+ // return combineLatest({
539
+ // eventData: eventData$,
540
+ // gridContainerPosition: gridContainerPosition$,
541
+ // layout: layout$,
542
+ // columnAmount: columnAmount$,
543
+ // rowAmount: rowAmount$
544
+ // }).pipe(
545
+ // switchMap(async d => d),
546
+ // map(data => {
547
+ // // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
548
+ // const eventData = {
549
+ // offsetX: data.eventData.offsetX * data.columnAmount % data.layout.rootWidth,
550
+ // offsetY: data.eventData.offsetY * data.rowAmount % data.layout.rootHeight
551
+ // }
552
+ // return eventData
553
+ // })
554
+ // )
546
555
  // }