@orbcharts/core 4.0.0-alpha.0 → 4.0.0-beta.0

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 (47) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +876 -865
  3. package/dist/orbcharts-core.umd.js +3 -3
  4. package/dist/src/types/Plugin.d.ts +1 -1
  5. package/package.json +1 -1
  6. package/src/OrbCharts.ts +34 -34
  7. package/src/chart/createChart.ts +1013 -996
  8. package/src/chart/createGraphData.ts +391 -391
  9. package/src/chart/createGridData.ts +247 -247
  10. package/src/chart/createMultivariateData.ts +181 -181
  11. package/src/chart/createSeriesData.ts +297 -297
  12. package/src/chart/createTreeData.ts +344 -344
  13. package/src/chart/defaults.ts +119 -119
  14. package/src/defineCanvasLayer.ts +23 -23
  15. package/src/defineCanvasPlugin.ts +38 -38
  16. package/src/defineSVGLayer.ts +23 -23
  17. package/src/defineSVGPlugin.ts +38 -38
  18. package/src/index.ts +8 -8
  19. package/src/layer/createLayer.ts +137 -137
  20. package/src/plugin/createPlugin.ts +487 -469
  21. package/src/test/createGraphData.test.ts +103 -103
  22. package/src/test/createTreeData.test.ts +97 -97
  23. package/src/test/simple-graph-test.js +51 -51
  24. package/src/test/simple-tree-test.js +58 -58
  25. package/src/types/Chart.ts +62 -62
  26. package/src/types/ChartContext.ts +41 -41
  27. package/src/types/Common.ts +4 -4
  28. package/src/types/Encoding.ts +42 -42
  29. package/src/types/Event.ts +25 -25
  30. package/src/types/Layers.ts +92 -92
  31. package/src/types/ModelData.ts +94 -94
  32. package/src/types/Plugin.ts +101 -98
  33. package/src/types/RawData.ts +67 -67
  34. package/src/types/RenderData.ts +15 -15
  35. package/src/types/Theme.ts +20 -20
  36. package/src/types/Validator.ts +35 -35
  37. package/src/types/index.ts +12 -12
  38. package/src/utils/aggregateUtils.ts +99 -99
  39. package/src/utils/colorUtils.ts +63 -63
  40. package/src/utils/commonUtils.ts +56 -56
  41. package/src/utils/dom-lifecycle.ts +164 -164
  42. package/src/utils/dom.ts +54 -54
  43. package/src/utils/errorMessage.ts +40 -40
  44. package/src/utils/index.ts +7 -7
  45. package/src/utils/observables.ts +16 -16
  46. package/src/utils/orbchartsUtils.ts +8 -8
  47. package/src/utils/validator.ts +127 -127
