@orbcharts/plugins-basic 3.0.0-beta.13 → 3.0.0-beta.15

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 (100) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic/src/utils/d3Utils.d.ts +1 -0
  3. package/dist/orbcharts-plugins-basic.es.js +5558 -5443
  4. package/dist/orbcharts-plugins-basic.umd.js +159 -78
  5. package/lib/core-types.ts +7 -7
  6. package/lib/core.ts +6 -6
  7. package/lib/plugins-basic-types.ts +6 -6
  8. package/package.json +44 -44
  9. package/src/base/BaseBars.ts +765 -765
  10. package/src/base/BaseBarsTriangle.ts +676 -676
  11. package/src/base/BaseDots.ts +464 -464
  12. package/src/base/BaseGroupAxis.ts +679 -679
  13. package/src/base/BaseLegend.ts +684 -684
  14. package/src/base/BaseLineAreas.ts +629 -629
  15. package/src/base/BaseLines.ts +706 -706
  16. package/src/base/BaseStackedBar.ts +782 -782
  17. package/src/base/BaseTooltip.ts +385 -385
  18. package/src/base/BaseValueAxis.ts +583 -583
  19. package/src/base/types.ts +2 -2
  20. package/src/const.ts +30 -30
  21. package/src/grid/defaults.ts +250 -246
  22. package/src/grid/gridObservables.ts +554 -554
  23. package/src/grid/index.ts +16 -16
  24. package/src/grid/plugins/Bars.ts +69 -69
  25. package/src/grid/plugins/BarsPN.ts +66 -66
  26. package/src/grid/plugins/BarsTriangle.ts +73 -73
  27. package/src/grid/plugins/Dots.ts +68 -68
  28. package/src/grid/plugins/GridLegend.ts +107 -107
  29. package/src/grid/plugins/GridTooltip.ts +66 -66
  30. package/src/grid/plugins/GridZoom.ts +218 -218
  31. package/src/grid/plugins/GroupAux.ts +1103 -1103
  32. package/src/grid/plugins/GroupAxis.ts +97 -97
  33. package/src/grid/plugins/LineAreas.ts +65 -65
  34. package/src/grid/plugins/Lines.ts +59 -59
  35. package/src/grid/plugins/StackedBar.ts +64 -64
  36. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  37. package/src/grid/plugins/ValueAxis.ts +94 -94
  38. package/src/index.ts +6 -6
  39. package/src/multiGrid/defaults.ts +228 -224
  40. package/src/multiGrid/index.ts +14 -14
  41. package/src/multiGrid/multiGridObservables.ts +49 -49
  42. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  43. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  44. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  45. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  46. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  47. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  48. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  49. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  50. package/src/multiGrid/plugins/MultiStackedBar.ts +106 -106
  51. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  52. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  53. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +299 -299
  54. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  55. package/src/multiValue/defaults.ts +166 -166
  56. package/src/multiValue/index.ts +8 -8
  57. package/src/multiValue/multiValueObservables.ts +297 -297
  58. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  59. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  60. package/src/multiValue/plugins/Scatter.ts +426 -426
  61. package/src/multiValue/plugins/ScatterBubbles.ts +554 -554
  62. package/src/multiValue/plugins/XYAux.ts +681 -681
  63. package/src/multiValue/plugins/XYAxes.ts +684 -684
  64. package/src/multiValue/plugins/XYZoom.ts +299 -299
  65. package/src/noneData/defaults.ts +102 -102
  66. package/src/noneData/index.ts +3 -3
  67. package/src/noneData/plugins/Container.ts +27 -27
  68. package/src/noneData/plugins/Tooltip.ts +373 -373
  69. package/src/relationship/defaults.ts +218 -196
  70. package/src/relationship/index.ts +5 -5
  71. package/src/relationship/plugins/ForceDirected.ts +1168 -1168
  72. package/src/relationship/plugins/ForceDirectedBubbles.ts +1403 -1395
  73. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  74. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  75. package/src/relationship/relationshipObservables.ts +49 -49
  76. package/src/series/defaults.ts +230 -207
  77. package/src/series/index.ts +9 -9
  78. package/src/series/plugins/Bubbles.ts +620 -606
  79. package/src/series/plugins/Pie.ts +623 -623
  80. package/src/series/plugins/PieEventTexts.ts +284 -284
  81. package/src/series/plugins/PieLabels.ts +640 -640
  82. package/src/series/plugins/Rose.ts +516 -516
  83. package/src/series/plugins/RoseLabels.ts +600 -600
  84. package/src/series/plugins/SeriesLegend.ts +107 -107
  85. package/src/series/plugins/SeriesTooltip.ts +66 -66
  86. package/src/series/seriesObservables.ts +145 -145
  87. package/src/series/seriesUtils.ts +51 -51
  88. package/src/tree/defaults.ts +100 -78
  89. package/src/tree/index.ts +4 -4
  90. package/src/tree/plugins/TreeLegend.ts +100 -100
  91. package/src/tree/plugins/TreeMap.ts +341 -333
  92. package/src/tree/plugins/TreeTooltip.ts +66 -66
  93. package/src/utils/commonUtils.ts +21 -21
  94. package/src/utils/d3Graphics.ts +174 -174
  95. package/src/utils/d3Utils.ts +92 -74
  96. package/src/utils/observables.ts +14 -14
  97. package/src/utils/orbchartsUtils.ts +129 -115
  98. package/tsconfig.base.json +13 -13
  99. package/tsconfig.json +2 -2
  100. package/vite.config.js +22 -22
