@orbcharts/core 3.0.2 → 3.0.4

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 (78) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2478 -2362
  3. package/dist/orbcharts-core.umd.js +5 -4
  4. package/dist/src/{utils → multiValue}/multiValueObservables.d.ts +20 -10
  5. package/dist/src/utils/errorMessage.d.ts +5 -3
  6. package/dist/src/utils/index.d.ts +0 -1
  7. package/dist/src/utils/observables.d.ts +3 -2
  8. package/dist/src/utils/orbchartsUtils.d.ts +1 -0
  9. package/lib/core-types.ts +7 -7
  10. package/package.json +46 -46
  11. package/src/AbstractChart.ts +57 -57
  12. package/src/GridChart.ts +24 -24
  13. package/src/MultiGridChart.ts +24 -24
  14. package/src/MultiValueChart.ts +24 -24
  15. package/src/RelationshipChart.ts +24 -24
  16. package/src/SeriesChart.ts +24 -24
  17. package/src/TreeChart.ts +24 -24
  18. package/src/base/createBaseChart.ts +524 -506
  19. package/src/base/createBasePlugin.ts +154 -154
  20. package/src/base/validators/chartOptionsValidator.ts +23 -23
  21. package/src/base/validators/chartParamsValidator.ts +133 -133
  22. package/src/base/validators/elementValidator.ts +13 -13
  23. package/src/base/validators/pluginsValidator.ts +14 -14
  24. package/src/defaults.ts +283 -282
  25. package/src/defineGridPlugin.ts +3 -3
  26. package/src/defineMultiGridPlugin.ts +3 -3
  27. package/src/defineMultiValuePlugin.ts +3 -3
  28. package/src/defineNoneDataPlugin.ts +4 -4
  29. package/src/defineRelationshipPlugin.ts +3 -3
  30. package/src/defineSeriesPlugin.ts +3 -3
  31. package/src/defineTreePlugin.ts +3 -3
  32. package/src/grid/computedDataFn.ts +129 -129
  33. package/src/grid/contextObserverCallback.ts +201 -198
  34. package/src/grid/dataFormatterValidator.ts +125 -120
  35. package/src/grid/dataValidator.ts +12 -12
  36. package/src/{utils → grid}/gridObservables.ts +718 -705
  37. package/src/index.ts +20 -20
  38. package/src/multiGrid/computedDataFn.ts +123 -123
  39. package/src/multiGrid/contextObserverCallback.ts +75 -72
  40. package/src/multiGrid/dataFormatterValidator.ts +120 -115
  41. package/src/multiGrid/dataValidator.ts +12 -12
  42. package/src/{utils → multiGrid}/multiGridObservables.ts +401 -401
  43. package/src/multiValue/computedDataFn.ts +113 -113
  44. package/src/multiValue/contextObserverCallback.ts +328 -276
  45. package/src/multiValue/dataFormatterValidator.ts +94 -89
  46. package/src/multiValue/dataValidator.ts +12 -12
  47. package/src/{utils → multiValue}/multiValueObservables.ts +1219 -1044
  48. package/src/relationship/computedDataFn.ts +159 -159
  49. package/src/relationship/contextObserverCallback.ts +80 -80
  50. package/src/relationship/dataFormatterValidator.ts +13 -13
  51. package/src/relationship/dataValidator.ts +13 -13
  52. package/src/{utils → relationship}/relationshipObservables.ts +84 -84
  53. package/src/series/computedDataFn.ts +88 -88
  54. package/src/series/contextObserverCallback.ts +107 -107
  55. package/src/series/dataFormatterValidator.ts +46 -41
  56. package/src/series/dataValidator.ts +12 -12
  57. package/src/{utils → series}/seriesObservables.ts +175 -175
  58. package/src/tree/computedDataFn.ts +129 -129
  59. package/src/tree/contextObserverCallback.ts +58 -58
  60. package/src/tree/dataFormatterValidator.ts +13 -13
  61. package/src/tree/dataValidator.ts +13 -13
  62. package/src/{utils → tree}/treeObservables.ts +105 -105
  63. package/src/utils/commonUtils.ts +55 -55
  64. package/src/utils/d3Scale.ts +198 -198
  65. package/src/utils/errorMessage.ts +40 -42
  66. package/src/utils/index.ts +4 -10
  67. package/src/utils/observables.ts +293 -281
  68. package/src/utils/orbchartsUtils.ts +396 -377
  69. package/src/utils/validator.ts +126 -126
  70. package/tsconfig.base.json +13 -13
  71. package/tsconfig.json +2 -2
  72. package/vite-env.d.ts +6 -6
  73. package/vite.config.js +22 -22
  74. /package/dist/src/{utils → grid}/gridObservables.d.ts +0 -0
  75. /package/dist/src/{utils → multiGrid}/multiGridObservables.d.ts +0 -0
  76. /package/dist/src/{utils → relationship}/relationshipObservables.d.ts +0 -0
  77. /package/dist/src/{utils → series}/seriesObservables.d.ts +0 -0
  78. /package/dist/src/{utils → tree}/treeObservables.d.ts +0 -0
