@orbcharts/core 3.0.0-beta.9 → 3.0.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 (35) hide show
  1. package/dist/orbcharts-core.es.js +2779 -2398
  2. package/dist/orbcharts-core.umd.js +4 -4
  3. package/dist/src/defaults.d.ts +2 -1
  4. package/dist/src/utils/gridObservables.d.ts +8 -4
  5. package/dist/src/utils/index.d.ts +0 -3
  6. package/dist/src/utils/multiGridObservables.d.ts +3 -2
  7. package/dist/src/utils/multiValueObservables.d.ts +76 -29
  8. package/dist/src/utils/observables.d.ts +8 -1
  9. package/dist/src/utils/orbchartsUtils.d.ts +9 -9
  10. package/dist/src/utils/seriesObservables.d.ts +1 -1
  11. package/package.json +2 -2
  12. package/src/base/createBaseChart.ts +4 -3
  13. package/src/base/createBasePlugin.ts +5 -4
  14. package/src/base/validators/chartParamsValidator.ts +4 -4
  15. package/src/defaults.ts +54 -10
  16. package/src/grid/contextObserverCallback.ts +31 -9
  17. package/src/grid/dataFormatterValidator.ts +42 -23
  18. package/src/multiGrid/contextObserverCallback.ts +38 -7
  19. package/src/multiValue/computedDataFn.ts +4 -1
  20. package/src/multiValue/contextObserverCallback.ts +159 -43
  21. package/src/multiValue/dataFormatterValidator.ts +85 -5
  22. package/src/multiValue/dataValidator.ts +9 -6
  23. package/src/relationship/computedDataFn.ts +37 -22
  24. package/src/relationship/dataFormatterValidator.ts +10 -6
  25. package/src/relationship/dataValidator.ts +10 -6
  26. package/src/series/contextObserverCallback.ts +18 -11
  27. package/src/tree/dataValidator.ts +1 -1
  28. package/src/utils/gridObservables.ts +32 -10
  29. package/src/utils/index.ts +3 -3
  30. package/src/utils/multiGridObservables.ts +34 -25
  31. package/src/utils/multiValueObservables.ts +479 -97
  32. package/src/utils/observables.ts +77 -15
  33. package/src/utils/orbchartsUtils.ts +9 -9
  34. package/src/utils/seriesObservables.ts +4 -4
  35. package/src/utils/validator.ts +1 -1
@@ -15,6 +15,7 @@ import type {
15
15
  ComputedDatumBase,
16
16
  ComputedDataTypeMap,
17
17
  ComputedDatumTypeMap,
18
+ ContainerPositionScaled,
18
19
  DataFormatterTypeMap,
19
20
  EventTypeMap,
20
21
  HighlightTarget,
@@ -45,6 +46,15 @@ export function resizeObservable(elem: HTMLElement | Element): Observable<DOMRec
45
46
  })
46
47
  }
47
48
 
49
+ interface HighlightTargetValue {
50
+ id: string | null
51
+ label: string | null
52
+ seriesLabel: string | null
53
+ groupLabel: string | null
54
+ categoryLabel: string | null
55
+ highlightDefault: string | null
56
+ }
57
+
48
58
  // 通用 highlight Observable
