@orbcharts/core 3.0.0-beta.6 → 3.0.0-beta.8

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 (69) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +486 -483
  3. package/dist/orbcharts-core.umd.js +3 -3
  4. package/dist/src/defaults.d.ts +1 -1
  5. package/lib/core-types.ts +7 -7
  6. package/package.json +42 -42
  7. package/src/AbstractChart.ts +57 -57
  8. package/src/GridChart.ts +24 -24
  9. package/src/MultiGridChart.ts +24 -24
  10. package/src/MultiValueChart.ts +24 -24
  11. package/src/RelationshipChart.ts +24 -24
  12. package/src/SeriesChart.ts +24 -24
  13. package/src/TreeChart.ts +24 -24
  14. package/src/base/createBaseChart.ts +505 -505
  15. package/src/base/createBasePlugin.ts +153 -153
  16. package/src/base/validators/chartOptionsValidator.ts +23 -23
  17. package/src/base/validators/chartParamsValidator.ts +133 -133
  18. package/src/base/validators/elementValidator.ts +13 -13
  19. package/src/base/validators/pluginsValidator.ts +14 -14
  20. package/src/defaults.ts +238 -235
  21. package/src/defineGridPlugin.ts +3 -3
  22. package/src/defineMultiGridPlugin.ts +3 -3
  23. package/src/defineMultiValuePlugin.ts +3 -3
  24. package/src/defineNoneDataPlugin.ts +4 -4
  25. package/src/defineRelationshipPlugin.ts +3 -3
  26. package/src/defineSeriesPlugin.ts +3 -3
  27. package/src/defineTreePlugin.ts +3 -3
  28. package/src/grid/computedDataFn.ts +129 -129
  29. package/src/grid/contextObserverCallback.ts +176 -176
  30. package/src/grid/dataFormatterValidator.ts +101 -101
  31. package/src/grid/dataValidator.ts +12 -12
  32. package/src/index.ts +20 -20
  33. package/src/multiGrid/computedDataFn.ts +123 -123
  34. package/src/multiGrid/contextObserverCallback.ts +41 -41
  35. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  36. package/src/multiGrid/dataValidator.ts +12 -12
  37. package/src/multiValue/computedDataFn.ts +110 -110
  38. package/src/multiValue/contextObserverCallback.ts +160 -160
  39. package/src/multiValue/dataFormatterValidator.ts +9 -9
  40. package/src/multiValue/dataValidator.ts +9 -9
  41. package/src/relationship/computedDataFn.ts +144 -144
  42. package/src/relationship/contextObserverCallback.ts +80 -80
  43. package/src/relationship/dataFormatterValidator.ts +9 -9
  44. package/src/relationship/dataValidator.ts +9 -9
  45. package/src/series/computedDataFn.ts +88 -88
  46. package/src/series/contextObserverCallback.ts +100 -100
  47. package/src/series/dataFormatterValidator.ts +41 -41
  48. package/src/series/dataValidator.ts +12 -12
  49. package/src/tree/computedDataFn.ts +129 -129
  50. package/src/tree/contextObserverCallback.ts +58 -58
  51. package/src/tree/dataFormatterValidator.ts +13 -13
  52. package/src/tree/dataValidator.ts +13 -13
  53. package/src/utils/commonUtils.ts +55 -55
  54. package/src/utils/d3Scale.ts +198 -198
  55. package/src/utils/errorMessage.ts +42 -42
  56. package/src/utils/gridObservables.ts +683 -683
  57. package/src/utils/index.ts +9 -9
  58. package/src/utils/multiGridObservables.ts +392 -392
  59. package/src/utils/multiValueObservables.ts +661 -661
  60. package/src/utils/observables.ts +219 -219
  61. package/src/utils/orbchartsUtils.ts +377 -377
  62. package/src/utils/relationshipObservables.ts +84 -84
  63. package/src/utils/seriesObservables.ts +175 -175
  64. package/src/utils/treeObservables.ts +105 -105
  65. package/src/utils/validator.ts +126 -126
  66. package/tsconfig.base.json +13 -13
  67. package/tsconfig.json +2 -2
  68. package/vite-env.d.ts +6 -6
  69. package/vite.config.js +22 -22
