@orbcharts/core 3.0.0-alpha.40 → 3.0.0-alpha.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1152 -1124
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/dist/src/types/ChartParams.d.ts +1 -1
  5. package/dist/src/types/ContextObserverGrid.d.ts +1 -0
  6. package/dist/src/types/ContextObserverMultiGrid.d.ts +1 -0
  7. package/dist/src/types/ContextObserverSeries.d.ts +1 -0
  8. package/dist/src/types/ContextObserverTree.d.ts +1 -0
  9. package/dist/src/utils/observables.d.ts +1 -0
  10. package/package.json +41 -41
  11. package/src/AbstractChart.ts +48 -48
  12. package/src/GridChart.ts +20 -20
  13. package/src/MultiGridChart.ts +20 -20
  14. package/src/MultiValueChart.ts +20 -20
  15. package/src/RelationshipChart.ts +20 -20
  16. package/src/SeriesChart.ts +20 -20
  17. package/src/TreeChart.ts +20 -20
  18. package/src/base/createBaseChart.ts +367 -367
  19. package/src/base/createBasePlugin.ts +89 -89
  20. package/src/defaults.ts +248 -247
  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/computeGridData.ts +205 -205
  29. package/src/grid/createGridContextObserver.ts +130 -124
  30. package/src/grid/gridObservables.ts +486 -486
  31. package/src/index.ts +21 -21
  32. package/src/multiGrid/computeMultiGridData.ts +173 -173
  33. package/src/multiGrid/createMultiGridContextObserver.ts +40 -34
  34. package/src/multiGrid/multiGridObservables.ts +285 -285
  35. package/src/multiValue/computeMultiValueData.ts +136 -136
  36. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  37. package/src/relationship/computeRelationshipData.ts +106 -106
  38. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  39. package/src/series/computeSeriesData.ts +153 -153
  40. package/src/series/createSeriesContextObserver.ts +38 -33
  41. package/src/series/seriesObservables.ts +23 -23
  42. package/src/tree/computeTreeData.ts +128 -128
  43. package/src/tree/createTreeContextObserver.ts +61 -56
  44. package/src/tree/treeObservables.ts +94 -94
  45. package/src/types/Chart.ts +48 -48
  46. package/src/types/ChartParams.ts +51 -51
  47. package/src/types/ComputedData.ts +82 -82
  48. package/src/types/ComputedDataGrid.ts +13 -13
  49. package/src/types/ComputedDataMultiGrid.ts +2 -2
  50. package/src/types/ComputedDataMultiValue.ts +9 -9
  51. package/src/types/ComputedDataRelationship.ts +19 -19
  52. package/src/types/ComputedDataSeries.ts +7 -7
  53. package/src/types/ComputedDataTree.ts +19 -19
  54. package/src/types/ContextObserver.ts +38 -38
  55. package/src/types/ContextObserverGrid.ts +33 -33
  56. package/src/types/ContextObserverMultiGrid.ts +28 -27
  57. package/src/types/ContextObserverMultiValue.ts +4 -4
  58. package/src/types/ContextObserverRelationship.ts +4 -4
  59. package/src/types/ContextObserverSeries.ts +8 -7
  60. package/src/types/ContextObserverTree.ts +11 -10
  61. package/src/types/ContextSubject.ts +18 -18
  62. package/src/types/Data.ts +45 -45
  63. package/src/types/DataFormatter.ts +95 -95
  64. package/src/types/DataFormatterGrid.ts +55 -55
  65. package/src/types/DataFormatterMultiGrid.ts +42 -42
  66. package/src/types/DataFormatterMultiValue.ts +20 -20
  67. package/src/types/DataFormatterRelationship.ts +22 -22
  68. package/src/types/DataFormatterSeries.ts +29 -29
  69. package/src/types/DataFormatterTree.ts +12 -12
  70. package/src/types/DataGrid.ts +11 -11
  71. package/src/types/DataMultiGrid.ts +6 -6
  72. package/src/types/DataMultiValue.ts +12 -12
  73. package/src/types/DataRelationship.ts +27 -27
  74. package/src/types/DataSeries.ts +11 -11
  75. package/src/types/DataTree.ts +20 -20
  76. package/src/types/Event.ts +153 -153
  77. package/src/types/Layout.ts +11 -11
  78. package/src/types/Padding.ts +5 -5
  79. package/src/types/Plugin.ts +60 -60
  80. package/src/types/TransformData.ts +7 -7
  81. package/src/types/index.ts +37 -37
  82. package/src/utils/commonUtils.ts +50 -50
  83. package/src/utils/d3Utils.ts +89 -89
  84. package/src/utils/index.ts +4 -4
  85. package/src/utils/observables.ts +202 -181
  86. package/src/utils/orbchartsUtils.ts +253 -253
  87. package/tsconfig.json +13 -13
  88. package/vite.config.js +44 -44
