@orbcharts/core 3.0.0-alpha.59 → 3.0.0-alpha.61
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +1245 -1223
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/types/Chart.d.ts +4 -0
- package/dist/src/types/DataFormatter.d.ts +2 -2
- package/dist/src/utils/d3Utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/base/createBaseChart.ts +21 -2
- package/src/defaults.ts +4 -2
- package/src/grid/gridObservables.ts +5 -4
- package/src/multiValue/computeMultiValueData.ts +40 -4
- package/src/types/Chart.ts +4 -0
- package/src/types/DataFormatter.ts +2 -2
- package/src/utils/d3Utils.ts +22 -6
@@ -23,13 +23,13 @@ export interface DataFormatterBase<T extends ChartType> {
|
|
23
23
|
export type DataFormatterBasePartial<T extends ChartType> = Partial<DataFormatterBase<T>>;
|
24
24
|
export interface DataFormatterValueAxis {
|
25
25
|
position: AxisPosition;
|
26
|
-
scaleDomain: [number | 'auto', number | 'auto'];
|
26
|
+
scaleDomain: [number | 'min' | 'auto', number | 'max' | 'auto'];
|
27
27
|
scaleRange: [number, number];
|
28
28
|
label: string;
|
29
29
|
}
|
30
30
|
export interface DataFormatterGroupAxis {
|
31
31
|
position: AxisPosition;
|
32
|
-
scaleDomain: [number
|
32
|
+
scaleDomain: [number, number | 'max'];
|
33
33
|
scalePadding: number;
|
34
34
|
label: string;
|
35
35
|
}
|
@@ -3,7 +3,7 @@ export declare const createAxisLinearScale: ({ maxValue, minValue, axisWidth, sc
|
|
3
3
|
maxValue: number;
|
4
4
|
minValue: number;
|
5
5
|
axisWidth: number;
|
6
|
-
scaleDomain: [number | "auto", number | "auto"];
|
6
|
+
scaleDomain: [number | "min" | "auto", number | "max" | "auto"];
|
7
7
|
scaleRange: [number, number];
|
8
8
|
}) => d3.ScaleLinear<number, number, never>;
|
9
9
|
export declare const createAxisPointScale: ({ axisLabels, axisWidth, padding }: {
|
package/package.json
CHANGED
@@ -212,8 +212,27 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
|
|
212
212
|
})
|
213
213
|
|
214
214
|
// 監聽外層的element尺寸
|
215
|
-
const rootSize
|
216
|
-
.
|
215
|
+
const rootSize$: Observable<{ width: number; height: number }> = of({
|
216
|
+
width: options?.width ?? CHART_OPTIONS_DEFAULT.width,
|
217
|
+
height: options?.height ?? CHART_OPTIONS_DEFAULT.height
|
218
|
+
}).pipe(
|
219
|
+
switchMap(size => {
|
220
|
+
// console.log('options', options)
|
221
|
+
// console.log('size', size)
|
222
|
+
return iif(
|
223
|
+
() => size.width === 'auto' || size.height === 'auto',
|
224
|
+
// 有 'auto' 的話就監聽element的尺寸
|
225
|
+
resizeObservable(element).pipe(
|
226
|
+
map((d) => {
|
227
|
+
return {
|
228
|
+
width: size.width === 'auto' ? d.width : size.width,
|
229
|
+
height: size.height === 'auto' ? d.height : size.height
|
230
|
+
}
|
231
|
+
})
|
232
|
+
),
|
233
|
+
of(size as { width: number; height: number })
|
234
|
+
)
|
235
|
+
}),
|
217
236
|
takeUntil(destroy$),
|
218
237
|
share()
|
219
238
|
)
|
package/src/defaults.ts
CHANGED
@@ -19,6 +19,8 @@ import type { Padding } from './types/Padding'
|
|
19
19
|
|
20
20
|
export const CHART_OPTIONS_DEFAULT: ChartOptionsPartial<any> = {
|
21
21
|
// preset: {} // 預設為空
|
22
|
+
width: 'auto',
|
23
|
+
height: 'auto'
|
22
24
|
}
|
23
25
|
|
24
26
|
// export const GLOBAL_DEFAULT: ChartGlobalDefault = {
|
@@ -99,14 +101,14 @@ export const DATA_RELATIONA_DEFAULTL: DataRelationship = {
|
|
99
101
|
|
100
102
|
export const DATA_FORMATTER_VALUE_AXIS_DEFAULT: DataFormatterValueAxis = {
|
101
103
|
position: 'left',
|
102
|
-
scaleDomain: [
|
104
|
+
scaleDomain: ['auto', 'auto'],
|
103
105
|
scaleRange: [0, 0.9],
|
104
106
|
label: '',
|
105
107
|
}
|
106
108
|
|
107
109
|
export const DATA_FORMATTER_GROUP_AXIS_DEFAULT: DataFormatterGroupAxis = {
|
108
110
|
position: 'bottom',
|
109
|
-
scaleDomain: [0, '
|
111
|
+
scaleDomain: [0, 'max'],
|
110
112
|
scalePadding: 0.5,
|
111
113
|
label: ''
|
112
114
|
}
|
@@ -278,10 +278,11 @@ export const gridGraphicTransformObservable = ({ computedData$, fullDataFormatte
|
|
278
278
|
: height
|
279
279
|
const groupMin = 0
|
280
280
|
const groupMax = data[0] ? data[0].length - 1 : 0
|
281
|
-
const groupScaleDomainMin = groupAxis.scaleDomain[0] === '
|
282
|
-
|
283
|
-
|
284
|
-
const
|
281
|
+
// const groupScaleDomainMin = groupAxis.scaleDomain[0] === 'min'
|
282
|
+
// ? groupMin - groupAxis.scalePadding
|
283
|
+
// : groupAxis.scaleDomain[0] as number - groupAxis.scalePadding
|
284
|
+
const groupScaleDomainMin = groupAxis.scaleDomain[0] - groupAxis.scalePadding
|
285
|
+
const groupScaleDomainMax = groupAxis.scaleDomain[1] === 'max'
|
285
286
|
? groupMax + groupAxis.scalePadding
|
286
287
|
: groupAxis.scaleDomain[1] as number + groupAxis.scalePadding
|
287
288
|
|
@@ -83,12 +83,48 @@ export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) =>
|
|
83
83
|
})
|
84
84
|
|
85
85
|
const _xScaleDoamin: [number, number] = [
|
86
|
-
dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
|
87
|
-
|
86
|
+
// dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
|
87
|
+
(() => {
|
88
|
+
if (dataFormatter.xAxis.scaleDomain[0] === 'auto') {
|
89
|
+
return xMinValue < 0 ? xMinValue : 0
|
90
|
+
} else if (dataFormatter.xAxis.scaleDomain[0] === 'min') {
|
91
|
+
return xMinValue
|
92
|
+
} else {
|
93
|
+
return dataFormatter.xAxis.scaleDomain[0]
|
94
|
+
}
|
95
|
+
})(),
|
96
|
+
// dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
|
97
|
+
(() => {
|
98
|
+
if (dataFormatter.xAxis.scaleDomain[1] === 'auto') {
|
99
|
+
return xMaxValue >= 0 ? xMaxValue : 0
|
100
|
+
} else if (dataFormatter.xAxis.scaleDomain[1] === 'max') {
|
101
|
+
return xMaxValue
|
102
|
+
} else {
|
103
|
+
return dataFormatter.xAxis.scaleDomain[1]
|
104
|
+
}
|
105
|
+
})()
|
88
106
|
]
|
89
107
|
const _yScaleDoamin: [number, number] = [
|
90
|
-
dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
|
91
|
-
|
108
|
+
// dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
|
109
|
+
(() => {
|
110
|
+
if (dataFormatter.yAxis.scaleDomain[0] === 'auto') {
|
111
|
+
return xMinValue < 0 ? xMinValue : 0
|
112
|
+
} else if (dataFormatter.yAxis.scaleDomain[0] === 'min') {
|
113
|
+
return xMinValue
|
114
|
+
} else {
|
115
|
+
return dataFormatter.yAxis.scaleDomain[0]
|
116
|
+
}
|
117
|
+
})(),
|
118
|
+
// dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
|
119
|
+
(() => {
|
120
|
+
if (dataFormatter.yAxis.scaleDomain[1] === 'auto') {
|
121
|
+
return xMaxValue >= 0 ? xMaxValue : 0
|
122
|
+
} else if (dataFormatter.yAxis.scaleDomain[1] === 'max') {
|
123
|
+
return xMaxValue
|
124
|
+
} else {
|
125
|
+
return dataFormatter.yAxis.scaleDomain[1]
|
126
|
+
}
|
127
|
+
})()
|
92
128
|
]
|
93
129
|
|
94
130
|
// // 篩選顯示狀態
|
package/src/types/Chart.ts
CHANGED
@@ -27,10 +27,14 @@ export interface ChartEntity<T extends ChartType> extends ContextSubject<T> {
|
|
27
27
|
|
28
28
|
export interface ChartOptions<T extends ChartType> {
|
29
29
|
preset: Preset<T, unknown>
|
30
|
+
width: number | 'auto'
|
31
|
+
height: number | 'auto'
|
30
32
|
}
|
31
33
|
|
32
34
|
export interface ChartOptionsPartial<T extends ChartType> {
|
33
35
|
preset?: Preset<T, unknown>
|
36
|
+
width?: number | 'auto'
|
37
|
+
height?: number | 'auto'
|
34
38
|
}
|
35
39
|
|
36
40
|
export interface Preset<T extends ChartType, AllPluginParams> {
|
@@ -47,14 +47,14 @@ export type DataFormatterBasePartial<T extends ChartType> = Partial<DataFormatte
|
|
47
47
|
|
48
48
|
export interface DataFormatterValueAxis {
|
49
49
|
position: AxisPosition
|
50
|
-
scaleDomain: [number | 'auto', number | 'auto']
|
50
|
+
scaleDomain: [number | 'min' | 'auto', number | 'max' | 'auto']
|
51
51
|
scaleRange: [number, number]
|
52
52
|
label: string
|
53
53
|
}
|
54
54
|
|
55
55
|
export interface DataFormatterGroupAxis {
|
56
56
|
position: AxisPosition
|
57
|
-
scaleDomain: [number
|
57
|
+
scaleDomain: [number, number | 'max']
|
58
58
|
scalePadding: number
|
59
59
|
label: string
|
60
60
|
}
|
package/src/utils/d3Utils.ts
CHANGED
@@ -12,19 +12,35 @@ export const createAxisLinearScale = ({
|
|
12
12
|
maxValue: number
|
13
13
|
minValue: number
|
14
14
|
axisWidth: number
|
15
|
-
scaleDomain: [number | 'auto', number | 'auto']
|
15
|
+
scaleDomain: [number | 'min' | 'auto', number | 'max' | 'auto']
|
16
16
|
scaleRange: [number, number] // 0-1
|
17
17
|
}) => {
|
18
18
|
// -- 無值補上預設值 --
|
19
|
-
const domainMin: number | 'auto' = scaleDomain[0] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[0]
|
20
|
-
const domainMax: number | 'auto' = scaleDomain[1] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[1]
|
19
|
+
const domainMin: number | 'min' | 'auto' = scaleDomain[0] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[0]
|
20
|
+
const domainMax: number | 'max' | 'auto' = scaleDomain[1] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[1]
|
21
21
|
const rangeMin: number = scaleRange[0] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleRange[0]
|
22
22
|
const rangeMax: number = scaleRange[1] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleRange[1]
|
23
23
|
|
24
|
-
// -- 'auto'
|
25
|
-
|
26
|
-
|
24
|
+
// -- 'auto' | 'max' | 'min' 替換成實際值 --
|
25
|
+
let domainMinValue: number = (() => {
|
26
|
+
if (domainMin === 'auto') {
|
27
|
+
return minValue < 0 ? minValue : 0
|
28
|
+
} else if (domainMin === 'min') {
|
29
|
+
return minValue
|
30
|
+
} else {
|
31
|
+
return domainMin
|
32
|
+
}
|
33
|
+
})()
|
27
34
|
|
35
|
+
let domainMaxValue: number = (() => {
|
36
|
+
if (domainMax === 'auto') {
|
37
|
+
return maxValue >= 0 ? maxValue : 0
|
38
|
+
} else if (domainMax === 'max') {
|
39
|
+
return maxValue
|
40
|
+
} else {
|
41
|
+
return domainMax
|
42
|
+
}
|
43
|
+
})()
|
28
44
|
// let rangeMinValue = axisWidth * rangeMin
|
29
45
|
// let rangeMaxValue = axisWidth * rangeMax
|
30
46
|
|