@kanaries/graphic-walker 0.2.14 → 0.2.16
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/App.d.ts +5 -2
- package/dist/assets/explainer.worker-8428eb12.js.map +1 -1
- package/dist/assets/transform.worker-5d54ff09.js.map +1 -0
- package/dist/assets/viewQuery.worker-ffefc111.js.map +1 -0
- package/dist/components/callout.d.ts +2 -0
- package/dist/components/codeExport/index.d.ts +3 -0
- package/dist/components/loadingLayer.d.ts +2 -0
- package/dist/components/tabs/defaultTab.d.ts +1 -0
- package/dist/components/tabs/editableTab.d.ts +1 -2
- package/dist/components/toolbar/components.d.ts +4 -1
- package/dist/components/toolbar/index.d.ts +2 -0
- package/dist/components/toolbar/toolbar-item.d.ts +3 -0
- package/dist/components/tooltip.d.ts +2 -0
- package/dist/dataSource/dataSelection/config.d.ts +1 -0
- package/dist/dataSource/dataSelection/utils.d.ts +2 -0
- package/dist/datasets/tmp/test.json +1 -0
- package/dist/fields/components.d.ts +0 -1
- package/dist/fields/filterField/filterEditDialog.d.ts +1 -1
- package/dist/graphic-walker.es.js +23930 -23320
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +143 -273
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/interfaces.d.ts +23 -1
- package/dist/lib/execExp.d.ts +8 -0
- package/dist/lib/interfaces.d.ts +22 -0
- package/dist/lib/op/aggregate.d.ts +3 -0
- package/dist/lib/op/bin.d.ts +3 -0
- package/dist/lib/op/fold.d.ts +3 -0
- package/dist/lib/op/stat.d.ts +8 -0
- package/dist/lib/viewQuery.d.ts +5 -0
- package/dist/models/visSpecHistory.d.ts +2 -0
- package/dist/renderer/index.d.ts +6 -3
- package/dist/renderer/specRenderer.d.ts +13 -0
- package/dist/services.d.ts +4 -1
- package/dist/store/commonStore.d.ts +6 -0
- package/dist/store/index.d.ts +3 -2
- package/dist/store/visualSpecStore.d.ts +11 -4
- package/dist/utils/dataPrep.d.ts +2 -0
- package/dist/utils/index.d.ts +3 -5
- package/dist/utils/media.d.ts +2 -1
- package/dist/utils/save.d.ts +1 -2
- package/dist/vis/react-vega.d.ts +4 -23
- package/dist/vis/spec/aggregate.d.ts +4 -0
- package/dist/vis/spec/encode.d.ts +19 -0
- package/dist/vis/spec/field.d.ts +2 -0
- package/dist/vis/spec/mark.d.ts +7 -0
- package/dist/vis/spec/stack.d.ts +4 -0
- package/dist/vis/spec/view.d.ts +67 -0
- package/dist/vis/theme.d.ts +36 -20
- package/dist/visualSettings/index.d.ts +2 -1
- package/dist/workers/transform.d.ts +2 -0
- package/package.json +4 -3
- package/src/App.tsx +23 -15
- package/src/components/callout.tsx +9 -7
- package/src/components/clickMenu.tsx +1 -7
- package/src/components/codeExport/index.tsx +114 -0
- package/src/components/dataTable/index.tsx +10 -10
- package/src/components/loadingLayer.tsx +7 -0
- package/src/components/modal.tsx +1 -15
- package/src/components/sizeSetting.tsx +2 -2
- package/src/components/tabs/defaultTab.tsx +4 -2
- package/src/components/tabs/editableTab.tsx +75 -40
- package/src/components/toolbar/components.tsx +8 -23
- package/src/components/toolbar/index.tsx +11 -4
- package/src/components/toolbar/toolbar-button.tsx +2 -1
- package/src/components/toolbar/toolbar-item.tsx +17 -12
- package/src/components/toolbar/toolbar-select-button.tsx +9 -13
- package/src/components/toolbar/toolbar-toggle-button.tsx +2 -1
- package/src/components/tooltip.tsx +10 -6
- package/src/dataSource/dataSelection/config.ts +11 -0
- package/src/dataSource/dataSelection/csvData.tsx +72 -40
- package/src/dataSource/dataSelection/gwFile.tsx +2 -2
- package/src/dataSource/dataSelection/utils.ts +28 -0
- package/src/dataSource/index.tsx +2 -3
- package/src/dataSource/utils.ts +8 -3
- package/src/fields/components.tsx +13 -50
- package/src/fields/datasetFields/index.tsx +3 -4
- package/src/fields/datasetFields/meaFields.tsx +12 -4
- package/src/fields/encodeFields/singleEncodeEditor.tsx +1 -1
- package/src/fields/filterField/filterEditDialog.tsx +63 -99
- package/src/fields/filterField/slider.tsx +1 -1
- package/src/index.css +4 -4
- package/src/index.tsx +22 -22
- package/src/insightBoard/mainBoard.tsx +9 -2
- package/src/interfaces.ts +30 -3
- package/src/lib/execExp.ts +147 -0
- package/src/lib/interfaces.ts +39 -0
- package/src/lib/op/aggregate.ts +49 -0
- package/src/lib/op/bin.ts +25 -0
- package/src/lib/op/fold.ts +17 -0
- package/src/lib/op/stat.ts +46 -0
- package/src/lib/viewQuery.ts +23 -0
- package/src/locales/en-US.json +8 -3
- package/src/locales/i18n.ts +7 -1
- package/src/locales/ja-JP.json +197 -0
- package/src/locales/zh-CN.json +8 -3
- package/src/main.tsx +1 -1
- package/src/models/visSpecHistory.ts +14 -0
- package/src/renderer/index.tsx +58 -101
- package/src/renderer/specRenderer.tsx +119 -0
- package/src/segments/segmentNav.tsx +3 -16
- package/src/segments/visNav.tsx +17 -6
- package/src/services.ts +37 -1
- package/src/store/commonStore.ts +14 -9
- package/src/store/index.tsx +11 -4
- package/src/store/visualSpecStore.ts +89 -50
- package/src/utils/dataPrep.ts +24 -0
- package/src/utils/index.ts +16 -17
- package/src/utils/media.ts +16 -11
- package/src/utils/normalization.ts +3 -1
- package/src/utils/save.ts +1 -2
- package/src/vis/react-vega.tsx +11 -332
- package/src/vis/spec/aggregate.ts +13 -0
- package/src/vis/spec/encode.ts +69 -0
- package/src/vis/spec/field.ts +10 -0
- package/src/vis/spec/mark.ts +30 -0
- package/src/vis/spec/stack.ts +11 -0
- package/src/vis/spec/view.ts +138 -0
- package/src/vis/theme.ts +35 -25
- package/src/visualSettings/index.tsx +22 -33
- package/src/workers/transform.ts +12 -0
- package/src/workers/transform.worker.js +13 -0
- package/src/workers/viewQuery.worker.js +16 -0
- package/dist/components/container.d.ts +0 -2
- package/dist/dataSource/pannel.d.ts +0 -5
- package/src/components/container.tsx +0 -25
- package/src/dataSource/pannel.tsx +0 -71
|
@@ -2,12 +2,14 @@ import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } fro
|
|
|
2
2
|
import produce from "immer";
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
4
|
import { Specification } from "visual-insights";
|
|
5
|
-
import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig } from "../interfaces";
|
|
5
|
+
import { DataSet, DraggableFieldState, IExpression, IFilterRule, IViewField, IVisSpec, IVisualConfig } from "../interfaces";
|
|
6
6
|
import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";
|
|
7
7
|
import { makeBinField, makeLogField } from "../utils/normalization";
|
|
8
8
|
import { VisSpecWithHistory } from "../models/visSpecHistory";
|
|
9
|
-
import { dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
|
|
9
|
+
import { IStoInfo, dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
|
|
10
10
|
import { CommonStore } from "./commonStore";
|
|
11
|
+
import { createCountField } from "../utils";
|
|
12
|
+
import { IViewQuery } from "../lib/viewQuery";
|
|
11
13
|
|
|
12
14
|
function getChannelSizeLimit(channel: string): number {
|
|
13
15
|
if (typeof CHANNEL_LIMIT[channel] === "undefined") return Infinity;
|
|
@@ -40,7 +42,7 @@ function geomAdapter(geom: string) {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
function initEncoding(): DraggableFieldState {
|
|
45
|
+
export function initEncoding(): DraggableFieldState {
|
|
44
46
|
return {
|
|
45
47
|
dimensions: [],
|
|
46
48
|
measures: [],
|
|
@@ -58,7 +60,7 @@ function initEncoding(): DraggableFieldState {
|
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
function initVisualConfig(): IVisualConfig {
|
|
63
|
+
export function initVisualConfig(): IVisualConfig {
|
|
62
64
|
return {
|
|
63
65
|
defaultAggregated: true,
|
|
64
66
|
geoms: [GEMO_TYPES[0]!],
|
|
@@ -92,6 +94,10 @@ const forwardVisualConfigs = (backwards: ReturnType<typeof parseGWContent>["spec
|
|
|
92
94
|
}));
|
|
93
95
|
};
|
|
94
96
|
|
|
97
|
+
function isDraggableStateEmpty(state: DeepReadonly<DraggableFieldState>): boolean {
|
|
98
|
+
return Object.values(state).every((value) => value.length === 0);
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
export class VizSpecStore {
|
|
96
102
|
// public fields: IViewField[] = [];
|
|
97
103
|
private commonStore: CommonStore;
|
|
@@ -139,7 +145,7 @@ export class VizSpecStore {
|
|
|
139
145
|
this.visualConfig = initVisualConfig();
|
|
140
146
|
this.visList.push(
|
|
141
147
|
new VisSpecWithHistory({
|
|
142
|
-
name:
|
|
148
|
+
name: 'Chart 1',
|
|
143
149
|
visId: uuidv4(),
|
|
144
150
|
config: this.visualConfig,
|
|
145
151
|
encodings: this.draggableFieldState,
|
|
@@ -151,13 +157,6 @@ export class VizSpecStore {
|
|
|
151
157
|
reactions: false,
|
|
152
158
|
});
|
|
153
159
|
this.reactions.push(
|
|
154
|
-
reaction(
|
|
155
|
-
() => commonStore.currentDataset,
|
|
156
|
-
(dataset) => {
|
|
157
|
-
// this.initState();
|
|
158
|
-
this.initMetaState(dataset);
|
|
159
|
-
}
|
|
160
|
-
),
|
|
161
160
|
reaction(
|
|
162
161
|
() => this.visList[this.visIndex],
|
|
163
162
|
(frame) => {
|
|
@@ -168,6 +167,15 @@ export class VizSpecStore {
|
|
|
168
167
|
this.canUndo = frame.canUndo;
|
|
169
168
|
this.canRedo = frame.canRedo;
|
|
170
169
|
}
|
|
170
|
+
),
|
|
171
|
+
reaction(
|
|
172
|
+
() => commonStore.currentDataset,
|
|
173
|
+
(dataset) => {
|
|
174
|
+
// this.initState();
|
|
175
|
+
if (isDraggableStateEmpty(this.draggableFieldState) && dataset.dataSource.length > 0 && dataset.rawFields.length > 0) {
|
|
176
|
+
this.initMetaState(dataset);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
171
179
|
)
|
|
172
180
|
);
|
|
173
181
|
}
|
|
@@ -275,10 +283,24 @@ export class VizSpecStore {
|
|
|
275
283
|
});
|
|
276
284
|
return fields;
|
|
277
285
|
}
|
|
278
|
-
public
|
|
286
|
+
public get allFields(): IViewField[] {
|
|
287
|
+
const { draggableFieldState } = this;
|
|
288
|
+
const dimensions = toJS(draggableFieldState.dimensions);
|
|
289
|
+
const measures = toJS(draggableFieldState.measures);
|
|
290
|
+
return [...dimensions, ...measures];
|
|
291
|
+
}
|
|
292
|
+
public get viewFilters() {
|
|
293
|
+
const { draggableFieldState } = this;
|
|
294
|
+
const state = toJS(draggableFieldState);
|
|
295
|
+
return state.filters;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
public addVisualization(defaultName?: string) {
|
|
300
|
+
const name = defaultName || 'Chart ' + (this.visList.length + 1);
|
|
279
301
|
this.visList.push(
|
|
280
302
|
new VisSpecWithHistory({
|
|
281
|
-
name
|
|
303
|
+
name,
|
|
282
304
|
visId: uuidv4(),
|
|
283
305
|
config: initVisualConfig(),
|
|
284
306
|
encodings: initEncoding(),
|
|
@@ -290,9 +312,10 @@ export class VizSpecStore {
|
|
|
290
312
|
this.visIndex = visIndex;
|
|
291
313
|
}
|
|
292
314
|
public setVisName(visIndex: number, name: string) {
|
|
293
|
-
this.
|
|
294
|
-
|
|
295
|
-
|
|
315
|
+
this.visList[visIndex] = this.visList[visIndex].clone();
|
|
316
|
+
this.visList[visIndex].updateLatest({
|
|
317
|
+
name
|
|
318
|
+
})
|
|
296
319
|
}
|
|
297
320
|
public initState() {
|
|
298
321
|
this.useMutable((tab) => {
|
|
@@ -301,6 +324,7 @@ export class VizSpecStore {
|
|
|
301
324
|
});
|
|
302
325
|
}
|
|
303
326
|
public initMetaState(dataset: DataSet) {
|
|
327
|
+
const countField = createCountField();
|
|
304
328
|
this.useMutable(({ encodings }) => {
|
|
305
329
|
encodings.fields = dataset.rawFields.map((f) => ({
|
|
306
330
|
dragId: uuidv4(),
|
|
@@ -309,7 +333,8 @@ export class VizSpecStore {
|
|
|
309
333
|
aggName: f.analyticType === "measure" ? "sum" : undefined,
|
|
310
334
|
analyticType: f.analyticType,
|
|
311
335
|
semanticType: f.semanticType,
|
|
312
|
-
}));
|
|
336
|
+
}))//.concat(countField);
|
|
337
|
+
encodings.fields.push(countField);
|
|
313
338
|
encodings.dimensions = dataset.rawFields
|
|
314
339
|
.filter((f) => f.analyticType === "dimension")
|
|
315
340
|
.map((f) => ({
|
|
@@ -329,17 +354,10 @@ export class VizSpecStore {
|
|
|
329
354
|
semanticType: f.semanticType,
|
|
330
355
|
aggName: "sum",
|
|
331
356
|
}));
|
|
357
|
+
encodings.measures.push(countField);
|
|
332
358
|
});
|
|
333
359
|
|
|
334
360
|
this.freezeHistory();
|
|
335
|
-
// this.draggableFieldState.measures.push({
|
|
336
|
-
// dragId: uuidv4(),
|
|
337
|
-
// fid: COUNT_FIELD_ID,
|
|
338
|
-
// name: '记录数',
|
|
339
|
-
// analyticType: 'measure',
|
|
340
|
-
// semanticType: 'quantitative',
|
|
341
|
-
// aggName: 'count'
|
|
342
|
-
// })
|
|
343
361
|
}
|
|
344
362
|
public clearState() {
|
|
345
363
|
this.useMutable(({ encodings }) => {
|
|
@@ -489,44 +507,59 @@ export class VizSpecStore {
|
|
|
489
507
|
encodings.rows = fieldsInCup as typeof encodings.rows; // assume this as writable
|
|
490
508
|
});
|
|
491
509
|
}
|
|
492
|
-
public createBinField(stateKey: keyof DraggableFieldState, index: number) {
|
|
510
|
+
public createBinField(stateKey: keyof DraggableFieldState, index: number, binType: 'bin' | 'binCount') {
|
|
493
511
|
this.useMutable(({ encodings }) => {
|
|
494
512
|
const originField = encodings[stateKey][index];
|
|
513
|
+
const newVarKey = uuidv4();
|
|
495
514
|
const binField: IViewField = {
|
|
496
|
-
fid:
|
|
497
|
-
dragId:
|
|
498
|
-
name:
|
|
515
|
+
fid: newVarKey,
|
|
516
|
+
dragId: newVarKey,
|
|
517
|
+
name: `${binType}(${originField.name})`,
|
|
499
518
|
semanticType: "ordinal",
|
|
500
519
|
analyticType: "dimension",
|
|
520
|
+
computed: true,
|
|
521
|
+
expressoion: {
|
|
522
|
+
op: binType,
|
|
523
|
+
as: newVarKey,
|
|
524
|
+
params: [
|
|
525
|
+
{
|
|
526
|
+
type: 'field',
|
|
527
|
+
value: originField.fid
|
|
528
|
+
}
|
|
529
|
+
]
|
|
530
|
+
}
|
|
501
531
|
};
|
|
502
532
|
encodings.dimensions.push(binField);
|
|
503
|
-
this.commonStore.currentDataset.dataSource = makeBinField(
|
|
504
|
-
this.commonStore.currentDataset.dataSource,
|
|
505
|
-
originField.fid,
|
|
506
|
-
binField.fid
|
|
507
|
-
);
|
|
508
533
|
});
|
|
509
534
|
}
|
|
510
|
-
public createLogField(stateKey: keyof DraggableFieldState, index: number) {
|
|
535
|
+
public createLogField(stateKey: keyof DraggableFieldState, index: number, scaleType: 'log10' | 'log2') {
|
|
511
536
|
if (stateKey === "filters") {
|
|
512
537
|
return;
|
|
513
538
|
}
|
|
514
539
|
|
|
515
540
|
this.useMutable(({ encodings }) => {
|
|
516
541
|
const originField = encodings[stateKey][index];
|
|
542
|
+
const newVarKey = uuidv4();
|
|
517
543
|
const logField: IViewField = {
|
|
518
|
-
fid:
|
|
519
|
-
dragId:
|
|
520
|
-
name:
|
|
544
|
+
fid: newVarKey,
|
|
545
|
+
dragId: newVarKey,
|
|
546
|
+
name: `${scaleType}(${originField.name})`,
|
|
521
547
|
semanticType: "quantitative",
|
|
522
548
|
analyticType: originField.analyticType,
|
|
549
|
+
aggName: 'sum',
|
|
550
|
+
computed: true,
|
|
551
|
+
expressoion: {
|
|
552
|
+
op: scaleType,
|
|
553
|
+
as: newVarKey,
|
|
554
|
+
params: [
|
|
555
|
+
{
|
|
556
|
+
type: 'field',
|
|
557
|
+
value: originField.fid
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
}
|
|
523
561
|
};
|
|
524
562
|
encodings[stateKey].push(logField);
|
|
525
|
-
this.commonStore.currentDataset.dataSource = makeLogField(
|
|
526
|
-
this.commonStore.currentDataset.dataSource,
|
|
527
|
-
originField.fid,
|
|
528
|
-
logField.fid
|
|
529
|
-
);
|
|
530
563
|
});
|
|
531
564
|
}
|
|
532
565
|
public setFieldAggregator(stateKey: keyof DraggableFieldState, index: number, aggName: string) {
|
|
@@ -677,13 +710,19 @@ export class VizSpecStore {
|
|
|
677
710
|
specList: pureVisList,
|
|
678
711
|
});
|
|
679
712
|
}
|
|
713
|
+
public exportViewSpec() {
|
|
714
|
+
const pureVisList = dumpsGWPureSpec(this.visList);
|
|
715
|
+
return pureVisList
|
|
716
|
+
}
|
|
717
|
+
public importStoInfo (stoInfo: IStoInfo) {
|
|
718
|
+
this.visList = parseGWPureSpec(forwardVisualConfigs(stoInfo.specList));
|
|
719
|
+
this.visIndex = 0;
|
|
720
|
+
this.commonStore.datasets = stoInfo.datasets;
|
|
721
|
+
this.commonStore.dataSources = stoInfo.dataSources;
|
|
722
|
+
this.commonStore.dsIndex = Math.max(stoInfo.datasets.length - 1, 0);
|
|
723
|
+
}
|
|
680
724
|
public importRaw(raw: string) {
|
|
681
725
|
const content = parseGWContent(raw);
|
|
682
|
-
this.
|
|
683
|
-
this.commonStore.dataSources = content.dataSources;
|
|
684
|
-
this.commonStore.dsIndex = Math.max(content.datasets.length - 1, 0);
|
|
685
|
-
// 补上初始化新版本特性
|
|
686
|
-
this.visList = parseGWPureSpec(forwardVisualConfigs(content.specList));
|
|
687
|
-
this.visIndex = 0;
|
|
726
|
+
this.importStoInfo(content);
|
|
688
727
|
}
|
|
689
728
|
}
|
package/src/utils/dataPrep.ts
CHANGED
|
@@ -41,4 +41,28 @@ export function guardDataKeys (data: IRow[], metas: IMutField[]): {
|
|
|
41
41
|
safeData,
|
|
42
42
|
safeMetas
|
|
43
43
|
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const SPLITOR = '__'
|
|
47
|
+
export function flatNestKeys (object: any): string[] {
|
|
48
|
+
const keys = Object.keys(object);
|
|
49
|
+
let flatColKeys: string[] = [];
|
|
50
|
+
for (let key of keys) {
|
|
51
|
+
if (typeof object[key] === 'object') {
|
|
52
|
+
const subKeys = flatNestKeys(object[key]);
|
|
53
|
+
flatColKeys = flatColKeys.concat(subKeys.map(k => `${key}${SPLITOR}${k}`));
|
|
54
|
+
} else {
|
|
55
|
+
flatColKeys.push(key)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return flatColKeys;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getValueByKeyPath (object: any, keyPath: string): any {
|
|
62
|
+
const keys = keyPath.split(SPLITOR);
|
|
63
|
+
let value = object;
|
|
64
|
+
for (let key of keys) {
|
|
65
|
+
value = value[key];
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
44
68
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import i18next from "i18next";
|
|
2
2
|
import { COUNT_FIELD_ID } from "../constants";
|
|
3
|
-
import { IRow, Filters, IMutField } from "../interfaces";
|
|
3
|
+
import { IRow, Filters, IMutField, IViewField } from "../interfaces";
|
|
4
4
|
interface NRReturns {
|
|
5
5
|
normalizedData: IRow[];
|
|
6
6
|
maxMeasures: IRow;
|
|
@@ -236,26 +236,21 @@ export function applyFilters(dataSource: IRow[], filters: Filters): IRow[] {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export function
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
dataSource: IRow[];
|
|
244
|
-
fields: IMutField[];
|
|
245
|
-
} {
|
|
246
|
-
const nextData = dataSource.map((r) => ({
|
|
247
|
-
...r,
|
|
248
|
-
[COUNT_FIELD_ID]: 1,
|
|
249
|
-
}));
|
|
250
|
-
const nextFields = fields.concat({
|
|
239
|
+
export function createCountField(): IViewField {
|
|
240
|
+
return {
|
|
241
|
+
// viewId: "",
|
|
242
|
+
dragId: COUNT_FIELD_ID,
|
|
251
243
|
fid: COUNT_FIELD_ID,
|
|
252
244
|
name: i18next.t("constant.row_count"),
|
|
253
245
|
analyticType: "measure",
|
|
254
246
|
semanticType: "quantitative",
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
247
|
+
aggName: 'sum',
|
|
248
|
+
computed: true,
|
|
249
|
+
expressoion: {
|
|
250
|
+
op: 'one',
|
|
251
|
+
params: [],
|
|
252
|
+
as: COUNT_FIELD_ID,
|
|
253
|
+
}
|
|
259
254
|
};
|
|
260
255
|
}
|
|
261
256
|
|
|
@@ -276,4 +271,8 @@ export function makeNumbersBeautiful (nums: number[]): number[] {
|
|
|
276
271
|
return nums.map((num) => {
|
|
277
272
|
return Math.round(num / step) * step;
|
|
278
273
|
})
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function classNames(...classes: string[]) {
|
|
277
|
+
return classes.filter(Boolean).join(' ')
|
|
279
278
|
}
|
package/src/utils/media.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
+
import { IDarkMode } from "../interfaces";
|
|
2
3
|
|
|
3
4
|
export function currentMediaTheme(): "dark" | "light" {
|
|
4
5
|
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
@@ -8,19 +9,23 @@ export function currentMediaTheme(): "dark" | "light" {
|
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export function useCurrentMediaTheme(): "dark" | "light" {
|
|
12
|
-
const [theme, setTheme] = useState<"dark" | "light">(currentMediaTheme());
|
|
12
|
+
export function useCurrentMediaTheme(mode: IDarkMode | undefined = 'media'): "dark" | "light" {
|
|
13
|
+
const [theme, setTheme] = useState<"dark" | "light">(mode === 'media' ? currentMediaTheme() : mode);
|
|
13
14
|
|
|
14
15
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
if (mode === 'media') {
|
|
17
|
+
const mediaQuery = window.matchMedia?.("(prefers-color-scheme: dark)") as MediaQueryList | undefined;
|
|
18
|
+
const listener = (e: MediaQueryListEvent) => {
|
|
19
|
+
setTheme(e.matches ? "dark" : "light");
|
|
20
|
+
};
|
|
21
|
+
mediaQuery?.addEventListener("change", listener);
|
|
22
|
+
return () => {
|
|
23
|
+
mediaQuery?.removeEventListener("change", listener);
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
setTheme(mode);
|
|
27
|
+
}
|
|
28
|
+
}, [mode]);
|
|
24
29
|
|
|
25
30
|
return theme;
|
|
26
31
|
}
|
|
@@ -146,7 +146,9 @@ export function makeBinField(dataSource: IRow[], fid: string, binFid: string, bi
|
|
|
146
146
|
if (bIndex === binSize) bIndex = binSize - 1;
|
|
147
147
|
return {
|
|
148
148
|
...r,
|
|
149
|
-
[binFid]:
|
|
149
|
+
[binFid]: [bIndex * step + _min, (bIndex + 1) * step + _min],
|
|
150
|
+
|
|
151
|
+
// [binFid]: Number(((bIndex * step + _min)).toFixed(beaStep)),
|
|
150
152
|
};
|
|
151
153
|
});
|
|
152
154
|
}
|
package/src/utils/save.ts
CHANGED
|
@@ -9,10 +9,9 @@ export function parseGWPureSpec(list: IVisSpec[]): VisSpecWithHistory[] {
|
|
|
9
9
|
return list.map((l) => new VisSpecWithHistory(l));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface IStoInfo {
|
|
12
|
+
export interface IStoInfo {
|
|
13
13
|
datasets: IDataSet[];
|
|
14
14
|
specList: {
|
|
15
|
-
/** 由于 gw 内部实现暂时未锁版本,这里获取到的信息可能会与当前实例内容有偏差,需要用初始值合入 */
|
|
16
15
|
[K in keyof IVisSpec]: K extends "config" ? Partial<IVisSpec[K]> : IVisSpec[K];
|
|
17
16
|
}[];
|
|
18
17
|
dataSources: IDataSource[];
|