@kanaries/graphic-walker 0.4.0 → 0.4.2
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 -1
- package/dist/assets/buildMetricTable.worker-5555966a.js.map +1 -0
- package/dist/components/dataTable/index.d.ts +2 -1
- package/dist/components/leafletRenderer/ChoroplethRenderer.d.ts +21 -0
- package/dist/components/leafletRenderer/POIRenderer.d.ts +19 -0
- package/dist/components/leafletRenderer/encodings.d.ts +7 -0
- package/dist/components/leafletRenderer/geoConfigPanel.d.ts +3 -0
- package/dist/components/leafletRenderer/index.d.ts +14 -0
- package/dist/components/leafletRenderer/tooltip.d.ts +9 -0
- package/dist/components/leafletRenderer/utils.d.ts +2 -0
- package/dist/components/pivotTable/index.d.ts +2 -1
- package/dist/components/pivotTable/inteface.d.ts +6 -2
- package/dist/components/pivotTable/leftTree.d.ts +1 -0
- package/dist/components/pivotTable/topTree.d.ts +2 -0
- package/dist/components/pivotTable/utils.d.ts +1 -2
- package/dist/config.d.ts +3 -2
- package/dist/graphic-walker.es.js +37802 -30402
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +145 -137
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/interfaces.d.ts +27 -0
- package/dist/renderer/specRenderer.d.ts +2 -1
- package/dist/services.d.ts +7 -1
- package/dist/store/commonStore.d.ts +6 -0
- package/dist/store/visualSpecStore.d.ts +180 -4
- package/dist/utils/save.d.ts +1 -0
- package/dist/workers/buildPivotTable.d.ts +7 -0
- package/package.json +14 -2
- package/src/App.tsx +18 -4
- package/src/components/askViz/index.tsx +2 -1
- package/src/components/dataTable/index.tsx +7 -5
- package/src/components/leafletRenderer/ChoroplethRenderer.tsx +293 -0
- package/src/components/leafletRenderer/POIRenderer.tsx +170 -0
- package/src/components/leafletRenderer/encodings.ts +194 -0
- package/src/components/leafletRenderer/geoConfigPanel.tsx +197 -0
- package/src/components/leafletRenderer/index.tsx +67 -0
- package/src/components/leafletRenderer/tooltip.tsx +24 -0
- package/src/components/leafletRenderer/utils.ts +52 -0
- package/src/components/limitSetting.tsx +8 -6
- package/src/components/pivotTable/index.tsx +171 -67
- package/src/components/pivotTable/inteface.ts +6 -2
- package/src/components/pivotTable/leftTree.tsx +24 -11
- package/src/components/pivotTable/metricTable.tsx +15 -10
- package/src/components/pivotTable/topTree.tsx +50 -17
- package/src/components/pivotTable/utils.ts +70 -11
- package/src/components/sizeSetting.tsx +9 -7
- package/src/components/visualConfig/index.tsx +17 -1
- package/src/computation/serverComputation.ts +8 -3
- package/src/config.ts +27 -16
- package/src/dataSource/table.tsx +9 -9
- package/src/fields/aestheticFields.tsx +4 -0
- package/src/fields/fieldsContext.tsx +3 -0
- package/src/fields/posFields/index.tsx +8 -2
- package/src/global.d.ts +4 -4
- package/src/hooks/index.ts +8 -0
- package/src/index.tsx +11 -9
- package/src/interfaces.ts +34 -0
- package/src/locales/en-US.json +27 -2
- package/src/locales/ja-JP.json +27 -2
- package/src/locales/zh-CN.json +27 -2
- package/src/renderer/hooks.ts +2 -48
- package/src/renderer/index.tsx +24 -1
- package/src/renderer/pureRenderer.tsx +26 -13
- package/src/renderer/specRenderer.tsx +45 -30
- package/src/services.ts +32 -23
- package/src/shadow-dom.tsx +7 -0
- package/src/store/commonStore.ts +29 -1
- package/src/store/visualSpecStore.ts +40 -24
- package/src/utils/save.ts +28 -1
- package/src/visualSettings/index.tsx +58 -7
- package/src/workers/buildMetricTable.worker.js +27 -0
- package/src/workers/buildPivotTable.ts +27 -0
package/src/utils/save.ts
CHANGED
|
@@ -11,15 +11,40 @@ export function parseGWPureSpec(list: IVisSpec[]): VisSpecWithHistory[] {
|
|
|
11
11
|
return list.map((l) => new VisSpecWithHistory(l));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export function initEncoding(): DraggableFieldState {
|
|
15
|
+
return {
|
|
16
|
+
dimensions: [],
|
|
17
|
+
measures: [],
|
|
18
|
+
rows: [],
|
|
19
|
+
columns: [],
|
|
20
|
+
color: [],
|
|
21
|
+
opacity: [],
|
|
22
|
+
size: [],
|
|
23
|
+
shape: [],
|
|
24
|
+
radius: [],
|
|
25
|
+
theta: [],
|
|
26
|
+
longitude: [],
|
|
27
|
+
latitude: [],
|
|
28
|
+
geoId: [],
|
|
29
|
+
details: [],
|
|
30
|
+
filters: [],
|
|
31
|
+
text: [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
export function initVisualConfig(): IVisualConfig {
|
|
36
|
+
const [ geom ] = GEMO_TYPES.generic;
|
|
15
37
|
return {
|
|
16
38
|
defaultAggregated: true,
|
|
17
|
-
geoms: [
|
|
39
|
+
geoms: [geom],
|
|
40
|
+
showTableSummary: false,
|
|
41
|
+
coordSystem: 'generic',
|
|
18
42
|
stack: 'stack',
|
|
19
43
|
showActions: false,
|
|
20
44
|
interactiveScale: false,
|
|
21
45
|
sorted: 'none',
|
|
22
46
|
zeroScale: true,
|
|
47
|
+
scaleIncludeUnmatchedChoropleth: false,
|
|
23
48
|
background: undefined,
|
|
24
49
|
size: {
|
|
25
50
|
mode: "auto",
|
|
@@ -31,6 +56,7 @@ export function initVisualConfig(): IVisualConfig {
|
|
|
31
56
|
timeFormat: undefined,
|
|
32
57
|
normalizedNumberFormat: undefined,
|
|
33
58
|
},
|
|
59
|
+
geoKey: 'name',
|
|
34
60
|
resolve: {
|
|
35
61
|
x: false,
|
|
36
62
|
y: false,
|
|
@@ -60,6 +86,7 @@ export function visSpecDecoder(visList: IVisSpecForExport[]): IVisSpec[] {
|
|
|
60
86
|
return {
|
|
61
87
|
...visSpec,
|
|
62
88
|
encodings: {
|
|
89
|
+
...initEncoding(),
|
|
63
90
|
...visSpec.encodings,
|
|
64
91
|
filters: updatedFilters,
|
|
65
92
|
},
|
|
@@ -19,6 +19,11 @@ import {
|
|
|
19
19
|
LightBulbIcon,
|
|
20
20
|
CodeBracketSquareIcon,
|
|
21
21
|
Cog6ToothIcon,
|
|
22
|
+
TableCellsIcon,
|
|
23
|
+
MapPinIcon,
|
|
24
|
+
GlobeAltIcon,
|
|
25
|
+
RectangleGroupIcon,
|
|
26
|
+
GlobeAmericasIcon,
|
|
22
27
|
HashtagIcon,
|
|
23
28
|
} from '@heroicons/react/24/outline';
|
|
24
29
|
import { observer } from 'mobx-react-lite';
|
|
@@ -26,7 +31,7 @@ import React, { SVGProps, useCallback, useMemo } from 'react';
|
|
|
26
31
|
import styled from 'styled-components';
|
|
27
32
|
import { useTranslation } from 'react-i18next';
|
|
28
33
|
import { ResizeDialog } from '../components/sizeSetting';
|
|
29
|
-
import { GEMO_TYPES, STACK_MODE, CHART_LAYOUT_TYPE } from '../config';
|
|
34
|
+
import { GEMO_TYPES, STACK_MODE, CHART_LAYOUT_TYPE, COORD_TYPES } from '../config';
|
|
30
35
|
import { useGlobalStore } from '../store';
|
|
31
36
|
import { IStackMode, IDarkMode } from '../interfaces';
|
|
32
37
|
import { IReactVegaHandler } from '../vis/react-vega';
|
|
@@ -37,7 +42,6 @@ import throttle from '../utils/throttle';
|
|
|
37
42
|
import KanariesLogo from '../assets/kanaries.png';
|
|
38
43
|
import { ImageWithFallback } from '../components/timeoutImg';
|
|
39
44
|
import LimitSetting from '../components/limitSetting';
|
|
40
|
-
import { runInAction } from 'mobx';
|
|
41
45
|
|
|
42
46
|
const Invisible = styled.div`
|
|
43
47
|
clip: rect(1px, 1px, 1px, 1px);
|
|
@@ -83,6 +87,8 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
83
87
|
const {
|
|
84
88
|
defaultAggregated,
|
|
85
89
|
geoms: [markType],
|
|
90
|
+
showTableSummary,
|
|
91
|
+
coordSystem = 'generic',
|
|
86
92
|
stack,
|
|
87
93
|
interactiveScale,
|
|
88
94
|
size: { mode: sizeMode, width, height },
|
|
@@ -164,7 +170,7 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
164
170
|
color: 'rgb(294,115,22)',
|
|
165
171
|
},
|
|
166
172
|
},
|
|
167
|
-
options: GEMO_TYPES.map((g) => ({
|
|
173
|
+
options: GEMO_TYPES[coordSystem].map((g) => ({
|
|
168
174
|
key: g,
|
|
169
175
|
label: tGlobal(`constant.mark_type.${g}`),
|
|
170
176
|
icon: {
|
|
@@ -349,6 +355,8 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
349
355
|
/>
|
|
350
356
|
</svg>
|
|
351
357
|
),
|
|
358
|
+
poi: MapPinIcon,
|
|
359
|
+
choropleth: RectangleGroupIcon,
|
|
352
360
|
}[g],
|
|
353
361
|
})),
|
|
354
362
|
value: markType,
|
|
@@ -394,6 +402,15 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
394
402
|
icon: BarsArrowDownIcon,
|
|
395
403
|
onClick: () => vizStore.applyDefaultSort('descending'),
|
|
396
404
|
},
|
|
405
|
+
{
|
|
406
|
+
key: 'table:summary',
|
|
407
|
+
label: t('table.summary'),
|
|
408
|
+
icon: TableCellsIcon,
|
|
409
|
+
checked: showTableSummary,
|
|
410
|
+
onChange: checked => {
|
|
411
|
+
vizStore.setVisualConfig('showTableSummary', checked);
|
|
412
|
+
},
|
|
413
|
+
},
|
|
397
414
|
'-',
|
|
398
415
|
{
|
|
399
416
|
key: 'axes_resize',
|
|
@@ -439,6 +456,34 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
439
456
|
),
|
|
440
457
|
},
|
|
441
458
|
'-',
|
|
459
|
+
{
|
|
460
|
+
key: 'coord_system',
|
|
461
|
+
label: tGlobal('constant.coord_system.__enum__'),
|
|
462
|
+
icon: StopIcon,
|
|
463
|
+
options: COORD_TYPES.map(c => ({
|
|
464
|
+
key: c,
|
|
465
|
+
label: tGlobal(`constant.coord_system.${c}`),
|
|
466
|
+
icon: {
|
|
467
|
+
generic: (props: SVGProps<SVGSVGElement>) => <svg stroke="currentColor" fill="none" strokeWidth="1.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden {...props}><path strokeLinecap="round" strokeLinejoin="round" d="M2 12h20M12 2v20" /><path strokeLinecap="round" strokeLinejoin="round" d="M12 7h2M12 16h2M7 12v-2M16 12v-2"/></svg>,
|
|
468
|
+
geographic: GlobeAltIcon,
|
|
469
|
+
}[c],
|
|
470
|
+
})),
|
|
471
|
+
value: coordSystem,
|
|
472
|
+
onSelect: value => {
|
|
473
|
+
const coord = value as typeof COORD_TYPES[number];
|
|
474
|
+
vizStore.setVisualConfig('coordSystem', coord);
|
|
475
|
+
vizStore.setVisualConfig('geoms', [GEMO_TYPES[coord][0]]);
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
coordSystem === 'geographic' && markType === 'choropleth' && {
|
|
479
|
+
key: 'geojson',
|
|
480
|
+
label: t('button.geojson'),
|
|
481
|
+
icon: GlobeAmericasIcon,
|
|
482
|
+
onClick: () => {
|
|
483
|
+
commonStore.setShowGeoJSONConfigPanel(true);
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
'-',
|
|
442
487
|
{
|
|
443
488
|
key: 'debug',
|
|
444
489
|
label: t('toggle.debug'),
|
|
@@ -448,7 +493,7 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
448
493
|
vizStore.setVisualConfig('showActions', checked);
|
|
449
494
|
},
|
|
450
495
|
},
|
|
451
|
-
{
|
|
496
|
+
...coordSystem === 'generic' ?[{
|
|
452
497
|
key: 'export_chart',
|
|
453
498
|
label: t('button.export_chart'),
|
|
454
499
|
icon: PhotoIcon,
|
|
@@ -478,7 +523,7 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
478
523
|
</button>
|
|
479
524
|
</FormContainer>
|
|
480
525
|
),
|
|
481
|
-
},
|
|
526
|
+
}]:[],
|
|
482
527
|
{
|
|
483
528
|
key: 'config',
|
|
484
529
|
label: 'config',
|
|
@@ -530,17 +575,23 @@ const VisualSettings: React.FC<IVisualSettings> = ({
|
|
|
530
575
|
</a>
|
|
531
576
|
),
|
|
532
577
|
},
|
|
533
|
-
] as ToolbarItemProps[];
|
|
578
|
+
].filter(Boolean) as ToolbarItemProps[];
|
|
534
579
|
|
|
535
580
|
const items = builtInItems.filter((item) => typeof item === 'string' || !exclude.includes(item.key));
|
|
536
581
|
|
|
537
|
-
|
|
582
|
+
switch (vizStore.visualConfig.geoms[0]) {
|
|
583
|
+
case 'table':
|
|
584
|
+
return items;
|
|
585
|
+
default:
|
|
586
|
+
return items.filter(item => typeof item === 'string' || item.key !== 'table:summary');
|
|
587
|
+
}
|
|
538
588
|
}, [
|
|
539
589
|
vizStore,
|
|
540
590
|
canUndo,
|
|
541
591
|
canRedo,
|
|
542
592
|
defaultAggregated,
|
|
543
593
|
markType,
|
|
594
|
+
coordSystem,
|
|
544
595
|
stack,
|
|
545
596
|
interactiveScale,
|
|
546
597
|
sizeMode,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint no-restricted-globals: 0 */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { buildPivotTable } from "./buildPivotTable"
|
|
4
|
+
/**
|
|
5
|
+
* @param {import('../interfaces').IViewField[]} dimsInRow
|
|
6
|
+
* @param {import('../interfaces').IViewField[]} dimsInColumn
|
|
7
|
+
* @param {import('../interfaces').IRow[]} allData
|
|
8
|
+
* @param {import('../interfaces').IRow} aggData
|
|
9
|
+
* @param {string[]} collapsedKeyList
|
|
10
|
+
* @param {boolean} showTableSummary
|
|
11
|
+
* @return {{lt: import('../components/pivotTable/inteface').INestNode, tt: import('../components/pivotTable/inteface').INestNode, metric: import('../interfaces').(IRow | null)[][]}}
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {MessageEvent<{ dimsInRow: import('../interfaces').IViewField[]; dimsInColumn: import('../interfaces').IViewField[]; allData: import('../interfaces').IRow[]; aggData: import('../interfaces').IRow[]; collapsedKeyList: string[]; showTableSummary: boolean }>} e
|
|
16
|
+
*/
|
|
17
|
+
const main = e => {
|
|
18
|
+
const { dimsInRow, dimsInColumn, allData, aggData, collapsedKeyList, showTableSummary } = e.data;
|
|
19
|
+
try {
|
|
20
|
+
const ans = buildPivotTable(dimsInRow, dimsInColumn, allData, aggData, collapsedKeyList, showTableSummary);
|
|
21
|
+
self.postMessage(ans);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
self.postMessage({ error: error.message });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
self.addEventListener('message', main, false);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { INestNode } from "../components/pivotTable/inteface";
|
|
2
|
+
import { buildMetricTableFromNestTree, buildNestTree } from "../components/pivotTable/utils"
|
|
3
|
+
import { IViewField, IRow } from "../interfaces"
|
|
4
|
+
|
|
5
|
+
export function buildPivotTable (
|
|
6
|
+
dimsInRow: IViewField[],
|
|
7
|
+
dimsInColumn: IViewField[],
|
|
8
|
+
allData: IRow[],
|
|
9
|
+
aggData: IRow[],
|
|
10
|
+
collapsedKeyList: string[],
|
|
11
|
+
showTableSummary: boolean
|
|
12
|
+
): {lt: INestNode, tt: INestNode, metric: (IRow | null)[][]} {
|
|
13
|
+
const lt = buildNestTree(
|
|
14
|
+
dimsInRow.map((d) => d.fid),
|
|
15
|
+
allData,
|
|
16
|
+
collapsedKeyList,
|
|
17
|
+
showTableSummary
|
|
18
|
+
);
|
|
19
|
+
const tt = buildNestTree(
|
|
20
|
+
dimsInColumn.map((d) => d.fid),
|
|
21
|
+
allData,
|
|
22
|
+
collapsedKeyList,
|
|
23
|
+
showTableSummary
|
|
24
|
+
);
|
|
25
|
+
const metric = buildMetricTableFromNestTree(lt, tt, [...allData, ...aggData])
|
|
26
|
+
return {lt, tt, metric}
|
|
27
|
+
}
|