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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +5 -4
  3. package/dist/orbcharts-core.umd.js +1 -1
  4. package/dist/src/types/ContextObserverGrid.d.ts +1 -1
  5. package/dist/src/types/ContextObserverSeries.d.ts +1 -1
  6. package/dist/src/types/ContextObserverTree.d.ts +1 -1
  7. package/dist/src/utils/observables.d.ts +5 -5
  8. package/package.json +41 -41
  9. package/src/AbstractChart.ts +48 -48
  10. package/src/GridChart.ts +20 -20
  11. package/src/MultiGridChart.ts +20 -20
  12. package/src/MultiValueChart.ts +20 -20
  13. package/src/RelationshipChart.ts +20 -20
  14. package/src/SeriesChart.ts +20 -20
  15. package/src/TreeChart.ts +20 -20
  16. package/src/base/createBaseChart.ts +367 -367
  17. package/src/base/createBasePlugin.ts +89 -89
  18. package/src/defaults.ts +247 -247
  19. package/src/defineGridPlugin.ts +3 -3
  20. package/src/defineMultiGridPlugin.ts +3 -3
  21. package/src/defineMultiValuePlugin.ts +3 -3
  22. package/src/defineNoneDataPlugin.ts +4 -4
  23. package/src/defineRelationshipPlugin.ts +3 -3
  24. package/src/defineSeriesPlugin.ts +3 -3
  25. package/src/defineTreePlugin.ts +3 -3
  26. package/src/grid/computeGridData.ts +205 -205
  27. package/src/grid/createGridContextObserver.ts +124 -124
  28. package/src/grid/gridObservables.ts +486 -486
  29. package/src/index.ts +21 -21
  30. package/src/multiGrid/computeMultiGridData.ts +173 -173
  31. package/src/multiGrid/createMultiGridContextObserver.ts +34 -34
  32. package/src/multiGrid/multiGridObservables.ts +285 -285
  33. package/src/multiValue/computeMultiValueData.ts +136 -136
  34. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  35. package/src/relationship/computeRelationshipData.ts +106 -106
  36. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  37. package/src/series/computeSeriesData.ts +153 -153
  38. package/src/series/createSeriesContextObserver.ts +33 -33
  39. package/src/series/seriesObservables.ts +23 -23
  40. package/src/tree/computeTreeData.ts +128 -128
  41. package/src/tree/createTreeContextObserver.ts +56 -56
  42. package/src/tree/treeObservables.ts +94 -94
  43. package/src/types/Chart.ts +48 -48
  44. package/src/types/ChartParams.ts +51 -51
  45. package/src/types/ComputedData.ts +82 -82
  46. package/src/types/ComputedDataGrid.ts +13 -13
  47. package/src/types/ComputedDataMultiGrid.ts +2 -2
  48. package/src/types/ComputedDataMultiValue.ts +9 -9
  49. package/src/types/ComputedDataRelationship.ts +19 -19
  50. package/src/types/ComputedDataSeries.ts +7 -7
  51. package/src/types/ComputedDataTree.ts +19 -19
  52. package/src/types/ContextObserver.ts +38 -38
  53. package/src/types/ContextObserverGrid.ts +33 -33
  54. package/src/types/ContextObserverMultiGrid.ts +27 -27
  55. package/src/types/ContextObserverMultiValue.ts +4 -4
  56. package/src/types/ContextObserverRelationship.ts +4 -4
  57. package/src/types/ContextObserverSeries.ts +7 -7
  58. package/src/types/ContextObserverTree.ts +10 -10
  59. package/src/types/ContextSubject.ts +18 -18
  60. package/src/types/Data.ts +45 -45
  61. package/src/types/DataFormatter.ts +95 -95
  62. package/src/types/DataFormatterGrid.ts +55 -55
  63. package/src/types/DataFormatterMultiGrid.ts +42 -42
  64. package/src/types/DataFormatterMultiValue.ts +20 -20
  65. package/src/types/DataFormatterRelationship.ts +22 -22
  66. package/src/types/DataFormatterSeries.ts +29 -29
  67. package/src/types/DataFormatterTree.ts +12 -12
  68. package/src/types/DataGrid.ts +11 -11
  69. package/src/types/DataMultiGrid.ts +6 -6
  70. package/src/types/DataMultiValue.ts +12 -12
  71. package/src/types/DataRelationship.ts +27 -27
  72. package/src/types/DataSeries.ts +11 -11
  73. package/src/types/DataTree.ts +20 -20
  74. package/src/types/Event.ts +153 -153
  75. package/src/types/Layout.ts +11 -11
  76. package/src/types/Padding.ts +5 -5
  77. package/src/types/Plugin.ts +60 -60
  78. package/src/types/TransformData.ts +7 -7
  79. package/src/types/index.ts +37 -37
  80. package/src/utils/commonUtils.ts +50 -50
  81. package/src/utils/d3Utils.ts +89 -89
  82. package/src/utils/index.ts +4 -4
  83. package/src/utils/observables.ts +181 -181
  84. package/src/utils/orbchartsUtils.ts +253 -253
  85. package/tsconfig.json +13 -13
  86. 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
+ }