@orbcharts/plugins-basic 3.0.0-beta.1 → 3.0.0-beta.10

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 (212) hide show
  1. package/LICENSE +200 -200
  2. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +2 -2
  3. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +2 -2
  4. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +2 -2
  5. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +2 -2
  6. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +1 -1
  7. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +3 -3
  8. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +3 -3
  9. package/dist/{src/base/BaseBarStack.d.ts → orbcharts-plugins-basic/src/base/BaseStackedBar.d.ts} +6 -6
  10. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -2
  11. package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +4 -4
  12. package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +5 -5
  13. package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +2 -2
  14. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedBar.d.ts +1 -0
  15. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedValueAxis.d.ts +1 -0
  16. package/dist/orbcharts-plugins-basic/src/index.d.ts +7 -0
  17. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/defaults.d.ts +4 -4
  18. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +3 -3
  19. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedBar.d.ts +1 -0
  20. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedValueAxis.d.ts +1 -0
  21. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +1 -0
  22. package/dist/orbcharts-plugins-basic/src/multiValue/defaults.d.ts +9 -0
  23. package/dist/orbcharts-plugins-basic/src/multiValue/index.d.ts +8 -0
  24. package/dist/orbcharts-plugins-basic/src/multiValue/multiValueObservables.d.ts +33 -0
  25. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueLegend.d.ts +1 -0
  26. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueTooltip.d.ts +1 -0
  27. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/Scatter.d.ts +3 -0
  28. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/ScatterBubbles.d.ts +3 -0
  29. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAux.d.ts +3 -0
  30. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAxes.d.ts +3 -0
  31. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYZoom.d.ts +1 -0
  32. package/dist/orbcharts-plugins-basic/src/relationship/defaults.d.ts +6 -0
  33. package/dist/orbcharts-plugins-basic/src/relationship/index.d.ts +5 -0
  34. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirected.d.ts +3 -0
  35. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirectedBubbles.d.ts +3 -0
  36. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipLegend.d.ts +1 -0
  37. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipTooltip.d.ts +1 -0
  38. package/dist/orbcharts-plugins-basic/src/relationship/relationshipObservables.d.ts +1 -0
  39. package/dist/{src → orbcharts-plugins-basic/src}/series/seriesObservables.d.ts +3 -3
  40. package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +1 -1
  41. package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +2 -2
  42. package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +1 -1
  43. package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +3 -3
  44. package/dist/orbcharts-plugins-basic.es.js +13264 -10298
  45. package/dist/orbcharts-plugins-basic.umd.js +105 -55
  46. package/dist/src/index.d.ts +1 -5
  47. package/lib/core-types.ts +7 -7
  48. package/lib/core.ts +6 -6
  49. package/lib/plugins-basic-types.ts +6 -6
  50. package/package.json +44 -44
  51. package/src/base/BaseBars.ts +765 -765
  52. package/src/base/BaseBarsTriangle.ts +676 -674
  53. package/src/base/BaseDots.ts +464 -515
  54. package/src/base/BaseGroupAxis.ts +679 -679
  55. package/src/base/BaseLegend.ts +684 -680
  56. package/src/base/BaseLineAreas.ts +629 -629
  57. package/src/base/BaseLines.ts +706 -706
  58. package/src/base/{BaseBarStack.ts → BaseStackedBar.ts} +782 -780
  59. package/src/base/BaseTooltip.ts +385 -382
  60. package/src/base/BaseValueAxis.ts +583 -580
  61. package/src/base/types.ts +2 -2
  62. package/src/const.ts +30 -30
  63. package/src/grid/defaults.ts +246 -244
  64. package/src/grid/gridObservables.ts +554 -545
  65. package/src/grid/index.ts +16 -16
  66. package/src/grid/plugins/Bars.ts +69 -69
  67. package/src/grid/plugins/BarsPN.ts +66 -66
  68. package/src/grid/plugins/BarsTriangle.ts +73 -73
  69. package/src/grid/plugins/Dots.ts +68 -68
  70. package/src/grid/plugins/GridLegend.ts +107 -107
  71. package/src/grid/plugins/GridTooltip.ts +66 -66
  72. package/src/grid/plugins/GridZoom.ts +218 -218
  73. package/src/grid/plugins/GroupAux.ts +1103 -1098
  74. package/src/grid/plugins/GroupAxis.ts +97 -97
  75. package/src/grid/plugins/LineAreas.ts +65 -65
  76. package/src/grid/plugins/Lines.ts +59 -59
  77. package/src/grid/plugins/{BarStack.ts → StackedBar.ts} +64 -64
  78. package/src/grid/plugins/{ValueStackAxis.ts → StackedValueAxis.ts} +96 -95
  79. package/src/grid/plugins/ValueAxis.ts +94 -93
  80. package/src/index.ts +6 -9
  81. package/src/multiGrid/defaults.ts +224 -224
  82. package/src/multiGrid/index.ts +15 -15
  83. package/src/multiGrid/multiGridObservables.ts +49 -49
  84. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  85. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  86. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  87. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  88. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  89. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  90. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  91. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  92. package/src/multiGrid/plugins/{MultiBarStack.ts → MultiStackedBar.ts} +106 -106
  93. package/src/multiGrid/plugins/{MultiValueStackAxis.ts → MultiStackedValueAxis.ts} +134 -133
  94. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -133
  95. package/src/multiGrid/plugins/{OverlappingValueStackAxes.ts → OverlappingStackedValueAxes.ts} +299 -298
  96. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -299
  97. package/src/multiValue/defaults.ts +167 -0
  98. package/src/multiValue/index.ts +9 -0
  99. package/src/multiValue/multiValueObservables.ts +297 -0
  100. package/src/multiValue/plugins/MultiValueLegend.ts +107 -0
  101. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -0
  102. package/src/multiValue/plugins/Scatter.ts +426 -0
  103. package/src/multiValue/plugins/ScatterBubbles.ts +554 -0
  104. package/src/multiValue/plugins/XYAux.ts +682 -0
  105. package/src/multiValue/plugins/XYAxes.ts +685 -0
  106. package/src/multiValue/plugins/XYZoom.ts +300 -0
  107. package/src/noneData/defaults.ts +102 -102
  108. package/src/noneData/index.ts +3 -3
  109. package/src/noneData/plugins/Container.ts +28 -28
  110. package/src/noneData/plugins/Tooltip.ts +374 -374
  111. package/src/relationship/defaults.ts +196 -0
  112. package/src/relationship/index.ts +5 -0
  113. package/src/relationship/plugins/ForceDirected.ts +1167 -0
  114. package/src/relationship/plugins/ForceDirectedBubbles.ts +1391 -0
  115. package/src/relationship/plugins/RelationshipLegend.ts +100 -0
  116. package/src/relationship/plugins/RelationshipTooltip.ts +66 -0
  117. package/src/relationship/relationshipObservables.ts +50 -0
  118. package/src/series/defaults.ts +206 -206
  119. package/src/series/index.ts +9 -9
  120. package/src/series/plugins/Bubbles.ts +606 -603
  121. package/src/series/plugins/Pie.ts +623 -623
  122. package/src/series/plugins/PieEventTexts.ts +284 -283
  123. package/src/series/plugins/PieLabels.ts +640 -640
  124. package/src/series/plugins/Rose.ts +516 -516
  125. package/src/series/plugins/RoseLabels.ts +600 -600
  126. package/src/series/plugins/SeriesLegend.ts +107 -107
  127. package/src/series/plugins/SeriesTooltip.ts +66 -66
  128. package/src/series/seriesObservables.ts +145 -145
  129. package/src/series/seriesUtils.ts +51 -51
  130. package/src/tree/defaults.ts +78 -78
  131. package/src/tree/index.ts +4 -4
  132. package/src/tree/plugins/TreeLegend.ts +100 -107
  133. package/src/tree/plugins/TreeMap.ts +333 -333
  134. package/src/tree/plugins/TreeTooltip.ts +66 -66
  135. package/src/utils/commonUtils.ts +21 -21
  136. package/src/utils/d3Graphics.ts +174 -174
  137. package/src/utils/d3Utils.ts +74 -73
  138. package/src/utils/observables.ts +14 -14
  139. package/src/utils/orbchartsUtils.ts +116 -100
  140. package/tsconfig.base.json +13 -13
  141. package/tsconfig.json +2 -2
  142. package/vite.config.js +22 -22
  143. package/dist/src/grid/plugins/BarStack.d.ts +0 -1
  144. package/dist/src/grid/plugins/ValueStackAxis.d.ts +0 -1
  145. package/dist/src/multiGrid/plugins/MultiBarStack.d.ts +0 -1
  146. package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +0 -1
  147. package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +0 -1
  148. package/dist/src/multiValue/plugins/Scatter.d.ts +0 -0
  149. package/dist/src/multiValue/plugins/ScatterAxes.d.ts +0 -0
  150. package/dist/src/noneData/plugins/Container.d.ts +0 -1
  151. package/dist/src/noneData/plugins/Tooltip.d.ts +0 -3
  152. package/dist/src/relationship/index.d.ts +0 -0
  153. package/dist/src/relationship/plugins/Relationship.d.ts +0 -0
  154. package/src/base/BaseGroupArea.ts +0 -0
  155. package/src/multiValue/plugins/ScatterAxes.ts +0 -0
  156. package/src/relationship/plugins/Relationship.ts +0 -0
  157. /package/dist/{lib → orbcharts-plugins-basic/lib}/core-types.d.ts +0 -0
  158. /package/dist/{lib → orbcharts-plugins-basic/lib}/core.d.ts +0 -0
  159. /package/dist/{lib → orbcharts-plugins-basic/lib}/plugins-basic-types.d.ts +0 -0
  160. /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseTooltip.d.ts +0 -0
  161. /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
  162. /package/dist/{src → orbcharts-plugins-basic/src}/const.d.ts +0 -0
  163. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
  164. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsPN.d.ts +0 -0
  165. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
  166. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
  167. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
  168. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridTooltip.d.ts +0 -0
  169. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridZoom.d.ts +0 -0
  170. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
  171. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
  172. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
  173. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
  174. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
  175. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/multiGridObservables.d.ts +0 -0
  176. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  177. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  178. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  179. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  180. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridTooltip.d.ts +0 -0
  181. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  182. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  183. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  184. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  185. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  186. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/Ranking.d.ts +0 -0
  187. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/RankingAxis.d.ts +0 -0
  188. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
  189. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/index.d.ts +0 -0
  190. /package/dist/{src/base/BaseGroupArea.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Container.d.ts} +0 -0
  191. /package/dist/{src/multiValue/index.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Tooltip.d.ts} +0 -0
  192. /package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +0 -0
  193. /package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +0 -0
  194. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
  195. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
  196. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieEventTexts.d.ts +0 -0
  197. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
  198. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Rose.d.ts +0 -0
  199. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/RoseLabels.d.ts +0 -0
  200. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
  201. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesTooltip.d.ts +0 -0
  202. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
  203. /package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +0 -0
  204. /package/dist/{src → orbcharts-plugins-basic/src}/tree/defaults.d.ts +0 -0
  205. /package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +0 -0
  206. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
  207. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
  208. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeTooltip.d.ts +0 -0
  209. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
  210. /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
  211. /package/src/{grid → multiValue}/plugins/Ranking.ts +0 -0
  212. /package/src/{grid → multiValue}/plugins/RankingAxis.ts +0 -0
