@orbcharts/plugins-basic 3.0.0-beta.15 → 3.0.0-beta.16

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 (180) hide show
  1. package/dist/orbcharts-plugins-basic.es.js +15129 -13927
  2. package/dist/orbcharts-plugins-basic.umd.js +72 -72
  3. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseBars.d.ts +3 -3
  4. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseBarsTriangle.d.ts +3 -3
  5. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseDots.d.ts +3 -3
  6. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLineAreas.d.ts +3 -3
  7. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLines.d.ts +3 -3
  8. package/dist/src/base/BaseRacingBars.d.ts +23 -0
  9. package/dist/src/base/BaseRacingLabels.d.ts +20 -0
  10. package/dist/src/base/BaseRacingValueLabels.d.ts +20 -0
  11. package/dist/{orbcharts-plugins-basic/src/base/BaseStackedBar.d.ts → src/base/BaseStackedBars.d.ts} +7 -7
  12. package/dist/{orbcharts-plugins-basic/src → src}/base/BaseValueAxis.d.ts +4 -7
  13. package/dist/src/base/BaseXAxis.d.ts +20 -0
  14. package/dist/src/base/BaseYAxis.d.ts +18 -0
  15. package/dist/{orbcharts-plugins-basic/src → src}/grid/defaults.d.ts +3 -3
  16. package/dist/{orbcharts-plugins-basic/src → src}/grid/gridObservables.d.ts +8 -1
  17. package/dist/{orbcharts-plugins-basic/src → src}/grid/index.d.ts +2 -2
  18. package/dist/src/grid/plugins/GroupZoom.d.ts +1 -0
  19. package/dist/src/grid/plugins/StackedBars.d.ts +1 -0
  20. package/dist/src/index.d.ts +7 -1
  21. package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/defaults.d.ts +2 -2
  22. package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/index.d.ts +1 -1
  23. package/dist/src/multiGrid/plugins/MultiStackedBars.d.ts +1 -0
  24. package/dist/src/multiValue/defaults.d.ts +13 -0
  25. package/dist/{orbcharts-plugins-basic/src → src}/multiValue/index.d.ts +5 -1
  26. package/dist/src/multiValue/multiValueObservables.d.ts +56 -0
  27. package/dist/src/multiValue/plugins/RacingBars.d.ts +1 -0
  28. package/dist/src/multiValue/plugins/RacingCounterTexts.d.ts +3 -0
  29. package/dist/src/multiValue/plugins/RacingValueAxis.d.ts +1 -0
  30. package/dist/src/multiValue/plugins/XAxis.d.ts +1 -0
  31. package/dist/src/multiValue/plugins/XYAxes.d.ts +1 -0
  32. package/dist/src/multiValue/plugins/XZoom.d.ts +1 -0
  33. package/lib/core.ts +1 -1
  34. package/package.json +4 -4
  35. package/src/base/BaseBars.ts +11 -11
  36. package/src/base/BaseBarsTriangle.ts +11 -11
  37. package/src/base/BaseDots.ts +10 -10
  38. package/src/base/BaseGroupAxis.ts +2 -0
  39. package/src/base/BaseLineAreas.ts +8 -8
  40. package/src/base/BaseLines.ts +7 -7
  41. package/src/base/BaseRacingBars.ts +552 -0
  42. package/src/base/BaseRacingLabels.ts +392 -0
  43. package/src/base/BaseRacingValueLabels.ts +403 -0
  44. package/src/base/{BaseStackedBar.ts → BaseStackedBars.ts} +22 -22
  45. package/src/base/BaseValueAxis.ts +70 -53
  46. package/src/base/BaseXAxis.ts +427 -0
  47. package/src/base/BaseYAxis.ts +389 -0
  48. package/src/grid/defaults.ts +4 -56
  49. package/src/grid/gridObservables.ts +58 -0
  50. package/src/grid/index.ts +2 -2
  51. package/src/grid/plugins/Bars.ts +2 -2
  52. package/src/grid/plugins/BarsPN.ts +2 -2
  53. package/src/grid/plugins/BarsTriangle.ts +2 -2
  54. package/src/grid/plugins/Dots.ts +2 -2
  55. package/src/grid/plugins/GridLegend.ts +7 -7
  56. package/src/grid/plugins/GroupAxis.ts +0 -24
  57. package/src/grid/plugins/{GridZoom.ts → GroupZoom.ts} +2 -2
  58. package/src/grid/plugins/LineAreas.ts +2 -2
  59. package/src/grid/plugins/Lines.ts +2 -2
  60. package/src/grid/plugins/{StackedBar.ts → StackedBars.ts} +6 -6
  61. package/src/multiGrid/defaults.ts +2 -2
  62. package/src/multiGrid/index.ts +1 -1
  63. package/src/multiGrid/multiGridObservables.ts +1 -0
  64. package/src/multiGrid/plugins/MultiBars.ts +3 -3
  65. package/src/multiGrid/plugins/MultiBarsTriangle.ts +3 -3
  66. package/src/multiGrid/plugins/MultiDots.ts +3 -3
  67. package/src/multiGrid/plugins/MultiGridLegend.ts +20 -10
  68. package/src/multiGrid/plugins/MultiLineAreas.ts +3 -3
  69. package/src/multiGrid/plugins/MultiLines.ts +3 -3
  70. package/src/multiGrid/plugins/{MultiStackedBar.ts → MultiStackedBars.ts} +7 -7
  71. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +1 -0
  72. package/src/multiValue/defaults.ts +137 -4
  73. package/src/multiValue/index.ts +5 -1
  74. package/src/multiValue/multiValueObservables.ts +414 -44
  75. package/src/multiValue/plugins/OrdinalBubbles.ts +0 -0
  76. package/src/multiValue/plugins/OrdinalXAxis.ts +0 -0
  77. package/src/multiValue/plugins/RacingBars.ts +362 -0
  78. package/src/multiValue/plugins/RacingCounterAxis.ts +0 -0
  79. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -0
  80. package/src/multiValue/plugins/RacingValueAxis.ts +115 -0
  81. package/src/multiValue/plugins/RankingAxis_legacy.ts +109 -0
  82. package/src/multiValue/plugins/Scatter.ts +13 -13
  83. package/src/multiValue/plugins/ScatterBubbles.ts +13 -13
  84. package/src/multiValue/plugins/XAxis.ts +108 -0
  85. package/src/multiValue/plugins/XYAux.ts +13 -13
  86. package/src/multiValue/plugins/XYAxes.ts +38 -528
  87. package/src/multiValue/plugins/XYAxes_legacy.ts +684 -0
  88. package/src/multiValue/plugins/{XYZoom.ts → XZoom.ts} +14 -14
  89. package/src/series/defaults.ts +2 -13
  90. package/src/series/plugins/Bubbles.ts +45 -29
  91. package/src/series/plugins/Pie.ts +5 -5
  92. package/src/series/plugins/PieEventTexts.ts +3 -3
  93. package/src/series/plugins/PieLabels.ts +5 -5
  94. package/src/series/plugins/Rose.ts +11 -11
  95. package/src/series/plugins/RoseLabels.ts +9 -9
  96. package/dist/orbcharts-plugins-basic/src/grid/plugins/GridZoom.d.ts +0 -1
  97. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedBar.d.ts +0 -1
  98. package/dist/orbcharts-plugins-basic/src/index.d.ts +0 -7
  99. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedBar.d.ts +0 -1
  100. package/dist/orbcharts-plugins-basic/src/multiValue/defaults.d.ts +0 -9
  101. package/dist/orbcharts-plugins-basic/src/multiValue/multiValueObservables.d.ts +0 -33
  102. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYZoom.d.ts +0 -1
  103. /package/dist/{orbcharts-plugins-basic/lib → lib}/core-types.d.ts +0 -0
  104. /package/dist/{orbcharts-plugins-basic/lib → lib}/core.d.ts +0 -0
  105. /package/dist/{orbcharts-plugins-basic/lib → lib}/plugins-basic-types.d.ts +0 -0
  106. /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseGroupAxis.d.ts +0 -0
  107. /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLegend.d.ts +0 -0
  108. /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseTooltip.d.ts +0 -0
  109. /package/dist/{orbcharts-plugins-basic/src → src}/base/types.d.ts +0 -0
  110. /package/dist/{orbcharts-plugins-basic/src → src}/const.d.ts +0 -0
  111. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Bars.d.ts +0 -0
  112. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/BarsPN.d.ts +0 -0
  113. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/BarsTriangle.d.ts +0 -0
  114. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Dots.d.ts +0 -0
  115. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GridLegend.d.ts +0 -0
  116. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GridTooltip.d.ts +0 -0
  117. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GroupAux.d.ts +0 -0
  118. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GroupAxis.d.ts +0 -0
  119. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/LineAreas.d.ts +0 -0
  120. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Lines.d.ts +0 -0
  121. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/StackedValueAxis.d.ts +0 -0
  122. /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/ValueAxis.d.ts +0 -0
  123. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/multiGridObservables.d.ts +0 -0
  124. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  125. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  126. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  127. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  128. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiGridTooltip.d.ts +0 -0
  129. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  130. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  131. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  132. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiStackedValueAxis.d.ts +0 -0
  133. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  134. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +0 -0
  135. /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  136. /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/MultiValueLegend.d.ts +0 -0
  137. /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/MultiValueTooltip.d.ts +0 -0
  138. /package/dist/{orbcharts-plugins-basic/src/multiValue/plugins/Ranking.d.ts → src/multiValue/plugins/OrdinalBubbles.d.ts} +0 -0
  139. /package/dist/{orbcharts-plugins-basic/src/multiValue/plugins/RankingAxis.d.ts → src/multiValue/plugins/OrdinalXAxis.d.ts} +0 -0
  140. /package/dist/{orbcharts-plugins-basic/src/noneData/plugins/Container.d.ts → src/multiValue/plugins/RacingCounterAxis.d.ts} +0 -0
  141. /package/dist/{orbcharts-plugins-basic/src/noneData/plugins/Tooltip.d.ts → src/multiValue/plugins/RankingAxis_legacy.d.ts} +0 -0
  142. /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/Scatter.d.ts +0 -0
  143. /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/ScatterBubbles.d.ts +0 -0
  144. /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/XYAux.d.ts +0 -0
  145. /package/dist/{orbcharts-plugins-basic/src/multiValue/plugins/XYAxes.d.ts → src/multiValue/plugins/XYAxes_legacy.d.ts} +0 -0
  146. /package/dist/{orbcharts-plugins-basic/src → src}/noneData/defaults.d.ts +0 -0
  147. /package/dist/{orbcharts-plugins-basic/src → src}/noneData/index.d.ts +0 -0
  148. /package/dist/{orbcharts-plugins-basic/src/series/plugins/Waffle.d.ts → src/noneData/plugins/Container.d.ts} +0 -0
  149. /package/{src/multiValue/plugins/Ranking.ts → dist/src/noneData/plugins/Tooltip.d.ts} +0 -0
  150. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/defaults.d.ts +0 -0
  151. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/index.d.ts +0 -0
  152. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/plugins/ForceDirected.d.ts +0 -0
  153. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/plugins/ForceDirectedBubbles.d.ts +0 -0
  154. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/plugins/RelationshipLegend.d.ts +0 -0
  155. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/plugins/RelationshipTooltip.d.ts +0 -0
  156. /package/dist/{orbcharts-plugins-basic/src → src}/relationship/relationshipObservables.d.ts +0 -0
  157. /package/dist/{orbcharts-plugins-basic/src → src}/series/defaults.d.ts +0 -0
  158. /package/dist/{orbcharts-plugins-basic/src → src}/series/index.d.ts +0 -0
  159. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Bubbles.d.ts +0 -0
  160. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Pie.d.ts +0 -0
  161. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/PieEventTexts.d.ts +0 -0
  162. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/PieLabels.d.ts +0 -0
  163. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Rose.d.ts +0 -0
  164. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/RoseLabels.d.ts +0 -0
  165. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/SeriesLegend.d.ts +0 -0
  166. /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/SeriesTooltip.d.ts +0 -0
  167. /package/{src/multiValue/plugins/RankingAxis.ts → dist/src/series/plugins/Waffle.d.ts} +0 -0
  168. /package/dist/{orbcharts-plugins-basic/src → src}/series/seriesObservables.d.ts +0 -0
  169. /package/dist/{orbcharts-plugins-basic/src → src}/series/seriesUtils.d.ts +0 -0
  170. /package/dist/{orbcharts-plugins-basic/src → src}/tree/defaults.d.ts +0 -0
  171. /package/dist/{orbcharts-plugins-basic/src → src}/tree/index.d.ts +0 -0
  172. /package/dist/{orbcharts-plugins-basic/src → src}/tree/plugins/TreeLegend.d.ts +0 -0
  173. /package/dist/{orbcharts-plugins-basic/src → src}/tree/plugins/TreeMap.d.ts +0 -0
  174. /package/dist/{orbcharts-plugins-basic/src → src}/tree/plugins/TreeTooltip.d.ts +0 -0
  175. /package/dist/{orbcharts-plugins-basic/src → src}/utils/commonUtils.d.ts +0 -0
  176. /package/dist/{orbcharts-plugins-basic/src → src}/utils/d3Graphics.d.ts +0 -0
  177. /package/dist/{orbcharts-plugins-basic/src → src}/utils/d3Utils.d.ts +0 -0
  178. /package/dist/{orbcharts-plugins-basic/src → src}/utils/observables.d.ts +0 -0
  179. /package/dist/{orbcharts-plugins-basic/src → src}/utils/orbchartsUtils.d.ts +0 -0
  180. /package/dist/{orbcharts-plugins-basic/vite.config.d.ts → vite.config.d.ts} +0 -0