@@ -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 './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) || Array.isArray(value)
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) || Array.isArray(value)
11
+ }
12
+ })
13
+ return result
14
14
  }
@@ -1,106 +1,106 @@
1
- import {
2
- combineLatest,
3
- distinctUntilChanged,
4
- filter,
5
- map,
6
- merge,
7
- takeUntil,
8
- shareReplay,
9
- switchMap,
10
- Subject,
11
- Observable } from 'rxjs'
12
- import type {
13
- ChartParams,
14
- ComputedDataTree,
15
- ComputedDataTypeMap,
16
- DataFormatterTree } from '../../lib/core-types'
17
-
18
-
19
- // 所有節點list結構
20
- export const nodeListObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
21
- return computedData$.pipe(
22
- map(data => {
23
- function setNodeList (accNodeList: ComputedDataTree[], branch: ComputedDataTree) {
24
- accNodeList.push(branch)
25
- if (branch.children) {
26
- branch.children.forEach(childBranch => {
27
- accNodeList = setNodeList(accNodeList, childBranch) // 遞迴子節點
28
- })
29
- }
30
- return accNodeList
31
- }
32
- return setNodeList([], data)
33
- })
34
- )
35
- }
36
-
37
- // export const categoryLabelsObservable = ({ nodeList$, fullDataFormatter$ }: {
38
- // nodeList$: Observable<ComputedDataTree[]>
39
- // fullDataFormatter$: Observable<DataFormatterTree>
40
- // }) => {
41
-
42
- // const categoryLabels$ = fullDataFormatter$.pipe(
43
- // map(d => d.categoryLabels),
44
- // distinctUntilChanged((a, b) => {
45
- // return JSON.stringify(a).length === JSON.stringify(b).length
46
- // }),
47
- // )
48
-
49
- // return combineLatest({
50
- // nodeList: nodeList$,
51
- // categoryLabels: categoryLabels$
52
- // }).pipe(
53
- // switchMap(async d => d),
54
- // map(data => {
55
- // const CurrentLabelSet = new Set(data.categoryLabels)
56
- // const ExistLabelSet = new Set(
57
- // data.nodeList.filter(node => node.visible).map(node => node.categoryLabel)
58
- // )
59
- // // 加入已存在的label(data.nodeList有,但是dataFormatter.categoryLabels沒有)
60
- // Array.from(ExistLabelSet).forEach(label => {
61
- // if (!CurrentLabelSet.has(label)) {
62
- // CurrentLabelSet.add(label)
63
- // }
64
- // })
65
- // // 移除不存在的label(dataFormatter.categoryLabels有,但是data.nodeList沒有)
66
- // Array.from(CurrentLabelSet).forEach(label => {
67
- // if (!ExistLabelSet.has(label)) {
68
- // ExistLabelSet.delete(label)
69
- // }
70
- // })
71
-
72
- // return Array.from(CurrentLabelSet)
73
- // }),
74
- // distinctUntilChanged((a, b) => {
75
- // return JSON.stringify(a).length === JSON.stringify(b).length
76
- // }),
77
- // )
78
- // }
79
-
80
- export const categoryLabelsObservable = (CategoryDataMap$: Observable<Map<string, ComputedDataTree[]>>) => {
81
- return CategoryDataMap$.pipe(
82
- map(data => {
83
- return Array.from(data.keys())
84
- }),
85
- distinctUntilChanged((a, b) => {
86
- return JSON.stringify(a).length === JSON.stringify(b).length
87
- }),
88
- )
89
- }
90
-
91
- // 所有可見的節點
92
- export const treeVisibleComputedDataObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
93
- return computedData$.pipe(
94
- map(data => {
95
- function filterChildren (accTree: ComputedDataTree) {
96
- if (accTree.children) {
97
- accTree.children = accTree.children
98
- .filter(child => child.visible) // 篩選visible
99
- .map(child => filterChildren(child)) // 遞迴子節點
100
- }
101
- return accTree
102
- }
103
- return filterChildren(data)
104
- })
105
- )
1
+ import {
2
+ combineLatest,
3
+ distinctUntilChanged,
4
+ filter,
5
+ map,
6
+ merge,
7
+ takeUntil,
8
+ shareReplay,
9
+ switchMap,
10
+ Subject,
11
+ Observable } from 'rxjs'
12
+ import type {
13
+ ChartParams,
14
+ ComputedDataTree,
15
+ ComputedDataTypeMap,
16
+ DataFormatterTree } from '../../lib/core-types'
17
+
18
+
19
+ // 所有節點list結構
20
+ export const nodeListObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
21
+ return computedData$.pipe(
22
+ map(data => {
23
+ function setNodeList (accNodeList: ComputedDataTree[], branch: ComputedDataTree) {
24
+ accNodeList.push(branch)
25
+ if (branch.children) {
26
+ branch.children.forEach(childBranch => {
27
+ accNodeList = setNodeList(accNodeList, childBranch) // 遞迴子節點
28
+ })
29
+ }
30
+ return accNodeList
31
+ }
32
+ return setNodeList([], data)
33
+ })
34
+ )
35
+ }
36
+
37
+ // export const categoryLabelsObservable = ({ nodeList$, fullDataFormatter$ }: {
38
+ // nodeList$: Observable<ComputedDataTree[]>
39
+ // fullDataFormatter$: Observable<DataFormatterTree>
40
+ // }) => {
41
+
42
+ // const categoryLabels$ = fullDataFormatter$.pipe(
43
+ // map(d => d.categoryLabels),
44
+ // distinctUntilChanged((a, b) => {
45
+ // return JSON.stringify(a).length === JSON.stringify(b).length
46
+ // }),
47
+ // )
48
+
49
+ // return combineLatest({
50
+ // nodeList: nodeList$,
51
+ // categoryLabels: categoryLabels$
52
+ // }).pipe(
53
+ // switchMap(async d => d),
54
+ // map(data => {
55
+ // const CurrentLabelSet = new Set(data.categoryLabels)
56
+ // const ExistLabelSet = new Set(
57
+ // data.nodeList.filter(node => node.visible).map(node => node.categoryLabel)
58
+ // )
59
+ // // 加入已存在的label(data.nodeList有,但是dataFormatter.categoryLabels沒有)
60
+ // Array.from(ExistLabelSet).forEach(label => {
61
+ // if (!CurrentLabelSet.has(label)) {
62
+ // CurrentLabelSet.add(label)
63
+ // }
64
+ // })
65
+ // // 移除不存在的label(dataFormatter.categoryLabels有,但是data.nodeList沒有)
66
+ // Array.from(CurrentLabelSet).forEach(label => {
67
+ // if (!ExistLabelSet.has(label)) {
68
+ // ExistLabelSet.delete(label)
69
+ // }
70
+ // })
71
+
72
+ // return Array.from(CurrentLabelSet)
73
+ // }),
74
+ // distinctUntilChanged((a, b) => {
75
+ // return JSON.stringify(a).length === JSON.stringify(b).length
76
+ // }),
77
+ // )
78
+ // }
79
+
80
+ export const categoryLabelsObservable = (CategoryDataMap$: Observable<Map<string, ComputedDataTree[]>>) => {
81
+ return CategoryDataMap$.pipe(
82
+ map(data => {
83
+ return Array.from(data.keys())
84
+ }),
85
+ distinctUntilChanged((a, b) => {
86
+ return JSON.stringify(a).length === JSON.stringify(b).length
87
+ }),
88
+ )
89
+ }
90
+
91
+ // 所有可見的節點
92
+ export const treeVisibleComputedDataObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
93
+ return computedData$.pipe(
94
+ map(data => {
95
+ function filterChildren (accTree: ComputedDataTree) {
96
+ if (accTree.children) {
97
+ accTree.children = accTree.children
98
+ .filter(child => child.visible) // 篩選visible
99
+ .map(child => filterChildren(child)) // 遞迴子節點
100
+ }
101
+ return accTree
102
+ }
103
+ return filterChildren(data)
104
+ })
105
+ )
106
106
  }
@@ -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
+ }