@@ -1,89 +1,89 @@
1
- import { takeUntil, map, shareReplay, startWith, Subject, Observable } from 'rxjs'
2
- import type { ChartType, CreateBasePlugin, PluginInitFn, PluginContext } from '../types'
3
- import { mergeOptionsWithDefault } from '../utils'
4
-
5
- // 建立plugin實例
6
- function createPlugin <T extends ChartType, PluginName, PluginParams>({ name, defaultParams, initFn }: {
7
- name: PluginName
8
- defaultParams: PluginParams
9
- initFn: PluginInitFn<T, PluginName, PluginParams>
10
- }) {
11
-
12
- const destroy$ = new Subject()
13
- const params$: Subject<Partial<typeof defaultParams>> = new Subject()
14
- const StoreMap = new WeakMap() // 避免memory leak
15
- let pluginDestroyFn = () => {}
16
- let pluginContext: PluginContext<T, PluginName, PluginParams> | undefined
17
- let mergedDefaultParams: PluginParams = defaultParams
18
-
19
- // 建立plugin實例
20
- return {
21
- params$,
22
- name,
23
- defaultParams,
24
- init () {
25
- if (!pluginContext) {
26
- return
27
- }
28
- // 執行
29
- pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
30
- StoreMap.set(pluginContext.selection, pluginContext)
31
- },
32
- destroy () {
33
- pluginDestroyFn()
34
- if (pluginContext) {
35
- pluginContext.selection.remove()
36
- pluginContext = undefined
37
- }
38
- destroy$.next(undefined)
39
- },
40
- setPresetParams: (presetParams: Partial<PluginParams>) => {
41
- mergedDefaultParams = mergeOptionsWithDefault(presetParams, defaultParams)
42
- },
43
- setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
44
- pluginContext = _pluginContext
45
- pluginContext.observer.fullParams$ = params$
46
- .pipe(
47
- takeUntil(destroy$),
48
- startWith({}),
49
- map(d => mergeOptionsWithDefault(d, mergedDefaultParams)),
50
- shareReplay(1),
51
- )
52
- }
53
- }
54
- }
55
-
56
- // 建立plugin類別
57
- export const createBasePlugin: CreateBasePlugin = <T extends ChartType>() => {
58
-
59
- // 定義plugin
60
- return function definePlugin<PluginName, PluginParams>(name: PluginName, defaultParams: PluginParams) {
61
-
62
- // 定義plugin的初始化function
63
- return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
64
-
65
- return class Plugin {
66
- params$: Subject<Partial<PluginParams>>
67
- name: PluginName
68
- defaultParams: PluginParams
69
- // presetParams: Partial<PluginParams>
70
- init: () => void
71
- destroy: () => void
72
- setPresetParams: (presetParams: Partial<PluginParams>) => void
73
- setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
74
- constructor () {
75
- const pluginEntity = createPlugin<T, PluginName, PluginParams>({ name, defaultParams, initFn })
76
-
77
- this.params$ = pluginEntity.params$
78
- this.name = pluginEntity.name
79
- this.defaultParams = pluginEntity.defaultParams
80
- // this.presetParams = pluginEntity.presetParams
81
- this.init = pluginEntity.init
82
- this.destroy = pluginEntity.destroy
83
- this.setPresetParams = pluginEntity.setPresetParams
84
- this.setContext = pluginEntity.setContext
85
- }
86
- }
87
- }
88
- }
89
- }
1
+ import { takeUntil, map, shareReplay, startWith, Subject, Observable } from 'rxjs'
2
+ import type { ChartType, CreateBasePlugin, PluginInitFn, PluginContext } from '../types'
3
+ import { mergeOptionsWithDefault } from '../utils'
4
+
5
+ // 建立plugin實例
6
+ function createPlugin <T extends ChartType, PluginName, PluginParams>({ name, defaultParams, initFn }: {
7
+ name: PluginName
8
+ defaultParams: PluginParams
9
+ initFn: PluginInitFn<T, PluginName, PluginParams>
10
+ }) {
11
+
12
+ const destroy$ = new Subject()
13
+ const params$: Subject<Partial<typeof defaultParams>> = new Subject()
14
+ const StoreMap = new WeakMap() // 避免memory leak
15
+ let pluginDestroyFn = () => {}
16
+ let pluginContext: PluginContext<T, PluginName, PluginParams> | undefined
17
+ let mergedDefaultParams: PluginParams = defaultParams
18
+
19
+ // 建立plugin實例
20
+ return {
21
+ params$,
22
+ name,
23
+ defaultParams,
24
+ init () {
25
+ if (!pluginContext) {
26
+ return
27
+ }
28
+ // 執行
29
+ pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
30
+ StoreMap.set(pluginContext.selection, pluginContext)
31
+ },
32
+ destroy () {
33
+ pluginDestroyFn()
34
+ if (pluginContext) {
35
+ pluginContext.selection.remove()
36
+ pluginContext = undefined
37
+ }
38
+ destroy$.next(undefined)
39
+ },
40
+ setPresetParams: (presetParams: Partial<PluginParams>) => {
41
+ mergedDefaultParams = mergeOptionsWithDefault(presetParams, defaultParams)
42
+ },
43
+ setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
44
+ pluginContext = _pluginContext
45
+ pluginContext.observer.fullParams$ = params$
46
+ .pipe(
47
+ takeUntil(destroy$),
48
+ startWith({}),
49
+ map(d => mergeOptionsWithDefault(d, mergedDefaultParams)),
50
+ shareReplay(1),
51
+ )
52
+ }
53
+ }
54
+ }
55
+
56
+ // 建立plugin類別
57
+ export const createBasePlugin: CreateBasePlugin = <T extends ChartType>() => {
58
+
59
+ // 定義plugin
60
+ return function definePlugin<PluginName, PluginParams>(name: PluginName, defaultParams: PluginParams) {
61
+
62
+ // 定義plugin的初始化function
63
+ return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
64
+
65
+ return class Plugin {
66
+ params$: Subject<Partial<PluginParams>>
67
+ name: PluginName
68
+ defaultParams: PluginParams
69
+ // presetParams: Partial<PluginParams>
70
+ init: () => void
71
+ destroy: () => void
72
+ setPresetParams: (presetParams: Partial<PluginParams>) => void
73
+ setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
74
+ constructor () {
75
+ const pluginEntity = createPlugin<T, PluginName, PluginParams>({ name, defaultParams, initFn })
76
+
77
+ this.params$ = pluginEntity.params$
78
+ this.name = pluginEntity.name
79
+ this.defaultParams = pluginEntity.defaultParams
80
+ // this.presetParams = pluginEntity.presetParams
81
+ this.init = pluginEntity.init
82
+ this.destroy = pluginEntity.destroy
83
+ this.setPresetParams = pluginEntity.setPresetParams
84
+ this.setContext = pluginEntity.setContext
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }