@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,392 @@
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Observable,
4
+ Subject,
5
+ combineLatest,
6
+ takeUntil,
7
+ map,
8
+ distinctUntilChanged,
9
+ of,
10
+ iif,
11
+ switchMap,
12
+ shareReplay
13
+ } from 'rxjs'
14
+ import type {
15
+ ChartParams,
16
+ ComputedDatumMultiValue,
17
+ ComputedDataMultiValue,
18
+ ComputedXYDatumMultiValue,
19
+ ContainerSize,
20
+ ContainerPositionScaled,
21
+ DataFormatterMultiValue,
22
+ Layout
23
+ } from '../../lib/core-types'
24
+ import type { BaseRacingLabelsParams } from '../../lib/plugins-basic-types'
25
+ import type { BasePluginFn } from './types'
26
+ import { getColor, getClassName, getUniID } from '../utils/orbchartsUtils'
27
+ import { multiValueContainerSelectionsObservable } from '../multiValue/multiValueObservables'
28
+
29
+ interface BaseRacingAxisContext {
30
+ selection: d3.Selection<any, unknown, any, unknown>
31
+ computedData$: Observable<ComputedDataMultiValue>
32
+ visibleComputedRankingData$: Observable<ComputedDatumMultiValue[][]>
33
+ rankingScaleList$: Observable<Array<d3.ScalePoint<string>>>
34
+ xScale$: Observable<(n: number) => number>
35
+ fullParams$: Observable<BaseRacingLabelsParams>
36
+ fullDataFormatter$: Observable<DataFormatterMultiValue>
37
+ fullChartParams$: Observable<ChartParams>
38
+ // layout$: Observable<Layout>
39
+ containerPosition$: Observable<ContainerPositionScaled[]>
40
+ containerSize$: Observable<ContainerSize>
41
+ isCategorySeprate$: Observable<boolean>
42
+ // xyValueIndex$: Observable<[number, number]>
43
+ }
44
+
45
+ type ClipPathDatum = {
46
+ id: string;
47
+ // x: number;
48
+ // y: number;
49
+ width: number;
50
+ height: number;
51
+ }
52
+
53
+ // const pluginName = 'RacingAxis'
54
+
55
+ const yTickTextAnchor = 'end'
56
+ const yTickDominantBaseline = 'middle'
57
+ const yAxisLabelAnchor = 'end'
58
+ const yAxisLabelDominantBaseline = 'auto'
59
+ // const textClassName = getClassName(pluginName, 'yLabel')
60
+
61
+ function renderRacingAxisLabel ({ selection, textClassName, fullParams, containerSize, fullDataFormatter, fullChartParams, textReverseTransform }: {
62
+ selection: d3.Selection<SVGGElement, any, any, any>,
63
+ textClassName: string
64
+ fullParams: BaseRacingLabelsParams
65
+ // axisLabelAlign: TextAlign
66
+ containerSize: ContainerSize
67
+ fullDataFormatter: DataFormatterMultiValue,
68
+ fullChartParams: ChartParams
69
+ textReverseTransform: string,
70
+ }) {
71
+ const offsetX = fullParams.barLabel.padding - fullParams.axisLabel.offset[0]
72
+ const offsetY = - fullParams.barLabel.padding - fullParams.axisLabel.offset[1]
73
+ let labelX = - offsetX
74
+ let labelY = - offsetY
75
+
76
+ selection
77
+ .attr('transform', d => `translate(0, ${containerSize.height})`)
78
+ .selectAll<SVGTextElement, BaseRacingLabelsParams>(`text`)
79
+ .data([fullParams])
80
+ .join(
81
+ enter => {
82
+ return enter
83
+ .append('text')
84
+ .style('font-weight', 'bold')
85
+ },
86
+ update => update,
87
+ exit => exit.remove()
88
+ )
89
+ .attr('text-anchor', yAxisLabelAnchor)
90
+ .attr('dominant-baseline', yAxisLabelDominantBaseline)
91
+ .attr('font-size', fullChartParams.styles.textSize)
92
+ .style('fill', getColor(fullParams.axisLabel.colorType, fullChartParams))
93
+ // .style('transform', textReverseTransform)
94
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
95
+ .attr('x', labelX)
96
+ .attr('y', labelY)
97
+ .text(d => fullDataFormatter.yAxis.label)
98
+ }
99
+
100
+ function renderRacingLabels ({ selection, fullParams, fullChartParams, rankingScale, valueScale, categoryData }: {
101
+ selection: d3.Selection<SVGGElement, any, any, any>,
102
+ fullParams: BaseRacingLabelsParams
103
+ fullChartParams: ChartParams
104
+ rankingScale: d3.ScalePoint<string>
105
+ valueScale: ((n: number) => number)
106
+ categoryData: ComputedDatumMultiValue[]
107
+ // textReverseTransformWithRotate: string,
108
+ // xyValueIndex: [number, number]
109
+ }) {
110
+ const labelData = fullParams.barLabel.position === 'none' ? [] : categoryData
111
+
112
+ const labelSelection = selection
113
+ .selectAll<SVGGElement, string>(`text`)
114
+ .data(labelData, (d: ComputedDatumMultiValue) => d.id)
115
+ // .join('g')
116
+ // .classed(boxClassName, true)
117
+ .join(
118
+ enter => {
119
+ return enter
120
+ .append('text')
121
+ .style('font-weight', 'bold')
122
+ .attr('x', d => valueScale(d.value[d.xValueIndex] ?? 0) - fullParams.barLabel.padding)
123
+ .attr('y', d => rankingScale(d.label)!)
124
+ },
125
+ update => {
126
+ return update
127
+ .transition()
128
+ .duration(fullChartParams.transitionDuration)
129
+ .ease(d3.easeLinear)
130
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
131
+ .attr('x', d => valueScale(d.value[d.xValueIndex] ?? 0) - fullParams.barLabel.padding)
132
+ .attr('y', d => rankingScale(d.label)!)
133
+ },
134
+ exit => exit.remove()
135
+ )
136
+ .attr('text-anchor', yTickTextAnchor)
137
+ .attr('dominant-baseline', yTickDominantBaseline)
138
+ .attr('font-size', fullChartParams.styles.textSize)
139
+ .style('fill', getColor(fullParams.barLabel.colorType, fullChartParams))
140
+ // .style('transform', textReverseTransformWithRotate)
141
+ .text(d => d.label)
142
+
143
+ return labelSelection
144
+ }
145
+
146
+
147
+ function renderClipPath ({ defsSelection, clipPathData }: {
148
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
149
+ clipPathData: ClipPathDatum[]
150
+ // textReverseTransform: string
151
+ }) {
152
+ const clipPath = defsSelection
153
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
154
+ .data(clipPathData)
155
+ .join(
156
+ enter => {
157
+ return enter
158
+ .append('clipPath')
159
+ },
160
+ update => update,
161
+ exit => exit.remove()
162
+ )
163
+ .attr('id', d => d.id)
164
+ // .attr('transform', textReverseTransform)
165
+ .each((d, i, g) => {
166
+ const rect = d3.select(g[i])
167
+ .selectAll<SVGRectElement, typeof d>('rect')
168
+ .data([d])
169
+ .join(
170
+ enter => {
171
+ return enter
172
+ .append('rect')
173
+ },
174
+ update => update,
175
+ exit => exit.remove()
176
+ )
177
+ .attr('x', _d => - _d.width)
178
+ .attr('y', 0)
179
+ .attr('width', _d => _d.width * 2)
180
+ .attr('height', _d => _d.height)
181
+ })
182
+ }
183
+
184
+ export const createBaseRacingLabels: BasePluginFn<BaseRacingAxisContext> = (pluginName: string, {
185
+ selection,
186
+ computedData$,
187
+ visibleComputedRankingData$,
188
+ rankingScaleList$,
189
+ xScale$,
190
+ fullParams$,
191
+ fullDataFormatter$,
192
+ fullChartParams$,
193
+ // layout$,
194
+ containerPosition$,
195
+ containerSize$,
196
+ isCategorySeprate$,
197
+ // xyValueIndex$
198
+ }) => {
199
+
200
+ const destroy$ = new Subject()
201
+
202
+ // const containerClassName = getClassName(pluginName, 'container')
203
+ const boxClassName = getClassName(pluginName, 'box')
204
+ const textClassName = getClassName(pluginName, 'text')
205
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
206
+
207
+ const containerSelection$ = multiValueContainerSelectionsObservable({
208
+ selection,
209
+ pluginName,
210
+ clipPathID: null,
211
+ computedData$,
212
+ containerPosition$,
213
+ isCategorySeprate$,
214
+ }).pipe(
215
+ takeUntil(destroy$),
216
+ )
217
+
218
+ // const containerSelection$ = combineLatest({
219
+ // computedData: computedData$.pipe(
220
+ // distinctUntilChanged((a, b) => {
221
+ // // 只有當series的數量改變時,才重新計算
222
+ // return a.length === b.length
223
+ // }),
224
+ // ),
225
+ // isCategorySeprate: isCategorySeprate$
226
+ // }).pipe(
227
+ // takeUntil(destroy$),
228
+ // switchMap(async (d) => d),
229
+ // map(data => {
230
+ // return data.isCategorySeprate
231
+ // // category分開的時候顯示各別axis
232
+ // ? data.computedData
233
+ // // category合併的時候只顯示第一個axis
234
+ // : [data.computedData[0]]
235
+ // }),
236
+ // map((computedData, i) => {
237
+ // return selection
238
+ // .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${containerClassName}`)
239
+ // .data(computedData, d => d[0] ? d[0].categoryIndex : i)
240
+ // .join('g')
241
+ // .classed(containerClassName, true)
242
+ // })
243
+ // )
244
+
245
+ // combineLatest({
246
+ // containerSelection: containerSelection$,
247
+ // containerPosition: containerPosition$
248
+ // }).pipe(
249
+ // takeUntil(destroy$),
250
+ // switchMap(async d => d)
251
+ // ).subscribe(data => {
252
+ // data.containerSelection
253
+ // .attr('transform', (d, i) => {
254
+ // const containerPosition = data.containerPosition[i] ?? data.containerPosition[0]
255
+ // const translate = containerPosition.translate
256
+ // const scale = containerPosition.scale
257
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
258
+ // return `translate(${translate[0]}, ${translate[1]})`
259
+ // })
260
+ // // .attr('opacity', 0)
261
+ // // .transition()
262
+ // // .attr('opacity', 1)
263
+ // })
264
+
265
+ const textReverseTransform$ = containerPosition$.pipe(
266
+ takeUntil(destroy$),
267
+ switchMap(async (d) => d),
268
+ map(containerPosition => {
269
+ // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
270
+ // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
271
+ const containerScaleReverseValue = `scale(${1 / containerPosition[0].scale[0]}, ${1 / containerPosition[0].scale[1]})`
272
+ // 抵消最外層scale
273
+ return `${containerScaleReverseValue}`
274
+ }),
275
+ distinctUntilChanged()
276
+ )
277
+
278
+ // const textReverseTransformWithRotate$ = combineLatest({
279
+ // textReverseTransform: textReverseTransform$,
280
+ // fullParams: fullParams$,
281
+ // }).pipe(
282
+ // takeUntil(destroy$),
283
+ // switchMap(async (d) => d),
284
+ // map(data => {
285
+ // // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
286
+ // return `${data.textReverseTransform} rotate(${data.fullParams.barLabel.rotate}deg)`
287
+ // })
288
+ // )
289
+
290
+ // const rankingLabelList$ = visibleComputedRankingData$.pipe(
291
+ // takeUntil(destroy$),
292
+ // map(data => {
293
+ // return data.map(categoryData => categoryData.map(d => d.label))
294
+ // })
295
+ // )
296
+
297
+ const valueScale$: Observable<((n: number) => number)> = fullParams$.pipe(
298
+ map(fullParams => fullParams.barLabel.position),
299
+ distinctUntilChanged(),
300
+ switchMap(position => {
301
+ return iif(
302
+ () => position === 'inside',
303
+ xScale$,
304
+ of(() => 0)
305
+ )
306
+ })
307
+ )
308
+
309
+ containerSize$.subscribe(data => {
310
+ const defsSelection = selection.selectAll<SVGDefsElement, any>('defs')
311
+ .data([clipPathID])
312
+ .join('defs')
313
+ const clipPathData = [{
314
+ id: clipPathID,
315
+ width: data.width,
316
+ height: data.height
317
+ }]
318
+ renderClipPath({
319
+ defsSelection: defsSelection,
320
+ clipPathData,
321
+ // textReverseTransform: data.textReverseTransform
322
+ })
323
+ })
324
+
325
+ combineLatest({
326
+ containerSelection: containerSelection$,
327
+ fullParams: fullParams$,
328
+ // layout: layout$,
329
+ containerSize: containerSize$,
330
+ fullDataFormatter: fullDataFormatter$,
331
+ fullChartParams: fullChartParams$,
332
+ visibleComputedRankingData: visibleComputedRankingData$,
333
+ // rankingLabelList: rankingLabelList$,
334
+ rankingScaleList: rankingScaleList$,
335
+ valueScale: valueScale$,
336
+ textReverseTransform: textReverseTransform$,
337
+ // textReverseTransformWithRotate: textReverseTransformWithRotate$,
338
+ // xyValueIndex: xyValueIndex$
339
+ }).pipe(
340
+ takeUntil(destroy$),
341
+ switchMap(async (d) => d),
342
+ ).subscribe(data => {
343
+
344
+ data.containerSelection.each((d, i, g) => {
345
+ const _containerSelection = d3.select(g[i])
346
+ // const rankingLabels = data.rankingLabelList[i]
347
+ const rankingScale = data.rankingScaleList[i]
348
+ if (!rankingScale) {
349
+ return
350
+ }
351
+
352
+ // const containerClipPathID = `${clipPathID}-${i}`
353
+ const axisSelection = _containerSelection
354
+ .selectAll<SVGGElement, any>(`g.${boxClassName}`)
355
+ .data([i])
356
+ .join('g')
357
+ .attr('class', boxClassName)
358
+ .attr('clip-path', `url(#${clipPathID})`)
359
+ const axisLabelSelection = _containerSelection
360
+ .selectAll<SVGGElement, BaseRacingLabelsParams>(`g.${textClassName}`)
361
+ .data([data.fullParams])
362
+ .join('g')
363
+ .classed(textClassName, true)
364
+
365
+ renderRacingLabels({
366
+ selection: axisSelection,
367
+ fullParams: data.fullParams,
368
+ fullChartParams: data.fullChartParams,
369
+ rankingScale: rankingScale,
370
+ categoryData: data.visibleComputedRankingData[i],
371
+ // textReverseTransformWithRotate: data.textReverseTransformWithRotate,
372
+ valueScale: data.valueScale,
373
+ // xyValueIndex: data.xyValueIndex,
374
+ })
375
+
376
+ renderRacingAxisLabel({
377
+ selection: axisLabelSelection,
378
+ textClassName,
379
+ fullParams: data.fullParams,
380
+ containerSize: data.containerSize,
381
+ fullDataFormatter: data.fullDataFormatter,
382
+ fullChartParams: data.fullChartParams,
383
+ textReverseTransform: data.textReverseTransform,
384
+ })
385
+ })
386
+
387
+ })
388
+
389
+ return () => {
390
+ destroy$.next(undefined)
391
+ }
392
+ }