@@ -1,138 +1,138 @@
1
- import {
2
- Subject,
3
- BehaviorSubject,
4
- filter,
5
- takeUntil,
6
- switchMap,
7
- combineLatest,
8
- of,
9
- map,
10
- shareReplay,
11
- debounceTime,
12
- } from "rxjs"
13
- import type {
14
- DefineLayerConfig,
15
- LayerEntity,
16
- ExtendableContext,
17
- LayerEnableProps
18
- } from "../types"
19
- import { deepOverwrite } from "../utils/commonUtils"
20
- import { createOrbChartsErrorMessage, createValidatorErrorMessage, createValidatorWarningMessage } from "../utils"
21
-
22
- export const createLayer = <
23
- ExtendContext extends ExtendableContext,
24
- PluginParams extends Record<string, any>,
25
- LayerParams extends Record<string, any>
26
- >(elementType: 'canvas' | 'svg', config: DefineLayerConfig<'svg' | 'canvas', ExtendContext, PluginParams, LayerParams>): LayerEntity<ExtendContext, PluginParams, LayerParams> => {
27
-
28
- // let svgElement: SVGSVGElement | null = null
29
- // let canvasElement: HTMLCanvasElement | null = null
30
-
31
- const layerParams$ = new BehaviorSubject<LayerParams>(Object.assign({}, config.defaultParams))
32
-
33
- // let _context: ChartContext<ExtendContext> = {} as ChartContext<ExtendContext>
34
- let destroySetup = () => {}
35
-
36
- const enableProps$ = new BehaviorSubject<LayerEnableProps<'svg' | 'canvas', ExtendContext, PluginParams, LayerParams> | null>(null)
37
-
38
- const enabledProps$ = enableProps$.pipe(
39
- filter(enableProps => enableProps !== null)
40
- )
41
-
42
- // show
43
- combineLatest({
44
- layerParams: layerParams$,
45
- enabledProps: enabledProps$
46
- }).pipe(
47
- debounceTime(0)
48
- ).subscribe(({ layerParams, enabledProps }) => {
49
- destroySetup()
50
- destroySetup = elementType === 'svg' ?
51
- config.setup({
52
- svgG: (enabledProps as LayerEnableProps<'svg', ExtendContext, PluginParams, LayerParams>).svgG,
53
- // canvas: enabledProps.canvas,
54
- // context: Object.assign({}, enabledProps.context),
55
- context: enabledProps.context,
56
- pluginParams$: enabledProps.pluginParams$,
57
- layerParams$: layerParams$.pipe(
58
- map(params => {
59
- return deepOverwrite(params, enabledProps.initLayerParams ?? {})
60
- }),
61
- )
62
- })
63
- : config.setup({
64
- // svgG: enabledProps.svgG,
65
- canvas: (enabledProps as LayerEnableProps<'canvas', ExtendContext, PluginParams, LayerParams>).canvas,
66
- // context: Object.assign({}, enabledProps.context),
67
- context: enabledProps.context,
68
- pluginParams$: enabledProps.pluginParams$,
69
- layerParams$: layerParams$.pipe(
70
- map(params => {
71
- return deepOverwrite(params, enabledProps.initLayerParams ?? {})
72
- }),
73
- )
74
- })
75
- })
76
-
77
- // hide
78
- enableProps$.pipe(filter(enableProps => enableProps === null)).subscribe(() => {
79
- destroySetup()
80
- })
81
-
82
- return {
83
- _name: config.name,
84
- _defaultParams: config.defaultParams,
85
- _layerIndex: config.layerIndex,
86
- _initShow: config.initShow,
87
- _enable: (enableProps) => {
88
- enableProps$.next(enableProps)
89
- },
90
- _disable: () => {
91
- enableProps$.next(null)
92
- },
93
- // setParams: (partial) => {
94
- // previousParams$.next(deepOverwrite(defaultParams$.getValue(), partial))
95
- // },
96
- _updateParams: (patch) => {
97
- try {
98
- // 檢查 data$ 資料格式是否正確
99
- const { status, columnName, expectToBe } = config.validator(patch)
100
- if (status === 'error') {
101
- throw new Error(createValidatorErrorMessage({
102
- columnName,
103
- expectToBe,
104
- from: `${config.name}.params$`
105
- }))
106
- } else if (status === 'warning') {
107
- console.warn(createValidatorWarningMessage({
108
- columnName,
109
- expectToBe,
110
- from: `${config.name}.params$`
111
- }))
112
- }
113
- } catch (e) {
114
- // throw new Error(e.message)
115
- // 驗證失敗仍繼續執行,才不會把 Observable 資料流給中斷掉
116
- console.error(createOrbChartsErrorMessage(e))
117
- }
118
- const layerParams = deepOverwrite(layerParams$.getValue(), patch)
119
- layerParams$.next(layerParams)
120
- },
121
- _forceReplaceParams: (full) => {
122
- layerParams$.next(full)
123
- },
124
- _getParams: () => {
125
- return layerParams$.getValue()
126
- },
127
- // injectContext: (context) => {
128
- // _context = Object.assign({}, context)
129
- // // re-setup layer with new context
130
- // enableProps$.next(true)
131
- // },
132
- _destroy: () => {
133
- enableProps$.next(null)
134
- enableProps$.complete()
135
- layerParams$.complete()
136
- }
137
- }
1
+ import {
2
+ Subject,
3
+ BehaviorSubject,
4
+ filter,
5
+ takeUntil,
6
+ switchMap,
7
+ combineLatest,
8
+ of,
9
+ map,
10
+ shareReplay,
11
+ debounceTime,
12
+ } from "rxjs"
13
+ import type {
14
+ DefineLayerConfig,
15
+ LayerEntity,
16
+ ExtendableContext,
17
+ LayerEnableProps
18
+ } from "../types"
19
+ import { deepOverwrite } from "../utils/commonUtils"
20
+ import { createOrbChartsErrorMessage, createValidatorErrorMessage, createValidatorWarningMessage } from "../utils"
21
+
22
+ export const createLayer = <
23
+ ExtendContext extends ExtendableContext,
24
+ PluginParams extends Record<string, any>,
25
+ LayerParams extends Record<string, any>
26
+ >(elementType: 'canvas' | 'svg', config: DefineLayerConfig<'svg' | 'canvas', ExtendContext, PluginParams, LayerParams>): LayerEntity<ExtendContext, PluginParams, LayerParams> => {
27
+
28
+ // let svgElement: SVGSVGElement | null = null
29
+ // let canvasElement: HTMLCanvasElement | null = null
30
+
31
+ const layerParams$ = new BehaviorSubject<LayerParams>(Object.assign({}, config.defaultParams))
32
+
33
+ // let _context: ChartContext<ExtendContext> = {} as ChartContext<ExtendContext>
34
+ let destroySetup = () => {}
35
+
36
+ const enableProps$ = new BehaviorSubject<LayerEnableProps<'svg' | 'canvas', ExtendContext, PluginParams, LayerParams> | null>(null)
37
+
38
+ const enabledProps$ = enableProps$.pipe(
39
+ filter(enableProps => enableProps !== null)
40
+ )
41
+
42
+ // show
43
+ combineLatest({
44
+ layerParams: layerParams$,
45
+ enabledProps: enabledProps$
46
+ }).pipe(
47
+ debounceTime(0)
48
+ ).subscribe(({ layerParams, enabledProps }) => {
49
+ destroySetup()
50
+ destroySetup = elementType === 'svg' ?
51
+ config.setup({
52
+ svgG: (enabledProps as LayerEnableProps<'svg', ExtendContext, PluginParams, LayerParams>).svgG,
53
+ // canvas: enabledProps.canvas,
54
+ // context: Object.assign({}, enabledProps.context),
55
+ context: enabledProps.context,
56
+ pluginParams$: enabledProps.pluginParams$,
57
+ layerParams$: layerParams$.pipe(
58
+ map(params => {
59
+ return deepOverwrite(params, enabledProps.initLayerParams ?? {})
60
+ }),
61
+ )
62
+ })
63
+ : config.setup({
64
+ // svgG: enabledProps.svgG,
65
+ canvas: (enabledProps as LayerEnableProps<'canvas', ExtendContext, PluginParams, LayerParams>).canvas,
66
+ // context: Object.assign({}, enabledProps.context),
67
+ context: enabledProps.context,
68
+ pluginParams$: enabledProps.pluginParams$,
69
+ layerParams$: layerParams$.pipe(
70
+ map(params => {
71
+ return deepOverwrite(params, enabledProps.initLayerParams ?? {})
72
+ }),
73
+ )
74
+ })
75
+ })
76
+
77
+ // hide
78
+ enableProps$.pipe(filter(enableProps => enableProps === null)).subscribe(() => {
79
+ destroySetup()
80
+ })
81
+
82
+ return {
83
+ _name: config.name,
84
+ _defaultParams: config.defaultParams,
85
+ _layerIndex: config.layerIndex,
86
+ _initShow: config.initShow,
87
+ _enable: (enableProps) => {
88
+ enableProps$.next(enableProps)
89
+ },
90
+ _disable: () => {
91
+ enableProps$.next(null)
92
+ },
93
+ // setParams: (partial) => {
94
+ // previousParams$.next(deepOverwrite(defaultParams$.getValue(), partial))
95
+ // },
96
+ _updateParams: (patch) => {
97
+ try {
98
+ // 檢查 data$ 資料格式是否正確
99
+ const { status, columnName, expectToBe } = config.validator(patch)
100
+ if (status === 'error') {
101
+ throw new Error(createValidatorErrorMessage({
102
+ columnName,
103
+ expectToBe,
104
+ from: `${config.name}.params$`
105
+ }))
106
+ } else if (status === 'warning') {
107
+ console.warn(createValidatorWarningMessage({
108
+ columnName,
109
+ expectToBe,
110
+ from: `${config.name}.params$`
111
+ }))
112
+ }
113
+ } catch (e) {
114
+ // throw new Error(e.message)
115
+ // 驗證失敗仍繼續執行,才不會把 Observable 資料流給中斷掉
116
+ console.error(createOrbChartsErrorMessage(e))
117
+ }
118
+ const layerParams = deepOverwrite(layerParams$.getValue(), patch)
119
+ layerParams$.next(layerParams)
120
+ },
121
+ _forceReplaceParams: (full) => {
122
+ layerParams$.next(full)
123
+ },
124
+ _getParams: () => {
125
+ return layerParams$.getValue()
126
+ },
127
+ // injectContext: (context) => {
128
+ // _context = Object.assign({}, context)
129
+ // // re-setup layer with new context
130
+ // enableProps$.next(true)
131
+ // },
132
+ _destroy: () => {
133
+ enableProps$.next(null)
134
+ enableProps$.complete()
135
+ layerParams$.complete()
136
+ }
137
+ }
138
138
  }