@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.
- package/dist/orbcharts-core.es.js +2779 -2398
- package/dist/orbcharts-core.umd.js +4 -4
- package/dist/src/defaults.d.ts +2 -1
- package/dist/src/utils/gridObservables.d.ts +8 -4
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/src/utils/multiGridObservables.d.ts +3 -2
- package/dist/src/utils/multiValueObservables.d.ts +76 -29
- package/dist/src/utils/observables.d.ts +8 -1
- package/dist/src/utils/orbchartsUtils.d.ts +9 -9
- package/dist/src/utils/seriesObservables.d.ts +1 -1
- package/package.json +2 -2
- package/src/base/createBaseChart.ts +4 -3
- package/src/base/createBasePlugin.ts +5 -4
- package/src/base/validators/chartParamsValidator.ts +4 -4
- package/src/defaults.ts +54 -10
- package/src/grid/contextObserverCallback.ts +31 -9
- package/src/grid/dataFormatterValidator.ts +42 -23
- package/src/multiGrid/contextObserverCallback.ts +38 -7
- package/src/multiValue/computedDataFn.ts +4 -1
- package/src/multiValue/contextObserverCallback.ts +159 -43
- package/src/multiValue/dataFormatterValidator.ts +85 -5
- package/src/multiValue/dataValidator.ts +9 -6
- package/src/relationship/computedDataFn.ts +37 -22
- package/src/relationship/dataFormatterValidator.ts +10 -6
- package/src/relationship/dataValidator.ts +10 -6
- package/src/series/contextObserverCallback.ts +18 -11
- package/src/tree/dataValidator.ts +1 -1
- package/src/utils/gridObservables.ts +32 -10
- package/src/utils/index.ts +3 -3
- package/src/utils/multiGridObservables.ts +34 -25
- package/src/utils/multiValueObservables.ts +479 -97
- package/src/utils/observables.ts +77 -15
- package/src/utils/orbchartsUtils.ts +9 -9
- package/src/utils/seriesObservables.ts +4 -4
- package/src/utils/validator.ts +1 -1
package/src/utils/observables.ts
CHANGED
@@ -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
|
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
|
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(
|
78
|
-
|
88
|
+
map(_d => {
|
89
|
+
const d = _d as any
|
90
|
+
return d.datum
|
79
91
|
? {
|
80
|
-
id:
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
107
|
-
|
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
|
-
|
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:
|
195
|
+
data: ComputedXYDatumMultiValue[][]
|
196
196
|
minX: number
|
197
197
|
maxX: number
|
198
198
|
minY: number
|
199
199
|
maxY: number
|
200
200
|
}) {
|
201
|
-
let filteredData:
|
202
|
-
let minXDatum:
|
203
|
-
let maxXDatum:
|
204
|
-
let minYDatum:
|
205
|
-
let maxYDatum:
|
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
|
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
|
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 {
|
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
|
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
|
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
|
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) => {
|
package/src/utils/validator.ts
CHANGED