@orbcharts/core 3.0.0-alpha.39 → 3.0.0-alpha.41

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ import { ContextObserverBase } from './ContextObserver';
3
3
  import { ContainerPosition, ContextObserverGridDetail } from './ContextObserverGrid';
4
4
 
5
5
  export interface ContextObserverMultiGrid<PluginParams> extends ContextObserverBase<'multiGrid', PluginParams> {
6
+ textSizePx$: Observable<number>;
6
7
  multiGridEachDetail$: Observable<ContextObserverGridDetail[]>;
7
8
  multiGridContainer$: Observable<ContainerPosition[][]>;
8
9
  }
@@ -3,6 +3,7 @@ import { ContextObserverBase } from './ContextObserver';
3
3
  import { ComputedDatumSeries } from './ComputedDataSeries';
4
4
 
5
5
  export interface ContextObserverSeries<PluginParams> extends ContextObserverBase<'series', PluginParams> {
6
- seriesHighlight$: Observable<string[]>;
6
+ textSizePx$: Observable<number>;
7
+ seriesHighlight$: Observable<ComputedDatumSeries[]>;
7
8
  SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>;
8
9
  }
@@ -3,7 +3,8 @@ import { ContextObserverBase } from './ContextObserver';
3
3
  import { ComputedDataTree } from './ComputedDataTree';
4
4
 
5
5
  export interface ContextObserverTree<PluginParams> extends ContextObserverBase<'tree', PluginParams> {
6
- treeHighlight$: Observable<string[]>;
6
+ textSizePx$: Observable<number>;
7
+ treeHighlight$: Observable<ComputedDataTree[]>;
7
8
  existCategoryLabels$: Observable<string[]>;
8
9
  CategoryDataMap$: Observable<Map<string, ComputedDataTree[]>>;
9
10
  visibleComputedData$: Observable<ComputedDataTree>;
@@ -1,11 +1,11 @@
1
1
  import { Subject, Observable } from 'rxjs';
2
- import { ChartParams, ComputedDatumTypeMap } from '../types';
2
+ import { ChartType, ChartParams, ComputedDatumTypeMap, EventTypeMap } from '../types';
3
3
 
4
- export declare const highlightObservable: ({ datumList$, fullChartParams$, event$ }: {
5
- datumList$: Observable<ComputedDatumTypeMap<"series" | "grid" | "multiValue" | "relationship" | "tree">[]>;
4
+ export declare const highlightObservable: <T extends ChartType, D>({ datumList$, fullChartParams$, event$ }: {
5
+ datumList$: Observable<D[]>;
6
6
  fullChartParams$: Observable<ChartParams>;
7
- event$: Subject<any>;
8
- }) => Observable<string[]>;
7
+ event$: Subject<EventTypeMap<T>>;
8
+ }) => Observable<D[]>;
9
9
  export declare const seriesDataMapObservable: <DatumType extends ComputedDatumTypeMap<"series" | "grid">>({ datumList$ }: {
10
10
  datumList$: Observable<DatumType[]>;
11
11
  }) => Observable<Map<string, DatumType[]>>;
@@ -15,3 +15,4 @@ export declare const groupDataMapObservable: <DatumType extends ComputedDatumTyp
15
15
  export declare const categoryDataMapObservable: <DatumType extends ComputedDatumTypeMap<"multiValue" | "relationship" | "tree">>({ datumList$ }: {
16
16
  datumList$: Observable<DatumType[]>;
17
17
  }) => Observable<Map<string, DatumType[]>>;
18
+ export declare const textSizePxObservable: (chartParams$: Observable<ChartParams>) => Observable<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbcharts/core",
3
- "version": "3.0.0-alpha.39",
3
+ "version": "3.0.0-alpha.41",
4
4
  "description": "OrbCharts is an open source chart library based on d3.js and rx.js",
5
5
  "author": "Blue Planet Inc.",
6
6
  "license": "Apache-2.0",
package/src/defaults.ts CHANGED
@@ -73,7 +73,8 @@ export const CHART_PARAMS_DEFAULT: ChartParams = {
73
73
  }
74
74
  },
75
75
  styles: {
76
- textSize: 14,
76
+ // textSize: 14,
77
+ textSize: '1rem',
77
78
  unhighlightedOpacity: 0.3
78
79
  },
79
80
  transitionDuration: 800,
