@orbcharts/plugins-basic 3.0.0-beta.14 → 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
@@ -1,4 +1,3 @@
1
- import * as d3 from 'd3'
2
1
  import {
3
2
  Observable,
4
3
  Subject,
@@ -6,62 +5,23 @@ import {
6
5
  takeUntil,
7
6
  map,
8
7
  distinctUntilChanged,
8
+ of,
9
9
  switchMap,
10
10
  shareReplay
11
11
  } from 'rxjs'
12
12
  import type {
13
- ColorType,
14
- ChartParams,
15
- ComputedDatumMultiValue,
16
- DataFormatterMultiValue,
17
13
  DefinePluginConfig,
18
14
  } from '../../../lib/core-types'
19
15
  import {
20
16
  defineMultiValuePlugin,
21
- createValueToAxisScale,
22
- getMinMax
23
17
  } from '../../../lib/core'
24
- import type { XYAxesParams
25
- } from '../../../lib/plugins-basic-types'
26
18
  import { DEFAULT_X_Y_AXES_PARAMS } from '../defaults'
27
19
  import { LAYER_INDEX_OF_AXIS } from '../../const'
28
- import { getColor, getDatumColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
29
- import { parseTickFormatValue } from '../../utils/d3Utils'
30
- import { filteredMinMaxXYDataObservable } from '../../../../orbcharts-core/src/utils/multiValueObservables'
31
- // import { multiValueSelectionsObservable } from '../multiValueObservables'
32
-
33
- interface TextAlign {
34
- textAnchor: "start" | "middle" | "end"
35
- dominantBaseline: "middle" | "auto" | "hanging"
36
- }
37
-
38
- // interface Axis {
39
- // labelOffset: [number, number]
40
- // labelColorType: ColorType
41
- // axisLineVisible: boolean
42
- // axisLineColorType: ColorType
43
- // ticks: number | null
44
- // tickFormat: string | ((text: d3.NumberValue) => string)
45
- // tickLineVisible: boolean
46
- // tickPadding: number
47
- // tickFullLine: boolean
48
- // tickFullLineDasharray: string
49
- // tickColorType: ColorType
50
- // tickTextColorType: ColorType
51
- // }
20
+ import { createBaseXAxis } from '../../base/BaseXAxis'
21
+ import { createBaseYAxis } from '../../base/BaseYAxis'
52
22
 
53
23
  const pluginName = 'XYAxes'
54
24
 
55
- const defaultTickSize = 6
56
-
57
- const xTickTextAnchor = 'middle'
58
- const xTickDominantBaseline = 'hanging'
59
- const xAxisLabelAnchor = 'start'
60
- const xAxisLabelDominantBaseline = 'hanging'
61
- const yTickTextAnchor = 'end'
62
- const yTickDominantBaseline = 'middle'
63
- const yAxisLabelAnchor = 'end'
64
- const yAxisLabelDominantBaseline = 'auto'
65
25
 
66
26
  const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_X_Y_AXES_PARAMS> = {
67
27
  name: pluginName,
@@ -178,508 +138,58 @@ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_X_Y_AXE
178
138
  }
179
139
  }
180
140
 
181
- function renderXAxisLabel ({ selection, xLabelClassName, fullParams, layout, fullDataFormatter, fullChartParams, textReverseTransform }: {
182
- selection: d3.Selection<SVGGElement, any, any, any>,
183
- xLabelClassName: string
184
- fullParams: XYAxesParams
185
- // axisLabelAlign: TextAlign
186
- layout: { width: number, height: number }
187
- fullDataFormatter: DataFormatterMultiValue,
188
- fullChartParams: ChartParams
189
- textReverseTransform: string,
190
- }) {
191
- const offsetX = fullParams.xAxis.tickPadding + fullParams.xAxis.labelOffset[0]
192
- const offsetY = fullParams.xAxis.tickPadding + fullParams.xAxis.labelOffset[1]
193
- let labelX = offsetX
194
- let labelY = offsetY
195
-
196
- const axisLabelSelection = selection
197
- .selectAll<SVGGElement, XYAxesParams>(`g.${xLabelClassName}`)
198
- .data([fullParams])
199
- .join('g')
200
- .classed(xLabelClassName, true)
201
- .each((d, i, g) => {
202
- const text = d3.select(g[i])
203
- .selectAll<SVGTextElement, XYAxesParams>(`text`)
204
- .data([d])
205
- .join(
206
- enter => {
207
- return enter
208
- .append('text')
209
- .style('font-weight', 'bold')
210
- },
211
- update => update,
212
- exit => exit.remove()
213
- )
214
- .attr('text-anchor', xAxisLabelAnchor)
215
- .attr('dominant-baseline', xAxisLabelDominantBaseline)
216
- .attr('font-size', fullChartParams.styles.textSize)
217
- .style('fill', getColor(fullParams.xAxis.labelColorType, fullChartParams))
218
- .style('transform', textReverseTransform)
219
- // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
220
- .attr('x', labelX)
221
- .attr('y', labelY)
222
- .text(d => fullDataFormatter.xAxis.label)
223
- })
224
- .attr('transform', d => `translate(${layout.width}, ${layout.height})`)
225
- }
226
-
227
- function renderYAxisLabel ({ selection, yLabelClassName, fullParams, layout, fullDataFormatter, fullChartParams, textReverseTransform }: {
228
- selection: d3.Selection<SVGGElement, any, any, any>,
229
- yLabelClassName: string
230
- fullParams: XYAxesParams
231
- // axisLabelAlign: TextAlign
232
- layout: { width: number, height: number }
233
- fullDataFormatter: DataFormatterMultiValue,
234
- fullChartParams: ChartParams
235
- textReverseTransform: string,
236
- }) {
237
- const offsetX = fullParams.yAxis.tickPadding - fullParams.yAxis.labelOffset[0]
238
- const offsetY = fullParams.yAxis.tickPadding + fullParams.yAxis.labelOffset[1]
239
- let labelX = - offsetX
240
- let labelY = - offsetY
241
-
242
- const axisLabelSelection = selection
243
- .selectAll<SVGGElement, XYAxesParams>(`g.${yLabelClassName}`)
244
- .data([fullParams])
245
- .join('g')
246
- .classed(yLabelClassName, true)
247
- .each((d, i, g) => {
248
- const text = d3.select(g[i])
249
- .selectAll<SVGTextElement, XYAxesParams>(`text`)
250
- .data([d])
251
- .join(
252
- enter => {
253
- return enter
254
- .append('text')
255
- .style('font-weight', 'bold')
256
- },
257
- update => update,
258
- exit => exit.remove()
259
- )
260
- .attr('text-anchor', yAxisLabelAnchor)
261
- .attr('dominant-baseline', yAxisLabelDominantBaseline)
262
- .attr('font-size', fullChartParams.styles.textSize)
263
- .style('fill', getColor(fullParams.yAxis.labelColorType, fullChartParams))
264
- .style('transform', textReverseTransform)
265
- // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
266
- .attr('x', labelX)
267
- .attr('y', labelY)
268
- .text(d => fullDataFormatter.yAxis.label)
269
- })
270
- // .attr('transform', d => `translate(0, ${layout.height})`)
271
- }
272
-
273
- function renderXAxis ({ selection, xAxisClassName, fullParams, layout, fullDataFormatter, fullChartParams, xScale, textReverseTransform, minMaxXY }: {
274
- selection: d3.Selection<SVGGElement, any, any, any>,
275
- xAxisClassName: string
276
- fullParams: XYAxesParams
277
- // tickTextAlign: TextAlign
278
- layout: { width: number, height: number }
279
- fullDataFormatter: DataFormatterMultiValue,
280
- fullChartParams: ChartParams
281
- xScale: d3.ScaleLinear<number, number>
282
- textReverseTransform: string,
283
- minMaxXY: {
284
- minX: number;
285
- maxX: number;
286
- minY: number;
287
- maxY: number;
288
- }
289
- }) {
290
-
291
- const xAxisSelection = selection
292
- .selectAll<SVGGElement, XYAxesParams>(`g.${xAxisClassName}`)
293
- .data([fullParams])
294
- .join('g')
295
- .classed(xAxisClassName, true)
296
- .attr('transform', `translate(0, ${layout.height})`)
297
-
298
- // const _xScale = d3.scaleLinear()
299
- // .domain([0, 150])
300
- // .range([416.5, 791.349])
301
-
302
- // 刻度文字偏移
303
- let tickPadding = fullParams.xAxis.tickPadding
304
-
305
- // 設定Y軸刻度
306
- const xAxis = d3.axisBottom(xScale)
307
- .scale(xScale)
308
- .ticks(fullParams.xAxis.ticks) // 刻度分段數量
309
- .tickFormat(d => parseTickFormatValue(d, fullParams.xAxis.tickFormat))
310
- .tickSize(fullParams.xAxis.tickFullLine == true
311
- ? -layout.height
312
- : defaultTickSize)
313
- .tickSizeOuter(-layout.height)
314
- .tickPadding(tickPadding)
315
-
316
- const xAxisEl = xAxisSelection
317
- .transition()
318
- .duration(100)
319
- .call(xAxis)
320
-
321
- xAxisEl.selectAll('line')
322
- .style('fill', 'none')
323
- .style('stroke', fullParams.xAxis.tickLineVisible == true ? getColor(fullParams.xAxis.tickColorType, fullChartParams) : 'none')
324
- .style('stroke-dasharray', fullParams.xAxis.tickFullLineDasharray)
325
- .attr('pointer-events', 'none')
326
-
327
- xAxisEl.selectAll('path')
328
- .style('fill', 'none')
329
- // .style('stroke', this.fullParams.axisLineColor!)
330
- .style('stroke', fullParams.xAxis.axisLineVisible == true ? getColor(fullParams.xAxis.axisLineColorType, fullChartParams) : 'none')
331
- .style('shape-rendering', 'crispEdges')
332
-
333
- // const xText = xAxisEl.selectAll('text')
334
- const xText = xAxisSelection.selectAll('text')
335
- // .style('font-family', 'sans-serif')
336
- .attr('font-size', fullChartParams.styles.textSize)
337
- .style('color', getColor(fullParams.xAxis.tickTextColorType, fullChartParams))
338
- .attr('text-anchor', xTickTextAnchor)
339
- .attr('dominant-baseline', xTickDominantBaseline)
340
- .attr('dy', 0)
341
- .attr('y', tickPadding)
342
- xText.style('transform', textReverseTransform)
343
-
344
- // // 抵消掉預設的偏移
345
- // if (fullDataFormatter.grid.valueAxis.position === 'bottom' || fullDataFormatter.grid.valueAxis.position === 'top') {
346
- // xText.attr('dy', 0)
347
- // }
348
-
349
- return xAxisSelection
350
- }
351
-
352
- function renderYAxis ({ selection, yAxisClassName, fullParams, layout, fullDataFormatter, fullChartParams, yScale, textReverseTransform, minMaxXY }: {
353
- selection: d3.Selection<SVGGElement, any, any, any>,
354
- yAxisClassName: string
355
- fullParams: XYAxesParams
356
- // tickTextAlign: TextAlign
357
- layout: { width: number, height: number }
358
- fullDataFormatter: DataFormatterMultiValue,
359
- fullChartParams: ChartParams
360
- yScale: d3.ScaleLinear<number, number>
361
- textReverseTransform: string,
362
- minMaxXY: {
363
- minX: number;
364
- maxX: number;
365
- minY: number;
366
- maxY: number;
367
- }
368
- }) {
369
-
370
- const yAxisSelection = selection
371
- .selectAll<SVGGElement, XYAxesParams>(`g.${yAxisClassName}`)
372
- .data([fullParams])
373
- .join('g')
374
- .classed(yAxisClassName, true)
375
-
376
- // const _yScale = d3.scaleLinear()
377
- // .domain([0, 150])
378
- // .range([416.5, 791.349])
379
-
380
- // 刻度文字偏移
381
- let tickPadding = fullParams.yAxis.tickPadding
382
-
383
- // 設定Y軸刻度
384
- const yAxis = d3.axisLeft(yScale)
385
- .scale(yScale)
386
- .ticks(fullParams.xAxis.ticks) // 刻度分段數量
387
- .tickFormat(d => parseTickFormatValue(d, fullParams.yAxis.tickFormat))
388
- .tickSize(fullParams.yAxis.tickFullLine == true
389
- ? -layout.width
390
- : defaultTickSize)
391
- .tickPadding(tickPadding)
392
-
393
- const yAxisEl = yAxisSelection
394
- .transition()
395
- .duration(100)
396
- .call(yAxis)
397
-
398
- yAxisEl.selectAll('line')
399
- .style('fill', 'none')
400
- .style('stroke', fullParams.yAxis.tickLineVisible == true ? getColor(fullParams.yAxis.tickColorType, fullChartParams) : 'none')
401
- .style('stroke-dasharray', fullParams.yAxis.tickFullLineDasharray)
402
- .attr('pointer-events', 'none')
403
-
404
- yAxisEl.selectAll('path')
405
- .style('fill', 'none')
406
- // .style('stroke', this.fullParams.axisLineColor!)
407
- .style('stroke', fullParams.yAxis.axisLineVisible == true ? getColor(fullParams.yAxis.axisLineColorType, fullChartParams) : 'none')
408
- .style('shape-rendering', 'crispEdges')
409
-
410
- // const yText = yAxisEl.selectAll('text')
411
- const yText = yAxisSelection.selectAll('text')
412
- // .style('font-family', 'sans-serif')
413
- .attr('font-size', fullChartParams.styles.textSize)
414
- .style('color', getColor(fullParams.yAxis.tickTextColorType, fullChartParams))
415
- .attr('text-anchor', yTickTextAnchor)
416
- .attr('dominant-baseline', yTickDominantBaseline)
417
- // .attr('dy', 0)
418
- .attr('x', - tickPadding)
419
- .attr('dy', 0)
420
- yText.style('transform', textReverseTransform)
421
-
422
- // // 抵消掉預設的偏移
423
- // if (fullDataFormatter.grid.valueAxis.position === 'bottom' || fullDataFormatter.grid.valueAxis.position === 'top') {
424
- // yText.attr('dy', 0)
425
- // }
426
-
427
- return yAxisSelection
428
- }
429
141
 
430
142
 
431
143
  export const XYAxes = defineMultiValuePlugin(pluginConfig)(({ selection, name, observer, subject }) => {
432
144
 
433
145
  const destroy$ = new Subject()
434
146
 
435
- const containerClassName = getClassName(pluginName, 'container')
436
- const xAxisGClassName = getClassName(pluginName, 'xAxisG')
437
- const xAxisClassName = getClassName(pluginName, 'xAxis')
438
- const yAxisGClassName = getClassName(pluginName, 'yAxisG')
439
- const yAxisClassName = getClassName(pluginName, 'yAxis')
440
- const xLabelClassName = getClassName(pluginName, 'xLabel')
441
- const yLabelClassName = getClassName(pluginName, 'yLabel')
442
-
443
- const containerSelection$ = combineLatest({
444
- computedData: observer.computedData$.pipe(
445
- distinctUntilChanged((a, b) => {
446
- // 只有當series的數量改變時,才重新計算
447
- return a.length === b.length
448
- }),
449
- ),
450
- isCategorySeprate: observer.isCategorySeprate$
451
- }).pipe(
147
+ const xAxisFullParams$ = observer.fullParams$.pipe(
452
148
  takeUntil(destroy$),
453
- switchMap(async (d) => d),
454
- map(data => {
455
- return data.isCategorySeprate
456
- // category分開的時候顯示各別axis
457
- ? data.computedData
458
- // category合併的時候只顯示第一個axis
459
- : [data.computedData[0]]
460
- }),
461
- map((computedData, i) => {
462
- return selection
463
- .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${containerClassName}`)
464
- .data(computedData, d => d[0] ? d[0].categoryIndex : i)
465
- .join('g')
466
- .classed(containerClassName, true)
467
- })
149
+ map(fullParams => fullParams.xAxis),
150
+ distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
468
151
  )
469
152
 
470
- const axisSelection$ = containerSelection$.pipe(
471
- takeUntil(destroy$),
472
- map((containerSelection, i) => {
473
- return containerSelection
474
- .selectAll<SVGGElement, ComputedDatumMultiValue[]>(`g.${yAxisGClassName}`)
475
- .data([yAxisGClassName])
476
- .join('g')
477
- .classed(yAxisGClassName, true)
478
- })
479
- )
480
-
481
- combineLatest({
482
- containerSelection: containerSelection$,
483
- gridContainerPosition: observer.multiValueContainerPosition$
484
- }).pipe(
485
- takeUntil(destroy$),
486
- switchMap(async d => d)
487
- ).subscribe(data => {
488
- data.containerSelection
489
- .attr('transform', (d, i) => {
490
- const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
491
- const translate = gridContainerPosition.translate
492
- const scale = gridContainerPosition.scale
493
- return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
494
- })
495
- // .attr('opacity', 0)
496
- // .transition()
497
- // .attr('opacity', 1)
498
- })
499
-
500
- const textReverseTransform$ = observer.multiValueContainerPosition$.pipe(
153
+ const yAxisFullParams$ = observer.fullParams$.pipe(
501
154
  takeUntil(destroy$),
502
- switchMap(async (d) => d),
503
- map(multiValueContainerPosition => {
504
- // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
505
- // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
506
- const containerScaleReverseValue = `scale(${1 / multiValueContainerPosition[0].scale[0]}, ${1 / multiValueContainerPosition[0].scale[1]})`
507
- // 抵消最外層scale
508
- return `${containerScaleReverseValue}`
509
- }),
510
- distinctUntilChanged()
155
+ map(fullParams => fullParams.xAxis),
156
+ distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
511
157
  )
512
158
 
513
- // const minMax$: Observable<[number, number]> = new Observable(subscriber => {
514
- // combineLatest({
515
- // fullDataFormatter: observer.fullDataFormatter$,
516
- // computedData: observer.computedData$
517
- // }).pipe(
518
- // takeUntil(destroy$),
519
- // switchMap(async (d) => d),
520
- // ).subscribe(data => {
521
- // const groupMin = 0
522
- // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
523
- // // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
524
- // // ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
525
- // // : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
526
- // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
527
- // const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
528
- // ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
529
- // : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
530
-
531
- // const filteredData = data.computedData.map((d, i) => {
532
- // return d.filter((_d, _i) => {
533
- // return _i >= groupScaleDomainMin && _i <= groupScaleDomainMax
534
- // })
535
- // })
536
-
537
- // const filteredMinMax = getMinMax(filteredData.flat().map(d => d.value[1]))
538
- // if (filteredMinMax[0] === filteredMinMax[1]) {
539
- // filteredMinMax[0] = filteredMinMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
540
- // }
541
- // subscriber.next(filteredMinMax)
542
- // })
543
- // })
544
-
545
- const xScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
546
- combineLatest({
547
- fullDataFormatter: observer.fullDataFormatter$,
548
- layout: observer.layout$,
549
- // minMaxXY: observer.minMaxXY$
550
- filteredMinMaxXYData: observer.filteredMinMaxXYData$
551
- }).pipe(
552
- takeUntil(destroy$),
553
- switchMap(async (d) => d),
554
- ).subscribe(data => {
555
- if (!data.filteredMinMaxXYData.minXDatum || !data.filteredMinMaxXYData.maxXDatum
556
- || data.filteredMinMaxXYData.minXDatum.value[0] == null || data.filteredMinMaxXYData.maxXDatum.value[0] == null
557
- ) {
558
- return
559
- }
560
- let maxValue = data.filteredMinMaxXYData.maxXDatum.value[0]
561
- let minValue = data.filteredMinMaxXYData.minXDatum.value[0]
562
- if (maxValue === minValue && maxValue === 0) {
563
- // 避免最大及最小值同等於 0 造成無法計算scale
564
- maxValue = 1
565
- }
566
-
567
- const xScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
568
- maxValue,
569
- minValue,
570
- axisWidth: data.layout.width,
571
- scaleDomain: data.fullDataFormatter.xAxis.scaleDomain,
572
- scaleRange: data.fullDataFormatter.xAxis.scaleRange,
573
- })
574
-
575
- subscriber.next(xScale)
576
- })
577
- })
578
-
579
- const yScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
580
- combineLatest({
581
- fullDataFormatter: observer.fullDataFormatter$,
582
- layout: observer.layout$,
583
- // minMaxXY: observer.minMaxXY$
584
- filteredMinMaxXYData: observer.filteredMinMaxXYData$
585
- }).pipe(
586
- takeUntil(destroy$),
587
- switchMap(async (d) => d),
588
- ).subscribe(data => {
589
- if (!data.filteredMinMaxXYData.minYDatum || !data.filteredMinMaxXYData.maxYDatum
590
- || data.filteredMinMaxXYData.minYDatum.value[1] == null || data.filteredMinMaxXYData.maxYDatum.value[1] == null
591
- ) {
592
- return
593
- }
594
- let maxValue = data.filteredMinMaxXYData.maxYDatum.value[1]
595
- let minValue = data.filteredMinMaxXYData.minYDatum.value[1]
596
- if (maxValue === minValue && maxValue === 0) {
597
- // 避免最大及最小值同等於 0 造成無法計算scale
598
- maxValue = 1
599
- }
600
-
601
- const yScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
602
- maxValue,
603
- minValue,
604
- axisWidth: data.layout.height,
605
- scaleDomain: data.fullDataFormatter.yAxis.scaleDomain,
606
- scaleRange: data.fullDataFormatter.yAxis.scaleRange,
607
- reverse: true
608
- })
609
-
610
- subscriber.next(yScale)
611
- })
159
+ const unsubscribeBaseXAxis = createBaseXAxis(`${pluginName}-x`, {
160
+ selection,
161
+ position$: of('bottom'),
162
+ transitionDuration$: of(100),
163
+ computedData$: observer.computedData$,
164
+ fullParams$: xAxisFullParams$,
165
+ fullDataFormatter$: observer.fullDataFormatter$,
166
+ fullChartParams$: observer.fullChartParams$,
167
+ isCategorySeprate$: observer.isCategorySeprate$,
168
+ containerPosition$: observer.containerPosition$,
169
+ // layout$: observer.layout$,
170
+ containerSize$: observer.containerSize$,
171
+ xScale$: observer.xScale$,
172
+ // filteredXYMinMaxData$: observer.filteredXYMinMaxData$,
173
+ // xyMinMax$: observer.xyMinMax$,
612
174
  })
613
175
 
614
-
615
- combineLatest({
616
- axisSelection: axisSelection$,
617
- fullParams: observer.fullParams$,
618
- // tickTextAlign: tickTextAlign$,
619
- // axisLabelAlign: axisLabelAlign$,
620
- computedData: observer.computedData$,
621
- layout: observer.layout$,
622
- fullDataFormatter: observer.fullDataFormatter$,
623
- fullChartParams: observer.fullChartParams$,
624
- xScale: xScale$,
625
- yScale: yScale$,
626
- textReverseTransform: textReverseTransform$,
627
- minMaxXY: observer.minMaxXY$
628
- }).pipe(
629
- takeUntil(destroy$),
630
- switchMap(async (d) => d),
631
- ).subscribe(data => {
632
-
633
- renderXAxis({
634
- selection: data.axisSelection,
635
- xAxisClassName,
636
- fullParams: data.fullParams,
637
- // tickTextAlign: data.tickTextAlign,
638
- layout: data.layout,
639
- fullDataFormatter: data.fullDataFormatter,
640
- fullChartParams: data.fullChartParams,
641
- xScale: data.xScale,
642
- textReverseTransform: data.textReverseTransform,
643
- minMaxXY: data.minMaxXY
644
- })
645
-
646
- renderYAxis({
647
- selection: data.axisSelection,
648
- yAxisClassName,
649
- fullParams: data.fullParams,
650
- // tickTextAlign: data.tickTextAlign,
651
- layout: data.layout,
652
- fullDataFormatter: data.fullDataFormatter,
653
- fullChartParams: data.fullChartParams,
654
- yScale: data.yScale,
655
- textReverseTransform: data.textReverseTransform,
656
- minMaxXY: data.minMaxXY
657
- })
658
-
659
- renderXAxisLabel({
660
- selection: data.axisSelection,
661
- xLabelClassName,
662
- fullParams: data.fullParams,
663
- // axisLabelAlign: data.axisLabelAlign,
664
- layout: data.layout,
665
- fullDataFormatter: data.fullDataFormatter,
666
- fullChartParams: data.fullChartParams,
667
- textReverseTransform: data.textReverseTransform,
668
- })
669
-
670
- renderYAxisLabel({
671
- selection: data.axisSelection,
672
- yLabelClassName,
673
- fullParams: data.fullParams,
674
- // axisLabelAlign: data.axisLabelAlign,
675
- layout: data.layout,
676
- fullDataFormatter: data.fullDataFormatter,
677
- fullChartParams: data.fullChartParams,
678
- textReverseTransform: data.textReverseTransform,
679
- })
176
+ const unsubscribeBaseYAxis = createBaseYAxis(`${pluginName}-y`, {
177
+ selection,
178
+ computedData$: observer.computedData$,
179
+ fullParams$: yAxisFullParams$,
180
+ fullDataFormatter$: observer.fullDataFormatter$,
181
+ fullChartParams$: observer.fullChartParams$,
182
+ isCategorySeprate$: observer.isCategorySeprate$,
183
+ containerPosition$: observer.containerPosition$,
184
+ containerSize$: observer.containerSize$,
185
+ yScale$: observer.yScale$,
186
+ // filteredXYMinMaxData$: observer.filteredXYMinMaxData$,
187
+ // xyMinMax$: observer.xyMinMax$,
680
188
  })
681
189
 
682
190
  return () => {
683
191
  destroy$.next(undefined)
192
+ unsubscribeBaseXAxis()
193
+ unsubscribeBaseYAxis()
684
194
  }
685
195
  })