@orbcharts/plugins-basic 3.0.0-beta.12 → 3.0.0-beta.14
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.
- package/dist/orbcharts-plugins-basic/src/utils/d3Utils.d.ts +1 -0
- package/dist/orbcharts-plugins-basic.es.js +5578 -5463
- package/dist/orbcharts-plugins-basic.umd.js +161 -80
- package/package.json +4 -4
- package/src/base/BaseBars.ts +4 -4
- package/src/base/BaseBarsTriangle.ts +4 -4
- package/src/base/BaseDots.ts +4 -4
- package/src/base/BaseLineAreas.ts +4 -4
- package/src/base/BaseLines.ts +4 -4
- package/src/base/BaseStackedBar.ts +4 -4
- package/src/grid/defaults.ts +21 -17
- package/src/grid/plugins/GroupAux.ts +18 -18
- package/src/multiGrid/defaults.ts +20 -16
- package/src/relationship/defaults.ts +47 -25
- package/src/relationship/plugins/ForceDirectedBubbles.ts +8 -0
- package/src/series/defaults.ts +26 -3
- package/src/series/plugins/Bubbles.ts +15 -1
- package/src/tree/defaults.ts +26 -4
- package/src/tree/plugins/TreeMap.ts +11 -3
- package/src/utils/d3Utils.ts +18 -0
- package/src/utils/orbchartsUtils.ts +30 -16
package/src/series/defaults.ts
CHANGED
@@ -18,6 +18,7 @@ export const DEFAULT_BUBBLES_PARAMS: BubblesParams = {
|
|
18
18
|
collisionSpacing: 2 // 泡泡間距
|
19
19
|
},
|
20
20
|
bubbleLabel: {
|
21
|
+
colorType: 'labelContrast',
|
21
22
|
fillRate: 0.6,
|
22
23
|
lineHeight: 1,
|
23
24
|
maxLineLength: 6,
|
@@ -121,7 +122,7 @@ export const DEFAULT_ROSE_PARAMS: RoseParams = {
|
|
121
122
|
outerRadius: 0.85,
|
122
123
|
padAngle: 0,
|
123
124
|
strokeColorType: 'background',
|
124
|
-
strokeWidth: 0,
|
125
|
+
strokeWidth: 0.5,
|
125
126
|
cornerRadius: 0,
|
126
127
|
arcScaleType: 'area',
|
127
128
|
angleIncreaseWhileHighlight: 0.05
|
@@ -173,8 +174,19 @@ export const DEFAULT_SERIES_TOOLTIP_PARAMS: SeriesTooltipParams = {
|
|
173
174
|
const datumLabelSvg = hasDatumLabel
|
174
175
|
? `<tspan>${eventData.datum.label}</tspan> `
|
175
176
|
: ''
|
177
|
+
const seriesLabelTextWidth = hasSeriesLabel
|
178
|
+
? utils.measureTextWidth(`${eventData.seriesLabel}${eventData.datum.value}`, styles.textSizePx) + styles.textSizePx * 1.5
|
179
|
+
: 0
|
180
|
+
const datumLabelTextWidth = hasDatumLabel
|
181
|
+
? utils.measureTextWidth(`${eventData.datum.label}${eventData.datum.value}`, styles.textSizePx)
|
182
|
+
: 0
|
183
|
+
const maxTextWidth = Math.max(seriesLabelTextWidth, datumLabelTextWidth)
|
184
|
+
const lineEndX = hasDatumLabel
|
185
|
+
? maxTextWidth + styles.textSizePx * 1.5
|
186
|
+
: 0
|
187
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
176
188
|
const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
177
|
-
${datumLabelSvg}<tspan font-weight="bold">${eventData.datum.value}</tspan>
|
189
|
+
${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${eventData.datum.value}</tspan>
|
178
190
|
</text>`
|
179
191
|
|
180
192
|
return `${seriesSvg}
|
@@ -197,8 +209,19 @@ DEFAULT_SERIES_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, u
|
|
197
209
|
const datumLabelSvg = hasDatumLabel
|
198
210
|
? \`<tspan>\${eventData.datum.label}</tspan> \`
|
199
211
|
: ''
|
212
|
+
const seriesLabelTextWidth = hasSeriesLabel
|
213
|
+
? utils.measureTextWidth(\`\${eventData.seriesLabel}\${eventData.datum.value}\`, styles.textSizePx) + styles.textSizePx * 1.5
|
214
|
+
: 0
|
215
|
+
const datumLabelTextWidth = hasDatumLabel
|
216
|
+
? utils.measureTextWidth(\`\${eventData.datum.label}\${eventData.datum.value}\`, styles.textSizePx)
|
217
|
+
: 0
|
218
|
+
const maxTextWidth = Math.max(seriesLabelTextWidth, datumLabelTextWidth)
|
219
|
+
const lineEndX = hasDatumLabel
|
220
|
+
? maxTextWidth + styles.textSizePx * 1.5
|
221
|
+
: 0
|
222
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
200
223
|
const datumSvg = \`<text font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
|
201
|
-
\${datumLabelSvg}<tspan font-weight="bold">\${eventData.datum.value}</tspan>
|
224
|
+
\${datumLabelSvg}<tspan font-weight="bold" text-anchor="\${valueTextAnchor}" x="\${lineEndX}">\${eventData.datum.value}</tspan>
|
202
225
|
</text>\`
|
203
226
|
|
204
227
|
return \`\${seriesSvg}
|
@@ -24,6 +24,7 @@ import type { BubblesParams, ArcScaleType } from '../../../lib/plugins-basic-typ
|
|
24
24
|
import { DEFAULT_BUBBLES_PARAMS } from '../defaults'
|
25
25
|
import { renderCircleText } from '../../utils/d3Graphics'
|
26
26
|
import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
|
27
|
+
import { getDatumColor } from '../../utils/orbchartsUtils'
|
27
28
|
|
28
29
|
interface BubblesDatum extends ComputedDatumSeries {
|
29
30
|
x: number
|
@@ -73,6 +74,9 @@ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_BUBBLES
|
|
73
74
|
}
|
74
75
|
if (params.bubbleLabel) {
|
75
76
|
const bubbleLabelResult = validateColumns(params.bubbleLabel, {
|
77
|
+
colorType: {
|
78
|
+
toBeOption: 'ColorType'
|
79
|
+
},
|
76
80
|
fillRate: {
|
77
81
|
toBeTypes: ['number']
|
78
82
|
},
|
@@ -204,10 +208,11 @@ function createBubblesData ({ visibleComputedLayoutData, LastBubbleDataMap, grap
|
|
204
208
|
})
|
205
209
|
}
|
206
210
|
|
207
|
-
function renderBubbles ({ selection, bubblesData, fullParams, sumSeries }: {
|
211
|
+
function renderBubbles ({ selection, bubblesData, fullParams, fullChartParams, sumSeries }: {
|
208
212
|
selection: d3.Selection<SVGGElement, any, any, any>
|
209
213
|
bubblesData: BubblesDatum[]
|
210
214
|
fullParams: BubblesParams
|
215
|
+
fullChartParams: ChartParams
|
211
216
|
sumSeries: boolean
|
212
217
|
}) {
|
213
218
|
const bubblesSelection = selection.selectAll<SVGGElement, BubblesDatum>("g")
|
@@ -272,6 +277,13 @@ function renderBubbles ({ selection, bubblesData, fullParams, sumSeries }: {
|
|
272
277
|
: fullParams.bubbleLabel.wordBreakAll
|
273
278
|
})
|
274
279
|
|
280
|
+
// -- text color --
|
281
|
+
gSelection.select('text').attr('fill', _ => getDatumColor({
|
282
|
+
datum: d,
|
283
|
+
colorType: fullParams.bubbleLabel.colorType,
|
284
|
+
fullChartParams: fullChartParams
|
285
|
+
}))
|
286
|
+
|
275
287
|
})
|
276
288
|
|
277
289
|
return bubblesSelection
|
@@ -436,6 +448,7 @@ export const Bubbles = defineSeriesPlugin(pluginConfig)(({ selection, name, obse
|
|
436
448
|
const bubblesSelection$ = combineLatest({
|
437
449
|
bubblesData: bubblesData$,
|
438
450
|
fullParams: observer.fullParams$,
|
451
|
+
fullChartParams: observer.fullChartParams$,
|
439
452
|
SeriesContainerPositionMap: observer.SeriesContainerPositionMap$,
|
440
453
|
sumSeries: sumSeries$
|
441
454
|
}).pipe(
|
@@ -450,6 +463,7 @@ export const Bubbles = defineSeriesPlugin(pluginConfig)(({ selection, name, obse
|
|
450
463
|
selection,
|
451
464
|
bubblesData: data.bubblesData,
|
452
465
|
fullParams: data.fullParams,
|
466
|
+
fullChartParams: data.fullChartParams,
|
453
467
|
sumSeries: data.sumSeries
|
454
468
|
})
|
455
469
|
|
package/src/tree/defaults.ts
CHANGED
@@ -3,7 +3,7 @@ import type { TreeMapParams, TreeLegendParams, TreeTooltipParams } from '../../l
|
|
3
3
|
export const DEFAULT_TREE_MAP_PARAMS: TreeMapParams = {
|
4
4
|
paddingInner: 2,
|
5
5
|
paddingOuter: 2,
|
6
|
-
labelColorType: '
|
6
|
+
labelColorType: 'labelContrast',
|
7
7
|
squarifyRatio: 1.618034, // 黃金比例
|
8
8
|
sort: (a, b) => b.value - a.value
|
9
9
|
}
|
@@ -44,8 +44,19 @@ export const DEFAULT_TREE_TOOLTIP_PARAMS: TreeTooltipParams = {
|
|
44
44
|
const datumLabelSvg = hasDatumLabel
|
45
45
|
? `<tspan>${eventData.datum.label}</tspan> `
|
46
46
|
: ''
|
47
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
48
|
+
? utils.measureTextWidth(`${eventData.categoryLabel}${eventData.datum.value}`, styles.textSizePx) + styles.textSizePx * 1.5
|
49
|
+
: 0
|
50
|
+
const datumLabelTextWidth = hasDatumLabel
|
51
|
+
? utils.measureTextWidth(`${eventData.datum.label}${eventData.datum.value}`, styles.textSizePx)
|
52
|
+
: 0
|
53
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
54
|
+
const lineEndX = hasDatumLabel
|
55
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
56
|
+
: 0
|
57
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
47
58
|
const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
48
|
-
${datumLabelSvg}<tspan font-weight="bold">${eventData.datum.value}</tspan>
|
59
|
+
${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${eventData.datum.value}</tspan>
|
49
60
|
</text>`
|
50
61
|
|
51
62
|
return `${categorySvg}
|
@@ -55,7 +66,7 @@ export const DEFAULT_TREE_TOOLTIP_PARAMS: TreeTooltipParams = {
|
|
55
66
|
},
|
56
67
|
}
|
57
68
|
DEFAULT_TREE_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, utils }) => {
|
58
|
-
|
69
|
+
const hasCategoryLabel = eventData.categoryLabel ? true : false
|
59
70
|
const hasDatumLabel = eventData.datum.label ? true : false
|
60
71
|
const bulletWidth = styles.textSizePx * 0.7
|
61
72
|
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
@@ -68,8 +79,19 @@ DEFAULT_TREE_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, uti
|
|
68
79
|
const datumLabelSvg = hasDatumLabel
|
69
80
|
? \`<tspan>\${eventData.datum.label}</tspan> \`
|
70
81
|
: ''
|
82
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
83
|
+
? utils.measureTextWidth(\`\${eventData.categoryLabel}\${eventData.datum.value}\`, styles.textSizePx) + styles.textSizePx * 1.5
|
84
|
+
: 0
|
85
|
+
const datumLabelTextWidth = hasDatumLabel
|
86
|
+
? utils.measureTextWidth(\`\${eventData.datum.label}\${eventData.datum.value}\`, styles.textSizePx)
|
87
|
+
: 0
|
88
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
89
|
+
const lineEndX = hasDatumLabel
|
90
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
91
|
+
: 0
|
92
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
71
93
|
const datumSvg = \`<text font-size="\${styles.textSizePx}" dominant-baseline="hanging" fill="\${styles.textColor}">
|
72
|
-
\${datumLabelSvg}<tspan font-weight="bold">\${eventData.datum.value}</tspan>
|
94
|
+
\${datumLabelSvg}<tspan font-weight="bold" text-anchor="\${valueTextAnchor}" x="\${lineEndX}">\${eventData.datum.value}</tspan>
|
73
95
|
</text>\`
|
74
96
|
|
75
97
|
return \`\${categorySvg}
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
import type { Layout, ComputedDataTree, DataFormatterTree, ChartParams } from '../../../lib/core-types'
|
16
16
|
import type { TreeMapParams } from '../../../lib/plugins-basic-types'
|
17
17
|
import { DEFAULT_TREE_MAP_PARAMS } from '../defaults'
|
18
|
-
import { getClassName,
|
18
|
+
import { getClassName, getDatumColor } from '../../utils/orbchartsUtils'
|
19
19
|
import { LAYER_INDEX_OF_GRAPHIC } from '../../const'
|
20
20
|
|
21
21
|
const pluginName = 'TreeMap'
|
@@ -112,7 +112,11 @@ function renderTree ({ selection, treeData, fullParams, fullChartParams, textSiz
|
|
112
112
|
.text(null)
|
113
113
|
.append("tspan")
|
114
114
|
.attr('cursor', 'pointer')
|
115
|
-
.attr('fill',
|
115
|
+
.attr('fill', getDatumColor({
|
116
|
+
colorType: fullParams.labelColorType,
|
117
|
+
datum: d.data,
|
118
|
+
fullChartParams
|
119
|
+
}))
|
116
120
|
.attr('font-size', fullChartParams.styles.textSize)
|
117
121
|
.attr("x", x)
|
118
122
|
.attr("y", y)
|
@@ -128,7 +132,11 @@ function renderTree ({ selection, treeData, fullParams, fullChartParams, textSiz
|
|
128
132
|
tspan = textElement
|
129
133
|
.append("tspan")
|
130
134
|
.attr('cursor', 'pointer')
|
131
|
-
.attr('fill',
|
135
|
+
.attr('fill', getDatumColor({
|
136
|
+
colorType: fullParams.labelColorType,
|
137
|
+
datum: d.data,
|
138
|
+
fullChartParams
|
139
|
+
}))
|
132
140
|
.attr('font-size', fullChartParams.styles.textSize)
|
133
141
|
.attr("x", x)
|
134
142
|
.attr("y", y)
|
package/src/utils/d3Utils.ts
CHANGED
@@ -71,4 +71,22 @@ export const parseDateTickFormatValue = (value: any, tickFormat: string | ((text
|
|
71
71
|
return d3.timeFormat(tickFormat as string)!(value)
|
72
72
|
}
|
73
73
|
|
74
|
+
export function isLightColor (color: string) {
|
75
|
+
// 1. 用 HSL 的亮度(較符合數學)
|
76
|
+
// const hslColor = d3.hsl(color) // 轉換為 HSL 格式
|
77
|
+
// const lightness = hslColor.l // 取得亮度值 (0 ~ 1)
|
78
|
+
// 2. 用 LAB 的明度(較符合人眼感知)
|
79
|
+
const labColor = d3.lab(color) // 轉換為 LAB 格式
|
80
|
+
const lightness = labColor.l // 取得明度值 (0 ~ 100)
|
74
81
|
|
82
|
+
// console.log(`顏色的亮度為: ${lightness}`);
|
83
|
+
|
84
|
+
// 判斷顏色深淺
|
85
|
+
if (lightness <= 60) {
|
86
|
+
// console.log("這是一個深色系");
|
87
|
+
return false
|
88
|
+
} else {
|
89
|
+
// console.log("這是一個淺色系");
|
90
|
+
return true
|
91
|
+
}
|
92
|
+
}
|
@@ -7,6 +7,7 @@ import type {
|
|
7
7
|
ComputedDatumBaseSeries,
|
8
8
|
ComputedDatumBaseCategory } from '../../lib/core-types'
|
9
9
|
import { getMinMax } from './commonUtils'
|
10
|
+
import { isLightColor } from './d3Utils'
|
10
11
|
|
11
12
|
// 取得最小及最大值 - datum格式陣列資料
|
12
13
|
export function getMinMaxValue (data: (ComputedDatumBase & ComputedDatumBaseValue)[]): [number, number] {
|
@@ -19,14 +20,13 @@ export function getMinMaxValue (data: (ComputedDatumBase & ComputedDatumBaseValu
|
|
19
20
|
// 取得colorType顏色
|
20
21
|
export function getColor (colorType: ColorType, fullChartParams: ChartParams) {
|
21
22
|
const colors = fullChartParams.colors[fullChartParams.colorScheme]
|
22
|
-
// 對應series資料中第1個顏色
|
23
23
|
if (colorType === 'label') {
|
24
|
-
return colors.label[0]
|
24
|
+
return colors.label[0] // default label color
|
25
|
+
} else if (colorType === 'labelContrast') {
|
26
|
+
return isLightColor(colors.label[0]) // default label color
|
27
|
+
? colors.labelContrast[1]
|
28
|
+
: colors.labelContrast[0]
|
25
29
|
}
|
26
|
-
// 對應colorType設定的顏色
|
27
|
-
// return colors[colorType] != null
|
28
|
-
// ? colors[colorType]
|
29
|
-
// : colors.primary
|
30
30
|
return colorType == 'none'
|
31
31
|
? 'none'
|
32
32
|
: colors[colorType] != undefined
|
@@ -42,7 +42,7 @@ export function getCategoryValueColor ({ datum, colorType, fullChartParams }: {
|
|
42
42
|
|
43
43
|
}
|
44
44
|
|
45
|
-
// // 取得Series顏色
|
45
|
+
// // 取得Series顏色
|
46
46
|
// export function getSeriesColor (seriesIndex: number, fullChartParams: ChartParams) {
|
47
47
|
// const colorIndex = seriesIndex < fullChartParams.colors[fullChartParams.colorScheme].series.length
|
48
48
|
// ? seriesIndex
|
@@ -50,23 +50,37 @@ export function getCategoryValueColor ({ datum, colorType, fullChartParams }: {
|
|
50
50
|
// return fullChartParams.colors[fullChartParams.colorScheme].series[colorIndex]
|
51
51
|
// }
|
52
52
|
|
53
|
-
// 取得Datum顏色
|
53
|
+
// 取得Datum顏色
|
54
54
|
export function getDatumColor ({ datum, colorType, fullChartParams }: { datum: ComputedDatumBase, colorType: ColorType, fullChartParams: ChartParams }) {
|
55
|
-
|
55
|
+
const colors = fullChartParams.colors[fullChartParams.colorScheme]
|
56
|
+
|
56
57
|
if (colorType === 'label') {
|
57
|
-
|
58
|
-
|
58
|
+
const datumColor: string | undefined = (datum as unknown as ComputedDatumBaseSeries).color
|
59
|
+
if (datumColor) {
|
60
|
+
return datumColor
|
59
61
|
} else {
|
60
|
-
//
|
61
|
-
return
|
62
|
+
// default label color
|
63
|
+
return colors.label[0]
|
64
|
+
}
|
65
|
+
} else if (colorType === 'labelContrast') {
|
66
|
+
const datumColor: string | undefined = (datum as unknown as ComputedDatumBaseSeries).color
|
67
|
+
if (datumColor) {
|
68
|
+
return isLightColor(datumColor)
|
69
|
+
? colors.labelContrast[1]
|
70
|
+
: colors.labelContrast[0]
|
71
|
+
} else {
|
72
|
+
// default label color
|
73
|
+
return isLightColor(colors.label[0])
|
74
|
+
? colors.labelContrast[1]
|
75
|
+
: colors.labelContrast[0]
|
62
76
|
}
|
63
77
|
}
|
64
78
|
// 對應colorType設定的顏色
|
65
79
|
return colorType == 'none'
|
66
80
|
? 'none'
|
67
|
-
:
|
68
|
-
?
|
69
|
-
:
|
81
|
+
: colors[colorType] != undefined
|
82
|
+
? colors[colorType]
|
83
|
+
: colors.primary
|
70
84
|
}
|
71
85
|
|
72
86
|
export function getClassName (pluginName: string, elementName: string, modifier?: string) {
|