@orbcharts/core 3.0.4 → 3.0.6

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.
@@ -1,26 +1,37 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { ComputedDatumSeries, ComputedDataTypeMap, DataFormatterTypeMap, ContainerPosition, Layout } from '../../lib/core-types';
3
3
 
4
+ export declare const datumLabelsObservable: ({ computedData$ }: {
5
+ computedData$: Observable<ComputedDataTypeMap<"series">>;
6
+ }) => Observable<string[]>;
4
7
  export declare const separateSeriesObservable: ({ fullDataFormatter$ }: {
5
8
  fullDataFormatter$: Observable<DataFormatterTypeMap<"series">>;
6
9
  }) => Observable<boolean>;
10
+ export declare const separateLabelObservable: ({ fullDataFormatter$ }: {
11
+ fullDataFormatter$: Observable<DataFormatterTypeMap<"series">>;
12
+ }) => Observable<boolean>;
13
+ export declare const sumSeriesObservable: ({ fullDataFormatter$ }: {
14
+ fullDataFormatter$: Observable<DataFormatterTypeMap<"series">>;
15
+ }) => Observable<boolean>;
7
16
  export declare const seriesLabelsObservable: ({ computedData$ }: {
8
17
  computedData$: Observable<ComputedDataTypeMap<"series">>;
9
18
  }) => Observable<string[]>;
10
19
  export declare const seriesVisibleComputedDataObservable: ({ computedData$ }: {
11
20
  computedData$: Observable<ComputedDataTypeMap<"series">>;
12
21
  }) => Observable<ComputedDatumSeries[][]>;
