@orbcharts/core 3.0.0-alpha.33 → 3.0.0-alpha.34
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +917 -914
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/utils/commonUtils.d.ts +1 -1
- package/package.json +1 -1
- package/src/base/createBaseChart.ts +24 -9
- package/src/defaults.ts +0 -1
- package/src/multiValue/computeMultiValueData.ts +1 -0
- package/src/tree/computeTreeData.ts +2 -2
- package/src/utils/commonUtils.ts +6 -6
- package/src/utils/orbchartsUtils.ts +5 -5
@@ -84,6 +84,18 @@ function resizeObservable(elem: HTMLElement | Element): Observable<DOMRectReadOn
|
|
84
84
|
})
|
85
85
|
}
|
86
86
|
|
87
|
+
function mergeDataFormatter <T>(dataFormatter: any, defaultDataFormatter: T, chartType: ChartType): T {
|
88
|
+
const mergedData = mergeOptionsWithDefault(dataFormatter, defaultDataFormatter)
|
89
|
+
|
90
|
+
if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList != null) {
|
91
|
+
// multiGrid欄位為陣列,需要各別來merge預設值
|
92
|
+
(mergedData as DataFormatterTypeMap<'multiGrid'>).gridList = (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList.map(d => {
|
93
|
+
return mergeOptionsWithDefault(d, (defaultDataFormatter as DataFormatterTypeMap<'multiGrid'>).gridList[0])
|
94
|
+
})
|
95
|
+
}
|
96
|
+
return mergedData
|
97
|
+
}
|
98
|
+
|
87
99
|
export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultDataFormatter, computedDataFn, contextObserverFn }: {
|
88
100
|
defaultDataFormatter: DataFormatterTypeMap<T>
|
89
101
|
computedDataFn: ComputedDataFn<T>
|
@@ -127,12 +139,14 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
|
|
127
139
|
const mergedPresetWithDefault: Preset<T> = ((options) => {
|
128
140
|
const _options = options ? options : CHART_OPTIONS_DEFAULT as ChartOptionsPartial<T>
|
129
141
|
const preset = _options.preset ? _options.preset : {} as PresetPartial<T>
|
142
|
+
|
130
143
|
return {
|
131
144
|
chartParams: preset.chartParams
|
132
145
|
? mergeOptionsWithDefault(preset.chartParams, CHART_PARAMS_DEFAULT)
|
133
146
|
: CHART_PARAMS_DEFAULT,
|
134
147
|
dataFormatter: preset.dataFormatter
|
135
|
-
? mergeOptionsWithDefault(preset.dataFormatter, defaultDataFormatter)
|
148
|
+
// ? mergeOptionsWithDefault(preset.dataFormatter, defaultDataFormatter)
|
149
|
+
? mergeDataFormatter(preset.dataFormatter, defaultDataFormatter, chartType)
|
136
150
|
: defaultDataFormatter,
|
137
151
|
allPluginParams: preset.allPluginParams
|
138
152
|
? preset.allPluginParams
|
@@ -147,15 +161,16 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
|
|
147
161
|
takeUntil(destroy$),
|
148
162
|
startWith({}),
|
149
163
|
map((dataFormatter) => {
|
150
|
-
const mergedData = mergeOptionsWithDefault(dataFormatter, mergedPresetWithDefault.dataFormatter)
|
164
|
+
// const mergedData = mergeOptionsWithDefault(dataFormatter, mergedPresetWithDefault.dataFormatter)
|
151
165
|
|
152
|
-
if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList != null) {
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
return mergedData
|
166
|
+
// if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList != null) {
|
167
|
+
// // multiGrid欄位為陣列,需要各別來merge預設值
|
168
|
+
// (mergedData as DataFormatterTypeMap<'multiGrid'>).gridList = (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList.map(d => {
|
169
|
+
// return mergeOptionsWithDefault(d, (mergedPresetWithDefault.dataFormatter as DataFormatterTypeMap<'multiGrid'>).gridList[0])
|
170
|
+
// })
|
171
|
+
// }
|
172
|
+
// return mergedData
|
173
|
+
return mergeDataFormatter(dataFormatter, mergedPresetWithDefault.dataFormatter, chartType)
|
159
174
|
}),
|
160
175
|
shareReplay(1)
|
161
176
|
)
|
package/src/defaults.ts
CHANGED
@@ -34,7 +34,6 @@ export const CHART_OPTIONS_DEFAULT: ChartOptionsPartial<any> = {
|
|
34
34
|
// }
|
35
35
|
|
36
36
|
// export const COLORS_DEFAULT = ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67']
|
37
|
-
// @Q@ 桃園儀表板
|
38
37
|
// ['#ff7ab9', '#66dec8', '#84c8ff', '#30ad1b', '#f8c43e', '#fa5640', '#9d79d7', '#ea4f98']
|
39
38
|
|
40
39
|
export const PADDING_DEFAULT: Padding = {
|
@@ -82,6 +82,7 @@ export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) =>
|
|
82
82
|
dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
|
83
83
|
dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
|
84
84
|
]
|
85
|
+
debugger
|
85
86
|
// 篩選顯示狀態
|
86
87
|
const visibleFilter = (datum: DataMultiValueDatum, rowIndex: number, columnIndex: number, context: DataFormatterContext<"multiValue">) => {
|
87
88
|
// 如果不在scale的範圍內則為false,不再做visibleFilter的判斷
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { DataTree, DataTreeObj, DataTreeDatum } from '../types/DataTree'
|
2
2
|
import type { ComputedDataFn } from '../types/ComputedData'
|
3
3
|
import type { ComputedDataTree } from '../types/ComputedDataTree'
|
4
|
-
import {
|
4
|
+
import { isPlainObject } from '../utils/commonUtils'
|
5
5
|
|
6
6
|
export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
|
7
7
|
const { data = [], dataFormatter, chartParams } = context
|
@@ -23,7 +23,7 @@ export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
|
|
23
23
|
try {
|
24
24
|
// 建立樹狀結構資料
|
25
25
|
const dataTreeObj: DataTreeObj = (function () {
|
26
|
-
if (
|
26
|
+
if (isPlainObject(data) === true) {
|
27
27
|
// 原本就是樹狀結構則直接複製
|
28
28
|
return structuredClone(data) as DataTreeObj
|
29
29
|
} else if (Array.isArray(data) === false) {
|
package/src/utils/commonUtils.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// import * as d3 from 'd3'
|
2
2
|
|
3
|
-
//
|
4
|
-
export function
|
3
|
+
// 是否為原始物件
|
4
|
+
export function isPlainObject(variable: any) {
|
5
5
|
return Object.prototype.toString.call(variable) === "[object Object]";
|
6
6
|
}
|
7
7
|
|
@@ -12,7 +12,7 @@ export function isFunction(fn: any) {
|
|
12
12
|
|
13
13
|
// 將可選的參數和預設值合併
|
14
14
|
export function mergeOptionsWithDefault<Options extends { [key: string]: any; }> (options: {[key: string]: any}, defaultOptions: Options): Options {
|
15
|
-
if (
|
15
|
+
if (isPlainObject(options) === false || isPlainObject(defaultOptions) === false) {
|
16
16
|
return Object.assign({}, defaultOptions)
|
17
17
|
}
|
18
18
|
const mergeObjColumns = (_options: {[key: string]: any}, _defaultOptions: {[key: string]: any}) => {
|
@@ -22,12 +22,12 @@ export function mergeOptionsWithDefault<Options extends { [key: string]: any; }>
|
|
22
22
|
continue
|
23
23
|
}
|
24
24
|
let objValue: any = undefined
|
25
|
-
// 下一層的object
|
26
|
-
if (
|
25
|
+
// 下一層的plain object
|
26
|
+
if (isPlainObject(_options[key]) && isPlainObject(_defaultOptions[key])) {
|
27
27
|
objValue = mergeObjColumns(_options[key], _defaultOptions[key])
|
28
28
|
obj[key as keyof Options] = objValue
|
29
29
|
}
|
30
|
-
// 不是object直接賦值
|
30
|
+
// 不是plain object直接賦值
|
31
31
|
else {
|
32
32
|
obj[key as keyof Options] = _options[key]
|
33
33
|
}
|
@@ -13,7 +13,7 @@ import type { ComputedDatumGrid, ComputedDataGrid } from '../types/ComputedDataG
|
|
13
13
|
import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
|
14
14
|
import type { Layout } from '../types/Layout'
|
15
15
|
// import type { ComputedDatumMultiGrid } from '../types/ComputedDataMultiGrid'
|
16
|
-
import {
|
16
|
+
import { isPlainObject } from './commonUtils'
|
17
17
|
|
18
18
|
export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
|
19
19
|
if (valueFormatter! instanceof Function == true) {
|
@@ -103,7 +103,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
|
|
103
103
|
? data.flat()
|
104
104
|
: data as (DataSeriesValue | DataSeriesDatum)[]
|
105
105
|
const arr = flatData
|
106
|
-
.filter(d => (d == null || (
|
106
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
|
107
107
|
.map(d => typeof d === 'number' ? d : d.value )
|
108
108
|
return getMinAndMax(arr)
|
109
109
|
}
|
@@ -112,7 +112,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
|
|
112
112
|
export function getMinAndMaxGrid (data: DataGrid): [number, number] {
|
113
113
|
const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
|
114
114
|
const arr = flatData
|
115
|
-
.filter(d => (d == null || (
|
115
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
|
116
116
|
.map(d => typeof d === 'number' ? d : d.value )
|
117
117
|
return getMinAndMax(arr)
|
118
118
|
}
|
@@ -121,7 +121,7 @@ export function getMinAndMaxGrid (data: DataGrid): [number, number] {
|
|
121
121
|
export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
|
122
122
|
const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
|
123
123
|
const arr = flatData
|
124
|
-
.filter(d => (d == null || (
|
124
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
|
125
125
|
.map(d => typeof d === 'number' ? d : d.value )
|
126
126
|
return getMinAndMax(arr)
|
127
127
|
}
|
@@ -130,7 +130,7 @@ export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
|
|
130
130
|
export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number = 2): [number, number] {
|
131
131
|
const flatData: (DataMultiValueDatum | DataMultiValueValue)[] = data.flat().filter((d, i) => i == valueIndex)
|
132
132
|
const arr = flatData
|
133
|
-
.filter(d => (d == null || (
|
133
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
|
134
134
|
.map(d => typeof d === 'number' ? d : d.value )
|
135
135
|
return getMinAndMax(arr)
|
136
136
|
}
|