@@ -1,13 +1,13 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataValidator: DataValidator<'series'> = (data: DataTypeMap<'series'>) => {
5
- const result = validateColumns({ data }, {
6
- data: {
7
- toBe: '(DataSeriesDatum | DataSeriesValue)[][] | (DataSeriesDatum | DataSeriesValue)[]',
8
- // 畢免資料量過大檢查不完,不深度檢查
9
- test: (value) => Array.isArray(value)
10
- }
11
- })
12
- return result
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'series'> = (data: DataTypeMap<'series'>) => {
5
+ const result = validateColumns({ data }, {
6
+ data: {
7
+ toBe: '(DataSeriesDatum | DataSeriesValue)[][] | (DataSeriesDatum | DataSeriesValue)[]',
8
+ // 畢免資料量過大檢查不完,不深度檢查
9
+ test: (value) => Array.isArray(value)
10
+ }
11
+ })
12
+ return result
13
13
  }
@@ -1,129 +1,129 @@
1
- import type { DataTree, DataTreeObj, DataTreeDatum, ComputedDataFn, ComputedDataTree } from '../../lib/core-types'
2
- import { isPlainObject } from '../utils/commonUtils'
3
- import { seriesColorPredicate, createDefaultCategoryLabel } from '../utils/orbchartsUtils'
4
-
5
- export const computedDataFn: ComputedDataFn<'tree'> = (context) => {
6
- const { data = [], dataFormatter, chartParams } = context
7
-
8
- const defaultCategoryLabel = createDefaultCategoryLabel()
9
-
10
- // <categoryLabel, categoryIndex>
11
- const CategoryIndexMap = new Map<string, number>(
12
- dataFormatter.categoryLabels.map((label, index) => [label, index])
13
- )
14
-
15
- let computedBranchData: ComputedDataTree = {
16
- id: '',
17
- index: 0,
18
- label: '',
19
- description: '',
20
- categoryIndex: -1,
21
- categoryLabel: '',
22
- color: '',
23
- visible: true,
24
- // tooltipContent: '',
25
- data: {},
26
- value: 0,
27
- level: 0,
28
- seq: 0,
29
- children: []
30
- }
31
-
32
- try {
33
- // 建立樹狀結構資料
34
- const dataTreeObj: DataTreeObj = (function () {
35
- if (isPlainObject(data) === true) {
36
- // 原本就是樹狀結構則直接複製
37
- // return structuredClone(data) as DataTreeObj
38
- return JSON.parse(JSON.stringify(data)) as DataTreeObj
39
- } else if (Array.isArray(data) === false) {
40
- return {
41
- id: ''
42
- }
43
- }
44
- // -- 陣列格式轉物件 --
45
- // let rootId = ''
46
- let root: DataTreeDatum | undefined = undefined
47
- // const DataMap: Map<string, DataTreeDatum> = new Map()
48
- const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
49
- ;(data as DataTreeDatum[]).forEach(d => {
50
- // DataMap.set(d.id, d)
51
-
52
- if (!d.parent) {
53
- // rootId = d.id
54
- root = d
55
- } else {
56
- const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
57
- children.push(d)
58
- ChildrenMap.set(d.parent!, children)
59
- }
60
- })
61
-
62
- const createBranchData = (root: DataTreeDatum): DataTreeObj => {
63
- return {
64
- id: root.id,
65
- label: root.label,
66
- data: root.data,
67
- // tooltipContent: root.tooltipContent,
68
- value: root.value,
69
- categoryLabel: root.categoryLabel ?? defaultCategoryLabel,
70
- children: (ChildrenMap.get(root.id) ?? []).map(d => {
71
- // 遞迴
72
- return createBranchData(d)
73
- })
74
- }
75
- }
76
- if (root) {
77
- return createBranchData(root)
78
- } else {
79
- return {
80
- id: ''
81
- }
82
- }
83
- })()
84
-
85
- let index = 0
86
-
87
- const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
88
- const childLayer = level + 1
89
- const categoryLabel: string = branch.categoryLabel ?? defaultCategoryLabel
90
- if (!CategoryIndexMap.has(categoryLabel)) {
91
- CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
92
- }
93
- const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
94
-
95
- const currentIndex = index
96
- index++
97
- const formattedBranchData: ComputedDataTree = {
98
- id: branch.id,
99
- index: currentIndex,
100
- level,
101
- seq,
102
- label: branch.label ?? '',
103
- description: branch.description ?? '',
104
- categoryIndex,
105
- categoryLabel,
106
- color: seriesColorPredicate(categoryIndex, chartParams),
107
- data: branch.data ?? {},
108
- // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
109
- value: branch.value,
110
- visible: true, // 先給預設值
111
- children: (branch.children ?? []).map((d, i) => {
112
- // 遞迴
113
- return formatBranchData(d, childLayer, i)
114
- })
115
- }
116
-
117
- formattedBranchData.visible = dataFormatter.visibleFilter(formattedBranchData, context)
118
-
119
- return formattedBranchData
120
- }
121
- computedBranchData = formatBranchData(dataTreeObj, 0, 0)
122
- } catch (e) {
123
- // console.error(e)
124
- throw Error(e)
125
- }
126
-
127
- return computedBranchData
128
-
129
- }
1
+ import type { DataTree, DataTreeObj, DataTreeDatum, ComputedDataFn, ComputedDataTree } from '../../lib/core-types'
2
+ import { isPlainObject } from '../utils/commonUtils'
3
+ import { seriesColorPredicate, createDefaultCategoryLabel } from '../utils/orbchartsUtils'
4
+
5
+ export const computedDataFn: ComputedDataFn<'tree'> = (context) => {
6
+ const { data = [], dataFormatter, chartParams } = context
7
+
8
+ const defaultCategoryLabel = createDefaultCategoryLabel()
9
+
10
+ // <categoryLabel, categoryIndex>
11
+ const CategoryIndexMap = new Map<string, number>(
12
+ dataFormatter.categoryLabels.map((label, index) => [label, index])
13
+ )
14
+
15
+ let computedBranchData: ComputedDataTree = {
16
+ id: '',
17
+ index: 0,
18
+ label: '',
19
+ description: '',
20
+ categoryIndex: -1,
21
+ categoryLabel: '',
22
+ color: '',
23
+ visible: true,
24
+ // tooltipContent: '',
25
+ data: {},
26
+ value: 0,
27
+ level: 0,
28
+ seq: 0,
29
+ children: []
30
+ }
31
+
32
+ try {
33
+ // 建立樹狀結構資料
34
+ const dataTreeObj: DataTreeObj = (function () {
35
+ if (isPlainObject(data) === true) {
36
+ // 原本就是樹狀結構則直接複製
37
+ // return structuredClone(data) as DataTreeObj
38
+ return JSON.parse(JSON.stringify(data)) as DataTreeObj
39
+ } else if (Array.isArray(data) === false) {
40
+ return {
41
+ id: ''
42
+ }
43
+ }
44
+ // -- 陣列格式轉物件 --
45
+ // let rootId = ''
46
+ let root: DataTreeDatum | undefined = undefined
47
+ // const DataMap: Map<string, DataTreeDatum> = new Map()
48
+ const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
49
+ ;(data as DataTreeDatum[]).forEach(d => {
50
+ // DataMap.set(d.id, d)
51
+
52
+ if (!d.parent) {
53
+ // rootId = d.id
54
+ root = d
55
+ } else {
56
+ const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
57
+ children.push(d)
58
+ ChildrenMap.set(d.parent!, children)
59
+ }
60
+ })
61
+
62
+ const createBranchData = (root: DataTreeDatum): DataTreeObj => {
63
+ return {
64
+ id: root.id,
65
+ label: root.label,
66
+ data: root.data,
67
+ // tooltipContent: root.tooltipContent,
68
+ value: root.value,
69
+ categoryLabel: root.categoryLabel ?? defaultCategoryLabel,
70
+ children: (ChildrenMap.get(root.id) ?? []).map(d => {
71
+ // 遞迴
72
+ return createBranchData(d)
73
+ })
74
+ }
75
+ }
76
+ if (root) {
77
+ return createBranchData(root)
78
+ } else {
79
+ return {
80
+ id: ''
81
+ }
82
+ }
83
+ })()
84
+
85
+ let index = 0
86
+
87
+ const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
88
+ const childLayer = level + 1
89
+ const categoryLabel: string = branch.categoryLabel ?? defaultCategoryLabel
90
+ if (!CategoryIndexMap.has(categoryLabel)) {
91
+ CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
92
+ }
93
+ const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
94
+
95
+ const currentIndex = index
96
+ index++
97
+ const formattedBranchData: ComputedDataTree = {
98
+ id: branch.id,
99
+ index: currentIndex,
100
+ level,
101
+ seq,
102
+ label: branch.label ?? '',
103
+ description: branch.description ?? '',
104
+ categoryIndex,
105
+ categoryLabel,
106
+ color: seriesColorPredicate(categoryIndex, chartParams),
107
+ data: branch.data ?? {},
108
+ // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
109
+ value: branch.value,
110
+ visible: true, // 先給預設值
111
+ children: (branch.children ?? []).map((d, i) => {
112
+ // 遞迴
113
+ return formatBranchData(d, childLayer, i)
114
+ })
115
+ }
116
+
117
+ formattedBranchData.visible = dataFormatter.visibleFilter(formattedBranchData, context)
118
+
119
+ return formattedBranchData
120
+ }
121
+ computedBranchData = formatBranchData(dataTreeObj, 0, 0)
122
+ } catch (e) {
123
+ // console.error(e)
124
+ throw Error(e)
125
+ }
126
+
127
+ return computedBranchData
128
+
129
+ }
@@ -1,58 +1,58 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverCallback } from '../../lib/core-types'
3
- import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
- import {
5
- nodeListObservable,
6
- categoryLabelsObservable,
7
- treeVisibleComputedDataObservable
8
- } from '../utils/treeObservables'
9
-
10
- export const contextObserverCallback: ContextObserverCallback<'tree'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const nodeList$ = nodeListObservable({
17
- computedData$: observer.computedData$
18
- }).pipe(
19
- shareReplay(1)
20
- )
21
-
22
- const treeHighlight$ = highlightObservable({
23
- datumList$: nodeList$,
24
- fullChartParams$: observer.fullChartParams$,
25
- event$: subject.event$
26
- }).pipe(
27
- shareReplay(1)
28
- )
29
-
30
- const CategoryDataMap$ = categoryDataMapObservable({
31
- datumList$: nodeList$
32
- }).pipe(
33
- shareReplay(1)
34
- )
35
-
36
- const categoryLabels$ = categoryLabelsObservable(CategoryDataMap$).pipe(
37
- shareReplay(1)
38
- )
39
-
40
- const visibleComputedData$ = treeVisibleComputedDataObservable({
41
- computedData$: observer.computedData$
42
- }).pipe(
43
- shareReplay(1)
44
- )
45
-
46
- return {
47
- fullParams$: observer.fullParams$,
48
- fullChartParams$: observer.fullChartParams$,
49
- fullDataFormatter$: observer.fullDataFormatter$,
50
- computedData$: observer.computedData$,
51
- layout$: observer.layout$,
52
- textSizePx$,
53
- treeHighlight$,
54
- categoryLabels$,
55
- CategoryDataMap$,
56
- visibleComputedData$
57
- }
58
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverCallback } from '../../lib/core-types'
3
+ import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
+ import {
5
+ nodeListObservable,
6
+ categoryLabelsObservable,
7
+ treeVisibleComputedDataObservable
8
+ } from '../utils/treeObservables'
9
+
10
+ export const contextObserverCallback: ContextObserverCallback<'tree'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const nodeList$ = nodeListObservable({
17
+ computedData$: observer.computedData$
18
+ }).pipe(
19
+ shareReplay(1)
20
+ )
21
+
22
+ const treeHighlight$ = highlightObservable({
23
+ datumList$: nodeList$,
24
+ fullChartParams$: observer.fullChartParams$,
25
+ event$: subject.event$
26
+ }).pipe(
27
+ shareReplay(1)
28
+ )
29
+
30
+ const CategoryDataMap$ = categoryDataMapObservable({
31
+ datumList$: nodeList$
32
+ }).pipe(
33
+ shareReplay(1)
34
+ )
35
+
36
+ const categoryLabels$ = categoryLabelsObservable(CategoryDataMap$).pipe(
37
+ shareReplay(1)
38
+ )
39
+
40
+ const visibleComputedData$ = treeVisibleComputedDataObservable({
41
+ computedData$: observer.computedData$
42
+ }).pipe(
43
+ shareReplay(1)
44
+ )
45
+
46
+ return {
47
+ fullParams$: observer.fullParams$,
48
+ fullChartParams$: observer.fullChartParams$,
49
+ fullDataFormatter$: observer.fullDataFormatter$,
50
+ computedData$: observer.computedData$,
51
+ layout$: observer.layout$,
52
+ textSizePx$,
53
+ treeHighlight$,
54
+ categoryLabels$,
55
+ CategoryDataMap$,
56
+ visibleComputedData$
57
+ }
58
+ }
@@ -1,14 +1,14 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataFormatterValidator: DataFormatterValidator<'tree'> = (dataFormatter: DataFormatterTypeMap<'tree'>) => {
5
- const result = validateColumns(dataFormatter, {
6
- visibleFilter: {
7
- toBeTypes: ['Function']
8
- },
9
- categoryLabels: {
10
- toBeTypes: ['string[]']
11
- }
12
- })
13
- return result
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'tree'> = (dataFormatter: DataFormatterTypeMap<'tree'>) => {
5
+ const result = validateColumns(dataFormatter, {
6
+ visibleFilter: {
7
+ toBeTypes: ['Function']
8
+ },
9
+ categoryLabels: {
10
+ toBeTypes: ['string[]']
11
+ }
12
+ })
13
+ return result
14
14
  }
@@ -1,14 +1,14 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
- import { isPlainObject } from '../utils'
4
-
5
- export const dataValidator: DataValidator<'tree'> = (data: DataTypeMap<'tree'>) => {
6
- const result = validateColumns({ data }, {
7
- data: {
8
- toBe: 'DataTreeObj | DataTreeDatum[]',
9
- // 畢免資料量過大檢查不完,不深度檢查
10
- test: (value) => isPlainObject(value) && value.id !== undefined
11
- }
12
- })
13
- return result
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+ import { isPlainObject } from '../utils'
4
+
5
+ export const dataValidator: DataValidator<'tree'> = (data: DataTypeMap<'tree'>) => {
6
+ const result = validateColumns({ data }, {
7
+ data: {
8
+ toBe: 'DataTreeObj | DataTreeDatum[]',
9
+ // 畢免資料量過大檢查不完,不深度檢查
10
+ test: (value) => isPlainObject(value) && value.id !== undefined
11
+ }
12
+ })
13
+ return result
14
14
  }
@@ -1,55 +1,55 @@
1
-
2
- // 是否為原始物件
3
- export function isPlainObject(variable: any) {
4
- return Object.prototype.toString.call(variable) === "[object Object]";
5
- }
6
-
7
- // 是否為function
8
- export function isFunction(fn: any) {
9
- // return !!fn && !fn.nodename && fn.constructor != String && fn.constructor != RegExp && fn.constructor != Array && /function/i.test(fn + "");
10
- return Object.prototype.toString.call(fn) === '[object Function]'
11
- }
12
-
13
- // 是否為dom
14
- export function isDom(obj: any) {
15
- return !!(obj && obj.nodeType);
16
- }
17
-
18
- // 將可選的參數和預設值合併
19
- export function mergeOptionsWithDefault<Options extends { [key: string]: any; }> (options: {[key: string]: any}, defaultOptions: Options): Options {
20
- if (isPlainObject(options) === false || isPlainObject(defaultOptions) === false) {
21
- return Object.assign({}, defaultOptions)
22
- }
23
- const mergeObjColumns = (_options: {[key: string]: any}, _defaultOptions: {[key: string]: any}) => {
24
- const obj: Options = (Object.assign({}, _defaultOptions) as any)
25
- for (let key of Object.keys(_options)) {
26
- if ((key in _defaultOptions) == false) {
27
- continue
28
- }
29
- let objValue: any = undefined
30
- // 下一層的plain object
31
- if (isPlainObject(_options[key]) && isPlainObject(_defaultOptions[key])) {
32
- objValue = mergeObjColumns(_options[key], _defaultOptions[key])
33
- obj[key as keyof Options] = objValue
34
- }
35
- // 不是plain object直接賦值
36
- else {
37
- obj[key as keyof Options] = _options[key]
38
- }
39
- }
40
- return obj
41
- }
42
-
43
- return mergeObjColumns(options, defaultOptions)
44
- }
45
-
46
- // 加上千分位 ,
47
- export function formatCommaNumber (num = 0): string {
48
- try {
49
- let parts = num.toString().split('.');
50
- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
51
- return parts.join('.');
52
- } catch (e: any) {
53
- console.error(e)
54
- }
55
- }
1
+
2
+ // 是否為原始物件
3
+ export function isPlainObject(variable: any) {
4
+ return Object.prototype.toString.call(variable) === "[object Object]";
5
+ }
6
+
7
+ // 是否為function
8
+ export function isFunction(fn: any) {
9
+ // return !!fn && !fn.nodename && fn.constructor != String && fn.constructor != RegExp && fn.constructor != Array && /function/i.test(fn + "");
10
+ return Object.prototype.toString.call(fn) === '[object Function]'
11
+ }
12
+
13
+ // 是否為dom
14
+ export function isDom(obj: any) {
15
+ return !!(obj && obj.nodeType);
16
+ }
17
+
18
+ // 將可選的參數和預設值合併
19
+ export function mergeOptionsWithDefault<Options extends { [key: string]: any; }> (options: {[key: string]: any}, defaultOptions: Options): Options {
20
+ if (isPlainObject(options) === false || isPlainObject(defaultOptions) === false) {
21
+ return Object.assign({}, defaultOptions)
22
+ }
23
+ const mergeObjColumns = (_options: {[key: string]: any}, _defaultOptions: {[key: string]: any}) => {
24
+ const obj: Options = (Object.assign({}, _defaultOptions) as any)
25
+ for (let key of Object.keys(_options)) {
26
+ if ((key in _defaultOptions) == false) {
27
+ continue
28
+ }
29
+ let objValue: any = undefined
30
+ // 下一層的plain object
31
+ if (isPlainObject(_options[key]) && isPlainObject(_defaultOptions[key])) {
32
+ objValue = mergeObjColumns(_options[key], _defaultOptions[key])
33
+ obj[key as keyof Options] = objValue
34
+ }
35
+ // 不是plain object直接賦值
36
+ else {
37
+ obj[key as keyof Options] = _options[key]
38
+ }
39
+ }
40
+ return obj
41
+ }
42
+
43
+ return mergeObjColumns(options, defaultOptions)
44
+ }
45
+
46
+ // 加上千分位 ,
47
+ export function formatCommaNumber (num = 0): string {
48
+ try {
49
+ let parts = num.toString().split('.');
50
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
51
+ return parts.join('.');
52
+ } catch (e: any) {
53
+ console.error(e)
54
+ }
55
+ }