@orbcharts/core 3.0.0-alpha.59 → 3.0.0-alpha.60

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 | 'auto', number | 'auto'];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbcharts/core",
3
- "version": "3.0.0-alpha.59",
3
+ "version": "3.0.0-alpha.60",
4
4
  "description": "OrbCharts is an open source chart library based on d3.js and rx.js",
5
5
  "author": "Blue Planet Inc.",
6
6
  "license": "Apache-2.0",
@@ -212,8 +212,25 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
212
212
  })
213
213
 
214
214
  // 監聽外層的element尺寸
215
- const rootSize$ = resizeObservable(element)
216
- .pipe(
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
+ return iif(
221
+ () => size.width === 'auto' || size.height === 'auto',
222
+ // 有 'auto' 的話就監聽element的尺寸
223
+ resizeObservable(element).pipe(
224
+ map((d) => {
225
+ return {
226
+ width: size.width === 'auto' ? d.width : size.width,
227
+ height: size.height === 'auto' ? d.height : size.height
228
+ }
229
+ })
230
+ ),
231
+ of(size as { width: number; height: number })
232
+ )
233
+ }),
217
234
  takeUntil(destroy$),
218
235
  share()
219
236
  )
package/src/defaults.ts CHANGED
@@ -99,14 +99,14 @@ export const DATA_RELATIONA_DEFAULTL: DataRelationship = {
99
99
 
100
100
  export const DATA_FORMATTER_VALUE_AXIS_DEFAULT: DataFormatterValueAxis = {
101
101
  position: 'left',
102
- scaleDomain: [0, 'auto'],
102
+ scaleDomain: ['auto', 'auto'],
103
103
  scaleRange: [0, 0.9],
104
104
  label: '',
105
105
  }
106
106
 
107
107
  export const DATA_FORMATTER_GROUP_AXIS_DEFAULT: DataFormatterGroupAxis = {
108
108
  position: 'bottom',
109
- scaleDomain: [0, 'auto'],
109
+ scaleDomain: [0, 'max'],
110
110
  scalePadding: 0.5,
111
111
  label: ''
112
112
  }
@@ -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] === 'auto'
282
- ? groupMin - groupAxis.scalePadding
283
- : groupAxis.scaleDomain[0] as number - groupAxis.scalePadding
284
- const groupScaleDomainMax = groupAxis.scaleDomain[1] === 'auto'
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
- dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
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
- dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
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
  // // 篩選顯示狀態
@@ -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 | 'auto', number | 'auto']
57
+ scaleDomain: [number, number | 'max']
58
58
  scalePadding: number
59
59
  label: string
60
60
  }
@@ -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
- const domainMinValue = domainMin === 'auto' ? minValue : domainMin
26
- const domainMaxValue = domainMax === 'auto' ? maxValue : domainMax
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