@@ -3,7 +3,8 @@ import type { ContextObserverFn } from '../types'
3
3
  import {
4
4
  highlightObservable,
5
5
  seriesDataMapObservable,
6
- groupDataMapObservable } from '../utils/observables'
6
+ groupDataMapObservable,
7
+ textSizePxObservable } from '../utils/observables'
7
8
  import {
8
9
  gridAxesTransformObservable,
9
10
  gridAxesReverseTransformObservable,
@@ -17,6 +18,10 @@ import {
17
18
 
18
19
  export const createGridContextObserver: ContextObserverFn<'grid'> = ({ subject, observer }) => {
19
20
 
21
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
22
+ shareReplay(1)
23
+ )
24
+
20
25
  const isSeriesPositionSeprate$ = isSeriesPositionSeprateObservable({
21
26
  computedData$: observer.computedData$,
22
27
  fullDataFormatter$: observer.fullDataFormatter$
@@ -108,6 +113,7 @@ export const createGridContextObserver: ContextObserverFn<'grid'> = ({ subject,
108
113
  fullDataFormatter$: observer.fullDataFormatter$,
109
114
  computedData$: observer.computedData$,
110
115
  layout$: observer.layout$,
116
+ textSizePx$,
111
117
  isSeriesPositionSeprate$,
112
118
  gridContainer$,
113
119
  gridAxesTransform$,
@@ -2,9 +2,14 @@ import {
2
2
  shareReplay } from 'rxjs'
3
3
  import type { ContextObserverFn } from '../types'
4
4
  import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
5
+ import { textSizePxObservable } from '../utils/observables'
5
6
 
6
7
  export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
7
8
 
9
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
10
+ shareReplay(1)
11
+ )
12
+
8
13
  const multiGridEachDetail$ = multiGridEachDetailObservable({
9
14
  fullDataFormatter$: observer.fullDataFormatter$,
10
15
  computedData$: observer.computedData$,
@@ -28,6 +33,7 @@ export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({
28
33
  fullDataFormatter$: observer.fullDataFormatter$,
29
34
  computedData$: observer.computedData$,
30
35
  layout$: observer.layout$,
36
+ textSizePx$,
31
37
  multiGridEachDetail$,
32
38
  multiGridContainer$
33
39
  }
@@ -3,10 +3,14 @@ import type { ContextObserverFn } from '../types'
3
3
  import {
4
4
  seriesDataMapObservable,
5
5
  groupDataMapObservable } from '../utils/observables'
6
- import { highlightObservable } from '../utils/observables'
6
+ import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
7
 
8
8
  export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
9
9
 
10
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
11
+ shareReplay(1)
12
+ )
13
+
10
14
  const seriesHighlight$ = highlightObservable({
11
15
  datumList$: observer.computedData$,
12
16
  fullChartParams$: observer.fullChartParams$,
@@ -27,6 +31,7 @@ export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subje
27
31
  fullDataFormatter$: observer.fullDataFormatter$,
28
32
  computedData$: observer.computedData$,
29
33
  layout$: observer.layout$,
34
+ textSizePx$,
30
35
  seriesHighlight$,
31
36
  SeriesDataMap$
32
37
  }
@@ -1,6 +1,6 @@
1
1
  import { map, shareReplay } from 'rxjs'
2
2
  import type { ContextObserverFn } from '../types'
3
- import { highlightObservable, categoryDataMapObservable } from '../utils/observables'
3
+ import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
4
  import {
5
5
  nodeListObservable,
6
6
  existCategoryLabelsObservable,
@@ -9,6 +9,10 @@ import {
9
9
 
10
10
  export const createTreeContextObserver: ContextObserverFn<'tree'> = ({ subject, observer }) => {
11
11
 
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
12
16
  const nodeList$ = nodeListObservable({
13
17
  computedData$: observer.computedData$
14
18
  }).pipe(
@@ -48,6 +52,7 @@ export const createTreeContextObserver: ContextObserverFn<'tree'> = ({ subject,
48
52
  fullDataFormatter$: observer.fullDataFormatter$,
49
53
  computedData$: observer.computedData$,
50
54
  layout$: observer.layout$,
55
+ textSizePx$,
51
56
  treeHighlight$,
52
57
  existCategoryLabels$,
53
58
  CategoryDataMap$,
@@ -36,7 +36,7 @@ function test (): ChartParamsPartial {
36
36
  export type HighlightTarget = 'series' | 'group' | 'category' | 'datum' | 'none'
37
37
 
38
38
  export interface Styles {
39
- textSize: number
39
+ textSize: string | number
40
40
  unhighlightedOpacity: number
41
41
  }
42
42
 
@@ -7,7 +7,7 @@ export interface ContextObserverGrid<PluginParams>
7
7
  extends
8
8
  ContextObserverBase<'grid', PluginParams>,
9
9
  ContextObserverGridDetail {
10
-
10
+ textSizePx$: Observable<number>
11
11
  }
12
12
 
13
13
  export interface ContextObserverGridDetail {
@@ -17,7 +17,7 @@ export interface ContextObserverGridDetail {
17
17
  gridGraphicTransform$: Observable<TransformData>
18
18
  gridGraphicReverseScale$: Observable<[number, number][]>
19
19
  gridAxesSize$: Observable<{ width: number; height: number; }>
20
- gridHighlight$: Observable<string[]>
20
+ gridHighlight$: Observable<ComputedDatumGrid[]>
21
21
  existSeriesLabels$: Observable<string[]>
22
22
  SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
23
23
  GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
@@ -6,6 +6,7 @@ import type { TransformData } from './TransformData'
6
6
  import type { ContextObserverGridDetail } from './ContextObserverGrid'
7
7
 
8
8
  export interface ContextObserverMultiGrid<PluginParams> extends ContextObserverBase<'multiGrid', PluginParams> {
9
+ textSizePx$: Observable<number>
9
10
  multiGridEachDetail$: Observable<ContextObserverGridDetail[]>
10
11
  multiGridContainer$: Observable<ContainerPosition[][]>
11
12
  }
@@ -3,6 +3,7 @@ import type { ContextObserverBase } from './ContextObserver'
3
3
  import type { ComputedDatumSeries } from './ComputedDataSeries'
4
4
 
5
5
  export interface ContextObserverSeries<PluginParams> extends ContextObserverBase<'series', PluginParams> {
6
- seriesHighlight$: Observable<string[]>
6
+ textSizePx$: Observable<number>
7
+ seriesHighlight$: Observable<ComputedDatumSeries[]>
7
8
  SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
8
9
  }
@@ -3,7 +3,8 @@ import type { ContextObserverBase } from './ContextObserver'
3
3
  import type { ComputedDataTree } from './ComputedDataTree'
4
4
 
5
5
  export interface ContextObserverTree<PluginParams> extends ContextObserverBase<'tree', PluginParams> {
6
- treeHighlight$: Observable<string[]>
6
+ textSizePx$: Observable<number>
7
+ treeHighlight$: Observable<ComputedDataTree[]>
7
8
  existCategoryLabels$: Observable<string[]>
8
9
  CategoryDataMap$: Observable<Map<string, ComputedDataTree[]>>
9
10
  visibleComputedData$: Observable<ComputedDataTree>
@@ -15,6 +15,7 @@ import type {
15
15
  ComputedDataTypeMap,
16
16
  ComputedDatumTypeMap,
17
17
  DataFormatterTypeMap,
18
+ EventTypeMap,
18
19
  HighlightTarget,
19
20
  Layout,
20
21
  TransformData } from '../types'
@@ -28,11 +29,11 @@ import type {
28
29
  // }
29
30
 
30
31
  // 通用 highlight Observable
31
- export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
32
- datumList$: Observable<ComputedDatumTypeMap<'series' | 'grid' | 'multiValue' | 'relationship' | 'tree'>[]>
32
+ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullChartParams$, event$ }: {
33
+ datumList$: Observable<D[]>
33
34
  fullChartParams$: Observable<ChartParams>
34
- event$: Subject<any>
35
- }): Observable<string[]> => {
35
+ event$: Subject<EventTypeMap<T>>
36
+ }): Observable<D[]> => {
36
37
  const destroy$ = new Subject()
37
38
 
38
39
  // 預設的highlight
@@ -83,31 +84,30 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
83
84
  switchMap(d => highlightDefault$)
84
85
  )
85
86
 
86
- function getDatumIds (datumList: ComputedDatumTypeMap<'series' | 'grid' | 'multiValue' | 'relationship' | 'tree'>[], id: string | null) {
87
- return id == null
88
- ? []
89
- : datumList.find(d => d.id === id) ? [id] : []
87
+ function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null) {
88
+ const datum = datumList.find(d => d.id === id)
89
+ return datum ? [datum] : []
90
90
  }
91
91
 
92
- function getSeriesIds (datumList: ComputedDatumTypeMap<'series' | 'grid'>[], seriesLabel: string | null) {
92
+ function getSeriesIds (datumList: ComputedDatumTypeMap<T>[], seriesLabel: string | null) {
93
93
  return seriesLabel == null
94
94
  ? []
95
- : datumList.filter(d => d.seriesLabel === seriesLabel).map(d => d.id)
95
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"series">).seriesLabel === seriesLabel)
96
96
  }
97
97
 
98
- function getGroupIds (datumList: ComputedDatumTypeMap<'grid'>[], groupLabel: string | null) {
98
+ function getGroupIds (datumList: ComputedDatumTypeMap<T>[], groupLabel: string | null) {
99
99
  return groupLabel == null
100
100
  ? []
101
- : datumList.filter(d => (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel).map(d => d.id)
101
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel)
102
102
  }
103
103
 
104
- function getCategoryIds (datumList: ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>[], categoryLabel: string | null) {
104
+ function getCategoryIds (datumList: ComputedDatumTypeMap<T>[], categoryLabel: string | null) {
105
105
  return categoryLabel == null
106
106
  ? []
107
- : datumList.filter(d => (d as ComputedDatumTypeMap<"multiValue" | "relationship" | "tree">).categoryLabel === categoryLabel).map(d => d.id)
107
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"multiValue" | "relationship" | "tree">).categoryLabel === categoryLabel)
108
108
  }
109
109
 
110
- return new Observable<string[]>(subscriber => {
110
+ return new Observable<D[]>(subscriber => {
111
111
  combineLatest({
112
112
  target: merge(highlightMouseover$, highlightMouseout$, highlightDefault$),
113
113
  datumList: datumList$,
@@ -116,19 +116,17 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
116
116
  takeUntil(destroy$),
117
117
  switchMap(async d => d)
118
118
  ).subscribe(data => {
119
- console.log('data.fullChartParams.highlightTarget', data.fullChartParams.highlightTarget)
120
- let ids: string[] = []
119
+ let datumList: ComputedDatumTypeMap<T>[] = []
121
120
  if (data.fullChartParams.highlightTarget === 'datum') {
122
- ids = getDatumIds(data.datumList, data.target.id)
121
+ datumList = getDatumIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.id)
123
122
  } else if (data.fullChartParams.highlightTarget === 'series') {
124
- ids = getSeriesIds(data.datumList as ComputedDatumTypeMap<'series' | 'grid'>[], data.target.seriesLabel)
123
+ datumList = getSeriesIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.seriesLabel)
125
124
  } else if (data.fullChartParams.highlightTarget === 'group') {
126
- ids = getGroupIds(data.datumList as ComputedDatumTypeMap<'grid'>[], data.target.groupLabel)
125
+ datumList = getGroupIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.groupLabel)
127
126
  } else if (data.fullChartParams.highlightTarget === 'category') {
128
- ids = getCategoryIds(data.datumList as ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>[], data.target.categoryLabel)
127
+ datumList = getCategoryIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.categoryLabel)
129
128
  }
130
- console.log('ids', ids)
131
- subscriber.next(ids)
129
+ subscriber.next(datumList as D[])
132
130
  })
133
131
 
134
132
  return function unsubscribe () {
@@ -181,3 +179,24 @@ export const categoryDataMapObservable = <DatumType extends ComputedDatumTypeMap
181
179
  )
182
180
  }
183
181
 
182
+ export const textSizePxObservable = (chartParams$: Observable<ChartParams>) => {
183
+ return chartParams$.pipe(
184
+ map(d => d.styles.textSize),
185
+ distinctUntilChanged(),
186
+ map(data => {
187
+ let value = NaN
188
+ if (typeof data === 'string') {
189
+ if (data.includes('rem')) {
190
+ const rootFontSizePx = parseFloat(getComputedStyle(document.documentElement).fontSize)
191
+ const num = parseFloat(data)
192
+ value = num * rootFontSizePx
193
+ } else if (data.includes('px')) {
194
+ value = parseFloat(data)
195
+ }
196
+ } else if (typeof data === 'number') {
197
+ return data
198
+ }
199
+ return value ? value : 14 // default
200
+ })
201
+ )
202
+ }