13
- export declare const seriesComputedSortedDataObservable: ({ computedData$, fullDataFormatter$ }: {
22
+ export declare const seriesComputedSortedDataObservable: ({ computedData$, separateSeries$, separateLabel$, sumSeries$, datumLabels$ }: {
14
23
  computedData$: Observable<ComputedDataTypeMap<"series">>;
15
- fullDataFormatter$: Observable<DataFormatterTypeMap<"series">>;
24
+ separateSeries$: Observable<boolean>;
25
+ separateLabel$: Observable<boolean>;
26
+ sumSeries$: Observable<boolean>;
27
+ datumLabels$: Observable<string[]>;
16
28
  }) => Observable<ComputedDatumSeries[][]>;
17
- export declare const seriesContainerPositionObservable: ({ computedData$, fullDataFormatter$, layout$ }: {
18
- computedData$: Observable<ComputedDataTypeMap<"series">>;
29
+ export declare const seriesContainerPositionObservable: ({ computedSortedData$, fullDataFormatter$, layout$ }: {
30
+ computedSortedData$: Observable<ComputedDatumSeries[][]>;
19
31
  fullDataFormatter$: Observable<DataFormatterTypeMap<"series">>;
20
32
  layout$: Observable<Layout>;
21
33
  }) => Observable<ContainerPosition[]>;
22
- export declare const seriesContainerPositionMapObservable: ({ seriesContainerPosition$, seriesLabels$, separateSeries$ }: {
34
+ export declare const datumContainerPositionMapObservable: ({ seriesContainerPosition$, computedSortedData$ }: {
23
35
  seriesContainerPosition$: Observable<ContainerPosition[]>;
24
- seriesLabels$: Observable<string[]>;
25
- separateSeries$: Observable<boolean>;
36
+ computedSortedData$: Observable<ComputedDatumSeries[][]>;
26
37
  }) => Observable<Map<string, ContainerPosition>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbcharts/core",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Core codes for OrbCharts",
5
5
  "author": "Blue Planet Inc.",
6
6
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "vite-plugin-dts": "^3.7.3"
40
40
  },
41
41
  "dependencies": {
42
- "@orbcharts/core-types": "^3.0.2",
42
+ "@orbcharts/core-types": "^3.0.4",
43
43
  "d3": "^7.8.5",
44
44
  "rxjs": "^7.8.1"
45
45
  }
@@ -306,24 +306,24 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({
306
306
  width: options?.width ?? DEFAULT_CHART_OPTIONS.width,
307
307
  height: options?.height ?? DEFAULT_CHART_OPTIONS.height
308
308
  }).pipe(
309
- switchMap(size => {
310
- return iif(
311
- () => size.width === 'auto' || size.height === 'auto',
312
- // 有 'auto' 的話就監聽element的尺寸
313
- resizeObservable(element).pipe(
314
- map((d) => {
315
- return {
316
- width: size.width === 'auto' ? d.width : size.width,
317
- height: size.height === 'auto' ? d.height : size.height
318
- }
319
- })
320
- ),
321
- of(size as { width: number; height: number })
322
- )
323
- }),
324
- takeUntil(destroy$),
325
- share()
326
- )
309
+ switchMap(size => {
310
+ return iif(
311
+ () => size.width === 'auto' || size.height === 'auto',
312
+ // 有 'auto' 的話就監聽element的尺寸
313
+ resizeObservable(element).pipe(
314
+ map((d) => {
315
+ return {
316
+ width: size.width === 'auto' ? d.width : size.width,
317
+ height: size.height === 'auto' ? d.height : size.height
318
+ }
319
+ })
320
+ ),
321
+ of(size as { width: number; height: number })
322
+ )
323
+ }),
324
+ takeUntil(destroy$),
325
+ share()
326
+ )
327
327
  const rootSizeFiltered$ = of().pipe(
328
328
  mergeWith(
329
329
  rootSize$.pipe(
package/src/defaults.ts CHANGED
@@ -173,6 +173,7 @@ export const DEFAULT_DATA_FORMATTER_SERIES: DataFormatterSeries = {
173
173
  ...DEFAULT_DATA_FORMATTER_CONTAINER
174
174
  },
175
175
  separateSeries: false,
176
+ separateLabel: false,
176
177
  sumSeries: false
177
178
  // mapSeries: (datum, rowIndex, columnIndex, { data, dataFormatter }) => {
178
179
  // const seriesIndex = rowIndex >= dataFormatter.seriesLabels.length
@@ -139,6 +139,13 @@ export const contextObserverCallback: ContextObserverCallback<'grid'> = ({ subje
139
139
  shareReplay(1)
140
140
  )
141
141
 
142
+ const filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
143
+ computedData$: computedStackedData$,
144
+ groupScaleDomainValue$: groupScaleDomainValue$,
145
+ }).pipe(
146
+ shareReplay(1)
147
+ )
148
+
142
149
  const gridAxesTransform$ = gridAxesTransformObservable({
143
150
  fullDataFormatter$: observer.fullDataFormatter$,
144
151
  layout$: observer.layout$
@@ -193,6 +200,7 @@ export const contextObserverCallback: ContextObserverCallback<'grid'> = ({ subje
193
200
  computedStackedData$,
194
201
  groupScaleDomainValue$,
195
202
  filteredMinMaxValue$,
203
+ filteredStackedMinMaxValue$,
196
204
  gridAxesTransform$,
197
205
  gridAxesReverseTransform$,
198
206
  gridGraphicTransform$,
@@ -206,7 +206,7 @@ export const gridSeriesLabelsObservable = ({ computedData$ }: { computedData$: O
206
206
  })
207
207
  }),
208
208
  distinctUntilChanged((a, b) => {
209
- return JSON.stringify(a).length === JSON.stringify(b).length
209
+ return JSON.stringify(a) === JSON.stringify(b)
210
210
  }),
211
211
  )
212
212
  }
@@ -272,34 +272,10 @@ export const gridContainerPositionObservable = ({ computedData$, fullDataFormatt
272
272
  if (data.fullDataFormatter.separateSeries) {
273
273
  // -- 依slotIndexes計算 --
274
274
  return calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, data.computedData.length)
275
- // return data.computedData.map((seriesData, seriesIndex) => {
276
- // const columnIndex = seriesIndex % data.fullDataFormatter.container.columnAmount
277
- // const rowIndex = Math.floor(seriesIndex / data.fullDataFormatter.container.columnAmount)
278
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
279
- // return {
280
- // slotIndex: seriesIndex,
281
- // rowIndex,
282
- // columnIndex,
283
- // translate,
284
- // scale,
285
- // }
286
- // })
287
275
  } else {
288
276
  // -- 無拆分 --
289
277
  const gridContainerPositionArr = calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, 1)
290
278
  return data.computedData.map((d, i) => gridContainerPositionArr[0]) // 每個series相同位置
291
- // const columnIndex = 0
292
- // const rowIndex = 0
293
- // return data.computedData.map((seriesData, seriesIndex) => {
294
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
295
- // return {
296
- // slotIndex: 0,
297
- // rowIndex,
298
- // columnIndex,
299
- // translate,
300
- // scale,
301
- // }
302
- // })
303
279
  }
304
280
  })
305
281
  )
@@ -610,9 +586,11 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
610
586
  // })
611
587
 
612
588
  // const filteredMinMax = getMinMaxGrid(filteredData)
613
- if (filteredMinMaxValue[0] === filteredMinMaxValue[1] && filteredMinMaxValue[1] === 0) {
589
+ const filteredMin = filteredMinMaxValue[0]
590
+ let filteredMax = filteredMinMaxValue[1]
591
+ if (filteredMin === filteredMax && filteredMax === 0) {
614
592
  // filteredMinMaxValue[0] = filteredMinMaxValue[1] - 1 // 避免最大及最小值相同造成無法計算scale
615
- filteredMinMaxValue[1] = 1 // 避免最大及最小值同等於 0 造成無法計算scale
593
+ filteredMax = 1 // 避免最大及最小值同等於 0 造成無法計算scale
616
594
  }
617
595
 
618
596
  const valueAxisWidth = (valueAxis.position === 'left' || valueAxis.position === 'right')
@@ -620,8 +598,8 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
620
598
  : width
621
599
 
622
600
  const valueScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
623
- maxValue: filteredMinMaxValue[1],
624
- minValue: filteredMinMaxValue[0],
601
+ maxValue: filteredMax,
602
+ minValue: filteredMin,
625
603
  axisWidth: valueAxisWidth,
626
604
  scaleDomain: valueAxis.scaleDomain,
627
605
  scaleRange: valueAxis.scaleRange
@@ -635,9 +613,11 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
635
613
  // })
636
614
  // -- translateY, scaleY --
637
615
  const minMax = getMinMaxGrid(data)
638
- if (minMax[0] === minMax[1] && minMax[1] === 0) {
616
+ const min = minMax[0]
617
+ let max = minMax[1]
618
+ if (min === max && max === 0) {
639
619
  // minMax[0] = minMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
640
- minMax[1] = 1 // 避免最大及最小值同等於 0 造成無法計算scale
620
+ max = 1 // 避免最大及最小值同等於 0 造成無法計算scale
641
621
  }
642
622
  // const rangeMinY = valueScale(minMax[0])
643
623
  const rangeMinY = valueScale(minMax[0] > 0 ? 0 : minMax[0]) // * 因為原本的座標就是以 0 到最大值或最小值範範圍計算的,所以這邊也是用同樣的方式計算
@@ -1,11 +1,15 @@
1
1
  import {
2
2
  map,
3
- shareReplay } from 'rxjs'
3
+ switchMap,
4
+ merge,
5
+ forkJoin,
6
+ shareReplay,
7
+ Observable } from 'rxjs'
4
8
  import type { ContextObserverCallback, DataGridDatum } from '../../lib/core-types'
5
9
  import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
6
10
  import { textSizePxObservable, containerSizeObservable, highlightObservable } from '../utils/observables'
7
11
  // import { createMultiGridSeriesLabels } from '../utils/orbchartsUtils'
8
- import { combineLatest } from 'rxjs/internal/observable/combineLatest'
12
+ import { filteredMinMaxValueObservable } from '../grid/gridObservables'
9
13
 
10
14
  export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
11
15
 
@@ -59,6 +63,34 @@ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({
59
63
  // console.log('multiGridContainerPosition$', d)
60
64
  // })
61
65
 
66
+ const filteredMinMaxValue$: Observable<[number, number]> = multiGridEachDetail$.pipe(
67
+ switchMap(details => {
68
+ return forkJoin(details.map((detail, index) => {
69
+ return detail.filteredMinMaxValue$
70
+ }))
71
+ }),
72
+ map(filteredMinMaxValue => {
73
+ return [
74
+ Math.min(...filteredMinMaxValue.map(d => d[0])),
75
+ Math.max(...filteredMinMaxValue.map(d => d[1]))
76
+ ]
77
+ })
78
+ )
79
+
80
+ const filteredStackedMinMaxValue$: Observable<[number, number]> = multiGridEachDetail$.pipe(
81
+ switchMap(details => {
82
+ return forkJoin(details.map((detail, index) => {
83
+ return detail.filteredStackedMinMaxValue$
84
+ }))
85
+ }),
86
+ map(filteredMinMaxValue => {
87
+ return [
88
+ Math.min(...filteredMinMaxValue.map(d => d[0])),
89
+ Math.max(...filteredMinMaxValue.map(d => d[1]))
90
+ ]
91
+ })
92
+ )
93
+
62
94
  return {
63
95
  fullParams$: observer.fullParams$,
64
96
  fullChartParams$: observer.fullChartParams$,
@@ -69,6 +101,8 @@ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({
69
101
  containerSize$,
70
102
  multiGridHighlight$,
71
103
  multiGridContainerPosition$,
104
+ filteredMinMaxValue$,
105
+ filteredStackedMinMaxValue$,
72
106
  multiGridEachDetail$,
73
107
  // multiGridContainer$
74
108
  }
@@ -247,6 +247,14 @@ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData
247
247
  shareReplay(1)
248
248
  )
249
249
 
250
+ const filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
251
+ computedData$: computedStackedData$,
252
+ groupScaleDomainValue$: groupScaleDomainValue$,
253
+ }).pipe(
254
+ takeUntil(destroy$),
255
+ shareReplay(1)
256
+ )
257
+
250
258
  const gridAxesTransform$ = gridAxesTransformObservable({
251
259
  fullDataFormatter$: gridDataFormatter$,
252
260
  layout$: layout$
@@ -297,6 +305,7 @@ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData
297
305
  computedStackedData$,
298
306
  groupScaleDomainValue$,
299
307
  filteredMinMaxValue$,
308
+ filteredStackedMinMaxValue$,
300
309
  gridAxesTransform$,
301
310
  gridAxesReverseTransform$,
302
311
  gridGraphicTransform$,
@@ -351,50 +360,6 @@ export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$
351
360
  }
352
361
  return seriesContainerArr
353
362
  })
354
- // console.log('gridContainerPositionArr', gridContainerPositionArr)
355
-
356
- // let accGridSlotIndex = 0
357
-
358
- // const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
359
- // const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
360
-
361
- // if (grid.separateSeries) {
362
- // // -- 依seriesSlotIndexes計算 --
363
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
364
- // const currentSlotIndex = accGridSlotIndex + seriesIndex
365
- // const columnIndex = currentSlotIndex % data.fullDataFormatter.container.columnAmount
366
- // const rowIndex = Math.floor(currentSlotIndex / data.fullDataFormatter.container.columnAmount)
367
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
368
- // return {
369
- // slotIndex: currentSlotIndex,
370
- // rowIndex,
371
- // columnIndex,
372
- // translate,
373
- // scale,
374
- // }
375
- // })
376
- // accGridSlotIndex += seriesContainerArr.length
377
- // return seriesContainerArr
378
- // } else {
379
- // // -- 依grid的slotIndex計算 --
380
- // const columnIndex = accGridSlotIndex % data.fullDataFormatter.container.columnAmount
381
- // const rowIndex = Math.floor(accGridSlotIndex / data.fullDataFormatter.container.columnAmount)
382
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
383
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
384
- // return {
385
- // slotIndex: accGridSlotIndex,
386
- // rowIndex,
387
- // columnIndex,
388
- // translate,
389
- // scale,
390
- // }
391
- // })
392
- // if (data.fullDataFormatter.separateGrid) {
393
- // accGridSlotIndex += 1
394
- // }
395
- // return seriesContainerArr
396
- // }
397
- // })
398
363
 
399
364
  return gridContainerPositionArr
400
365
  }),