@orbcharts/plugins-basic 3.0.0-beta.2 → 3.0.0-beta.20

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 (182) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +15169 -10684
  3. package/dist/orbcharts-plugins-basic.umd.js +296 -83
  4. package/dist/src/base/BaseBars.d.ts +4 -4
  5. package/dist/src/base/BaseBarsTriangle.d.ts +4 -4
  6. package/dist/src/base/BaseDots.d.ts +4 -4
  7. package/dist/src/base/BaseGroupAxis.d.ts +2 -2
  8. package/dist/src/base/BaseLegend.d.ts +1 -1
  9. package/dist/src/base/BaseLineAreas.d.ts +5 -5
  10. package/dist/src/base/BaseLines.d.ts +5 -5
  11. package/dist/src/base/BaseRacingBars.d.ts +23 -0
  12. package/dist/src/base/BaseRacingLabels.d.ts +20 -0
  13. package/dist/src/base/BaseRacingValueLabels.d.ts +20 -0
  14. package/dist/src/base/{BaseBarStack.d.ts → BaseStackedBars.d.ts} +8 -8
  15. package/dist/src/base/BaseValueAxis.d.ts +6 -8
  16. package/dist/src/base/BaseXAxis.d.ts +20 -0
  17. package/dist/src/base/BaseYAxis.d.ts +18 -0
  18. package/dist/src/grid/defaults.d.ts +5 -5
  19. package/dist/src/grid/gridObservables.d.ts +12 -5
  20. package/dist/src/grid/index.d.ts +3 -3
  21. package/dist/src/grid/plugins/GroupZoom.d.ts +1 -0
  22. package/dist/src/grid/plugins/StackedBars.d.ts +1 -0
  23. package/dist/src/grid/plugins/StackedValueAxis.d.ts +1 -0
  24. package/dist/src/index.d.ts +2 -0
  25. package/dist/src/multiGrid/defaults.d.ts +4 -4
  26. package/dist/src/multiGrid/index.d.ts +3 -3
  27. package/dist/src/multiGrid/plugins/MultiStackedBars.d.ts +1 -0
  28. package/dist/src/multiGrid/plugins/MultiStackedValueAxis.d.ts +1 -0
  29. package/dist/src/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +1 -0
  30. package/dist/src/multiValue/defaults.d.ts +13 -0
  31. package/dist/src/multiValue/index.d.ts +12 -0
  32. package/dist/src/multiValue/multiValueObservables.d.ts +56 -0
  33. package/dist/src/multiValue/plugins/MultiValueLegend.d.ts +1 -0
  34. package/dist/src/multiValue/plugins/MultiValueTooltip.d.ts +1 -0
  35. package/dist/src/multiValue/plugins/RacingBars.d.ts +1 -0
  36. package/dist/src/multiValue/plugins/RacingCounterTexts.d.ts +3 -0
  37. package/dist/src/multiValue/plugins/RacingValueAxis.d.ts +1 -0
  38. package/dist/src/multiValue/plugins/Scatter.d.ts +3 -0
  39. package/dist/src/multiValue/plugins/ScatterBubbles.d.ts +3 -0
  40. package/dist/src/multiValue/plugins/XAxis.d.ts +1 -0
  41. package/dist/src/multiValue/plugins/XYAux.d.ts +3 -0
  42. package/dist/src/multiValue/plugins/XYAxes.d.ts +1 -0
  43. package/dist/src/multiValue/plugins/XYAxes_legacy.d.ts +3 -0
  44. package/dist/src/multiValue/plugins/XZoom.d.ts +1 -0
  45. package/dist/src/noneData/plugins/Container.d.ts +0 -1
  46. package/dist/src/noneData/plugins/Tooltip.d.ts +0 -3
  47. package/dist/src/relationship/defaults.d.ts +6 -0
  48. package/dist/src/relationship/index.d.ts +5 -0
  49. package/dist/src/relationship/plugins/ForceDirected.d.ts +3 -0
  50. package/dist/src/relationship/plugins/ForceDirectedBubbles.d.ts +3 -0
  51. package/dist/src/relationship/plugins/RelationshipLegend.d.ts +1 -0
  52. package/dist/src/relationship/plugins/RelationshipTooltip.d.ts +1 -0
  53. package/dist/src/relationship/relationshipObservables.d.ts +1 -0
  54. package/dist/src/series/seriesObservables.d.ts +3 -3
  55. package/dist/src/utils/commonUtils.d.ts +2 -1
  56. package/dist/src/utils/d3Graphics.d.ts +2 -1
  57. package/dist/src/utils/d3Utils.d.ts +3 -2
  58. package/dist/src/utils/observables.d.ts +1 -1
  59. package/dist/src/utils/orbchartsUtils.d.ts +3 -3
  60. package/lib/core-types.ts +7 -7
  61. package/lib/core.ts +6 -6
  62. package/lib/plugins-basic-types.ts +6 -6
  63. package/package.json +44 -44
  64. package/src/base/BaseBars.ts +765 -765
  65. package/src/base/BaseBarsTriangle.ts +676 -674
  66. package/src/base/BaseDots.ts +464 -515
  67. package/src/base/BaseGroupAxis.ts +691 -679
  68. package/src/base/BaseLegend.ts +684 -680
  69. package/src/base/BaseLineAreas.ts +629 -629
  70. package/src/base/BaseLines.ts +706 -706
  71. package/src/base/BaseRacingBars.ts +552 -0
  72. package/src/base/BaseRacingLabels.ts +396 -0
  73. package/src/base/BaseRacingValueLabels.ts +403 -0
  74. package/src/base/{BaseBarStack.ts → BaseStackedBars.ts} +782 -780
  75. package/src/base/BaseTooltip.ts +386 -385
  76. package/src/base/BaseValueAxis.ts +600 -580
  77. package/src/base/BaseXAxis.ts +427 -0
  78. package/src/base/BaseYAxis.ts +389 -0
  79. package/src/base/types.ts +2 -2
  80. package/src/const.ts +30 -30
  81. package/src/grid/defaults.ts +213 -244
  82. package/src/grid/gridObservables.ts +612 -545
  83. package/src/grid/index.ts +16 -16
  84. package/src/grid/plugins/Bars.ts +69 -69
  85. package/src/grid/plugins/BarsPN.ts +66 -66
  86. package/src/grid/plugins/BarsTriangle.ts +73 -73
  87. package/src/grid/plugins/Dots.ts +68 -68
  88. package/src/grid/plugins/GridLegend.ts +107 -107
  89. package/src/grid/plugins/GridTooltip.ts +66 -66
  90. package/src/grid/plugins/GroupAux.ts +1120 -1098
  91. package/src/grid/plugins/GroupAxis.ts +73 -97
  92. package/src/grid/plugins/{GridZoom.ts → GroupZoom.ts} +218 -218
  93. package/src/grid/plugins/LineAreas.ts +65 -65
  94. package/src/grid/plugins/Lines.ts +59 -59
  95. package/src/grid/plugins/{BarStack.ts → StackedBars.ts} +64 -64
  96. package/src/grid/plugins/{ValueStackAxis.ts → StackedValueAxis.ts} +96 -95
  97. package/src/grid/plugins/ValueAxis.ts +94 -93
  98. package/src/index.ts +6 -9
  99. package/src/multiGrid/defaults.ts +244 -224
  100. package/src/multiGrid/index.ts +15 -15
  101. package/src/multiGrid/multiGridObservables.ts +50 -49
  102. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  103. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  104. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  105. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -159
  106. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  107. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  108. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  109. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  110. package/src/multiGrid/plugins/{MultiBarStack.ts → MultiStackedBars.ts} +106 -106
  111. package/src/multiGrid/plugins/{MultiValueStackAxis.ts → MultiStackedValueAxis.ts} +134 -133
  112. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -133
  113. package/src/multiGrid/plugins/{OverlappingValueStackAxes.ts → OverlappingStackedValueAxes.ts} +300 -298
  114. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -299
  115. package/src/multiValue/defaults.ts +432 -0
  116. package/src/multiValue/index.ts +13 -0
  117. package/src/multiValue/multiValueObservables.ts +667 -0
  118. package/src/multiValue/plugins/MultiValueLegend.ts +107 -0
  119. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -0
  120. package/src/multiValue/plugins/RacingBars.ts +373 -0
  121. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -0
  122. package/src/multiValue/plugins/RacingValueAxis.ts +115 -0
  123. package/src/multiValue/plugins/RankingAxis_legacy.ts +109 -0
  124. package/src/multiValue/plugins/Scatter.ts +426 -0
  125. package/src/multiValue/plugins/ScatterBubbles.ts +554 -0
  126. package/src/multiValue/plugins/XAxis.ts +108 -0
  127. package/src/multiValue/plugins/XYAux.ts +683 -0
  128. package/src/multiValue/plugins/XYAxes.ts +195 -0
  129. package/src/multiValue/plugins/XYAxes_legacy.ts +684 -0
  130. package/src/multiValue/plugins/XZoom.ts +300 -0
  131. package/src/noneData/defaults.ts +102 -102
  132. package/src/noneData/index.ts +3 -3
  133. package/src/noneData/plugins/Container.ts +28 -28
  134. package/src/noneData/plugins/Tooltip.ts +374 -374
  135. package/src/relationship/defaults.ts +222 -0
  136. package/src/relationship/index.ts +5 -0
  137. package/src/relationship/plugins/ForceDirected.ts +1174 -0
  138. package/src/relationship/plugins/ForceDirectedBubbles.ts +1412 -0
  139. package/src/relationship/plugins/RelationshipLegend.ts +100 -0
  140. package/src/relationship/plugins/RelationshipTooltip.ts +66 -0
  141. package/src/relationship/relationshipObservables.ts +50 -0
  142. package/src/series/defaults.ts +221 -206
  143. package/src/series/index.ts +9 -9
  144. package/src/series/plugins/Bubbles.ts +636 -603
  145. package/src/series/plugins/Pie.ts +623 -623
  146. package/src/series/plugins/PieEventTexts.ts +284 -283
  147. package/src/series/plugins/PieLabels.ts +640 -640
  148. package/src/series/plugins/Rose.ts +516 -516
  149. package/src/series/plugins/RoseLabels.ts +600 -600
  150. package/src/series/plugins/SeriesLegend.ts +107 -107
  151. package/src/series/plugins/SeriesTooltip.ts +66 -66
  152. package/src/series/seriesObservables.ts +145 -145
  153. package/src/series/seriesUtils.ts +51 -51
  154. package/src/tree/defaults.ts +102 -78
  155. package/src/tree/index.ts +4 -4
  156. package/src/tree/plugins/TreeLegend.ts +100 -107
  157. package/src/tree/plugins/TreeMap.ts +341 -333
  158. package/src/tree/plugins/TreeTooltip.ts +66 -66
  159. package/src/utils/commonUtils.ts +31 -22
  160. package/src/utils/d3Graphics.ts +176 -174
  161. package/src/utils/d3Utils.ts +92 -73
  162. package/src/utils/observables.ts +14 -14
  163. package/src/utils/orbchartsUtils.ts +130 -100
  164. package/tsconfig.base.json +13 -13
  165. package/tsconfig.json +2 -2
  166. package/vite.config.js +22 -22
  167. package/dist/src/grid/plugins/BarStack.d.ts +0 -1
  168. package/dist/src/grid/plugins/GridZoom.d.ts +0 -1
  169. package/dist/src/grid/plugins/ValueStackAxis.d.ts +0 -1
  170. package/dist/src/multiGrid/plugins/MultiBarStack.d.ts +0 -1
  171. package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +0 -1
  172. package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +0 -1
  173. package/src/grid/plugins/RankingAxis.ts +0 -0
  174. package/src/multiValue/plugins/ScatterAxes.ts +0 -0
  175. package/src/relationship/plugins/Relationship.ts +0 -0
  176. /package/dist/src/{base/BaseGroupArea.d.ts → multiValue/plugins/OrdinalBubbles.d.ts} +0 -0
  177. /package/dist/src/{grid/plugins/Ranking.d.ts → multiValue/plugins/OrdinalXAxis.d.ts} +0 -0
  178. /package/dist/src/{grid/plugins/RankingAxis.d.ts → multiValue/plugins/RacingCounterAxis.d.ts} +0 -0
  179. /package/dist/src/multiValue/plugins/{ScatterAxes.d.ts → RankingAxis_legacy.d.ts} +0 -0
  180. /package/{dist/src/relationship/plugins/Relationship.d.ts → src/multiValue/plugins/OrdinalBubbles.ts} +0 -0
  181. /package/src/{base/BaseGroupArea.ts → multiValue/plugins/OrdinalXAxis.ts} +0 -0
  182. /package/src/{grid/plugins/Ranking.ts → multiValue/plugins/RacingCounterAxis.ts} +0 -0
