@orbcharts/core 3.0.0-alpha.32 → 3.0.0-alpha.34
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 +1673 -1512
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/defaults.d.ts +4 -3
- package/dist/src/grid/gridObservables.d.ts +27 -3
- package/dist/src/multiGrid/multiGridObservables.d.ts +3 -15
- package/dist/src/types/ContextObserverGrid.d.ts +15 -2
- package/dist/src/types/ContextObserverMultiGrid.d.ts +3 -24
- package/dist/src/types/DataFormatterGrid.d.ts +24 -6
- package/dist/src/types/DataFormatterMultiGrid.d.ts +9 -9
- package/dist/src/utils/commonUtils.d.ts +1 -1
- package/dist/src/utils/orbchartsUtils.d.ts +7 -2
- package/package.json +1 -1
- package/src/base/createBaseChart.ts +24 -9
- package/src/defaults.ts +31 -19
- package/src/grid/computeGridData.ts +87 -30
- package/src/grid/createGridContextObserver.ts +42 -9
- package/src/grid/gridObservables.ts +155 -28
- package/src/multiGrid/computeMultiGridData.ts +16 -12
- package/src/multiGrid/multiGridObservables.ts +188 -114
- package/src/multiValue/computeMultiValueData.ts +1 -0
- package/src/tree/computeTreeData.ts +2 -2
- package/src/types/ContextObserverGrid.ts +20 -2
- package/src/types/ContextObserverMultiGrid.ts +18 -19
- package/src/types/DataFormatterGrid.ts +28 -13
- package/src/types/DataFormatterMultiGrid.ts +14 -12
- package/src/utils/commonUtils.ts +6 -6
- package/src/utils/orbchartsUtils.ts +31 -15
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { ComputedDataTypeMap, DataFormatterTypeMap, DataFormatterGrid, Layout, TransformData } from '../types';
|
|
2
|
+
import { ChartParams, ComputedDataTypeMap, DataFormatterTypeMap, DataFormatterGrid, ContainerPosition, Layout, TransformData } from '../types';
|
|
3
3
|
|
|
4
4
|
export declare const gridAxesTransformObservable: ({ fullDataFormatter$, layout$ }: {
|
|
5
5
|
fullDataFormatter$: Observable<DataFormatterTypeMap<"grid">>;
|
|
6
6
|
layout$: Observable<Layout>;
|
|
7
7
|
}) => Observable<TransformData>;
|
|
8
|
+
export declare const gridAxesReverseTransformObservable: ({ gridAxesTransform$ }: {
|
|
9
|
+
gridAxesTransform$: Observable<TransformData>;
|
|
10
|
+
}) => Observable<TransformData>;
|
|
8
11
|
export declare const gridGraphicTransformObservable: ({ computedData$, fullDataFormatter$, layout$ }: {
|
|
9
12
|
computedData$: Observable<ComputedDataTypeMap<"grid">>;
|
|
10
13
|
fullDataFormatter$: Observable<DataFormatterTypeMap<"grid">>;
|
|
11
14
|
layout$: Observable<Layout>;
|
|
12
15
|
}) => Observable<TransformData>;
|
|
13
|
-
export declare const
|
|
16
|
+
export declare const gridGraphicReverseScaleObservable: ({ gridContainer$, gridAxesTransform$, gridGraphicTransform$ }: {
|
|
17
|
+
gridContainer$: Observable<ContainerPosition[]>;
|
|
14
18
|
gridAxesTransform$: Observable<TransformData>;
|
|
15
|
-
|
|
19
|
+
gridGraphicTransform$: Observable<TransformData>;
|
|
20
|
+
}) => Observable<[number, number][]>;
|
|
16
21
|
export declare const gridAxesSizeObservable: ({ fullDataFormatter$, layout$ }: {
|
|
17
22
|
fullDataFormatter$: Observable<DataFormatterGrid>;
|
|
18
23
|
layout$: Observable<Layout>;
|
|
@@ -20,6 +25,25 @@ export declare const gridAxesSizeObservable: ({ fullDataFormatter$, layout$ }: {
|
|
|
20
25
|
width: number;
|
|
21
26
|
height: number;
|
|
22
27
|
}>;
|
|
28
|
+
export declare const existedSeriesLabelsObservable: ({ computedData$ }: {
|
|
29
|
+
computedData$: Observable<ComputedDataTypeMap<"grid">>;
|
|
30
|
+
}) => Observable<string[]>;
|
|
23
31
|
export declare const gridVisibleComputedDataObservable: ({ computedData$ }: {
|
|
24
32
|
computedData$: Observable<ComputedDataTypeMap<"grid">>;
|
|
25
33
|
}) => Observable<import('../types').ComputedDatumGrid[][]>;
|
|
34
|
+
export declare const isSeriesPositionSeprateObservable: ({ computedData$, fullDataFormatter$ }: {
|
|
35
|
+
computedData$: Observable<ComputedDataTypeMap<"grid">>;
|
|
36
|
+
fullDataFormatter$: Observable<DataFormatterTypeMap<"grid">>;
|
|
37
|
+
}) => Observable<boolean>;
|
|
38
|
+
export declare const gridContainerObservable: ({ computedData$, fullDataFormatter$, fullChartParams$, layout$ }: {
|
|
39
|
+
computedData$: Observable<ComputedDataTypeMap<"grid">>;
|
|
40
|
+
fullDataFormatter$: Observable<DataFormatterTypeMap<"grid">>;
|
|
41
|
+
fullChartParams$: Observable<ChartParams>;
|
|
42
|
+
layout$: Observable<Layout>;
|
|
43
|
+
}) => Observable<{
|
|
44
|
+
slotIndex: number;
|
|
45
|
+
rowIndex: number;
|
|
46
|
+
columnIndex: number;
|
|
47
|
+
translate: [number, number];
|
|
48
|
+
scale: [number, number];
|
|
49
|
+
}[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subject, Observable } from 'rxjs';
|
|
2
|
-
import { ChartParams, ComputedDataTypeMap, DataFormatterTypeMap, EventMultiGrid, Layout,
|
|
2
|
+
import { ChartParams, ComputedDataTypeMap, DataFormatterTypeMap, EventMultiGrid, Layout, ContextObserverGridDetail } from '../types';
|
|
3
3
|
|
|
4
4
|
export declare const multiGridEachDetailObservable: ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$ }: {
|
|
5
5
|
fullDataFormatter$: Observable<DataFormatterTypeMap<"multiGrid">>;
|
|
@@ -7,19 +7,7 @@ export declare const multiGridEachDetailObservable: ({ fullDataFormatter$, compu
|
|
|
7
7
|
layout$: Observable<Layout>;
|
|
8
8
|
fullChartParams$: Observable<ChartParams>;
|
|
9
9
|
event$: Subject<EventMultiGrid>;
|
|
10
|
-
}) => Observable<
|
|
11
|
-
gridAxesTransform$: Observable<TransformData>;
|
|
12
|
-
gridGraphicTransform$: Observable<TransformData>;
|
|
13
|
-
gridAxesOppositeTransform$: Observable<TransformData>;
|
|
14
|
-
gridAxesSize$: Observable<{
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
}>;
|
|
18
|
-
gridHighlight$: Observable<string[]>;
|
|
19
|
-
SeriesDataMap$: Observable<Map<string, import('../types').ComputedDatumGrid[]>>;
|
|
20
|
-
GroupDataMap$: Observable<Map<string, import('../types').ComputedDatumGrid[]>>;
|
|
21
|
-
visibleComputedData$: Observable<import('../types').ComputedDatumGrid[][]>;
|
|
22
|
-
}[]>;
|
|
10
|
+
}) => Observable<ContextObserverGridDetail[]>;
|
|
23
11
|
export declare const multiGridContainerObservable: ({ computedData$, fullDataFormatter$, fullChartParams$, layout$ }: {
|
|
24
12
|
computedData$: Observable<ComputedDataTypeMap<"multiGrid">>;
|
|
25
13
|
fullDataFormatter$: Observable<DataFormatterTypeMap<"multiGrid">>;
|
|
@@ -31,4 +19,4 @@ export declare const multiGridContainerObservable: ({ computedData$, fullDataFor
|
|
|
31
19
|
columnIndex: number;
|
|
32
20
|
translate: [number, number];
|
|
33
21
|
scale: [number, number];
|
|
34
|
-
}[]>;
|
|
22
|
+
}[][]>;
|
|
@@ -3,16 +3,29 @@ import { ContextObserverBase } from './ContextObserver';
|
|
|
3
3
|
import { ComputedDataGrid, ComputedDatumGrid } from './ComputedDataGrid';
|
|
4
4
|
import { TransformData } from './TransformData';
|
|
5
5
|
|
|
6
|
-
export interface ContextObserverGrid<PluginParams> extends ContextObserverBase<'grid', PluginParams
|
|
6
|
+
export interface ContextObserverGrid<PluginParams> extends ContextObserverBase<'grid', PluginParams>, ContextObserverGridDetail {
|
|
7
|
+
}
|
|
8
|
+
export interface ContextObserverGridDetail {
|
|
9
|
+
gridContainer$: Observable<ContainerPosition[]>;
|
|
7
10
|
gridAxesTransform$: Observable<TransformData>;
|
|
11
|
+
gridAxesReverseTransform$: Observable<TransformData>;
|
|
8
12
|
gridGraphicTransform$: Observable<TransformData>;
|
|
9
|
-
|
|
13
|
+
gridGraphicReverseScale$: Observable<[number, number][]>;
|
|
10
14
|
gridAxesSize$: Observable<{
|
|
11
15
|
width: number;
|
|
12
16
|
height: number;
|
|
13
17
|
}>;
|
|
14
18
|
gridHighlight$: Observable<string[]>;
|
|
19
|
+
existedSeriesLabels$: Observable<string[]>;
|
|
15
20
|
SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>;
|
|
16
21
|
GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>;
|
|
17
22
|
visibleComputedData$: Observable<ComputedDataGrid>;
|
|
23
|
+
isSeriesPositionSeprate$: Observable<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export interface ContainerPosition {
|
|
26
|
+
slotIndex: number;
|
|
27
|
+
rowIndex: number;
|
|
28
|
+
columnIndex: number;
|
|
29
|
+
translate: [number, number];
|
|
30
|
+
scale: [number, number];
|
|
18
31
|
}
|
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { ContextObserverBase } from './ContextObserver';
|
|
3
|
-
import {
|
|
4
|
-
import { TransformData } from './TransformData';
|
|
3
|
+
import { ContainerPosition, ContextObserverGridDetail } from './ContextObserverGrid';
|
|
5
4
|
|
|
6
5
|
export interface ContextObserverMultiGrid<PluginParams> extends ContextObserverBase<'multiGrid', PluginParams> {
|
|
7
|
-
multiGridEachDetail$: Observable<
|
|
8
|
-
multiGridContainer$: Observable<
|
|
9
|
-
}
|
|
10
|
-
export interface MultiGridObservableAll {
|
|
11
|
-
gridAxesTransform$: Observable<TransformData>;
|
|
12
|
-
gridGraphicTransform$: Observable<TransformData>;
|
|
13
|
-
gridAxesOppositeTransform$: Observable<TransformData>;
|
|
14
|
-
gridAxesSize$: Observable<{
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
}>;
|
|
18
|
-
gridHighlight$: Observable<string[]>;
|
|
19
|
-
SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>;
|
|
20
|
-
GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>;
|
|
21
|
-
visibleComputedData$: Observable<ComputedDataGrid>;
|
|
22
|
-
}
|
|
23
|
-
export interface GridContainerBox {
|
|
24
|
-
slotIndex: number;
|
|
25
|
-
rowIndex: number;
|
|
26
|
-
columnIndex: number;
|
|
27
|
-
translate: [number, number];
|
|
28
|
-
scale: [number, number];
|
|
6
|
+
multiGridEachDetail$: Observable<ContextObserverGridDetail[]>;
|
|
7
|
+
multiGridContainer$: Observable<ContainerPosition[][]>;
|
|
29
8
|
}
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, DataFormatterGroupAxis, VisibleFilter } from './DataFormatter';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type SeriesDirection = 'row' | 'column';
|
|
4
4
|
export interface DataFormatterGrid extends DataFormatterBase<'grid'> {
|
|
5
|
-
visibleFilter: VisibleFilter<'grid'>;
|
|
6
5
|
grid: DataFormatterGridGrid;
|
|
6
|
+
container: DataFormatterGridContainer;
|
|
7
|
+
}
|
|
8
|
+
export interface DataFormatterGridPartial extends DataFormatterBasePartial<'grid'> {
|
|
9
|
+
grid?: DataFormatterGridGridPartial;
|
|
10
|
+
container?: Partial<DataFormatterGridContainer>;
|
|
11
|
+
}
|
|
12
|
+
export interface DataFormatterGridGrid {
|
|
13
|
+
visibleFilter: VisibleFilter<'grid'>;
|
|
14
|
+
gridData: DataFormatterGridGridData;
|
|
7
15
|
valueAxis: DataFormatterValueAxis;
|
|
8
16
|
groupAxis: DataFormatterGroupAxis;
|
|
17
|
+
slotIndex: number | null;
|
|
18
|
+
seriesSlotIndexes: number[] | null;
|
|
9
19
|
}
|
|
10
|
-
export interface
|
|
11
|
-
|
|
20
|
+
export interface DataFormatterGridGridPartial {
|
|
21
|
+
visibleFilter?: VisibleFilter<'grid'>;
|
|
22
|
+
gridData?: Partial<DataFormatterGridGridData>;
|
|
12
23
|
valueAxis?: Partial<DataFormatterValueAxis>;
|
|
13
24
|
groupAxis?: Partial<DataFormatterGroupAxis>;
|
|
25
|
+
slotIndex?: number | null;
|
|
26
|
+
seriesSlotIndexes?: number[] | null;
|
|
14
27
|
}
|
|
15
|
-
export interface
|
|
28
|
+
export interface DataFormatterGridContainer {
|
|
29
|
+
gap: number;
|
|
30
|
+
rowAmount: number;
|
|
31
|
+
columnAmount: number;
|
|
32
|
+
}
|
|
33
|
+
export interface DataFormatterGridGridData {
|
|
34
|
+
seriesDirection: SeriesDirection;
|
|
16
35
|
rowLabels: string[];
|
|
17
36
|
columnLabels: string[];
|
|
18
|
-
seriesType: SeriesType;
|
|
19
37
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { VisibleFilter, DataFormatterBase, DataFormatterBasePartial } from './DataFormatter';
|
|
2
|
-
import {
|
|
2
|
+
import { DataFormatterGridGrid, DataFormatterGridGridPartial, DataFormatterGridContainer } from './DataFormatterGrid';
|
|
3
3
|
|
|
4
4
|
export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
|
|
5
5
|
visibleFilter: VisibleFilter<'multiGrid'>;
|
|
6
|
-
|
|
6
|
+
gridList: Array<DataFormatterGridGrid>;
|
|
7
7
|
container: DataFormatterMultiGridContainer;
|
|
8
8
|
}
|
|
9
9
|
export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
|
|
10
|
-
|
|
10
|
+
visibleFilter?: VisibleFilter<'multiGrid'>;
|
|
11
|
+
gridList?: Array<DataFormatterGridGridPartial>;
|
|
12
|
+
container?: Partial<DataFormatterMultiGridContainer>;
|
|
11
13
|
}
|
|
12
|
-
export interface
|
|
13
|
-
slotIndex: number;
|
|
14
|
+
export interface DataFormatterMultiGridGrid extends DataFormatterGridGrid {
|
|
14
15
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
columnAmount: number;
|
|
16
|
+
export interface DataFormatterMultiGridGridPartial extends DataFormatterGridGridPartial {
|
|
17
|
+
}
|
|
18
|
+
export interface DataFormatterMultiGridContainer extends DataFormatterGridContainer {
|
|
19
19
|
}
|
|
@@ -5,7 +5,8 @@ import { DataSeries } from '../types/DataSeries';
|
|
|
5
5
|
import { DataGrid, DataGridDatum } from '../types/DataGrid';
|
|
6
6
|
import { DataMultiGrid } from '../types/DataMultiGrid';
|
|
7
7
|
import { DataMultiValue } from '../types/DataMultiValue';
|
|
8
|
-
import {
|
|
8
|
+
import { SeriesDirection, DataFormatterGrid, DataFormatterGridContainer } from '../types/DataFormatterGrid';
|
|
9
|
+
import { Layout } from '../types/Layout';
|
|
9
10
|
import * as d3 from 'd3';
|
|
10
11
|
export declare function formatValueToLabel(value: any, valueFormatter: string | ((text: d3.NumberValue) => string)): string;
|
|
11
12
|
export declare function createDefaultDatumId(chartTypeOrPrefix: string, levelOneIndex: number, levelTwoIndex: number, levelThreeIndex?: number): string;
|
|
@@ -29,5 +30,9 @@ export declare function getMinAndMaxSeries(data: DataSeries): [number, number];
|
|
|
29
30
|
export declare function getMinAndMaxGrid(data: DataGrid): [number, number];
|
|
30
31
|
export declare function getMinAndMaxMultiGrid(data: DataMultiGrid): [number, number];
|
|
31
32
|
export declare function getMinAndMaxMultiValue(data: DataMultiValue, valueIndex?: number): [number, number];
|
|
32
|
-
export declare function transposeData<T>(
|
|
33
|
+
export declare function transposeData<T>(seriesDirection: SeriesDirection, data: T[][]): T[][];
|
|
33
34
|
export declare function seriesColorPredicate(seriesIndex: number, chartParams: ChartParams): string;
|
|
35
|
+
export declare function calcGridContainerPosition(layout: Layout, container: DataFormatterGridContainer, rowIndex: number, columnIndex: number): {
|
|
36
|
+
translate: [number, number];
|
|
37
|
+
scale: [number, number];
|
|
38
|
+
};
|
package/package.json
CHANGED
|
@@ -84,6 +84,18 @@ function resizeObservable(elem: HTMLElement | Element): Observable<DOMRectReadOn
|
|
|
84
84
|
})
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
function mergeDataFormatter <T>(dataFormatter: any, defaultDataFormatter: T, chartType: ChartType): T {
|
|
88
|
+
const mergedData = mergeOptionsWithDefault(dataFormatter, defaultDataFormatter)
|
|
89
|
+
|
|
90
|
+
if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList != null) {
|
|
91
|
+
// multiGrid欄位為陣列,需要各別來merge預設值
|
|
92
|
+
(mergedData as DataFormatterTypeMap<'multiGrid'>).gridList = (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList.map(d => {
|
|
93
|
+
return mergeOptionsWithDefault(d, (defaultDataFormatter as DataFormatterTypeMap<'multiGrid'>).gridList[0])
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
return mergedData
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultDataFormatter, computedDataFn, contextObserverFn }: {
|
|
88
100
|
defaultDataFormatter: DataFormatterTypeMap<T>
|
|
89
101
|
computedDataFn: ComputedDataFn<T>
|
|
@@ -127,12 +139,14 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
|
|
|
127
139
|
const mergedPresetWithDefault: Preset<T> = ((options) => {
|
|
128
140
|
const _options = options ? options : CHART_OPTIONS_DEFAULT as ChartOptionsPartial<T>
|
|
129
141
|
const preset = _options.preset ? _options.preset : {} as PresetPartial<T>
|
|
142
|
+
|
|
130
143
|
return {
|
|
131
144
|
chartParams: preset.chartParams
|
|
132
145
|
? mergeOptionsWithDefault(preset.chartParams, CHART_PARAMS_DEFAULT)
|
|
133
146
|
: CHART_PARAMS_DEFAULT,
|
|
134
147
|
dataFormatter: preset.dataFormatter
|
|
135
|
-
? mergeOptionsWithDefault(preset.dataFormatter, defaultDataFormatter)
|
|
148
|
+
// ? mergeOptionsWithDefault(preset.dataFormatter, defaultDataFormatter)
|
|
149
|
+
? mergeDataFormatter(preset.dataFormatter, defaultDataFormatter, chartType)
|
|
136
150
|
: defaultDataFormatter,
|
|
137
151
|
allPluginParams: preset.allPluginParams
|
|
138
152
|
? preset.allPluginParams
|
|
@@ -147,15 +161,16 @@ export const createBaseChart: CreateBaseChart = <T extends ChartType>({ defaultD
|
|
|
147
161
|
takeUntil(destroy$),
|
|
148
162
|
startWith({}),
|
|
149
163
|
map((dataFormatter) => {
|
|
150
|
-
const mergedData = mergeOptionsWithDefault(dataFormatter, mergedPresetWithDefault.dataFormatter)
|
|
164
|
+
// const mergedData = mergeOptionsWithDefault(dataFormatter, mergedPresetWithDefault.dataFormatter)
|
|
151
165
|
|
|
152
|
-
if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
return mergedData
|
|
166
|
+
// if (chartType === 'multiGrid' && (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList != null) {
|
|
167
|
+
// // multiGrid欄位為陣列,需要各別來merge預設值
|
|
168
|
+
// (mergedData as DataFormatterTypeMap<'multiGrid'>).gridList = (dataFormatter as DataFormatterPartialTypeMap<'multiGrid'>).gridList.map(d => {
|
|
169
|
+
// return mergeOptionsWithDefault(d, (mergedPresetWithDefault.dataFormatter as DataFormatterTypeMap<'multiGrid'>).gridList[0])
|
|
170
|
+
// })
|
|
171
|
+
// }
|
|
172
|
+
// return mergedData
|
|
173
|
+
return mergeDataFormatter(dataFormatter, mergedPresetWithDefault.dataFormatter, chartType)
|
|
159
174
|
}),
|
|
160
175
|
shareReplay(1)
|
|
161
176
|
)
|
package/src/defaults.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type { DataTree } from './types/DataTree'
|
|
|
9
9
|
import type { DataRelationship } from './types/DataRelationship'
|
|
10
10
|
import type { DataFormatterBase, DataFormatterValueAxis, DataFormatterGroupAxis } from './types/DataFormatter'
|
|
11
11
|
import type { DataFormatterSeries } from './types/DataFormatterSeries'
|
|
12
|
-
import type { DataFormatterGrid } from './types/DataFormatterGrid'
|
|
13
|
-
import type { DataFormatterMultiGrid,
|
|
12
|
+
import type { DataFormatterGrid, DataFormatterGridGrid } from './types/DataFormatterGrid'
|
|
13
|
+
import type { DataFormatterMultiGrid, DataFormatterMultiGridGrid } from './types/DataFormatterMultiGrid'
|
|
14
14
|
import type { DataFormatterMultiValue } from './types/DataFormatterMultiValue'
|
|
15
15
|
import type { DataFormatterTree } from './types/DataFormatterTree'
|
|
16
16
|
import type { DataFormatterRelationship } from './types/DataFormatterRelationship'
|
|
@@ -34,7 +34,6 @@ export const CHART_OPTIONS_DEFAULT: ChartOptionsPartial<any> = {
|
|
|
34
34
|
// }
|
|
35
35
|
|
|
36
36
|
// export const COLORS_DEFAULT = ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67']
|
|
37
|
-
// @Q@ 桃園儀表板
|
|
38
37
|
// ['#ff7ab9', '#66dec8', '#84c8ff', '#30ad1b', '#f8c43e', '#fa5640', '#9d79d7', '#ea4f98']
|
|
39
38
|
|
|
40
39
|
export const PADDING_DEFAULT: Padding = {
|
|
@@ -158,42 +157,55 @@ export const DATA_FORMATTER_SERIES_DEFAULT: DataFormatterSeries = {
|
|
|
158
157
|
sort: null,
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
export const
|
|
162
|
-
// ...DATA_FORMATTER_WITH_VALUE,
|
|
163
|
-
type: 'grid',
|
|
160
|
+
export const DATA_FORMATTER_GRID_GRID_DEFAULT: DataFormatterGridGrid = {
|
|
164
161
|
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
gridData: {
|
|
163
|
+
seriesDirection: 'row',
|
|
167
164
|
rowLabels: [],
|
|
168
|
-
// rowLabelFormat: label => label,
|
|
169
|
-
// columnUnitLabel: '',
|
|
170
165
|
columnLabels: [],
|
|
171
|
-
// columnLabelFormat: label => label,
|
|
172
|
-
seriesType: 'row'
|
|
173
166
|
},
|
|
174
167
|
valueAxis: { ...DATA_FORMATTER_VALUE_AXIS },
|
|
175
168
|
groupAxis: { ...DATA_FORMATTER_GROUP_AXIS, },
|
|
169
|
+
slotIndex: 0,
|
|
170
|
+
seriesSlotIndexes: null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
|
|
174
|
+
// ...DATA_FORMATTER_WITH_VALUE,
|
|
175
|
+
type: 'grid',
|
|
176
|
+
grid: {
|
|
177
|
+
...DATA_FORMATTER_GRID_GRID_DEFAULT
|
|
178
|
+
},
|
|
179
|
+
container: {
|
|
180
|
+
gap: 120,
|
|
181
|
+
rowAmount: 1,
|
|
182
|
+
columnAmount: 1
|
|
183
|
+
}
|
|
176
184
|
// visibleGroupRange: null,
|
|
177
185
|
// colorsPredicate: (datum, rowIndex, columnIndex, { chartParams, dataFormatter }) => {
|
|
178
|
-
// const seriesIndex = dataFormatter.grid.
|
|
186
|
+
// const seriesIndex = dataFormatter.grid.seriesDirection === 'row' ? rowIndex : columnIndex
|
|
179
187
|
// return chartParams.colors[chartParams.colorScheme].series[seriesIndex]
|
|
180
188
|
// },
|
|
181
189
|
}
|
|
182
190
|
|
|
183
|
-
export const DATA_FORMATTER_MULTI_GRID_MULTI_GRID_DEFAULT: DataFormatterMultiGridMultiGrid = {
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
// export const DATA_FORMATTER_MULTI_GRID_MULTI_GRID_DEFAULT: DataFormatterMultiGridMultiGrid = {
|
|
192
|
+
// ...DATA_FORMATTER_GRID_DEFAULT,
|
|
193
|
+
// slotIndex: 0,
|
|
194
|
+
// seriesSlotIndexes: null
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
export const DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT: DataFormatterMultiGridGrid = {
|
|
198
|
+
...DATA_FORMATTER_GRID_GRID_DEFAULT
|
|
186
199
|
}
|
|
187
200
|
|
|
188
201
|
export const DATA_FORMATTER_MULTI_GRID_DEFAULT: DataFormatterMultiGrid = {
|
|
189
202
|
type: 'multiGrid',
|
|
190
203
|
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
191
|
-
|
|
204
|
+
gridList: [
|
|
192
205
|
{
|
|
193
|
-
...
|
|
206
|
+
...DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
|
|
194
207
|
},
|
|
195
208
|
],
|
|
196
|
-
// visibleGroupRange: null,
|
|
197
209
|
container: {
|
|
198
210
|
gap: 120,
|
|
199
211
|
rowAmount: 1,
|
|
@@ -49,7 +49,7 @@ export const computeBaseGridData = (context: DataFormatterContext<'grid'>, chart
|
|
|
49
49
|
return d.map((_d, _i) => {
|
|
50
50
|
|
|
51
51
|
// const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
|
|
52
|
-
const _visible = dataFormatter.visibleFilter(_d, i, _i, context)
|
|
52
|
+
const _visible = dataFormatter.grid.visibleFilter(_d, i, _i, context)
|
|
53
53
|
|
|
54
54
|
const datum: DataGridDatumTemp = _d == null
|
|
55
55
|
? {
|
|
@@ -85,21 +85,26 @@ export const computeBaseGridData = (context: DataFormatterContext<'grid'>, chart
|
|
|
85
85
|
})
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
// 依
|
|
89
|
-
const transposedDataGrid = transposeData(dataFormatter.grid.
|
|
88
|
+
// 依seriesDirection轉置資料矩陣
|
|
89
|
+
const transposedDataGrid = transposeData(dataFormatter.grid.gridData.seriesDirection, dataGrid)
|
|
90
90
|
|
|
91
91
|
// -- groupScale --
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
const { groupScale } = (() => {
|
|
93
|
+
const groupAxisWidth = (dataFormatter.grid.groupAxis.position === 'top' || dataFormatter.grid.groupAxis.position === 'bottom')
|
|
94
|
+
? layout.width
|
|
95
|
+
: layout.height
|
|
96
|
+
const groupEndIndex = transposedDataGrid[0] ? transposedDataGrid[0].length - 1 : 0
|
|
97
|
+
const groupScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
98
|
+
maxValue: groupEndIndex,
|
|
99
|
+
minValue: 0,
|
|
100
|
+
axisWidth: groupAxisWidth,
|
|
101
|
+
scaleDomain: [0, groupEndIndex], // 不使用dataFormatter設定
|
|
102
|
+
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
103
|
+
})
|
|
104
|
+
return { groupScale }
|
|
105
|
+
})()
|
|
106
|
+
|
|
107
|
+
|
|
103
108
|
|
|
104
109
|
// const seriesColors = chartParams.colors[chartParams.colorScheme].series
|
|
105
110
|
|
|
@@ -131,26 +136,76 @@ export const computeBaseGridData = (context: DataFormatterContext<'grid'>, chart
|
|
|
131
136
|
// })
|
|
132
137
|
// })
|
|
133
138
|
|
|
134
|
-
// -- valueScale --
|
|
135
|
-
const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
136
|
-
const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
137
|
-
|
|
138
|
-
const valueAxisWidth = (dataFormatter.valueAxis.position === 'left' || dataFormatter.valueAxis.position === 'right')
|
|
139
|
-
? layout.height
|
|
140
|
-
: layout.width
|
|
141
|
-
|
|
142
139
|
const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex })
|
|
143
140
|
const groupLabels = createGridGroupLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex })
|
|
144
141
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
// 每一個series的valueScale
|
|
143
|
+
const seriesValueScaleArr = (() => {
|
|
144
|
+
const valueAxisWidth = (dataFormatter.grid.valueAxis.position === 'left' || dataFormatter.grid.valueAxis.position === 'right')
|
|
145
|
+
? layout.height
|
|
146
|
+
: layout.width
|
|
147
|
+
|
|
148
|
+
// // 每一個series的 [minValue, maxValue]
|
|
149
|
+
// const minAndMaxValueArr = (() => {
|
|
150
|
+
// // 有設定series定位,各別series計算各自的最大最小值
|
|
151
|
+
// if (dataFormatter.grid.seriesSlotIndexes
|
|
152
|
+
// && dataFormatter.grid.seriesSlotIndexes.length === transposedDataGrid.length
|
|
153
|
+
// ) {
|
|
154
|
+
// return transposedDataGrid
|
|
155
|
+
// .map(series => {
|
|
156
|
+
// const visibleData = series.filter(d => d._visible != false)
|
|
157
|
+
// return getMinAndMaxValue(visibleData)
|
|
158
|
+
// })
|
|
159
|
+
// } else {
|
|
160
|
+
// // 沒有設定series定位,全部資料一起計算最大值最小值
|
|
161
|
+
// const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
162
|
+
// const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
163
|
+
// return transposedDataGrid
|
|
164
|
+
// .map(series => {
|
|
165
|
+
// return [minValue, maxValue]
|
|
166
|
+
// })
|
|
167
|
+
// }
|
|
168
|
+
// })()
|
|
152
169
|
|
|
153
|
-
|
|
170
|
+
const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
171
|
+
const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
172
|
+
|
|
173
|
+
return transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
174
|
+
// const minValue = minAndMaxValueArr[seriesIndex][0]
|
|
175
|
+
// const maxValue = minAndMaxValueArr[seriesIndex][1]
|
|
176
|
+
const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
177
|
+
maxValue,
|
|
178
|
+
minValue,
|
|
179
|
+
axisWidth: valueAxisWidth,
|
|
180
|
+
scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
|
|
181
|
+
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
182
|
+
})
|
|
183
|
+
return valueScale
|
|
184
|
+
})
|
|
185
|
+
})()
|
|
186
|
+
|
|
187
|
+
// const { valueScale } = (() => {
|
|
188
|
+
|
|
189
|
+
// const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
190
|
+
// const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
191
|
+
|
|
192
|
+
// const valueAxisWidth = (dataFormatter.grid.valueAxis.position === 'left' || dataFormatter.grid.valueAxis.position === 'right')
|
|
193
|
+
// ? layout.height
|
|
194
|
+
// : layout.width
|
|
195
|
+
|
|
196
|
+
// const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
197
|
+
// maxValue,
|
|
198
|
+
// minValue,
|
|
199
|
+
// axisWidth: valueAxisWidth,
|
|
200
|
+
// scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
|
|
201
|
+
// scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
202
|
+
// })
|
|
203
|
+
// return { valueScale }
|
|
204
|
+
// })()
|
|
205
|
+
|
|
206
|
+
const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
|
|
207
|
+
return seriesValueScaleArr[seriesIndex]!(0)
|
|
208
|
+
})
|
|
154
209
|
|
|
155
210
|
let _index = 0
|
|
156
211
|
computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
@@ -159,7 +214,9 @@ export const computeBaseGridData = (context: DataFormatterContext<'grid'>, chart
|
|
|
159
214
|
const defaultId = createDefaultDatumId(chartType, gridIndex, seriesIndex, groupIndex)
|
|
160
215
|
// const visible = visibleFilter(groupDatum, seriesIndex, groupIndex, context)
|
|
161
216
|
const groupLabel = groupLabels[groupIndex]
|
|
217
|
+
const valueScale = seriesValueScaleArr[seriesIndex]
|
|
162
218
|
const axisY = valueScale(groupDatum.value ?? 0)
|
|
219
|
+
const zeroY = zeroYArr[seriesIndex]
|
|
163
220
|
|
|
164
221
|
const computedDatum: ComputedDatumGrid = {
|
|
165
222
|
id: groupDatum.id ? groupDatum.id : defaultId,
|