@@ -1,580 +1,583 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- distinctUntilChanged,
6
- first,
7
- map,
8
- takeUntil,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import { createAxisLinearScale } from '../../lib/core'
12
- import type { BasePluginFn } from './types'
13
- import type {
14
- ComputedDataGrid,
15
- DataFormatterGrid,
16
- ChartParams,
17
- ComputedDatumGrid,
18
- GridContainerPosition,
19
- TransformData,
20
- EventGrid,
21
- ColorType
22
- } from '../../lib/core-types'
23
- import type { BaseValueAxisParams } from '../../lib/plugins-basic-types'
24
- import { parseTickFormatValue } from '../utils/d3Utils'
25
- import { getColor, getMinAndMaxValue, getClassName, getUniID } from '../utils/orbchartsUtils'
26
-
27
- // export interface BaseValueAxisParams {
28
- // labelOffset: [number, number]
29
- // labelColorType: ColorType
30
- // axisLineVisible: boolean
31
- // axisLineColorType: ColorType
32
- // ticks: number
33
- // tickFormat: string | ((text: d3.NumberValue) => string)
34
- // tickLineVisible: boolean
35
- // tickPadding: number
36
- // tickFullLine: boolean
37
- // tickFullLineDasharray: string
38
- // tickColorType: ColorType
39
- // tickTextRotate: number
40
- // tickTextColorType: ColorType
41
- // }
42
-
43
- interface BaseLinesContext {
44
- selection: d3.Selection<any, unknown, any, unknown>
45
- computedData$: Observable<ComputedDataGrid>
46
- fullParams$: Observable<BaseValueAxisParams>
47
- fullDataFormatter$: Observable<DataFormatterGrid>
48
- fullChartParams$: Observable<ChartParams>
49
- gridAxesTransform$: Observable<TransformData>
50
- gridAxesReverseTransform$: Observable<TransformData>
51
- gridAxesSize$: Observable<{
52
- width: number;
53
- height: number;
54
- }>
55
- gridContainerPosition$: Observable<GridContainerPosition[]>
56
- isSeriesSeprate$: Observable<boolean>
57
- }
58
-
59
- interface TextAlign {
60
- textAnchor: "start" | "middle" | "end"
61
- dominantBaseline: "middle" | "auto" | "hanging"
62
- }
63
-
64
- // const pluginName = 'ValueAxis'
65
- // const containerClassName = getClassName(pluginName, 'container')
66
- // const yAxisGClassName = getClassName(pluginName, 'yAxisG')
67
- // const yAxisClassName = getClassName(pluginName, 'yAxis')
68
- // const textClassName = getClassName(pluginName, 'text')
69
- const defaultTickSize = 6
70
-
71
- function renderAxisLabel ({ selection, textClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, fullChartParams, textReverseTransform }: {
72
- selection: d3.Selection<SVGGElement, any, any, any>,
73
- textClassName: string
74
- fullParams: BaseValueAxisParams
75
- axisLabelAlign: TextAlign
76
- gridAxesSize: { width: number, height: number }
77
- fullDataFormatter: DataFormatterGrid,
78
- fullChartParams: ChartParams
79
- textReverseTransform: string,
80
- }) {
81
- const offsetX = fullParams.tickPadding - fullParams.labelOffset[0]
82
- const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
83
- let labelX = 0
84
- let labelY = 0
85
- if (fullDataFormatter.grid.groupAxis.position === 'bottom') {
86
- // labelY = - gridAxesSize.height - offsetY
87
- labelY = - offsetY
88
- if (fullDataFormatter.grid.valueAxis.position === 'left') {
89
- labelX = - offsetX
90
- } else if (fullDataFormatter.grid.valueAxis.position === 'right') {
91
- labelX = offsetX
92
- }
93
- } else if (fullDataFormatter.grid.groupAxis.position === 'top') {
94
- // labelY = gridAxesSize.height + offsetY
95
- labelY = offsetY
96
- if (fullDataFormatter.grid.valueAxis.position === 'left') {
97
- labelX = - offsetX
98
- } else if (fullDataFormatter.grid.valueAxis.position === 'right') {
99
- labelX = offsetX
100
- }
101
- } else if (fullDataFormatter.grid.groupAxis.position === 'left') {
102
- // labelX = gridAxesSize.width + offsetX
103
- labelX = offsetX
104
- if (fullDataFormatter.grid.valueAxis.position === 'bottom') {
105
- labelY = offsetY
106
- } else if (fullDataFormatter.grid.valueAxis.position === 'top') {
107
- labelY = - offsetY
108
- }
109
- } else if (fullDataFormatter.grid.groupAxis.position === 'right') {
110
- labelX = - offsetX
111
- if (fullDataFormatter.grid.valueAxis.position === 'bottom') {
112
- labelY = offsetY
113
- } else if (fullDataFormatter.grid.valueAxis.position === 'top') {
114
- labelY = - offsetY
115
- }
116
- }
117
-
118
- const axisLabelSelection = selection
119
- .selectAll<SVGGElement, BaseValueAxisParams>(`g.${textClassName}`)
120
- .data([fullParams])
121
- .join('g')
122
- .classed(textClassName, true)
123
- .each((d, i, g) => {
124
- const text = d3.select(g[i])
125
- .selectAll<SVGTextElement, BaseValueAxisParams>(`text`)
126
- .data([d])
127
- .join(
128
- enter => {
129
- return enter
130
- .append('text')
131
- .style('font-weight', 'bold')
132
- },
133
- update => update,
134
- exit => exit.remove()
135
- )
136
- .attr('text-anchor', axisLabelAlign.textAnchor)
137
- .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
138
- .attr('font-size', fullChartParams.styles.textSize)
139
- .style('fill', getColor(fullParams.labelColorType, fullChartParams))
140
- .style('transform', textReverseTransform)
141
- // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
142
- .attr('x', labelX)
143
- .attr('y', labelY)
144
- .text(d => fullDataFormatter.grid.valueAxis.label)
145
- })
146
- .attr('transform', d => `translate(0, ${gridAxesSize.height})`)
147
- // .attr('transform', d => `translate(${- fullParams.tickPadding + fullParams.labelOffset[0]}, ${gridAxesSize.height + fullParams.tickPadding + fullParams.labelOffset[1]})`)
148
-
149
-
150
- }
151
-
152
- function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, fullChartParams, valueScale, textReverseTransformWithRotate, minAndMax }: {
153
- selection: d3.Selection<SVGGElement, any, any, any>,
154
- yAxisClassName: string
155
- fullParams: BaseValueAxisParams
156
- tickTextAlign: TextAlign
157
- gridAxesSize: { width: number, height: number }
158
- fullDataFormatter: DataFormatterGrid,
159
- fullChartParams: ChartParams
160
- valueScale: d3.ScaleLinear<number, number>
161
- textReverseTransformWithRotate: string,
162
- minAndMax: [number, number]
163
- }) {
164
-
165
- const yAxisSelection = selection
166
- .selectAll<SVGGElement, BaseValueAxisParams>(`g.${yAxisClassName}`)
167
- .data([fullParams])
168
- .join('g')
169
- .classed(yAxisClassName, true)
170
-
171
- const valueLength = minAndMax[1] - minAndMax[0]
172
-
173
- // const _valueScale = d3.scaleLinear()
174
- // .domain([0, 150])
175
- // .range([416.5, 791.349])
176
-
177
- // 刻度文字偏移
178
- let tickPadding = 0
179
- let textY = 0
180
- if (fullDataFormatter.grid.valueAxis.position === 'left') {
181
- tickPadding = fullParams.tickPadding
182
- textY = 0
183
- } else if (fullDataFormatter.grid.valueAxis.position === 'right') {
184
- tickPadding = - fullParams.tickPadding
185
- textY = 0
186
- } else if (fullDataFormatter.grid.valueAxis.position === 'bottom') {
187
- tickPadding = 0
188
- textY = fullParams.tickPadding
189
- } else if (fullDataFormatter.grid.valueAxis.position === 'top') {
190
- tickPadding = 0
191
- textY = - fullParams.tickPadding
192
- }
193
-
194
- // 設定Y軸刻度
195
- const yAxis = d3.axisLeft(valueScale)
196
- .scale(valueScale)
197
- .ticks(valueLength > fullParams.ticks
198
- ? fullParams.ticks
199
- : ((minAndMax[0] === 0 && minAndMax[1] === 0)
200
- ? 1
201
- : Math.ceil(valueLength))) // 刻度分段數量
202
- .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
203
- .tickSize(fullParams.tickFullLine == true
204
- ? -gridAxesSize.width
205
- : defaultTickSize)
206
- .tickPadding(tickPadding)
207
-
208
- const yAxisEl = yAxisSelection
209
- .transition()
210
- .duration(100)
211
- .call(yAxis)
212
-
213
- yAxisEl.selectAll('line')
214
- .style('fill', 'none')
215
- .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
216
- .style('stroke-dasharray', fullParams.tickFullLineDasharray)
217
- .attr('pointer-events', 'none')
218
-
219
- yAxisEl.selectAll('path')
220
- .style('fill', 'none')
221
- // .style('stroke', this.fullParams.axisLineColor!)
222
- .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
223
- .style('shape-rendering', 'crispEdges')
224
-
225
- // const yText = yAxisEl.selectAll('text')
226
- const yText = yAxisSelection.selectAll('text')
227
- // .style('font-family', 'sans-serif')
228
- .attr('font-size', fullChartParams.styles.textSize)
229
- .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
230
- .attr('text-anchor', tickTextAlign.textAnchor)
231
- .attr('dominant-baseline', tickTextAlign.dominantBaseline)
232
- // .attr('dy', 0)
233
- .attr('y', textY)
234
- yText.style('transform', textReverseTransformWithRotate)
235
-
236
- // 抵消掉預設的偏移
237
- if (fullDataFormatter.grid.valueAxis.position === 'bottom' || fullDataFormatter.grid.valueAxis.position === 'top') {
238
- yText.attr('dy', 0)
239
- }
240
-
241
- return yAxisSelection
242
- }
243
-
244
-
245
-
246
- export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName: string, {
247
- selection,
248
- computedData$,
249
- fullParams$,
250
- fullDataFormatter$,
251
- fullChartParams$,
252
- gridAxesTransform$,
253
- gridAxesReverseTransform$,
254
- gridAxesSize$,
255
- gridContainerPosition$,
256
- isSeriesSeprate$,
257
- }) => {
258
-
259
- const destroy$ = new Subject()
260
-
261
- const containerClassName = getClassName(pluginName, 'container')
262
- const yAxisGClassName = getClassName(pluginName, 'yAxisG')
263
- const yAxisClassName = getClassName(pluginName, 'yAxis')
264
- const textClassName = getClassName(pluginName, 'text')
265
-
266
- const containerSelection$ = combineLatest({
267
- computedData: computedData$.pipe(
268
- distinctUntilChanged((a, b) => {
269
- // 只有當series的數量改變時,才重新計算
270
- return a.length === b.length
271
- }),
272
- ),
273
- isSeriesSeprate: isSeriesSeprate$
274
- }).pipe(
275
- takeUntil(destroy$),
276
- switchMap(async (d) => d),
277
- map(data => {
278
- return data.isSeriesSeprate
279
- // series分開的時候顯示各別axis
280
- ? data.computedData
281
- // series合併的時候只顯示第一個axis
282
- : [data.computedData[0]]
283
- }),
284
- map((computedData, i) => {
285
- return selection
286
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
287
- .data(computedData, d => d[0] ? d[0].seriesIndex : 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, ComputedDatumGrid[]>(`g.${yAxisGClassName}`)
298
- .data([yAxisGClassName])
299
- .join('g')
300
- .classed(yAxisGClassName, true)
301
- })
302
- )
303
-
304
- combineLatest({
305
- containerSelection: containerSelection$,
306
- gridContainerPosition: gridContainerPosition$
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
- })
318
- // .attr('opacity', 0)
319
- // .transition()
320
- // .attr('opacity', 1)
321
- })
322
-
323
- combineLatest({
324
- axisSelection: axisSelection$,
325
- gridAxesTransform: gridAxesTransform$,
326
- }).pipe(
327
- takeUntil(destroy$),
328
- switchMap(async d => d)
329
- ).subscribe(data => {
330
- data.axisSelection
331
- .style('transform', data.gridAxesTransform.value)
332
- // .attr('opacity', 0)
333
- // .transition()
334
- // .attr('opacity', 1)
335
-
336
- })
337
-
338
- // const gridAxesSize$ = gridAxisSizeObservable({
339
- // fullDataFormatter$,
340
- // layout$
341
- // })
342
-
343
- // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
344
- // combineLatest({
345
- // fullParams: fullParams$,
346
- // layout: layout$
347
- // }).pipe(
348
- // takeUntil(destroy$),
349
- // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
350
- // switchMap(async (d) => d),
351
- // ).subscribe(data => {
352
-
353
- // const transformData = Object.assign({}, data.layout.content.axesTransformData)
354
-
355
- // const value = getAxesTransformValue({
356
- // translate: [0, 0],
357
- // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
358
- // rotate: transformData.rotate * -1 + data.fullParams.tickTextRotate,
359
- // rotateX: transformData.rotateX * -1,
360
- // rotateY: transformData.rotateY * -1
361
- // })
362
-
363
- // subscriber.next(value)
364
- // })
365
- // })
366
- // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
367
- // takeUntil(destroy$),
368
- // map(d => {
369
- // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
370
- // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
371
- // const rotate = d.rotate * -1
372
- // const rotateX = d.rotateX * -1
373
- // const rotateY = d.rotateY * -1
374
- // return {
375
- // translate,
376
- // scale,
377
- // rotate,
378
- // rotateX,
379
- // rotateY,
380
- // value: ''
381
- // }
382
- // }),
383
- // )
384
- const textReverseTransform$ = combineLatest({
385
- gridAxesReverseTransform: gridAxesReverseTransform$,
386
- gridContainerPosition: gridContainerPosition$
387
- }).pipe(
388
- takeUntil(destroy$),
389
- switchMap(async (d) => d),
390
- map(data => {
391
- // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
392
- const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
393
- const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
394
- const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
395
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
396
- return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
397
- }),
398
- distinctUntilChanged()
399
- )
400
-
401
- const textReverseTransformWithRotate$ = combineLatest({
402
- textReverseTransform: textReverseTransform$,
403
- fullParams: fullParams$,
404
- }).pipe(
405
- takeUntil(destroy$),
406
- switchMap(async (d) => d),
407
- map(data => {
408
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
409
- return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
410
- })
411
- )
412
-
413
- const minAndMax$: Observable<[number, number]> = new Observable(subscriber => {
414
- combineLatest({
415
- fullDataFormatter: fullDataFormatter$,
416
- gridAxesSize: gridAxesSize$,
417
- computedData: computedData$
418
- }).pipe(
419
- takeUntil(destroy$),
420
- switchMap(async (d) => d),
421
- ).subscribe(data => {
422
- const groupMin = 0
423
- const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
424
- // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
425
- // ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
426
- // : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
427
- const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
428
- const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
429
- ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
430
- : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
431
-
432
- const filteredData = data.computedData.map((d, i) => {
433
- return d.filter((_d, _i) => {
434
- return _i >= groupScaleDomainMin && _i <= groupScaleDomainMax
435
- })
436
- })
437
-
438
- const filteredMinAndMax = getMinAndMaxValue(filteredData.flat())
439
- if (filteredMinAndMax[0] === filteredMinAndMax[1]) {
440
- filteredMinAndMax[0] = filteredMinAndMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
441
- }
442
- subscriber.next(filteredMinAndMax)
443
- })
444
- })
445
-
446
- const valueScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
447
- combineLatest({
448
- fullDataFormatter: fullDataFormatter$,
449
- gridAxesSize: gridAxesSize$,
450
- minAndMax: minAndMax$
451
- }).pipe(
452
- takeUntil(destroy$),
453
- switchMap(async (d) => d),
454
- ).subscribe(data => {
455
-
456
- const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
457
- maxValue: data.minAndMax[1],
458
- minValue: data.minAndMax[0],
459
- axisWidth: data.gridAxesSize.height,
460
- scaleDomain: data.fullDataFormatter.grid.valueAxis.scaleDomain,
461
- scaleRange: data.fullDataFormatter.grid.valueAxis.scaleRange
462
- })
463
-
464
- subscriber.next(valueScale)
465
- })
466
- })
467
-
468
- const tickTextAlign$: Observable<TextAlign> = combineLatest({
469
- fullDataFormatter: fullDataFormatter$,
470
- fullParams: fullParams$
471
- }).pipe(
472
- takeUntil(destroy$),
473
- switchMap(async (d) => d),
474
- map(data => {
475
- let textAnchor: 'start' | 'middle' | 'end' = 'start'
476
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
477
-
478
- if (data.fullDataFormatter.grid.valueAxis.position === 'left') {
479
- textAnchor = 'end'
480
- dominantBaseline = 'middle'
481
- } else if (data.fullDataFormatter.grid.valueAxis.position === 'right') {
482
- textAnchor = 'start'
483
- dominantBaseline = 'middle'
484
- } else if (data.fullDataFormatter.grid.valueAxis.position === 'bottom') {
485
- textAnchor = data.fullParams.tickTextRotate
486
- ? 'end'
487
- : 'middle'
488
- dominantBaseline = 'hanging'
489
- } else if (data.fullDataFormatter.grid.valueAxis.position === 'top') {
490
- textAnchor = data.fullParams.tickTextRotate
491
- ? 'start'
492
- : 'middle'
493
- dominantBaseline = 'auto'
494
- }
495
- return {
496
- textAnchor,
497
- dominantBaseline
498
- }
499
- })
500
- )
501
-
502
- const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
503
- takeUntil(destroy$),
504
- map(d => {
505
- let textAnchor: 'start' | 'middle' | 'end' = 'start'
506
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
507
-
508
- if (d.grid.groupAxis.position === 'bottom') {
509
- dominantBaseline = 'auto'
510
- } else if (d.grid.groupAxis.position === 'top') {
511
- dominantBaseline = 'hanging'
512
- } else if (d.grid.groupAxis.position === 'left') {
513
- textAnchor = 'start'
514
- } else if (d.grid.groupAxis.position === 'right') {
515
- textAnchor = 'end'
516
- }
517
- if (d.grid.valueAxis.position === 'left') {
518
- textAnchor = 'end'
519
- } else if (d.grid.valueAxis.position === 'right') {
520
- textAnchor = 'start'
521
- } else if (d.grid.valueAxis.position === 'bottom') {
522
- dominantBaseline = 'hanging'
523
- } else if (d.grid.valueAxis.position === 'top') {
524
- dominantBaseline = 'auto'
525
- }
526
- return {
527
- textAnchor,
528
- dominantBaseline
529
- }
530
- })
531
- )
532
-
533
-
534
- combineLatest({
535
- axisSelection: axisSelection$,
536
- fullParams: fullParams$,
537
- tickTextAlign: tickTextAlign$,
538
- axisLabelAlign: axisLabelAlign$,
539
- computedData: computedData$,
540
- gridAxesSize: gridAxesSize$,
541
- fullDataFormatter: fullDataFormatter$,
542
- fullChartParams: fullChartParams$,
543
- valueScale: valueScale$,
544
- textReverseTransform: textReverseTransform$,
545
- textReverseTransformWithRotate: textReverseTransformWithRotate$,
546
- minAndMax: minAndMax$
547
- }).pipe(
548
- takeUntil(destroy$),
549
- switchMap(async (d) => d),
550
- ).subscribe(data => {
551
-
552
- renderAxis({
553
- selection: data.axisSelection,
554
- yAxisClassName,
555
- fullParams: data.fullParams,
556
- tickTextAlign: data.tickTextAlign,
557
- gridAxesSize: data.gridAxesSize,
558
- fullDataFormatter: data.fullDataFormatter,
559
- fullChartParams: data.fullChartParams,
560
- valueScale: data.valueScale,
561
- textReverseTransformWithRotate: data.textReverseTransformWithRotate,
562
- minAndMax: data.minAndMax
563
- })
564
-
565
- renderAxisLabel({
566
- selection: data.axisSelection,
567
- textClassName,
568
- fullParams: data.fullParams,
569
- axisLabelAlign: data.axisLabelAlign,
570
- gridAxesSize: data.gridAxesSize,
571
- fullDataFormatter: data.fullDataFormatter,
572
- fullChartParams: data.fullChartParams,
573
- textReverseTransform: data.textReverseTransform,
574
- })
575
- })
576
-
577
- return () => {
578
- destroy$.next(undefined)
579
- }
580
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ distinctUntilChanged,
6
+ first,
7
+ map,
8
+ takeUntil,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import { createValueToAxisScale } from '../../lib/core'
12
+ import type { BasePluginFn } from './types'
13
+ import type {
14
+ ComputedDataGrid,
15
+ DataFormatterGrid,
16
+ ChartParams,
17
+ ComputedDatumGrid,
18
+ ContainerPositionScaled,
19
+ TransformData,
20
+ EventGrid,
21
+ ColorType
22
+ } from '../../lib/core-types'
23
+ import type { BaseValueAxisParams } from '../../lib/plugins-basic-types'
24
+ import { parseTickFormatValue } from '../utils/d3Utils'
25
+ import { getColor, getMinMaxValue, getClassName, getUniID } from '../utils/orbchartsUtils'
26
+
27
+ // export interface BaseValueAxisParams {
28
+ // labelOffset: [number, number]
29
+ // labelColorType: ColorType
30
+ // axisLineVisible: boolean
31
+ // axisLineColorType: ColorType
32
+ // ticks: number
33
+ // tickFormat: string | ((text: d3.NumberValue) => string)
34
+ // tickLineVisible: boolean
35
+ // tickPadding: number
36
+ // tickFullLine: boolean
37
+ // tickFullLineDasharray: string
38
+ // tickColorType: ColorType
39
+ // tickTextRotate: number
40
+ // tickTextColorType: ColorType
41
+ // }
42
+
43
+ interface BaseLinesContext {
44
+ selection: d3.Selection<any, unknown, any, unknown>
45
+ computedData$: Observable<ComputedDataGrid>
46
+ filteredMinMaxValue$: Observable<[number, number]>
47
+ fullParams$: Observable<BaseValueAxisParams>
48
+ fullDataFormatter$: Observable<DataFormatterGrid>
49
+ fullChartParams$: Observable<ChartParams>
50
+ gridAxesTransform$: Observable<TransformData>
51
+ gridAxesReverseTransform$: Observable<TransformData>
52
+ gridAxesSize$: Observable<{
53
+ width: number;
54
+ height: number;
55
+ }>
56
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
57
+ isSeriesSeprate$: Observable<boolean>
58
+ }
59
+
60
+ interface TextAlign {
61
+ textAnchor: "start" | "middle" | "end"
62
+ dominantBaseline: "middle" | "auto" | "hanging"
63
+ }
64
+
65
+ // const pluginName = 'ValueAxis'
66
+ // const containerClassName = getClassName(pluginName, 'container')
67
+ // const yAxisGClassName = getClassName(pluginName, 'yAxisG')
68
+ // const yAxisClassName = getClassName(pluginName, 'yAxis')
69
+ // const textClassName = getClassName(pluginName, 'text')
70
+ const defaultTickSize = 6
71
+
72
+ function renderAxisLabel ({ selection, textClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, fullChartParams, textReverseTransform }: {
73
+ selection: d3.Selection<SVGGElement, any, any, any>,
74
+ textClassName: string
75
+ fullParams: BaseValueAxisParams
76
+ axisLabelAlign: TextAlign
77
+ gridAxesSize: { width: number, height: number }
78
+ fullDataFormatter: DataFormatterGrid,
79
+ fullChartParams: ChartParams
80
+ textReverseTransform: string,
81
+ }) {
82
+ const offsetX = fullParams.tickPadding - fullParams.labelOffset[0]
83
+ const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
84
+ let labelX = 0
85
+ let labelY = 0
86
+ if (fullDataFormatter.groupAxis.position === 'bottom') {
87
+ // labelY = - gridAxesSize.height - offsetY
88
+ labelY = - offsetY
89
+ if (fullDataFormatter.valueAxis.position === 'left') {
90
+ labelX = - offsetX
91
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
92
+ labelX = offsetX
93
+ }
94
+ } else if (fullDataFormatter.groupAxis.position === 'top') {
95
+ // labelY = gridAxesSize.height + offsetY
96
+ labelY = offsetY
97
+ if (fullDataFormatter.valueAxis.position === 'left') {
98
+ labelX = - offsetX
99
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
100
+ labelX = offsetX
101
+ }
102
+ } else if (fullDataFormatter.groupAxis.position === 'left') {
103
+ // labelX = gridAxesSize.width + offsetX
104
+ labelX = offsetX
105
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
106
+ labelY = offsetY
107
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
108
+ labelY = - offsetY
109
+ }
110
+ } else if (fullDataFormatter.groupAxis.position === 'right') {
111
+ labelX = - offsetX
112
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
113
+ labelY = offsetY
114
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
115
+ labelY = - offsetY
116
+ }
117
+ }
118
+
119
+ const axisLabelSelection = selection
120
+ .selectAll<SVGGElement, BaseValueAxisParams>(`g.${textClassName}`)
121
+ .data([fullParams])
122
+ .join('g')
123
+ .classed(textClassName, true)
124
+ .each((d, i, g) => {
125
+ const text = d3.select(g[i])
126
+ .selectAll<SVGTextElement, BaseValueAxisParams>(`text`)
127
+ .data([d])
128
+ .join(
129
+ enter => {
130
+ return enter
131
+ .append('text')
132
+ .style('font-weight', 'bold')
133
+ },
134
+ update => update,
135
+ exit => exit.remove()
136
+ )
137
+ .attr('text-anchor', axisLabelAlign.textAnchor)
138
+ .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
139
+ .attr('font-size', fullChartParams.styles.textSize)
140
+ .style('fill', getColor(fullParams.labelColorType, fullChartParams))
141
+ .style('transform', textReverseTransform)
142
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
143
+ .attr('x', labelX)
144
+ .attr('y', labelY)
145
+ .text(d => fullDataFormatter.valueAxis.label)
146
+ })
147
+ .attr('transform', d => `translate(0, ${gridAxesSize.height})`)
148
+ // .attr('transform', d => `translate(${- fullParams.tickPadding + fullParams.labelOffset[0]}, ${gridAxesSize.height + fullParams.tickPadding + fullParams.labelOffset[1]})`)
149
+
150
+
151
+ }
152
+
153
+ function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, fullChartParams, valueScale, textReverseTransformWithRotate, filteredMinMaxValue }: {
154
+ selection: d3.Selection<SVGGElement, any, any, any>,
155
+ yAxisClassName: string
156
+ fullParams: BaseValueAxisParams
157
+ tickTextAlign: TextAlign
158
+ gridAxesSize: { width: number, height: number }
159
+ fullDataFormatter: DataFormatterGrid,
160
+ fullChartParams: ChartParams
161
+ valueScale: d3.ScaleLinear<number, number>
162
+ textReverseTransformWithRotate: string,
163
+ filteredMinMaxValue: [number, number]
164
+ }) {
165
+
166
+ const yAxisSelection = selection
167
+ .selectAll<SVGGElement, BaseValueAxisParams>(`g.${yAxisClassName}`)
168
+ .data([fullParams])
169
+ .join('g')
170
+ .classed(yAxisClassName, true)
171
+
172
+ // const _valueScale = d3.scaleLinear()
173
+ // .domain([0, 150])
174
+ // .range([416.5, 791.349])
175
+
176
+ // 刻度文字偏移
177
+ let tickPadding = 0
178
+ let textY = 0
179
+ if (fullDataFormatter.valueAxis.position === 'left') {
180
+ tickPadding = fullParams.tickPadding
181
+ textY = 0
182
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
183
+ tickPadding = - fullParams.tickPadding
184
+ textY = 0
185
+ } else if (fullDataFormatter.valueAxis.position === 'bottom') {
186
+ tickPadding = 0
187
+ textY = fullParams.tickPadding
188
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
189
+ tickPadding = 0
190
+ textY = - fullParams.tickPadding
191
+ }
192
+
193
+ // 設定Y軸刻度
194
+ const yAxis = d3.axisLeft(valueScale)
195
+ .scale(valueScale)
196
+ .ticks(fullParams.ticks) // 刻度分段數量
197
+ .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
198
+ .tickSize(fullParams.tickFullLine == true
199
+ ? -gridAxesSize.width
200
+ : defaultTickSize)
201
+ .tickPadding(tickPadding)
202
+
203
+ const yAxisEl = yAxisSelection
204
+ .transition()
205
+ .duration(100)
206
+ .call(yAxis)
207
+
208
+ yAxisEl.selectAll('line')
209
+ .style('fill', 'none')
210
+ .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
211
+ .style('stroke-dasharray', fullParams.tickFullLineDasharray)
212
+ .attr('pointer-events', 'none')
213
+
214
+ yAxisEl.selectAll('path')
215
+ .style('fill', 'none')
216
+ // .style('stroke', this.fullParams.axisLineColor!)
217
+ .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
218
+ .style('shape-rendering', 'crispEdges')
219
+
220
+ // const yText = yAxisEl.selectAll('text')
221
+ const yText = yAxisSelection.selectAll('text')
222
+ // .style('font-family', 'sans-serif')
223
+ .attr('font-size', fullChartParams.styles.textSize)
224
+ .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
225
+ .attr('text-anchor', tickTextAlign.textAnchor)
226
+ .attr('dominant-baseline', tickTextAlign.dominantBaseline)
227
+ // .attr('dy', 0)
228
+ .attr('y', textY)
229
+ .attr('dy', 0)
230
+ yText.style('transform', textReverseTransformWithRotate)
231
+
232
+ // 抵消掉預設的偏移
233
+ if (fullDataFormatter.valueAxis.position === 'bottom' || fullDataFormatter.valueAxis.position === 'top') {
234
+ yText.attr('dy', 0)
235
+ }
236
+
237
+ return yAxisSelection
238
+ }
239
+
240
+
241
+
242
+ export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName: string, {
243
+ selection,
244
+ computedData$,
245
+ filteredMinMaxValue$,
246
+ fullParams$,
247
+ fullDataFormatter$,
248
+ fullChartParams$,
249
+ gridAxesTransform$,
250
+ gridAxesReverseTransform$,
251
+ gridAxesSize$,
252
+ gridContainerPosition$,
253
+ isSeriesSeprate$,
254
+ }) => {
255
+
256
+ const destroy$ = new Subject()
257
+
258
+ const containerClassName = getClassName(pluginName, 'container')
259
+ const yAxisGClassName = getClassName(pluginName, 'yAxisG')
260
+ const yAxisClassName = getClassName(pluginName, 'yAxis')
261
+ const textClassName = getClassName(pluginName, 'text')
262
+
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
+ )
289
+
290
+ const axisSelection$ = containerSelection$.pipe(
291
+ takeUntil(destroy$),
292
+ map((containerSelection, i) => {
293
+ return containerSelection
294
+ .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${yAxisGClassName}`)
295
+ .data([yAxisGClassName])
296
+ .join('g')
297
+ .classed(yAxisGClassName, true)
298
+ })
299
+ )
300
+
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
+ })
319
+
320
+ combineLatest({
321
+ axisSelection: axisSelection$,
322
+ gridAxesTransform: gridAxesTransform$,
323
+ }).pipe(
324
+ takeUntil(destroy$),
325
+ switchMap(async d => d)
326
+ ).subscribe(data => {
327
+ data.axisSelection
328
+ .style('transform', data.gridAxesTransform.value)
329
+ // .attr('opacity', 0)
330
+ // .transition()
331
+ // .attr('opacity', 1)
332
+
333
+ })
334
+
335
+ // const gridAxesSize$ = gridAxisSizeObservable({
336
+ // fullDataFormatter$,
337
+ // layout$
338
+ // })
339
+
340
+ // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
341
+ // combineLatest({
342
+ // fullParams: fullParams$,
343
+ // layout: layout$
344
+ // }).pipe(
345
+ // takeUntil(destroy$),
346
+ // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
347
+ // switchMap(async (d) => d),
348
+ // ).subscribe(data => {
349
+
350
+ // const transformData = Object.assign({}, data.layout.content.axesTransformData)
351
+
352
+ // const value = getAxesTransformValue({
353
+ // translate: [0, 0],
354
+ // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
355
+ // rotate: transformData.rotate * -1 + data.fullParams.tickTextRotate,
356
+ // rotateX: transformData.rotateX * -1,
357
+ // rotateY: transformData.rotateY * -1
358
+ // })
359
+
360
+ // subscriber.next(value)
361
+ // })
362
+ // })
363
+ // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
364
+ // takeUntil(destroy$),
365
+ // map(d => {
366
+ // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
367
+ // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
368
+ // const rotate = d.rotate * -1
369
+ // const rotateX = d.rotateX * -1
370
+ // const rotateY = d.rotateY * -1
371
+ // return {
372
+ // translate,
373
+ // scale,
374
+ // rotate,
375
+ // rotateX,
376
+ // rotateY,
377
+ // value: ''
378
+ // }
379
+ // }),
380
+ // )
381
+ const textReverseTransform$ = combineLatest({
382
+ gridAxesReverseTransform: gridAxesReverseTransform$,
383
+ gridContainerPosition: gridContainerPosition$
384
+ }).pipe(
385
+ takeUntil(destroy$),
386
+ switchMap(async (d) => d),
387
+ map(data => {
388
+ // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
389
+ const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
390
+ const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
391
+ const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
392
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
393
+ return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
394
+ }),
395
+ distinctUntilChanged()
396
+ )
397
+
398
+ const textReverseTransformWithRotate$ = combineLatest({
399
+ textReverseTransform: textReverseTransform$,
400
+ fullParams: fullParams$,
401
+ }).pipe(
402
+ takeUntil(destroy$),
403
+ switchMap(async (d) => d),
404
+ map(data => {
405
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
406
+ return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
407
+ })
408
+ )
409
+
410
+ // const minMax$: Observable<[number, number]> = new Observable(subscriber => {
411
+ // combineLatest({
412
+ // fullDataFormatter: fullDataFormatter$,
413
+ // computedData: computedData$
414
+ // }).pipe(
415
+ // takeUntil(destroy$),
416
+ // switchMap(async (d) => d),
417
+ // ).subscribe(data => {
418
+ // const groupMin = 0
419
+ // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
420
+ // // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
421
+ // // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
422
+ // // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
423
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
424
+ // const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
425
+ // ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
426
+ // : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
427
+
428
+ // const filteredData = data.computedData.map((d, i) => {
429
+ // return d.filter((_d, _i) => {
430
+ // return _i >= groupScaleDomainMin && _i <= groupScaleDomainMax
431
+ // })
432
+ // })
433
+
434
+ // const filteredMinMax = getMinMaxValue(filteredData.flat())
435
+ // if (filteredMinMax[0] === filteredMinMax[1]) {
436
+ // filteredMinMax[0] = filteredMinMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
437
+ // }
438
+ // subscriber.next(filteredMinMax)
439
+ // })
440
+ // })
441
+
442
+ const valueScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
443
+ combineLatest({
444
+ fullDataFormatter: fullDataFormatter$,
445
+ gridAxesSize: gridAxesSize$,
446
+ // minMax: minMax$
447
+ filteredMinMaxValue: filteredMinMaxValue$
448
+ }).pipe(
449
+ takeUntil(destroy$),
450
+ switchMap(async (d) => d),
451
+ ).subscribe(data => {
452
+ let maxValue = data.filteredMinMaxValue[1]
453
+ let minValue = data.filteredMinMaxValue[0]
454
+ if (maxValue === minValue && maxValue === 0) {
455
+ // 避免最大及最小值同等於 0 造成無法計算scale
456
+ maxValue = 1
457
+ }
458
+
459
+ const valueScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
460
+ maxValue,
461
+ minValue,
462
+ axisWidth: data.gridAxesSize.height,
463
+ scaleDomain: data.fullDataFormatter.valueAxis.scaleDomain,
464
+ scaleRange: data.fullDataFormatter.valueAxis.scaleRange
465
+ })
466
+
467
+ subscriber.next(valueScale)
468
+ })
469
+ })
470
+
471
+ const tickTextAlign$: Observable<TextAlign> = combineLatest({
472
+ fullDataFormatter: fullDataFormatter$,
473
+ fullParams: fullParams$
474
+ }).pipe(
475
+ takeUntil(destroy$),
476
+ switchMap(async (d) => d),
477
+ map(data => {
478
+ let textAnchor: 'start' | 'middle' | 'end' = 'start'
479
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
480
+
481
+ if (data.fullDataFormatter.valueAxis.position === 'left') {
482
+ textAnchor = 'end'
483
+ dominantBaseline = 'middle'
484
+ } else if (data.fullDataFormatter.valueAxis.position === 'right') {
485
+ textAnchor = 'start'
486
+ dominantBaseline = 'middle'
487
+ } else if (data.fullDataFormatter.valueAxis.position === 'bottom') {
488
+ textAnchor = data.fullParams.tickTextRotate
489
+ ? 'end'
490
+ : 'middle'
491
+ dominantBaseline = 'hanging'
492
+ } else if (data.fullDataFormatter.valueAxis.position === 'top') {
493
+ textAnchor = data.fullParams.tickTextRotate
494
+ ? 'start'
495
+ : 'middle'
496
+ dominantBaseline = 'auto'
497
+ }
498
+ return {
499
+ textAnchor,
500
+ dominantBaseline
501
+ }
502
+ })
503
+ )
504
+
505
+ const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
506
+ takeUntil(destroy$),
507
+ map(d => {
508
+ let textAnchor: 'start' | 'middle' | 'end' = 'start'
509
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
510
+
511
+ if (d.groupAxis.position === 'bottom') {
512
+ dominantBaseline = 'auto'
513
+ } else if (d.groupAxis.position === 'top') {
514
+ dominantBaseline = 'hanging'
515
+ } else if (d.groupAxis.position === 'left') {
516
+ textAnchor = 'start'
517
+ } else if (d.groupAxis.position === 'right') {
518
+ textAnchor = 'end'
519
+ }
520
+ if (d.valueAxis.position === 'left') {
521
+ textAnchor = 'end'
522
+ } else if (d.valueAxis.position === 'right') {
523
+ textAnchor = 'start'
524
+ } else if (d.valueAxis.position === 'bottom') {
525
+ dominantBaseline = 'hanging'
526
+ } else if (d.valueAxis.position === 'top') {
527
+ dominantBaseline = 'auto'
528
+ }
529
+ return {
530
+ textAnchor,
531
+ dominantBaseline
532
+ }
533
+ })
534
+ )
535
+
536
+
537
+ combineLatest({
538
+ axisSelection: axisSelection$,
539
+ fullParams: fullParams$,
540
+ tickTextAlign: tickTextAlign$,
541
+ axisLabelAlign: axisLabelAlign$,
542
+ computedData: computedData$,
543
+ gridAxesSize: gridAxesSize$,
544
+ fullDataFormatter: fullDataFormatter$,
545
+ fullChartParams: fullChartParams$,
546
+ valueScale: valueScale$,
547
+ textReverseTransform: textReverseTransform$,
548
+ textReverseTransformWithRotate: textReverseTransformWithRotate$,
549
+ filteredMinMaxValue: filteredMinMaxValue$
550
+ }).pipe(
551
+ takeUntil(destroy$),
552
+ switchMap(async (d) => d),
553
+ ).subscribe(data => {
554
+
555
+ renderAxis({
556
+ selection: data.axisSelection,
557
+ yAxisClassName,
558
+ fullParams: data.fullParams,
559
+ tickTextAlign: data.tickTextAlign,
560
+ gridAxesSize: data.gridAxesSize,
561
+ fullDataFormatter: data.fullDataFormatter,
562
+ fullChartParams: data.fullChartParams,
563
+ valueScale: data.valueScale,
564
+ textReverseTransformWithRotate: data.textReverseTransformWithRotate,
565
+ filteredMinMaxValue: data.filteredMinMaxValue
566
+ })
567
+
568
+ renderAxisLabel({
569
+ selection: data.axisSelection,
570
+ textClassName,
571
+ fullParams: data.fullParams,
572
+ axisLabelAlign: data.axisLabelAlign,
573
+ gridAxesSize: data.gridAxesSize,
574
+ fullDataFormatter: data.fullDataFormatter,
575
+ fullChartParams: data.fullChartParams,
576
+ textReverseTransform: data.textReverseTransform,
577
+ })
578
+ })
579
+
580
+ return () => {
581
+ destroy$.next(undefined)
582
+ }
583
+ }