@@ -0,0 +1,389 @@
1
+ import * as d3 from 'd3'
2
+ import {
3
+ Observable,
4
+ Subject,
5
+ combineLatest,
6
+ takeUntil,
7
+ map,
8
+ distinctUntilChanged,
9
+ switchMap,
10
+ shareReplay
11
+ } from 'rxjs'
12
+ import type {
13
+ ColorType,
14
+ ChartParams,
15
+ ComputedDatumMultiValue,
16
+ ComputedDataMultiValue,
17
+ ComputedXYDatumMultiValue,
18
+ ContainerPositionScaled,
19
+ ContainerSize,
20
+ DataFormatterMultiValue,
21
+ DefinePluginConfig,
22
+ TransformData,
23
+ Layout
24
+ } from '../../lib/core-types'
25
+ import {
26
+ createValueToAxisScale,
27
+ } from '../../lib/core'
28
+ import type { BaseYAxisParams
29
+ } from '../../lib/plugins-basic-types'
30
+ import type { BasePluginFn } from './types'
31
+ // import { DEFAULT_X_Y_AXES_PARAMS } from '../defaults'
32
+ // import { LAYER_INDEX_OF_AXIS } from '../const'
33
+ import { getColor, getDatumColor, getClassName, getUniID } from '../utils/orbchartsUtils'
34
+ import { parseTickFormatValue } from '../utils/d3Utils'
35
+ import { multiValueContainerSelectionsObservable } from '../multiValue/multiValueObservables'
36
+
37
+ interface BaseYAxisContext {
38
+ selection: d3.Selection<any, unknown, any, unknown>
39
+ computedData$: Observable<ComputedDataMultiValue>
40
+ // filteredMinMaxValue$: Observable<[number, number]>
41
+ fullParams$: Observable<BaseYAxisParams>
42
+ fullDataFormatter$: Observable<DataFormatterMultiValue>
43
+ fullChartParams$: Observable<ChartParams>
44
+ isCategorySeprate$: Observable<boolean>
45
+ containerPosition$: Observable<ContainerPositionScaled[]>
46
+ containerSize$: Observable<ContainerSize>
47
+ // layout$: Observable<Layout>
48
+ // filteredXYMinMaxData$: Observable<{
49
+ // datumList: ComputedXYDatumMultiValue[];
50
+ // minXDatum: ComputedXYDatumMultiValue | null;
51
+ // maxXDatum: ComputedXYDatumMultiValue | null;
52
+ // minYDatum: ComputedXYDatumMultiValue | null;
53
+ // maxYDatum: ComputedXYDatumMultiValue | null;
54
+ // }>
55
+ yScale$: Observable<d3.ScaleLinear<number, number>>
56
+ // xyMinMax$: Observable<{
57
+ // minX: number;
58
+ // maxX: number;
59
+ // minY: number;
60
+ // maxY: number;
61
+ // }>
62
+ }
63
+
64
+ // interface TextAlign {
65
+ // textAnchor: "start" | "middle" | "end"
66
+ // dominantBaseline: "middle" | "auto" | "hanging"
67
+ // }
68
+
69
+ const defaultTickSize = 6
70
+
71
+ const yTickTextAnchor = 'end'
72
+ const yTickDominantBaseline = 'middle'
73
+ const yAxisLabelAnchor = 'end'
74
+ const yAxisLabelDominantBaseline = 'auto'
75
+
76
+ function renderYAxisLabel ({ selection, yLabelClassName, fullParams, containerSize, fullDataFormatter, fullChartParams }: {
77
+ selection: d3.Selection<SVGGElement, any, any, any>,
78
+ yLabelClassName: string
79
+ fullParams: BaseYAxisParams
80
+ // axisLabelAlign: TextAlign
81
+ containerSize: { width: number, height: number }
82
+ fullDataFormatter: DataFormatterMultiValue,
83
+ fullChartParams: ChartParams
84
+ // textReverseTransform: string,
85
+ }) {
86
+ const offsetX = fullParams.tickPadding - fullParams.labelOffset[0]
87
+ const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
88
+ let labelX = - offsetX
89
+ let labelY = - offsetY
90
+
91
+ const axisLabelSelection = selection
92
+ .selectAll<SVGGElement, BaseYAxisParams>(`g.${yLabelClassName}`)
93
+ .data([fullParams])
94
+ .join('g')
95
+ .classed(yLabelClassName, true)
96
+ .each((d, i, g) => {
97
+ const text = d3.select(g[i])
98
+ .selectAll<SVGTextElement, BaseYAxisParams>(`text`)
99
+ .data([d])
100
+ .join(
101
+ enter => {
102
+ return enter
103
+ .append('text')
104
+ .style('font-weight', 'bold')
105
+ },
106
+ update => update,
107
+ exit => exit.remove()
108
+ )
109
+ .attr('text-anchor', yAxisLabelAnchor)
110
+ .attr('dominant-baseline', yAxisLabelDominantBaseline)
111
+ .attr('font-size', fullChartParams.styles.textSize)
112
+ .style('fill', getColor(fullParams.labelColorType, fullChartParams))
113
+ // .style('transform', textReverseTransform)
114
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
115
+ .attr('x', labelX)
116
+ .attr('y', labelY)
117
+ .text(d => fullDataFormatter.yAxis.label)
118
+ })
119
+ // .attr('transform', d => `translate(0, ${layout.height})`)
120
+ }
121
+
122
+ function renderYAxis ({ selection, yAxisClassName, fullParams, containerSize, fullDataFormatter, fullChartParams, yScale }: {
123
+ selection: d3.Selection<SVGGElement, any, any, any>,
124
+ yAxisClassName: string
125
+ fullParams: BaseYAxisParams
126
+ // tickTextAlign: TextAlign
127
+ containerSize: ContainerSize
128
+ fullDataFormatter: DataFormatterMultiValue,
129
+ fullChartParams: ChartParams
130
+ yScale: d3.ScaleLinear<number, number>
131
+ // textReverseTransform: string,
132
+ // xyMinMax: {
133
+ // minX: number;
134
+ // maxX: number;
135
+ // minY: number;
136
+ // maxY: number;
137
+ // }
138
+ }) {
139
+
140
+ const yAxisSelection = selection
141
+ .selectAll<SVGGElement, BaseYAxisParams>(`g.${yAxisClassName}`)
142
+ .data([fullParams])
143
+ .join('g')
144
+ .classed(yAxisClassName, true)
145
+
146
+ // const _yScale = d3.scaleLinear()
147
+ // .domain([0, 150])
148
+ // .range([416.5, 791.349])
149
+
150
+ // 刻度文字偏移
151
+ let tickPadding = fullParams.tickPadding
152
+
153
+ // 設定Y軸刻度
154
+ const yAxis = d3.axisLeft(yScale)
155
+ .scale(yScale)
156
+ .ticks(fullParams.ticks) // 刻度分段數量
157
+ .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
158
+ .tickSize(fullParams.tickFullLine == true
159
+ ? -containerSize.width
160
+ : defaultTickSize)
161
+ .tickPadding(tickPadding)
162
+
163
+ const yAxisEl = yAxisSelection
164
+ .transition()
165
+ .duration(100)
166
+ .ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
167
+ .call(yAxis)
168
+
169
+ yAxisEl.selectAll('line')
170
+ .style('fill', 'none')
171
+ .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
172
+ .style('stroke-dasharray', fullParams.tickFullLineDasharray)
173
+ .attr('pointer-events', 'none')
174
+
175
+ yAxisEl.selectAll('path')
176
+ .style('fill', 'none')
177
+ // .style('stroke', this.fullParams.axisLineColor!)
178
+ .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
179
+ .style('shape-rendering', 'crispEdges')
180
+
181
+ // const yText = yAxisEl.selectAll('text')
182
+ const yText = yAxisSelection.selectAll('text')
183
+ // .style('font-family', 'sans-serif')
184
+ .attr('font-size', fullChartParams.styles.textSize)
185
+ .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
186
+ .attr('text-anchor', yTickTextAnchor)
187
+ .attr('dominant-baseline', yTickDominantBaseline)
188
+ // .attr('dy', 0)
189
+ .attr('x', - tickPadding)
190
+ .attr('dy', 0)
191
+ // yText.style('transform', textReverseTransform)
192
+
193
+ // // 抵消掉預設的偏移
194
+ // if (fullDataFormatter.grid.valueAxis.position === 'bottom' || fullDataFormatter.grid.valueAxis.position === 'top') {
195
+ // yText.attr('dy', 0)
196
+ // }
197
+
198
+ return yAxisSelection
199
+ }
200
+
201
+ export const createBaseYAxis: BasePluginFn<BaseYAxisContext> = (pluginName: string, {
202
+ selection,
203
+ computedData$,
204
+ fullParams$,
205
+ fullDataFormatter$,
206
+ fullChartParams$,
207
+ isCategorySeprate$,
208
+ containerPosition$,
209
+ containerSize$,
210
+ // layout$,
211
+ // filteredXYMinMaxData$,
212
+ yScale$,
213
+ // xyMinMax$
214
+ }) => {
215
+
216
+ const destroy$ = new Subject()
217
+
218
+ // const containerClassName = getClassName(pluginName, 'container')
219
+ const yAxisGClassName = getClassName(pluginName, 'yAxisG')
220
+ const yAxisClassName = getClassName(pluginName, 'yAxis')
221
+ const yLabelClassName = getClassName(pluginName, 'yLabel')
222
+
223
+ const containerSelection$ = multiValueContainerSelectionsObservable({
224
+ selection,
225
+ pluginName,
226
+ clipPathID: null,
227
+ computedData$,
228
+ containerPosition$,
229
+ isCategorySeprate$,
230
+ }).pipe(
231
+ takeUntil(destroy$),
232
+ )
233
+
234
+ // const containerSelection$ = combineLatest({
235
+ // computedData: computedData$.pipe(
236
+ // distinctUntilChanged((a, b) => {
237
+ // // 只有當series的數量改變時,才重新計算
238
+ // return a.length === b.length
239
+ // }),
240
+ // ),
241
+ // isCategorySeprate: isCategorySeprate$
242
+ // }).pipe(
243
+ // takeUntil(destroy$),
244
+ // switchMap(async (d) => d),
245
+ // map(data => {
246
+ // return data.isCategorySeprate
247
+ // // category分開的時候顯示各別axis
248
+ // ? data.computedData
249
+ // // category合併的時候只顯示第一個axis
250
+ // : [data.computedData[0]]
251
+ // }),
252
+ // map((computedData, i) => {
253
+ // return selection
254
+ // .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${containerClassName}`)
255
+ // .data(computedData, d => d[0] ? d[0].categoryIndex : i)
256
+ // .join('g')
257
+ // .classed(containerClassName, true)
258
+ // })
259
+ // )
260
+
261
+ const axisSelection$ = containerSelection$.pipe(
262
+ takeUntil(destroy$),
263
+ map((containerSelection, i) => {
264
+ return containerSelection
265
+ .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${yAxisGClassName}`)
266
+ .data([yAxisGClassName])
267
+ .join('g')
268
+ .classed(yAxisGClassName, true)
269
+ })
270
+ )
271
+
272
+ // combineLatest({
273
+ // containerSelection: containerSelection$,
274
+ // gridContainerPosition: containerPosition$
275
+ // }).pipe(
276
+ // takeUntil(destroy$),
277
+ // switchMap(async d => d)
278
+ // ).subscribe(data => {
279
+ // data.containerSelection
280
+ // .attr('transform', (d, i) => {
281
+ // const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
282
+ // const translate = gridContainerPosition.translate
283
+ // const scale = gridContainerPosition.scale
284
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
285
+ // return `translate(${translate[0]}, ${translate[1]})`
286
+ // })
287
+ // // .attr('opacity', 0)
288
+ // // .transition()
289
+ // // .attr('opacity', 1)
290
+ // })
291
+
292
+ // const textReverseTransform$ = containerPosition$.pipe(
293
+ // takeUntil(destroy$),
294
+ // switchMap(async (d) => d),
295
+ // map(containerPosition => {
296
+ // // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
297
+ // // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
298
+ // const containerScaleReverseValue = `scale(${1 / containerPosition[0].scale[0]}, ${1 / containerPosition[0].scale[1]})`
299
+ // // 抵消最外層scale
300
+ // return `${containerScaleReverseValue}`
301
+ // }),
302
+ // distinctUntilChanged()
303
+ // )
304
+
305
+ // const yScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
306
+ // combineLatest({
307
+ // fullDataFormatter: fullDataFormatter$,
308
+ // layout: layout$,
309
+ // // xyMinMax: observer.xyMinMax$
310
+ // filteredXYMinMaxData: filteredXYMinMaxData$
311
+ // }).pipe(
312
+ // takeUntil(destroy$),
313
+ // switchMap(async (d) => d),
314
+ // ).subscribe(data => {
315
+ // const valueIndex = data.fullDataFormatter.xAxis.valueIndex
316
+ // if (!data.filteredXYMinMaxData.minYDatum || !data.filteredXYMinMaxData.maxYDatum
317
+ // || data.filteredXYMinMaxData.minYDatum.value[valueIndex] == null || data.filteredXYMinMaxData.maxYDatum.value[valueIndex] == null
318
+ // ) {
319
+ // return
320
+ // }
321
+ // let maxValue = data.filteredXYMinMaxData.maxYDatum.value[valueIndex]
322
+ // let minValue = data.filteredXYMinMaxData.minYDatum.value[valueIndex]
323
+ // if (maxValue === minValue && maxValue === 0) {
324
+ // // 避免最大及最小值同等於 0 造成無法計算scale
325
+ // maxValue = 1
326
+ // }
327
+
328
+ // const yScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
329
+ // maxValue,
330
+ // minValue,
331
+ // axisWidth: data.layout.height,
332
+ // scaleDomain: data.fullDataFormatter.yAxis.scaleDomain,
333
+ // scaleRange: data.fullDataFormatter.yAxis.scaleRange,
334
+ // reverse: true
335
+ // })
336
+
337
+ // subscriber.next(yScale)
338
+ // })
339
+ // })
340
+
341
+
342
+ combineLatest({
343
+ axisSelection: axisSelection$,
344
+ fullParams: fullParams$,
345
+ // tickTextAlign: tickTextAlign$,
346
+ // axisLabelAlign: axisLabelAlign$,
347
+ computedData: computedData$,
348
+ containerSize: containerSize$,
349
+ fullDataFormatter: fullDataFormatter$,
350
+ fullChartParams: fullChartParams$,
351
+ yScale: yScale$,
352
+ // textReverseTransform: textReverseTransform$,
353
+ // xyMinMax: xyMinMax$
354
+ }).pipe(
355
+ takeUntil(destroy$),
356
+ switchMap(async (d) => d),
357
+ ).subscribe(data => {
358
+
359
+ renderYAxis({
360
+ selection: data.axisSelection,
361
+ yAxisClassName,
362
+ fullParams: data.fullParams,
363
+ // tickTextAlign: data.tickTextAlign,
364
+ containerSize: data.containerSize,
365
+ fullDataFormatter: data.fullDataFormatter,
366
+ fullChartParams: data.fullChartParams,
367
+ yScale: data.yScale,
368
+ // textReverseTransform: data.textReverseTransform,
369
+ // xyMinMax: data.xyMinMax
370
+ })
371
+
372
+ renderYAxisLabel({
373
+ selection: data.axisSelection,
374
+ yLabelClassName,
375
+ fullParams: data.fullParams,
376
+ // axisLabelAlign: data.axisLabelAlign,
377
+ containerSize: data.containerSize,
378
+ fullDataFormatter: data.fullDataFormatter,
379
+ fullChartParams: data.fullChartParams,
380
+ // textReverseTransform: data.textReverseTransform,
381
+ })
382
+
383
+ })
384
+
385
+
386
+ return () => {
387
+ destroy$.next(undefined)
388
+ }
389
+ }
package/src/base/types.ts CHANGED
@@ -1,3 +1,3 @@
1
- export interface BasePluginFn<Context> {
2
- (pluginName: string, context: Context): () => void // return unsubscribe function
1
+ export interface BasePluginFn<Context> {
2
+ (pluginName: string, context: Context): () => void // return unsubscribe function
3
3
  }
package/src/const.ts CHANGED
@@ -1,30 +1,30 @@
1
-
2
- // 圖層索引 - 底層(無圖型)
3
- export const LAYER_INDEX_OF_ROOT = 0
4
-
5
- // 圖層索引 - 背景 *預留
6
- export const LAYER_INDEX_OF_BG = 1
7
-
8
- // 圖層索引 - 圖軸
9
- export const LAYER_INDEX_OF_AXIS = 2
10
-
11
- // 圖層索引 - 輔助線、圖軸的輔助資訊
12
- export const LAYER_INDEX_OF_AUX = 3
13
-
14
- // 圖層索引 - 底層圖型
15
- export const LAYER_INDEX_OF_GRAPHIC_GROUND = 4
16
-
17
- // 圖層索引 - 一般圖型
18
- export const LAYER_INDEX_OF_GRAPHIC = 5
19
-
20
- // 圖層索引 - 覆蓋圖型
21
- export const LAYER_INDEX_OF_GRAPHIC_COVER = 6
22
-
23
- // 圖層索引 - 圖型上的標籤文字
24
- export const LAYER_INDEX_OF_LABEL = 7
25
-
26
- // 圖層索引 - 圖例、圖表上的文字
27
- export const LAYER_INDEX_OF_INFO = 8
28
-
29
- // 圖層索引 - Tooltip、事件觸發的覆蓋圖型
30
- export const LAYER_INDEX_OF_TOOLTIP = 9
1
+
2
+ // 圖層索引 - 底層(無圖型)
3
+ export const LAYER_INDEX_OF_ROOT = 0
4
+
5
+ // 圖層索引 - 背景 *預留
6
+ export const LAYER_INDEX_OF_BG = 1
7
+
8
+ // 圖層索引 - 圖軸
9
+ export const LAYER_INDEX_OF_AXIS = 2
10
+
11
+ // 圖層索引 - 輔助線、圖軸的輔助資訊
12
+ export const LAYER_INDEX_OF_AUX = 3
13
+
14
+ // 圖層索引 - 底層圖型
15
+ export const LAYER_INDEX_OF_GRAPHIC_GROUND = 4
16
+
17
+ // 圖層索引 - 一般圖型
18
+ export const LAYER_INDEX_OF_GRAPHIC = 5
19
+
20
+ // 圖層索引 - 覆蓋圖型
21
+ export const LAYER_INDEX_OF_GRAPHIC_COVER = 6
22
+
23
+ // 圖層索引 - 圖型上的標籤文字
24
+ export const LAYER_INDEX_OF_LABEL = 7
25
+
26
+ // 圖層索引 - 圖例、圖表上的文字
27
+ export const LAYER_INDEX_OF_INFO = 8
28
+
29
+ // 圖層索引 - Tooltip、事件觸發的覆蓋圖型
30
+ export const LAYER_INDEX_OF_TOOLTIP = 9