49
59
  export const highlightObservable = <T extends ChartType, D>({ datumList$, fullChartParams$, event$ }: {
50
60
  datumList$: Observable<D[]>
@@ -54,42 +64,46 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
54
64
  const destroy$ = new Subject()
55
65
 
56
66
  // 預設的highlight
57
- const highlightDefault$ = fullChartParams$.pipe(
67
+ const highlightDefault$: Observable<HighlightTargetValue> = fullChartParams$.pipe(
58
68
  takeUntil(destroy$),
59
69
  map(d => {
60
70
  return {
61
71
  id: null,
72
+ label: null,
62
73
  seriesLabel: null,
63
74
  groupLabel: null,
64
75
  categoryLabel: null,
65
76
  highlightDefault: d.highlightDefault
66
- }
77
+ } as HighlightTargetValue
67
78
  }),
68
79
  distinctUntilChanged()
69
80
  )
70
81
 
71
82
  // 事件觸發的highlight
72
- const highlightMouseover$ = event$.pipe(
83
+ const highlightMouseover$: Observable<HighlightTargetValue> = event$.pipe(
73
84
  takeUntil(destroy$),
74
85
  // filter(d => d.eventName === 'mouseover' || d.eventName === 'mousemove'),
75
86
  filter(d => d.eventName === 'mouseover'),
76
87
  // distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
77
- map(d => {
78
- return (d as any).datum
88
+ map(_d => {
89
+ const d = _d as any
90
+ return d.datum
79
91
  ? {
80
- id: ((d as any).datum as any).id,
81
- seriesLabel: ((d as any).datum as any).seriesLabel,
82
- groupLabel: ((d as any).datum as any).groupLabel,
83
- categoryLabel: ((d as any).datum as any).categoryLabel,
92
+ id: d.datum.id,
93
+ label: d.datum.label,
94
+ seriesLabel: d.datum.seriesLabel,
95
+ groupLabel: d.datum.groupLabel,
96
+ categoryLabel: d.datum.categoryLabel,
84
97
  highlightDefault: null
85
- }
98
+ } as HighlightTargetValue
86
99
  : {
87
100
  id: null,
101
+ label: null,
88
102
  seriesLabel: null,
89
103
  groupLabel: null,
90
104
  categoryLabel: null,
91
105
  highlightDefault: null
92
- }
106
+ } as HighlightTargetValue
93
107
  })
94
108
  )
95
109
  const highlightMouseout$ = event$.pipe(
@@ -102,9 +116,14 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
102
116
  switchMap(d => highlightDefault$)
103
117
  )
104
118
 
105
- function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null) {
106
- const datum = datumList.find(d => (d as ComputedDatumBase).id === id)
107
- return datum ? [datum] : []
119
+ // function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null) {
120
+ // const datum = datumList.find(d => (d as ComputedDatumBase).id === id)
121
+ // return datum ? [datum] : []
122
+ // }
123
+ function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null, label: string | null) {
124
+ return id == null && label == null
125
+ ? []
126
+ : datumList.filter(d => (d as ComputedDatumBase).id === id || (d as ComputedDatumBase).label === label)
108
127
  }
109
128
 
110
129
  function getSeriesIds (datumList: ComputedDatumTypeMap<T>[], seriesLabel: string | null) {
@@ -136,7 +155,7 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
136
155
  ).subscribe(data => {
137
156
  let datumList: ComputedDatumTypeMap<T>[] = []
138
157
  if (data.fullChartParams.highlightTarget === 'datum') {
139
- datumList = getDatumIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.id)
158
+ datumList = getDatumIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.id, data.target.label)
140
159
  } else if (data.fullChartParams.highlightTarget === 'series') {
141
160
  datumList = getSeriesIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.seriesLabel)
142
161
  } else if (data.fullChartParams.highlightTarget === 'group') {
@@ -217,4 +236,47 @@ export const textSizePxObservable = (chartParams$: Observable<ChartParams>) => {
217
236
  return value ? value : 14 // default
218
237
  })
219
238
  )
239
+ }
240
+
241
+ export const containerSizeObservable = ({ layout$, containerPosition$ }: {
242
+ layout$: Observable<Layout>
243
+ containerPosition$: Observable<ContainerPositionScaled[]>
244
+ }) => {
245
+ const rowAmount$ = containerPosition$.pipe(
246
+ map(containerPosition => {
247
+ const maxRowIndex = containerPosition.reduce((acc, current) => {
248
+ return current.rowIndex > acc ? current.rowIndex : acc
249
+ }, 0)
250
+ return maxRowIndex + 1
251
+ }),
252
+ distinctUntilChanged(),
253
+ )
254
+
255
+ const columnAmount$ = containerPosition$.pipe(
256
+ map(containerPosition => {
257
+ const maxColumnIndex = containerPosition.reduce((acc, current) => {
258
+ return current.columnIndex > acc ? current.columnIndex : acc
259
+ }, 0)
260
+ return maxColumnIndex + 1
261
+ }),
262
+ distinctUntilChanged()
263
+ )
264
+
265
+ return combineLatest({
266
+ layout: layout$,
267
+ rowAmount: rowAmount$,
268
+ columnAmount: columnAmount$
269
+ }).pipe(
270
+ switchMap(async (d) => d),
271
+ map(data => {
272
+ const width = (data.layout.rootWidth / data.columnAmount) - (data.layout.left + data.layout.right)
273
+ const height = (data.layout.rootHeight / data.rowAmount) - (data.layout.top + data.layout.bottom)
274
+ return {
275
+ width,
276
+ height
277
+ }
278
+ }),
279
+ distinctUntilChanged((a, b) => a.width === b.width && a.height === b.height),
280
+ // shareReplay(1)
281
+ )
220
282
  }
@@ -13,7 +13,7 @@ import type {
13
13
  DataMultiValue,
14
14
  DataMultiValueDatum,
15
15
  DataMultiValueValue,
16
- ComputedLayoutDatumMultiValue,
16
+ ComputedXYDatumMultiValue,
17
17
  DataFormatterContainer,
18
18
  SeriesDirection,
19
19
  DataFormatterGridGrid,
@@ -192,17 +192,17 @@ export function getMinMaxMultiValue (data: DataMultiValue, valueIndex: number):
192
192
  }
193
193
 
194
194
  export function getMinMaxMultiValueXY ({ data, minX, maxX, minY, maxY }: {
195
- data: ComputedLayoutDatumMultiValue[][]
195
+ data: ComputedXYDatumMultiValue[][]
196
196
  minX: number
197
197
  maxX: number
198
198
  minY: number
199
199
  maxY: number
200
200
  }) {
201
- let filteredData: ComputedLayoutDatumMultiValue[][] = []
202
- let minXDatum: ComputedLayoutDatumMultiValue | null = null
203
- let maxXDatum: ComputedLayoutDatumMultiValue | null = null
204
- let minYDatum: ComputedLayoutDatumMultiValue | null = null
205
- let maxYDatum: ComputedLayoutDatumMultiValue | null = null
201
+ let filteredData: ComputedXYDatumMultiValue[][] = []
202
+ let minXDatum: ComputedXYDatumMultiValue | null = null
203
+ let maxXDatum: ComputedXYDatumMultiValue | null = null
204
+ let minYDatum: ComputedXYDatumMultiValue | null = null
205
+ let maxYDatum: ComputedXYDatumMultiValue | null = null
206
206
 
207
207
  for (let categoryData of data) {
208
208
  for (let datum of categoryData) {
@@ -291,7 +291,7 @@ function calcGridDimensions (amount: number): { rowAmount: number; columnAmount:
291
291
  return { rowAmount, columnAmount }
292
292
  }
293
293
 
294
- export function calcSeriesContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPosition[] {
294
+ export function calcContainerPosition (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPosition[] {
295
295
  const { gap } = container
296
296
  const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
297
297
  // 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
@@ -324,7 +324,7 @@ export function calcSeriesContainerLayout (layout: Layout, container: DataFormat
324
324
  })
325
325
  }
326
326
 
327
- export function calcGridContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPositionScaled[] {
327
+ export function calcContainerPositionScaled (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPositionScaled[] {
328
328
  const { gap } = container
329
329
  const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
330
330
  // 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
@@ -16,7 +16,7 @@ import type {
16
16
  DataFormatterTypeMap,
17
17
  ContainerPosition,
18
18
  Layout } from '../../lib/core-types'
19
- import { calcSeriesContainerLayout } from './orbchartsUtils'
19
+ import { calcContainerPosition } from './orbchartsUtils'
20
20
 
21
21
  export const separateSeriesObservable = ({ fullDataFormatter$ }: { fullDataFormatter$: Observable<DataFormatterTypeMap<'series'>> }) => {
22
22
  return fullDataFormatter$.pipe(
@@ -50,7 +50,7 @@ export const seriesVisibleComputedDataObservable = ({ computedData$ }: { compute
50
50
  )
51
51
  }
52
52
 
53
- export const seriesComputedLayoutDataObservable = ({ computedData$, fullDataFormatter$ }: {
53
+ export const seriesComputedSortedDataObservable = ({ computedData$, fullDataFormatter$ }: {
54
54
  computedData$: Observable<ComputedDataTypeMap<'series'>>,
55
55
  fullDataFormatter$: Observable<DataFormatterTypeMap<'series'>>
56
56
  }) => {
@@ -109,7 +109,7 @@ export const seriesContainerPositionObservable = ({ computedData$, fullDataForma
109
109
 
110
110
  if (data.fullDataFormatter.separateSeries) {
111
111
  // -- 依slotIndexes計算 --
112
- return calcSeriesContainerLayout(data.layout, data.fullDataFormatter.container, data.computedData.length)
112
+ return calcContainerPosition(data.layout, data.fullDataFormatter.container, data.computedData.length)
113
113
  // return data.computedData.map((seriesData, seriesIndex) => {
114
114
  // const columnIndex = seriesIndex % data.fullDataFormatter.container.columnAmount
115
115
  // const rowIndex = Math.floor(seriesIndex / data.fullDataFormatter.container.columnAmount)
@@ -128,7 +128,7 @@ export const seriesContainerPositionObservable = ({ computedData$, fullDataForma
128
128
  // })
129
129
  } else {
130
130
  // -- 無拆分 --
131
- return calcSeriesContainerLayout(data.layout, data.fullDataFormatter.container, 1)
131
+ return calcContainerPosition(data.layout, data.fullDataFormatter.container, 1)
132
132
  // const columnIndex = 0
133
133
  // const rowIndex = 0
134
134
  // return data.computedData.map((seriesData, seriesIndex) => {
@@ -46,7 +46,7 @@ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
46
46
  || value === 'label'
47
47
  || value === 'primary'
48
48
  || value === 'secondary'
49
- || value === 'white'
49
+ || value === 'labelContrast'
50
50
  || value === 'background'
51
51
  },
52
52
  }