@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
@@ -16,6 +16,7 @@ import type {
16
16
  ChartParams,
17
17
  ComputedDatumGrid,
18
18
  ContainerPositionScaled,
19
+ ContainerSize,
19
20
  TransformData,
20
21
  EventGrid,
21
22
  ColorType
@@ -23,6 +24,7 @@ import type {
23
24
  import type { BaseValueAxisParams } from '../../lib/plugins-basic-types'
24
25
  import { parseTickFormatValue } from '../utils/d3Utils'
25
26
  import { getColor, getMinMaxValue, getClassName, getUniID } from '../utils/orbchartsUtils'
27
+ import { gridContainerSelectionsObservable } from '../grid/gridObservables'
26
28
 
27
29
  // export interface BaseValueAxisParams {
28
30
  // labelOffset: [number, number]
@@ -40,7 +42,7 @@ import { getColor, getMinMaxValue, getClassName, getUniID } from '../utils/orbch
40
42
  // tickTextColorType: ColorType
41
43
  // }
42
44
 
43
- interface BaseLinesContext {
45
+ interface BaseValueAxisContext {
44
46
  selection: d3.Selection<any, unknown, any, unknown>
45
47
  computedData$: Observable<ComputedDataGrid>
46
48
  filteredMinMaxValue$: Observable<[number, number]>
@@ -49,11 +51,13 @@ interface BaseLinesContext {
49
51
  fullChartParams$: Observable<ChartParams>
50
52
  gridAxesTransform$: Observable<TransformData>
51
53
  gridAxesReverseTransform$: Observable<TransformData>
52
- gridAxesSize$: Observable<{
53
- width: number;
54
- height: number;
55
- }>
54
+ // gridAxesSize$: Observable<{
55
+ // width: number;
56
+ // height: number;
57
+ // }>
56
58
  gridContainerPosition$: Observable<ContainerPositionScaled[]>
59
+ gridAxesSize$: Observable<ContainerSize>
60
+ // gridAxesContainerSize$: Observable<ContainerSize>
57
61
  isSeriesSeprate$: Observable<boolean>
58
62
  }
59
63
 
@@ -74,7 +78,7 @@ function renderAxisLabel ({ selection, textClassName, fullParams, axisLabelAlign
74
78
  textClassName: string
75
79
  fullParams: BaseValueAxisParams
76
80
  axisLabelAlign: TextAlign
77
- gridAxesSize: { width: number, height: number }
81
+ gridAxesSize: ContainerSize
78
82
  fullDataFormatter: DataFormatterGrid,
79
83
  fullChartParams: ChartParams
80
84
  textReverseTransform: string,
@@ -155,7 +159,7 @@ function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gri
155
159
  yAxisClassName: string
156
160
  fullParams: BaseValueAxisParams
157
161
  tickTextAlign: TextAlign
158
- gridAxesSize: { width: number, height: number }
162
+ gridAxesSize: ContainerSize
159
163
  fullDataFormatter: DataFormatterGrid,
160
164
  fullChartParams: ChartParams
161
165
  valueScale: d3.ScaleLinear<number, number>
@@ -203,12 +207,14 @@ function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gri
203
207
  const yAxisEl = yAxisSelection
204
208
  .transition()
205
209
  .duration(100)
210
+ .ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
206
211
  .call(yAxis)
207
212
 
208
213
  yAxisEl.selectAll('line')
209
214
  .style('fill', 'none')
210
215
  .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
211
216
  .style('stroke-dasharray', fullParams.tickFullLineDasharray)
217
+ .style('vector-effect', 'non-scaling-stroke') // 避免 scale 導致線條變形
212
218
  .attr('pointer-events', 'none')
213
219
 
214
220
  yAxisEl.selectAll('path')
@@ -239,17 +245,19 @@ function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gri
239
245
 
240
246
 
241
247
 
242
- export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName: string, {
248
+ export const createBaseValueAxis: BasePluginFn<BaseValueAxisContext> = (pluginName: string, {
243
249
  selection,
244
250
  computedData$,
245
251
  filteredMinMaxValue$,
246
252
  fullParams$,
247
253
  fullDataFormatter$,
248
254
  fullChartParams$,
255
+ gridAxesSize$,
249
256
  gridAxesTransform$,
250
257
  gridAxesReverseTransform$,
251
- gridAxesSize$,
258
+ // gridAxesSize$,
252
259
  gridContainerPosition$,
260
+ // gridAxesContainerSize$,
253
261
  isSeriesSeprate$,
254
262
  }) => {
255
263
 
@@ -260,32 +268,40 @@ export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName:
260
268
  const yAxisClassName = getClassName(pluginName, 'yAxis')
261
269
  const textClassName = getClassName(pluginName, 'text')
262
270
 
263
- const containerSelection$ = combineLatest({
264
- computedData: computedData$.pipe(
265
- distinctUntilChanged((a, b) => {
266
- // 只有當series的數量改變時,才重新計算
267
- return a.length === b.length
268
- }),
269
- ),
270
- isSeriesSeprate: isSeriesSeprate$
271
- }).pipe(
272
- takeUntil(destroy$),
273
- switchMap(async (d) => d),
274
- map(data => {
275
- return data.isSeriesSeprate
276
- // series分開的時候顯示各別axis
277
- ? data.computedData
278
- // series合併的時候只顯示第一個axis
279
- : [data.computedData[0]]
280
- }),
281
- map((computedData, i) => {
282
- return selection
283
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
284
- .data(computedData, d => d[0] ? d[0].seriesIndex : i)
285
- .join('g')
286
- .classed(containerClassName, true)
287
- })
288
- )
271
+ const containerSelection$ = gridContainerSelectionsObservable({
272
+ selection,
273
+ pluginName,
274
+ computedData$,
275
+ gridContainerPosition$,
276
+ isSeriesSeprate$
277
+ })
278
+
279
+ // const containerSelection$ = combineLatest({
280
+ // computedData: computedData$.pipe(
281
+ // distinctUntilChanged((a, b) => {
282
+ // // 只有當series的數量改變時,才重新計算
283
+ // return a.length === b.length
284
+ // }),
285
+ // ),
286
+ // isSeriesSeprate: isSeriesSeprate$
287
+ // }).pipe(
288
+ // takeUntil(destroy$),
289
+ // switchMap(async (d) => d),
290
+ // map(data => {
291
+ // return data.isSeriesSeprate
292
+ // // series分開的時候顯示各別axis
293
+ // ? data.computedData
294
+ // // series合併的時候只顯示第一個axis
295
+ // : [data.computedData[0]]
296
+ // }),
297
+ // map((computedData, i) => {
298
+ // return selection
299
+ // .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
300
+ // .data(computedData, d => d[0] ? d[0].seriesIndex : i)
301
+ // .join('g')
302
+ // .classed(containerClassName, true)
303
+ // })
304
+ // )
289
305
 
290
306
  const axisSelection$ = containerSelection$.pipe(
291
307
  takeUntil(destroy$),
@@ -298,24 +314,25 @@ export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName:
298
314
  })
299
315
  )
300
316
 
301
- combineLatest({
302
- containerSelection: containerSelection$,
303
- gridContainerPosition: gridContainerPosition$
304
- }).pipe(
305
- takeUntil(destroy$),
306
- switchMap(async d => d)
307
- ).subscribe(data => {
308
- data.containerSelection
309
- .attr('transform', (d, i) => {
310
- const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
311
- const translate = gridContainerPosition.translate
312
- const scale = gridContainerPosition.scale
313
- return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
314
- })
315
- // .attr('opacity', 0)
316
- // .transition()
317
- // .attr('opacity', 1)
318
- })
317
+ // combineLatest({
318
+ // containerSelection: containerSelection$,
319
+ // gridContainerPosition: gridContainerPosition$
320
+ // }).pipe(
321
+ // takeUntil(destroy$),
322
+ // switchMap(async d => d)
323
+ // ).subscribe(data => {
324
+ // data.containerSelection
325
+ // .attr('transform', (d, i) => {
326
+ // const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
327
+ // const translate = gridContainerPosition.translate
328
+ // const scale = gridContainerPosition.scale
329
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
330
+ // return `translate(${translate[0]}, ${translate[1]})`
331
+ // })
332
+ // // .attr('opacity', 0)
333
+ // // .transition()
334
+ // // .attr('opacity', 1)
335
+ // })
319
336
 
320
337
  combineLatest({
321
338
  axisSelection: axisSelection$,
@@ -0,0 +1,427 @@
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
+ ContainerSize,
16
+ ComputedDatumMultiValue,
17
+ ComputedDataMultiValue,
18
+ ComputedXYDatumMultiValue,
19
+ ContainerPositionScaled,
20
+ DataFormatterMultiValue,
21
+ DefinePluginConfig,
22
+ TransformData,
23
+ Layout
24
+ } from '../../lib/core-types'
25
+ import {
26
+ defineMultiValuePlugin,
27
+ createValueToAxisScale,
28
+ getMinMax
29
+ } from '../../lib/core'
30
+ import type { BaseXAxisParams
31
+ } from '../../lib/plugins-basic-types'
32
+ import type { BasePluginFn } from './types'
33
+ // import { DEFAULT_X_Y_AXES_PARAMS } from '../defaults'
34
+ // import { LAYER_INDEX_OF_AXIS } from '../const'
35
+ import { getColor, getDatumColor, getClassName, getUniID } from '../utils/orbchartsUtils'
36
+ import { parseTickFormatValue } from '../utils/d3Utils'
37
+ import { multiValueContainerSelectionsObservable } from '../multiValue/multiValueObservables'
38
+
39
+ interface BaseXAxisContext {
40
+ selection: d3.Selection<any, unknown, any, unknown>
41
+ position$: Observable<'top' | 'bottom'>
42
+ transitionDuration$: Observable<number>
43
+ computedData$: Observable<ComputedDataMultiValue>
44
+ // filteredMinMaxValue$: Observable<[number, number]>
45
+ fullParams$: Observable<BaseXAxisParams>
46
+ fullDataFormatter$: Observable<DataFormatterMultiValue>
47
+ fullChartParams$: Observable<ChartParams>
48
+ isCategorySeprate$: Observable<boolean>
49
+ containerPosition$: Observable<ContainerPositionScaled[]>
50
+ // layout$: Observable<Layout>
51
+ containerSize$: Observable<ContainerSize>
52
+ xScale$: Observable<d3.ScaleLinear<number, number>>
53
+ // filteredXYMinMaxData$: Observable<{
54
+ // datumList: ComputedXYDatumMultiValue[];
55
+ // minXDatum: ComputedXYDatumMultiValue | null;
56
+ // maxXDatum: ComputedXYDatumMultiValue | null;
57
+ // minYDatum: ComputedXYDatumMultiValue | null;
58
+ // maxYDatum: ComputedXYDatumMultiValue | null;
59
+ // }>
60
+ // xyMinMax$: Observable<{
61
+ // minX: number;
62
+ // maxX: number;
63
+ // minY: number;
64
+ // maxY: number;
65
+ // }>
66
+ }
67
+
68
+ // interface TextAlign {
69
+ // textAnchor: "start" | "middle" | "end"
70
+ // dominantBaseline: "middle" | "auto" | "hanging"
71
+ // }
72
+
73
+ const defaultTickSize = 6
74
+
75
+ const xTickTextAnchor = 'middle'
76
+ const xTickDominantBaseline = 'hanging'
77
+ const xAxisLabelAnchor = 'start'
78
+ const xAxisLabelDominantBaseline = 'hanging'
79
+
80
+ function renderXAxisLabel ({ selection, position, xLabelClassName, fullParams, containerSize, fullDataFormatter, fullChartParams }: {
81
+ selection: d3.Selection<SVGGElement, any, any, any>,
82
+ position: 'top' | 'bottom'
83
+ xLabelClassName: string
84
+ fullParams: BaseXAxisParams
85
+ // axisLabelAlign: TextAlign
86
+ containerSize: ContainerSize
87
+ fullDataFormatter: DataFormatterMultiValue,
88
+ fullChartParams: ChartParams
89
+ // textReverseTransform: string,
90
+ }) {
91
+ const offsetX = fullParams.tickPadding + fullParams.labelOffset[0]
92
+ // const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
93
+ let labelX = offsetX
94
+
95
+
96
+ let y: number // = position === 'top' ? 0 : layout.height
97
+ let offsetY
98
+ if (position === 'top') {
99
+ y = 0
100
+ offsetY = -fullParams.tickPadding - fullParams.labelOffset[1]
101
+ } else {
102
+ y = containerSize.height
103
+ offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
104
+ }
105
+
106
+ let labelY = offsetY
107
+
108
+ const axisLabelSelection = selection
109
+ .selectAll<SVGGElement, BaseXAxisParams>(`g.${xLabelClassName}`)
110
+ .data([fullParams])
111
+ .join('g')
112
+ .classed(xLabelClassName, true)
113
+ .each((d, i, g) => {
114
+ const text = d3.select(g[i])
115
+ .selectAll<SVGTextElement, BaseXAxisParams>(`text`)
116
+ .data([d])
117
+ .join(
118
+ enter => {
119
+ return enter
120
+ .append('text')
121
+ .style('font-weight', 'bold')
122
+ },
123
+ update => update,
124
+ exit => exit.remove()
125
+ )
126
+ .attr('text-anchor', xAxisLabelAnchor)
127
+ .attr('dominant-baseline', xAxisLabelDominantBaseline)
128
+ .attr('font-size', fullChartParams.styles.textSize)
129
+ .style('fill', getColor(fullParams.labelColorType, fullChartParams))
130
+ // .style('transform', textReverseTransform)
131
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
132
+ .attr('x', labelX)
133
+ .attr('y', labelY)
134
+ .text(d => fullDataFormatter.xAxis.label)
135
+ })
136
+ .attr('transform', d => `translate(${containerSize.width}, ${y})`)
137
+ }
138
+
139
+ function renderXAxis ({ selection, position, xAxisClassName, fullParams, containerSize, fullChartParams, xScale, transitionDuration }: {
140
+ selection: d3.Selection<SVGGElement, any, any, any>,
141
+ position: 'top' | 'bottom'
142
+ xAxisClassName: string
143
+ fullParams: BaseXAxisParams
144
+ // tickTextAlign: TextAlign
145
+ containerSize: ContainerSize
146
+ // fullDataFormatter: DataFormatterMultiValue,
147
+ fullChartParams: ChartParams
148
+ xScale: d3.ScaleLinear<number, number>
149
+ // textReverseTransform: string,
150
+ // xyMinMax: {
151
+ // minX: number;
152
+ // maxX: number;
153
+ // minY: number;
154
+ // maxY: number;
155
+ // }
156
+ transitionDuration: number
157
+ }) {
158
+
159
+ let y: number
160
+ let d3Axis: d3.Axis<d3.NumberValue>
161
+ if (position === 'top') {
162
+ y = 0
163
+ d3Axis = d3.axisTop(xScale)
164
+ } else {
165
+ y = containerSize.height
166
+ d3Axis = d3.axisBottom(xScale)
167
+ }
168
+
169
+ const xAxisSelection = selection
170
+ .selectAll<SVGGElement, BaseXAxisParams>(`g.${xAxisClassName}`)
171
+ .data([fullParams])
172
+ .join('g')
173
+ .classed(xAxisClassName, true)
174
+ .attr('transform', `translate(0, ${y})`)
175
+
176
+ // const _xScale = d3.scaleLinear()
177
+ // .domain([0, 150])
178
+ // .range([416.5, 791.349])
179
+
180
+ // 刻度文字偏移
181
+ let tickPadding = fullParams.tickPadding
182
+
183
+ // 設定Y軸刻度
184
+ const xAxis = d3Axis
185
+ .scale(xScale)
186
+ .ticks(fullParams.ticks) // 刻度分段數量
187
+ .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
188
+ .tickSize(fullParams.tickFullLine == true
189
+ ? -containerSize.height
190
+ : defaultTickSize)
191
+ .tickSizeOuter(-containerSize.height)
192
+ .tickPadding(tickPadding)
193
+
194
+ const xAxisEl = xAxisSelection
195
+ .transition()
196
+ .duration(transitionDuration)
197
+ .ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
198
+ .call(xAxis)
199
+
200
+ xAxisEl.selectAll('line')
201
+ .style('fill', 'none')
202
+ .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
203
+ .style('stroke-dasharray', fullParams.tickFullLineDasharray)
204
+ .attr('pointer-events', 'none')
205
+
206
+ xAxisEl.selectAll('path')
207
+ .style('fill', 'none')
208
+ // .style('stroke', this.fullParams.axisLineColor!)
209
+ .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
210
+ .style('shape-rendering', 'crispEdges')
211
+
212
+ // const xText = xAxisEl.selectAll('text')
213
+ const xText = xAxisSelection.selectAll('text')
214
+ // .style('font-family', 'sans-serif')
215
+ .attr('font-size', fullChartParams.styles.textSize)
216
+ .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
217
+ .attr('text-anchor', xTickTextAnchor)
218
+ .attr('dominant-baseline', xTickDominantBaseline)
219
+ // .attr('dy', tickPadding)
220
+ // .attr('y', tickPadding)
221
+ // xText.style('transform', textReverseTransform)
222
+
223
+ // // 抵消掉預設的偏移
224
+ // if (fullDataFormatter.grid.valueAxis.position === 'bottom' || fullDataFormatter.grid.valueAxis.position === 'top') {
225
+ xText.attr('dy', 0)
226
+ // }
227
+
228
+ return xAxisSelection
229
+ }
230
+
231
+ export const createBaseXAxis: BasePluginFn<BaseXAxisContext> = (pluginName: string, {
232
+ selection,
233
+ position$,
234
+ computedData$,
235
+ fullParams$,
236
+ fullDataFormatter$,
237
+ fullChartParams$,
238
+ isCategorySeprate$,
239
+ containerPosition$,
240
+ // layout$,
241
+ containerSize$,
242
+ xScale$,
243
+ // filteredXYMinMaxData$,
244
+ // xyMinMax$
245
+ transitionDuration$
246
+ }) => {
247
+
248
+ const destroy$ = new Subject()
249
+
250
+ // const containerClassName = getClassName(pluginName, 'container')
251
+ const xAxisGClassName = getClassName(pluginName, 'xAxisG')
252
+ const xAxisClassName = getClassName(pluginName, 'xAxis')
253
+ const xLabelClassName = getClassName(pluginName, 'xLabel')
254
+
255
+ const containerSelection$ = multiValueContainerSelectionsObservable({
256
+ selection,
257
+ pluginName,
258
+ clipPathID: null,
259
+ computedData$,
260
+ containerPosition$,
261
+ isCategorySeprate$,
262
+ }).pipe(
263
+ takeUntil(destroy$),
264
+ )
265
+
266
+ // const containerSelection$ = combineLatest({
267
+ // computedData: computedData$.pipe(
268
+ // distinctUntilChanged((a, b) => {
269
+ // // 只有當series的數量改變時,才重新計算
270
+ // return a.length === b.length
271
+ // }),
272
+ // ),
273
+ // isCategorySeprate: isCategorySeprate$
274
+ // }).pipe(
275
+ // takeUntil(destroy$),
276
+ // switchMap(async (d) => d),
277
+ // map(data => {
278
+ // return data.isCategorySeprate
279
+ // // category分開的時候顯示各別axis
280
+ // ? data.computedData
281
+ // // category合併的時候只顯示第一個axis
282
+ // : [data.computedData[0]]
283
+ // }),
284
+ // map((computedData, i) => {
285
+ // return selection
286
+ // .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${containerClassName}`)
287
+ // .data(computedData, d => d[0] ? d[0].categoryIndex : i)
288
+ // .join('g')
289
+ // .classed(containerClassName, true)
290
+ // })
291
+ // )
292
+
293
+ const axisSelection$ = containerSelection$.pipe(
294
+ takeUntil(destroy$),
295
+ map((containerSelection, i) => {
296
+ return containerSelection
297
+ .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${xAxisGClassName}`)
298
+ .data([xAxisGClassName])
299
+ .join('g')
300
+ .classed(xAxisGClassName, true)
301
+ })
302
+ )
303
+
304
+ // combineLatest({
305
+ // containerSelection: containerSelection$,
306
+ // gridContainerPosition: containerPosition$
307
+ // }).pipe(
308
+ // takeUntil(destroy$),
309
+ // switchMap(async d => d)
310
+ // ).subscribe(data => {
311
+ // data.containerSelection
312
+ // .attr('transform', (d, i) => {
313
+ // const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
314
+ // const translate = gridContainerPosition.translate
315
+ // const scale = gridContainerPosition.scale
316
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
317
+ // return `translate(${translate[0]}, ${translate[1]})`
318
+ // })
319
+ // // .attr('opacity', 0)
320
+ // // .transition()
321
+ // // .attr('opacity', 1)
322
+ // })
323
+
324
+ // const textReverseTransform$ = containerPosition$.pipe(
325
+ // takeUntil(destroy$),
326
+ // switchMap(async (d) => d),
327
+ // map(containerPosition => {
328
+ // // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
329
+ // // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
330
+ // const containerScaleReverseValue = `scale(${1 / containerPosition[0].scale[0]}, ${1 / containerPosition[0].scale[1]})`
331
+ // // 抵消最外層scale
332
+ // return `${containerScaleReverseValue}`
333
+ // }),
334
+ // distinctUntilChanged()
335
+ // )
336
+
337
+ // const xScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
338
+ // combineLatest({
339
+ // fullDataFormatter: fullDataFormatter$,
340
+ // layout: layout$,
341
+ // // xyMinMax: xyMinMax$
342
+ // filteredXYMinMaxData: filteredXYMinMaxData$
343
+ // }).pipe(
344
+ // takeUntil(destroy$),
345
+ // switchMap(async (d) => d),
346
+ // ).subscribe(data => {
347
+ // const valueIndex = data.fullDataFormatter.xAxis.valueIndex
348
+ // if (!data.filteredXYMinMaxData.minXDatum || !data.filteredXYMinMaxData.maxXDatum
349
+ // || data.filteredXYMinMaxData.minXDatum.value[valueIndex] == null || data.filteredXYMinMaxData.maxXDatum.value[valueIndex] == null
350
+ // ) {
351
+ // return
352
+ // }
353
+ // let maxValue = data.filteredXYMinMaxData.maxXDatum.value[valueIndex]
354
+ // let minValue = data.filteredXYMinMaxData.minXDatum.value[valueIndex]
355
+ // if (maxValue === minValue && maxValue === 0) {
356
+ // // 避免最大及最小值同等於 0 造成無法計算scale
357
+ // maxValue = 1
358
+ // }
359
+
360
+ // const xScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
361
+ // maxValue,
362
+ // minValue,
363
+ // axisWidth: data.layout.width,
364
+ // scaleDomain: data.fullDataFormatter.xAxis.scaleDomain,
365
+ // scaleRange: data.fullDataFormatter.xAxis.scaleRange,
366
+ // })
367
+
368
+ // subscriber.next(xScale)
369
+ // })
370
+ // })
371
+
372
+ combineLatest({
373
+ axisSelection: axisSelection$,
374
+ position: position$,
375
+ fullParams: fullParams$,
376
+ // tickTextAlign: tickTextAlign$,
377
+ // axisLabelAlign: axisLabelAlign$,
378
+ computedData: computedData$,
379
+ // layout: layout$,
380
+ containerSize: containerSize$,
381
+ fullDataFormatter: fullDataFormatter$,
382
+ fullChartParams: fullChartParams$,
383
+ xScale: xScale$,
384
+ // textReverseTransform: textReverseTransform$,
385
+ // xyMinMax: xyMinMax$
386
+ transitionDuration: transitionDuration$
387
+ }).pipe(
388
+ takeUntil(destroy$),
389
+ switchMap(async (d) => d),
390
+ ).subscribe(data => {
391
+ // console.log('data.layout', data.layout)
392
+ // console.log('data.containerSize', data.containerSize)
393
+
394
+ renderXAxis({
395
+ selection: data.axisSelection,
396
+ position: data.position,
397
+ xAxisClassName,
398
+ fullParams: data.fullParams,
399
+ // tickTextAlign: data.tickTextAlign,
400
+ containerSize: data.containerSize,
401
+ // fullDataFormatter: data.fullDataFormatter,
402
+ fullChartParams: data.fullChartParams,
403
+ xScale: data.xScale,
404
+ // textReverseTransform: data.textReverseTransform,
405
+ // xyMinMax: data.xyMinMax
406
+ transitionDuration: data.transitionDuration
407
+ })
408
+
409
+ renderXAxisLabel({
410
+ selection: data.axisSelection,
411
+ position: data.position,
412
+ xLabelClassName,
413
+ fullParams: data.fullParams,
414
+ // axisLabelAlign: data.axisLabelAlign,
415
+ containerSize: data.containerSize,
416
+ fullDataFormatter: data.fullDataFormatter,
417
+ fullChartParams: data.fullChartParams,
418
+ // textReverseTransform: data.textReverseTransform,
419
+ })
420
+
421
+ })
422
+
423
+
424
+ return () => {
425
+ destroy$.next(undefined)
426
+ }
427
+ }