@@ -1,66 +1,66 @@
1
- import {
2
- Subject,
3
- } from 'rxjs'
4
- import type { DefinePluginConfig } from '../../../lib/core-types'
5
- import {
6
- defineTreePlugin } from '../../../lib/core'
7
- import { DEFAULT_TREE_TOOLTIP_PARAMS } from '../defaults'
8
- import { LAYER_INDEX_OF_TOOLTIP } from '../../const'
9
- import { createBaseTooltip } from '../../base/BaseTooltip'
10
-
11
- const pluginName = 'TreeTooltip'
12
-
13
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_TREE_TOOLTIP_PARAMS> = {
14
- name: pluginName,
15
- defaultParams: DEFAULT_TREE_TOOLTIP_PARAMS,
16
- layerIndex: LAYER_INDEX_OF_TOOLTIP,
17
- validator: (params, { validateColumns }) => {
18
- const result = validateColumns(params, {
19
- backgroundColorType: {
20
- toBeOption: 'ColorType',
21
- },
22
- backgroundOpacity: {
23
- toBeTypes: ['number']
24
- },
25
- strokeColorType: {
26
- toBeOption: 'ColorType',
27
- },
28
- offset: {
29
- toBe: '[number, number]',
30
- test: (value: any) => {
31
- return Array.isArray(value)
32
- && value.length === 2
33
- && typeof value[0] === 'number'
34
- && typeof value[1] === 'number'
35
- }
36
- },
37
- padding: {
38
- toBeTypes: ['number']
39
- },
40
- textColorType: {
41
- toBeOption: 'ColorType',
42
- },
43
- renderFn: {
44
- toBeTypes: ['Function']
45
- },
46
- })
47
- return result
48
- }
49
- }
50
-
51
- export const TreeTooltip = defineTreePlugin(pluginConfig)(({ selection, rootSelection, name, subject, observer }) => {
52
- const destroy$ = new Subject()
53
-
54
- const unsubscribeTooltip = createBaseTooltip(pluginName, {
55
- rootSelection,
56
- fullParams$: observer.fullParams$,
57
- fullChartParams$: observer.fullChartParams$,
58
- layout$: observer.layout$,
59
- event$: subject.event$,
60
- })
61
-
62
- return () => {
63
- destroy$.next(undefined)
64
- unsubscribeTooltip()
65
- }
66
- })
1
+ import {
2
+ Subject,
3
+ } from 'rxjs'
4
+ import type { DefinePluginConfig } from '../../../lib/core-types'
5
+ import {
6
+ defineTreePlugin } from '../../../lib/core'
7
+ import { DEFAULT_TREE_TOOLTIP_PARAMS } from '../defaults'
8
+ import { LAYER_INDEX_OF_TOOLTIP } from '../../const'
9
+ import { createBaseTooltip } from '../../base/BaseTooltip'
10
+
11
+ const pluginName = 'TreeTooltip'
12
+
13
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_TREE_TOOLTIP_PARAMS> = {
14
+ name: pluginName,
15
+ defaultParams: DEFAULT_TREE_TOOLTIP_PARAMS,
16
+ layerIndex: LAYER_INDEX_OF_TOOLTIP,
17
+ validator: (params, { validateColumns }) => {
18
+ const result = validateColumns(params, {
19
+ backgroundColorType: {
20
+ toBeOption: 'ColorType',
21
+ },
22
+ backgroundOpacity: {
23
+ toBeTypes: ['number']
24
+ },
25
+ strokeColorType: {
26
+ toBeOption: 'ColorType',
27
+ },
28
+ offset: {
29
+ toBe: '[number, number]',
30
+ test: (value: any) => {
31
+ return Array.isArray(value)
32
+ && value.length === 2
33
+ && typeof value[0] === 'number'
34
+ && typeof value[1] === 'number'
35
+ }
36
+ },
37
+ padding: {
38
+ toBeTypes: ['number']
39
+ },
40
+ textColorType: {
41
+ toBeOption: 'ColorType',
42
+ },
43
+ renderFn: {
44
+ toBeTypes: ['Function']
45
+ },
46
+ })
47
+ return result
48
+ }
49
+ }
50
+
51
+ export const TreeTooltip = defineTreePlugin(pluginConfig)(({ selection, rootSelection, name, subject, observer }) => {
52
+ const destroy$ = new Subject()
53
+
54
+ const unsubscribeTooltip = createBaseTooltip(pluginName, {
55
+ rootSelection,
56
+ fullParams$: observer.fullParams$,
57
+ fullChartParams$: observer.fullChartParams$,
58
+ layout$: observer.layout$,
59
+ event$: subject.event$,
60
+ })
61
+
62
+ return () => {
63
+ destroy$.next(undefined)
64
+ unsubscribeTooltip()
65
+ }
66
+ })
@@ -1,22 +1,22 @@
1
- // 取得文字寬度
2
- export function measureTextWidth (text: string, size: number = 10) {
3
- const context = document.createElement("canvas").getContext("2d")
4
- let width = context?.measureText(text)?.width ?? 0
5
- return width * size / 10 // 以10為基準
6
- }
7
-
8
- // 取得最小及最大值 - 數字陣列
9
- export function getMinMax (data: number[]): [number, number] {
10
- const defaultMinMax: [number, number] = [0, 0] // default
11
- if (!data.length) {
12
- return defaultMinMax
13
- }
14
- const minMax: [number, number] = data.reduce((prev, current) => {
15
- // [min, max]
16
- return [
17
- current < prev[0] ? current : prev[0],
18
- current > prev[1] ? current : prev[1]
19
- ]
20
- }, [data[0], data[0]])
21
- return minMax
1
+ // 取得文字寬度
2
+ export function measureTextWidth (text: string, size: number = 10) {
3
+ const context = document.createElement("canvas").getContext("2d")
4
+ let width = context?.measureText(text)?.width ?? 0
5
+ return width * size / 10 // 以10為基準
6
+ }
7
+
8
+ // 取得最小及最大值 - 數字陣列
9
+ export function getMinMax (data: number[]): [number, number] {
10
+ const defaultMinMax: [number, number] = [0, 0] // default
11
+ if (!data.length) {
12
+ return defaultMinMax
13
+ }
14
+ const minMax: [number, number] = data.reduce((prev, current) => {
15
+ // [min, max]
16
+ return [
17
+ current < prev[0] ? current : prev[0],
18
+ current > prev[1] ? current : prev[1]
19
+ ]
20
+ }, [data[0], data[0]])
21
+ return minMax
22
22
  }
@@ -1,175 +1,175 @@
1
-
2
- type RenderCircleTextParams = {
3
- text: string,
4
- radius: number,
5
- lineHeight: number,
6
- isBreakAll: boolean,
7
- limit?:number
8
- }
9
-
10
- type Line = { width: number; text: string }
11
-
12
- export function renderCircleText (selection: d3.Selection<any, any, any, any>, {
13
- text,
14
- radius,
15
- lineHeight,
16
- isBreakAll = false,
17
- limit = 0
18
- }: RenderCircleTextParams): d3.Selection<SVGTSpanElement, Line, SVGTextElement, any> | undefined {
19
- if (selection == null || text == null) {
20
- console.error("selection or text is not defined")
21
- return
22
- }
23
- if (radius == null) {
24
- const getBox = selection.node().getBBox()
25
- radius = getBox.width / 2
26
- }
27
-
28
- function getWords (text: string) {
29
- let words
30
- if (isBreakAll) {
31
- words = text.split('')
32
- } else {
33
- words = text.split(/\s+/g) // To hyphenate: /\s+|(?<=-)/
34
- }
35
- if (!words[words.length - 1]) words.pop()
36
- if (!words[0]) words.shift()
37
- return words
38
- }
39
-
40
- // 省略文章字數
41
- function ellipisText (text:string, limit:number) {
42
- if (text && limit) {
43
- if (text.length > limit) {
44
- text = text.substring(0, limit) + "..."; // 超過字數以"..."取代
45
- }
46
- }
47
- return text;
48
- }
49
-
50
- function measureWidth (text: string) {
51
- const context = document.createElement("canvas").getContext("2d")
52
- // return text => context.measureText(text).width
53
- return context?.measureText(text)?.width ?? 0
54
- }
55
-
56
- function getTargetWidth (text: string) {
57
- const m = measureWidth(text.trim())
58
- const result = Math.sqrt(m * lineHeight)
59
- return result
60
- // return(
61
- // Math.sqrt(measureWidth(text.trim()) * lineHeight)
62
- // )
63
- }
64
-
65
- function getLines (words: string[], targetWidth: number) {
66
- let line: Line = { width: 0, text: '' }
67
- let lineWidth0 = Infinity
68
- const lines: Array<Line> = []
69
- let space = " "
70
- if (isBreakAll) {
71
- space = ""
72
- }
73
- for (let i = 0, n = words.length; i < n; ++i) {
74
- const lineText1 = (line.text ? line.text + space : '') + words[i]
75
- const lineWidth1 = measureWidth(lineText1)
76
- if ((lineWidth0 + lineWidth1) / 2 < targetWidth) {
77
- line.width = lineWidth0 = lineWidth1
78
- line.text = lineText1
79
- } else {
80
- lineWidth0 = measureWidth(words[i])
81
- line = {width: lineWidth0, text: words[i]}
82
- lines.push(line)
83
- }
84
- }
85
- return lines
86
- }
87
-
88
- function getTextRadius (lines: Array<Line>) {
89
- let radius = 0
90
- for (let i = 0, n = lines.length; i < n; ++i) {
91
- const dy: number = (Math.abs(i - n / 2 + 0.5) + 0.5) * lineHeight
92
- const dx: number = lines[i].width / 2
93
- radius = Math.max(radius, Math.sqrt(dx ** 2 + dy ** 2))
94
- }
95
- return radius
96
- }
97
-
98
- function draw (selection: d3.Selection<any, any, any, any>, text: string) {
99
- if(limit > 0) text = ellipisText(text,limit)
100
- const words = getWords(text)
101
- const targetWidth = getTargetWidth(text)
102
- const lines = getLines(words, targetWidth)
103
- const textRadius = getTextRadius(lines)
104
-
105
- let t = selection.select<SVGTextElement>("text")
106
- if (!t.size()) {
107
- t = selection.append("text")
108
- }
109
- t.attr("transform", `translate(${0},${0}) scale(${radius / textRadius})`)
110
- const tspanUpdate = t.selectAll<SVGTSpanElement, Line>("tspan")
111
- .data(lines)
112
- const tspanEnter = tspanUpdate.enter()
113
- .append<SVGTSpanElement>("tspan")
114
- .attr("x", 0)
115
- .merge(tspanUpdate as d3.Selection<SVGTSpanElement, Line, SVGTextElement, undefined>)
116
- .attr("y", (d: Line, i: number) => (i - lines.length / 2 + 0.8) * lineHeight)
117
- .text((d: Line) => d.text)
118
- tspanUpdate.exit().remove()
119
-
120
- // return selection.node()
121
- return tspanUpdate.merge(tspanEnter)
122
- }
123
-
124
- return draw(selection, text)
125
- }
126
-
127
- // 圖軸上的多行tspan
128
- export function renderTspansOnAxis (textSelection: d3.Selection<d3.BaseType, unknown, null, undefined>, {
129
- textArr,
130
- textSizePx,
131
- groupAxisPosition
132
- }: {
133
- textArr: string[]
134
- textSizePx: number
135
- groupAxisPosition: 'top' | 'right' | 'bottom' | 'left'
136
- }) {
137
- // -- 將原本單行文字改為多行文字 --
138
- textSelection.text(null) // 先清空原本的 text
139
-
140
- const textX = Number(textSelection.attr('x'))
141
- let textY = Number(textSelection.attr('y'))
142
- if (groupAxisPosition === 'top') {
143
- // 當文字在上方時,要往上偏移第一行的高度
144
- textY -= (textArr.length - 1) * textSizePx
145
- }
146
-
147
- textSelection
148
- .selectAll('tspan')
149
- .data(textArr)
150
- .join('tspan')
151
- .attr('x', textX)
152
- .attr('y', (_d, _i) => textY + _i * textSizePx)
153
- .text(d => d)
154
- }
155
-
156
- // 四象限上的多行tspan
157
- export function renderTspansOnQuadrant (textSelection: d3.Selection<d3.BaseType, unknown, null, undefined>, {
158
- textArr,
159
- textSizePx,
160
- quadrant
161
- }: {
162
- textArr: string[]
163
- textSizePx: number
164
- quadrant: number
165
- }) {
166
- textSelection
167
- .selectAll('tspan')
168
- .data(textArr)
169
- .join('tspan')
170
- .attr('x', 0)
171
- .attr('y', (_d, _i) => quadrant == 1 || quadrant == 2
172
- ? - (textArr.length - 1 - _i) * textSizePx
173
- : _i * textSizePx)
174
- .text(d => d)
1
+
2
+ type RenderCircleTextParams = {
3
+ text: string,
4
+ radius: number,
5
+ lineHeight: number,
6
+ isBreakAll: boolean,
7
+ limit?:number
8
+ }
9
+
10
+ type Line = { width: number; text: string }
11
+
12
+ export function renderCircleText (selection: d3.Selection<any, any, any, any>, {
13
+ text,
14
+ radius,
15
+ lineHeight,
16
+ isBreakAll = false,
17
+ limit = 0
18
+ }: RenderCircleTextParams): d3.Selection<SVGTSpanElement, Line, SVGTextElement, any> | undefined {
19
+ if (selection == null || text == null) {
20
+ console.error("selection or text is not defined")
21
+ return
22
+ }
23
+ if (radius == null) {
24
+ const getBox = selection.node().getBBox()
25
+ radius = getBox.width / 2
26
+ }
27
+
28
+ function getWords (text: string) {
29
+ let words
30
+ if (isBreakAll) {
31
+ words = text.split('')
32
+ } else {
33
+ words = text.split(/\s+/g) // To hyphenate: /\s+|(?<=-)/
34
+ }
35
+ if (!words[words.length - 1]) words.pop()
36
+ if (!words[0]) words.shift()
37
+ return words
38
+ }
39
+
40
+ // 省略文章字數
41
+ function ellipisText (text:string, limit:number) {
42
+ if (text && limit) {
43
+ if (text.length > limit) {
44
+ text = text.substring(0, limit) + "..."; // 超過字數以"..."取代
45
+ }
46
+ }
47
+ return text;
48
+ }
49
+
50
+ function measureWidth (text: string) {
51
+ const context = document.createElement("canvas").getContext("2d")
52
+ // return text => context.measureText(text).width
53
+ return context?.measureText(text)?.width ?? 0
54
+ }
55
+
56
+ function getTargetWidth (text: string) {
57
+ const m = measureWidth(text.trim())
58
+ const result = Math.sqrt(m * lineHeight)
59
+ return result
60
+ // return(
61
+ // Math.sqrt(measureWidth(text.trim()) * lineHeight)
62
+ // )
63
+ }
64
+
65
+ function getLines (words: string[], targetWidth: number) {
66
+ let line: Line = { width: 0, text: '' }
67
+ let lineWidth0 = Infinity
68
+ const lines: Array<Line> = []
69
+ let space = " "
70
+ if (isBreakAll) {
71
+ space = ""
72
+ }
73
+ for (let i = 0, n = words.length; i < n; ++i) {
74
+ const lineText1 = (line.text ? line.text + space : '') + words[i]
75
+ const lineWidth1 = measureWidth(lineText1)
76
+ if ((lineWidth0 + lineWidth1) / 2 < targetWidth) {
77
+ line.width = lineWidth0 = lineWidth1
78
+ line.text = lineText1
79
+ } else {
80
+ lineWidth0 = measureWidth(words[i])
81
+ line = {width: lineWidth0, text: words[i]}
82
+ lines.push(line)
83
+ }
84
+ }
85
+ return lines
86
+ }
87
+
88
+ function getTextRadius (lines: Array<Line>) {
89
+ let radius = 0
90
+ for (let i = 0, n = lines.length; i < n; ++i) {
91
+ const dy: number = (Math.abs(i - n / 2 + 0.5) + 0.5) * lineHeight
92
+ const dx: number = lines[i].width / 2
93
+ radius = Math.max(radius, Math.sqrt(dx ** 2 + dy ** 2))
94
+ }
95
+ return radius
96
+ }
97
+
98
+ function draw (selection: d3.Selection<any, any, any, any>, text: string) {
99
+ if(limit > 0) text = ellipisText(text,limit)
100
+ const words = getWords(text)
101
+ const targetWidth = getTargetWidth(text)
102
+ const lines = getLines(words, targetWidth)
103
+ const textRadius = getTextRadius(lines)
104
+
105
+ let t = selection.select<SVGTextElement>("text")
106
+ if (!t.size()) {
107
+ t = selection.append("text")
108
+ }
109
+ t.attr("transform", `translate(${0},${0}) scale(${radius / textRadius})`)
110
+ const tspanUpdate = t.selectAll<SVGTSpanElement, Line>("tspan")
111
+ .data(lines)
112
+ const tspanEnter = tspanUpdate.enter()
113
+ .append<SVGTSpanElement>("tspan")
114
+ .attr("x", 0)
115
+ .merge(tspanUpdate as d3.Selection<SVGTSpanElement, Line, SVGTextElement, undefined>)
116
+ .attr("y", (d: Line, i: number) => (i - lines.length / 2 + 0.8) * lineHeight)
117
+ .text((d: Line) => d.text)
118
+ tspanUpdate.exit().remove()
119
+
120
+ // return selection.node()
121
+ return tspanUpdate.merge(tspanEnter)
122
+ }
123
+
124
+ return draw(selection, text)
125
+ }
126
+
127
+ // 圖軸上的多行tspan
128
+ export function renderTspansOnAxis (textSelection: d3.Selection<d3.BaseType, unknown, null, undefined>, {
129
+ textArr,
130
+ textSizePx,
131
+ groupAxisPosition
132
+ }: {
133
+ textArr: string[]
134
+ textSizePx: number
135
+ groupAxisPosition: 'top' | 'right' | 'bottom' | 'left'
136
+ }) {
137
+ // -- 將原本單行文字改為多行文字 --
138
+ textSelection.text(null) // 先清空原本的 text
139
+
140
+ const textX = Number(textSelection.attr('x'))
141
+ let textY = Number(textSelection.attr('y'))
142
+ if (groupAxisPosition === 'top') {
143
+ // 當文字在上方時,要往上偏移第一行的高度
144
+ textY -= (textArr.length - 1) * textSizePx
145
+ }
146
+
147
+ textSelection
148
+ .selectAll('tspan')
149
+ .data(textArr)
150
+ .join('tspan')
151
+ .attr('x', textX)
152
+ .attr('y', (_d, _i) => textY + _i * textSizePx)
153
+ .text(d => d)
154
+ }
155
+
156
+ // 四象限上的多行tspan
157
+ export function renderTspansOnQuadrant (textSelection: d3.Selection<d3.BaseType, unknown, null, undefined>, {
158
+ textArr,
159
+ textSizePx,
160
+ quadrant
161
+ }: {
162
+ textArr: string[]
163
+ textSizePx: number
164
+ quadrant: number
165
+ }) {
166
+ textSelection
167
+ .selectAll('tspan')
168
+ .data(textArr)
169
+ .join('tspan')
170
+ .attr('x', 0)
171
+ .attr('y', (_d, _i) => quadrant == 1 || quadrant == 2
172
+ ? - (textArr.length - 1 - _i) * textSizePx
173
+ : _i * textSizePx)
174
+ .text(d => d)
175
175
  }