@@ -0,0 +1,552 @@
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ switchMap,
6
+ takeUntil,
7
+ distinctUntilChanged,
8
+ shareReplay,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import type { BasePluginFn } from './types'
12
+ import type {
13
+ ComputedDatumMultiValue,
14
+ ComputedDataMultiValue,
15
+ // ComputedLayoutDataGrid,
16
+ DataFormatterTypeMap,
17
+ ContainerPositionScaled,
18
+ ContainerSize,
19
+ EventMultiValue,
20
+ ChartParams,
21
+ Layout,
22
+ TransformData } from '../../lib/core-types'
23
+ import type { BaseRacingBarsParams } from '../../lib/plugins-basic-types'
24
+ import { getD3TransitionEase } from '../utils/d3Utils'
25
+ import { getClassName, getUniID } from '../utils/orbchartsUtils'
26
+ import { multiValueContainerSelectionsObservable } from '../multiValue/multiValueObservables'
27
+
28
+ // export interface BaseBarsParams {
29
+ // // barType: BarType
30
+ // barWidth: number
31
+ // barPadding: number
32
+ // barGroupPadding: number // 群組和群組間的間隔
33
+ // barRadius: number | boolean
34
+ // }
35
+
36
+ interface BaseRacingBarsContext {
37
+ selection: d3.Selection<any, unknown, any, unknown>
38
+ computedData$: Observable<ComputedDataMultiValue>
39
+ visibleComputedRankingData$: Observable<ComputedDatumMultiValue[][]>
40
+ CategoryDataMap$: Observable<Map<string, ComputedDatumMultiValue[]>>
41
+ fullParams$: Observable<BaseRacingBarsParams>
42
+ fullChartParams$: Observable<ChartParams>
43
+ // xyValueIndex$: Observable<[number, number]>
44
+ highlight$: Observable<ComputedDatumMultiValue[]>
45
+ rankingItemHeight$: Observable<number>
46
+ rankingScaleList$: Observable<d3.ScalePoint<string>[]>
47
+ containerPosition$: Observable<ContainerPositionScaled[]>
48
+ containerSize$: Observable<ContainerSize>
49
+ xScale$: Observable<(n: number) => number>
50
+ isCategorySeprate$: Observable<boolean>
51
+ event$: Subject<EventMultiValue>
52
+ }
53
+
54
+ interface RenderGraphicGParams {
55
+ containerSelection: d3.Selection<SVGGElement, ComputedDatumMultiValue[], any, any>
56
+ visibleComputedRankingData: ComputedDatumMultiValue[][]
57
+ rankingScaleList: d3.ScalePoint<string>[]
58
+ transitionDuration: number
59
+ }
60
+
61
+ interface RenderBarParams {
62
+ graphicGSelection: d3.Selection<SVGGElement, ComputedDatumMultiValue, any, any>
63
+ rectClassName: string
64
+ // xyValueIndex: [number, number]
65
+ xScale: (n: number) => number
66
+ fullParams: BaseRacingBarsParams
67
+ barWidth: number
68
+ transitionDuration: number
69
+ }
70
+
71
+ type ClipPathDatum = {
72
+ id: string;
73
+ // x: number;
74
+ // y: number;
75
+ width: number;
76
+ height: number;
77
+ }
78
+
79
+
80
+ function renderGraphicG ({ containerSelection, visibleComputedRankingData, rankingScaleList, transitionDuration }: RenderGraphicGParams) {
81
+ containerSelection
82
+ .each((_, categoryIndex, g) => {
83
+ const container = d3.select(g[categoryIndex])
84
+ const graphicG = container.selectAll<SVGGElement, ComputedDatumMultiValue>(`g`)
85
+ .data(visibleComputedRankingData[categoryIndex] ?? [], d => d.id)
86
+ .join(
87
+ enter => {
88
+ return enter
89
+ .append('g')
90
+ .attr('cursor', 'pointer')
91
+ .attr('transform', d => {
92
+ return `translate(0, ${rankingScaleList[categoryIndex] && rankingScaleList[categoryIndex](d.label)})`
93
+ })
94
+ },
95
+ update => {
96
+ return update
97
+ .transition()
98
+ .duration(transitionDuration)
99
+ .ease(d3.easeLinear)
100
+ .attr('transform', d => {
101
+ return `translate(0, ${rankingScaleList[categoryIndex] && rankingScaleList[categoryIndex](d.label)})`
102
+ })
103
+ },
104
+ exit => exit.remove()
105
+ )
106
+ })
107
+
108
+ const graphicBarSelection: d3.Selection<SVGRectElement, ComputedDatumMultiValue, SVGGElement, unknown> = containerSelection.selectAll(`g`)
109
+
110
+ return graphicBarSelection
111
+ }
112
+
113
+ function renderRectBars ({ graphicGSelection, rectClassName, xScale, fullParams, barWidth, transitionDuration }: RenderBarParams) {
114
+
115
+ graphicGSelection
116
+ .each((datum, i, g) => {
117
+ // const containerIndex = isCategorySeprate ? datum.categoryIndex : 0
118
+ // const barWidth = barWidthList[containerIndex]
119
+ const barHalfWidth = barWidth / 2
120
+ const radius = fullParams.bar.barRadius === true ? barHalfWidth
121
+ : fullParams.bar.barRadius === false ? 0
122
+ : typeof fullParams.bar.barRadius == 'number' ? fullParams.bar.barRadius
123
+ : 0
124
+
125
+ const gSelection = d3.select(g[i])
126
+ gSelection.selectAll<SVGRectElement, ComputedDatumMultiValue>(`rect.${rectClassName}`)
127
+ .data([datum], d => d.id)
128
+ .join(
129
+ enter => {
130
+ return enter
131
+ .append('rect')
132
+ .classed(rectClassName, true)
133
+ .attr('cursor', 'pointer')
134
+ // .attr('width', d => 1)
135
+ .attr('width', d => xScale(d.value[d.xValueIndex]) ?? 1)
136
+ .attr('height', barWidth)
137
+ },
138
+ update => {
139
+ return update
140
+ .transition()
141
+ .duration(transitionDuration)
142
+ .ease(d3.easeLinear)
143
+ .attr('width', d => xScale(d.value[d.xValueIndex]) ?? 1)
144
+ .attr('height', barWidth)
145
+ },
146
+ exit => exit.remove()
147
+ )
148
+ .attr('transform', `translate(0, ${-barHalfWidth})`)
149
+ .attr('fill', d => d.color)
150
+ .attr('rx', radius)
151
+ .attr('ry', radius)
152
+ })
153
+
154
+ const graphicBarSelection: d3.Selection<SVGRectElement, ComputedDatumMultiValue, SVGGElement, unknown> = graphicGSelection.selectAll(`rect.${rectClassName}`)
155
+
156
+ return graphicBarSelection
157
+ }
158
+
159
+ function renderClipPath ({ defsSelection, clipPathData }: {
160
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
161
+ clipPathData: ClipPathDatum[]
162
+ }) {
163
+ const clipPath = defsSelection
164
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
165
+ .data(clipPathData)
166
+ .join(
167
+ enter => {
168
+ return enter
169
+ .append('clipPath')
170
+ },
171
+ update => update,
172
+ exit => exit.remove()
173
+ )
174
+ .attr('id', d => d.id)
175
+ .each((d, i, g) => {
176
+ const rect = d3.select(g[i])
177
+ .selectAll<SVGRectElement, typeof d>('rect')
178
+ .data([d])
179
+ .join(
180
+ enter => {
181
+ return enter
182
+ .append('rect')
183
+ },
184
+ update => update,
185
+ exit => exit.remove()
186
+ )
187
+ .attr('x', 0)
188
+ .attr('y', 0)
189
+ .attr('width', _d => _d.width)
190
+ .attr('height', _d => _d.height)
191
+ })
192
+ }
193
+
194
+ function highlight ({ selection, ids, fullChartParams }: {
195
+ selection: d3.Selection<any, ComputedDatumMultiValue, any, any>
196
+ ids: string[]
197
+ fullChartParams: ChartParams
198
+ }) {
199
+ selection.interrupt('highlight')
200
+
201
+ if (!ids.length) {
202
+ // remove highlight
203
+ selection
204
+ .transition('highlight')
205
+ .duration(200)
206
+ .style('opacity', 1)
207
+ return
208
+ }
209
+
210
+ selection
211
+ .each((d, i, n) => {
212
+ if (ids.includes(d.id)) {
213
+ d3.select(n[i])
214
+ .style('opacity', 1)
215
+ } else {
216
+ d3.select(n[i])
217
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
218
+ }
219
+ })
220
+ }
221
+
222
+
223
+ export const createBaseRacingBars: BasePluginFn<BaseRacingBarsContext> = (pluginName: string, {
224
+ selection,
225
+ computedData$,
226
+ visibleComputedRankingData$,
227
+ // xyValueIndex$,
228
+ // categoryLabels$,
229
+ CategoryDataMap$,
230
+ fullParams$,
231
+ fullChartParams$,
232
+ // layout$,
233
+ // graphicTransform$,
234
+ // graphicReverseScale$,
235
+ highlight$,
236
+ // computedRankingAmountList$,
237
+ rankingItemHeight$,
238
+ rankingScaleList$,
239
+ containerPosition$,
240
+ containerSize$,
241
+ // layout$,
242
+ xScale$,
243
+ isCategorySeprate$,
244
+ event$
245
+ }) => {
246
+
247
+ const destroy$ = new Subject()
248
+
249
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
250
+ const rectClassName = getClassName(pluginName, 'rect')
251
+ // const containerClassName = getClassName(pluginName, 'container')
252
+
253
+ // const {
254
+ // categorySelection$,
255
+ // axesSelection$,
256
+ // defsSelection$,
257
+ // graphicGSelection$
258
+ // } = multiValueSelectionsObservable({
259
+ // selection,
260
+ // pluginName,
261
+ // clipPathID,
262
+ // categoryLabels$: categoryLabels$,
263
+ // containerPosition$: containerPosition$,
264
+ // graphicTransform$: graphicTransform$
265
+ // })
266
+
267
+ // const clipPathSubscription = combineLatest({
268
+ // defsSelection: defsSelection$,
269
+ // layout: layout$,
270
+ // }).pipe(
271
+ // takeUntil(destroy$),
272
+ // switchMap(async (d) => d),
273
+ // ).subscribe(data => {
274
+ // // 外層的遮罩
275
+ // const clipPathData = [{
276
+ // id: clipPathID,
277
+ // width: data.layout.width,
278
+ // height: data.layout.height
279
+ // }]
280
+ // renderClipPath({
281
+ // defsSelection: data.defsSelection,
282
+ // clipPathData,
283
+ // })
284
+ // })
285
+
286
+ const containerSelection$ = multiValueContainerSelectionsObservable({
287
+ selection,
288
+ pluginName,
289
+ clipPathID,
290
+ computedData$,
291
+ containerPosition$,
292
+ isCategorySeprate$,
293
+ }).pipe(
294
+ takeUntil(destroy$),
295
+ )
296
+
297
+ // const containerSelection$ = combineLatest({
298
+ // computedData: computedData$.pipe(
299
+ // distinctUntilChanged((a, b) => {
300
+ // // 只有當series的數量改變時,才重新計算
301
+ // return a.length === b.length
302
+ // }),
303
+ // ),
304
+ // isCategorySeprate: isCategorySeprate$
305
+ // }).pipe(
306
+ // takeUntil(destroy$),
307
+ // switchMap(async (d) => d),
308
+ // map(data => {
309
+ // return data.isCategorySeprate
310
+ // // category分開的時候顯示各別axis
311
+ // ? data.computedData
312
+ // // category合併的時候只顯示第一個axis
313
+ // : [data.computedData[0]]
314
+ // }),
315
+ // map((computedData, i) => {
316
+ // return selection
317
+ // .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${containerClassName}`)
318
+ // .data(computedData, d => d[0] ? d[0].categoryIndex : i)
319
+ // .join('g')
320
+ // .classed(containerClassName, true)
321
+ // .attr('clip-path', `url(#${clipPathID})`)
322
+ // })
323
+ // )
324
+
325
+ containerSize$.subscribe(data => {
326
+ const defsSelection = selection.selectAll<SVGDefsElement, any>('defs')
327
+ .data([clipPathID])
328
+ .join('defs')
329
+ const clipPathData = [{
330
+ id: clipPathID,
331
+ width: data.width,
332
+ height: data.height
333
+ }]
334
+ renderClipPath({
335
+ defsSelection: defsSelection,
336
+ clipPathData,
337
+ // textReverseTransform: data.textReverseTransform
338
+ })
339
+ })
340
+
341
+ // combineLatest({
342
+ // containerSelection: containerSelection$,
343
+ // containerPosition: containerPosition$
344
+ // }).pipe(
345
+ // takeUntil(destroy$),
346
+ // switchMap(async d => d)
347
+ // ).subscribe(data => {
348
+ // data.containerSelection
349
+ // .attr('transform', (d, i) => {
350
+ // const containerPosition = data.containerPosition[i] ?? data.containerPosition[0]
351
+ // const translate = containerPosition.translate
352
+ // const scale = containerPosition.scale
353
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
354
+ // return `translate(${translate[0]}, ${translate[1]})`
355
+ // })
356
+ // // .attr('opacity', 0)
357
+ // // .transition()
358
+ // // .attr('opacity', 1)
359
+ // })
360
+
361
+ const barWidth$ = combineLatest({
362
+ fullParams: fullParams$,
363
+ rankingItemHeight: rankingItemHeight$,
364
+ }).pipe(
365
+ takeUntil(destroy$),
366
+ switchMap(async d => d),
367
+ map(data => {
368
+ if (data.fullParams.bar.barWidth) {
369
+ return data.fullParams.bar.barWidth
370
+ } else {
371
+ return data.rankingItemHeight - data.fullParams.bar.barPadding
372
+ }
373
+ }),
374
+ distinctUntilChanged()
375
+ )
376
+
377
+ const transitionDuration$ = fullChartParams$.pipe(
378
+ takeUntil(destroy$),
379
+ map(d => d.transitionDuration),
380
+ distinctUntilChanged()
381
+ )
382
+
383
+ const graphicGSelection$ = combineLatest({
384
+ containerSelection: containerSelection$,
385
+ visibleComputedRankingData: visibleComputedRankingData$,
386
+ rankingScaleList: rankingScaleList$,
387
+ transitionDuration: transitionDuration$,
388
+ }).pipe(
389
+ takeUntil(destroy$),
390
+ switchMap(async (d) => d),
391
+ map(data => {
392
+
393
+ return renderGraphicG({
394
+ containerSelection: data.containerSelection,
395
+ visibleComputedRankingData: data.visibleComputedRankingData,
396
+ rankingScaleList: data.rankingScaleList,
397
+ transitionDuration: data.transitionDuration
398
+ })
399
+ })
400
+ )
401
+
402
+ const graphicSelection$ = combineLatest({
403
+ graphicGSelection: graphicGSelection$,
404
+ // xyValueIndex: xyValueIndex$,
405
+ xScale: xScale$,
406
+ barWidth: barWidth$,
407
+ transitionDuration: transitionDuration$,
408
+ fullParams: fullParams$,
409
+ }).pipe(
410
+ takeUntil(destroy$),
411
+ switchMap(async (d) => d),
412
+ map(data => {
413
+
414
+ return renderRectBars({
415
+ graphicGSelection: data.graphicGSelection,
416
+ rectClassName,
417
+ // xyValueIndex: data.xyValueIndex,
418
+ xScale: data.xScale,
419
+ fullParams: data.fullParams,
420
+ barWidth: data.barWidth,
421
+ transitionDuration: data.transitionDuration,
422
+ })
423
+ }),
424
+ shareReplay(1)
425
+ )
426
+
427
+ const highlightTarget$ = fullChartParams$.pipe(
428
+ takeUntil(destroy$),
429
+ map(d => d.highlightTarget),
430
+ distinctUntilChanged()
431
+ )
432
+
433
+ combineLatest({
434
+ graphicSelection: graphicSelection$,
435
+ computedData: computedData$,
436
+ CategoryDataMap: CategoryDataMap$,
437
+ highlightTarget: highlightTarget$
438
+ }).pipe(
439
+ takeUntil(destroy$),
440
+ switchMap(async (d) => d),
441
+ ).subscribe(data => {
442
+
443
+ data.graphicSelection
444
+ .on('mouseover', (event, datum) => {
445
+ // event.stopPropagation()
446
+ // console.log({
447
+ // type: 'multiValue',
448
+ // eventName: 'mouseover',
449
+ // pluginName,
450
+ // highlightTarget: data.highlightTarget,
451
+ // datum,
452
+ // category: data.CategoryDataMap.get(datum.categoryLabel)!,
453
+ // categoryIndex: datum.categoryIndex,
454
+ // categoryLabel: datum.categoryLabel,
455
+ // data: data.computedData,
456
+ // event,
457
+ // })
458
+
459
+ // 只顯示目前的值
460
+ datum._visibleValue = [datum.value[datum.xValueIndex]]
461
+
462
+ event$.next({
463
+ type: 'multiValue',
464
+ eventName: 'mouseover',
465
+ pluginName,
466
+ highlightTarget: data.highlightTarget,
467
+ datum,
468
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
469
+ categoryIndex: datum.categoryIndex,
470
+ categoryLabel: datum.categoryLabel,
471
+ data: data.computedData,
472
+ event,
473
+ })
474
+ })
475
+ .on('mousemove', (event, datum) => {
476
+ // event.stopPropagation()
477
+
478
+ // 只顯示目前的值
479
+ datum._visibleValue = [datum.value[datum.xValueIndex]]
480
+
481
+ event$.next({
482
+ type: 'multiValue',
483
+ eventName: 'mousemove',
484
+ pluginName,
485
+ highlightTarget: data.highlightTarget,
486
+ datum,
487
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
488
+ categoryIndex: datum.categoryIndex,
489
+ categoryLabel: datum.categoryLabel,
490
+ data: data.computedData,
491
+ event,
492
+ })
493
+ })
494
+ .on('mouseout', (event, datum) => {
495
+ // event.stopPropagation()
496
+
497
+ event$.next({
498
+ type: 'multiValue',
499
+ eventName: 'mouseout',
500
+ pluginName,
501
+ highlightTarget: data.highlightTarget,
502
+ datum,
503
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
504
+ categoryIndex: datum.categoryIndex,
505
+ categoryLabel: datum.categoryLabel,
506
+ data: data.computedData,
507
+ event,
508
+ })
509
+ })
510
+ .on('click', (event, datum) => {
511
+ // event.stopPropagation()
512
+
513
+ // 只顯示目前的值
514
+ datum._visibleValue = [datum.value[datum.xValueIndex]]
515
+
516
+ event$.next({
517
+ type: 'multiValue',
518
+ eventName: 'click',
519
+ pluginName,
520
+ highlightTarget: data.highlightTarget,
521
+ datum,
522
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
523
+ categoryIndex: datum.categoryIndex,
524
+ categoryLabel: datum.categoryLabel,
525
+ data: data.computedData,
526
+ event,
527
+ })
528
+ })
529
+
530
+ })
531
+
532
+ combineLatest({
533
+ graphicSelection: graphicSelection$,
534
+ highlight: highlight$.pipe(
535
+ map(data => data.map(d => d.id))
536
+ ),
537
+ fullChartParams: fullChartParams$
538
+ }).pipe(
539
+ takeUntil(destroy$),
540
+ switchMap(async d => d)
541
+ ).subscribe(data => {
542
+ highlight({
543
+ selection: data.graphicSelection,
544
+ ids: data.highlight,
545
+ fullChartParams: data.fullChartParams
546
+ })
547
+ })
548
+
549
+ return () => {
550
+ destroy$.next(undefined)
551
+ }
552
+ }