@kanaries/graphic-walker 0.2.16 → 0.2.17

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.
Files changed (73) hide show
  1. package/dist/App.d.ts +3 -4
  2. package/dist/assets/viewQuery.worker-ffefc111.js.map +1 -1
  3. package/dist/dataSource/index.d.ts +0 -1
  4. package/dist/fields/encodeFields/singleEncodeEditor.d.ts +4 -4
  5. package/dist/graphic-walker.es.js +29716 -34642
  6. package/dist/graphic-walker.es.js.map +1 -1
  7. package/dist/graphic-walker.umd.js +218 -256
  8. package/dist/graphic-walker.umd.js.map +1 -1
  9. package/dist/interfaces.d.ts +31 -16
  10. package/dist/lib/inferMeta.d.ts +2 -9
  11. package/dist/lib/insights/explainByChildren.d.ts +16 -0
  12. package/dist/lib/insights/explainBySelection.d.ts +5 -0
  13. package/dist/lib/insights/explainValue.d.ts +2 -0
  14. package/dist/lib/insights/utils.d.ts +11 -0
  15. package/dist/lib/interfaces.d.ts +2 -1
  16. package/dist/lib/op/aggregate.d.ts +1 -1
  17. package/dist/lib/op/bin.d.ts +1 -1
  18. package/dist/lib/op/fold.d.ts +1 -1
  19. package/dist/lib/viewQuery.d.ts +1 -2
  20. package/dist/services.d.ts +1 -30
  21. package/dist/store/visualSpecStore.d.ts +1 -2
  22. package/dist/utils/autoMark.d.ts +1 -1
  23. package/dist/utils/dataPrep.d.ts +1 -2
  24. package/dist/vis/react-vega.d.ts +1 -0
  25. package/dist/vis/spec/encode.d.ts +1 -0
  26. package/dist/vis/spec/mark.d.ts +1 -1
  27. package/dist/vis/spec/tooltip.d.ts +4 -0
  28. package/dist/vis/spec/view.d.ts +9 -3
  29. package/package.json +2 -4
  30. package/src/App.tsx +55 -68
  31. package/src/dataSource/index.tsx +0 -17
  32. package/src/fields/aestheticFields.tsx +1 -2
  33. package/src/fields/encodeFields/singleEncodeEditor.tsx +11 -12
  34. package/src/fields/fieldsContext.tsx +1 -0
  35. package/src/interfaces.ts +75 -63
  36. package/src/lib/inferMeta.ts +26 -29
  37. package/src/lib/insights/explainByChildren.ts +50 -0
  38. package/src/lib/insights/explainBySelection.ts +47 -0
  39. package/src/lib/insights/explainValue.ts +30 -0
  40. package/src/lib/insights/utils.ts +21 -0
  41. package/src/lib/interfaces.ts +3 -9
  42. package/src/lib/op/aggregate.ts +1 -1
  43. package/src/lib/op/bin.ts +1 -1
  44. package/src/lib/op/fold.ts +1 -1
  45. package/src/lib/viewQuery.ts +1 -2
  46. package/src/locales/en-US.json +2 -1
  47. package/src/locales/zh-CN.json +2 -1
  48. package/src/renderer/specRenderer.tsx +2 -0
  49. package/src/services.ts +65 -67
  50. package/src/store/visualSpecStore.ts +2 -4
  51. package/src/utils/autoMark.ts +1 -1
  52. package/src/utils/dataPrep.ts +1 -2
  53. package/src/vis/react-vega.tsx +5 -0
  54. package/src/vis/spec/encode.ts +1 -0
  55. package/src/vis/spec/mark.ts +1 -1
  56. package/src/vis/spec/tooltip.ts +16 -0
  57. package/src/vis/spec/view.ts +12 -14
  58. package/dist/assets/explainer.worker-8428eb12.js.map +0 -1
  59. package/dist/insightBoard/index.d.ts +0 -3
  60. package/dist/insightBoard/mainBoard.d.ts +0 -11
  61. package/dist/insightBoard/radioGroupButtons.d.ts +0 -12
  62. package/dist/insightBoard/selectionSpec.d.ts +0 -13
  63. package/dist/insightBoard/std2vegaSpec.d.ts +0 -12
  64. package/dist/insightBoard/utils.d.ts +0 -8
  65. package/dist/insights.d.ts +0 -61
  66. package/src/insightBoard/index.tsx +0 -31
  67. package/src/insightBoard/mainBoard.tsx +0 -224
  68. package/src/insightBoard/radioGroupButtons.tsx +0 -57
  69. package/src/insightBoard/selectionSpec.ts +0 -113
  70. package/src/insightBoard/std2vegaSpec.ts +0 -184
  71. package/src/insightBoard/utils.ts +0 -32
  72. package/src/insights.ts +0 -408
  73. package/src/workers/explainer.worker.js +0 -76
package/src/services.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { toJS } from 'mobx';
2
- import { View, Specification } from 'visual-insights';
3
- import { IRow, Filters, SemanticType, IMeasure, IMutField, IFilterField } from './interfaces';
2
+ import { IRow, IMutField, IFilterField, Specification } from './interfaces';
4
3
  /* eslint import/no-webpack-loader-syntax:0 */
5
4
  // @ts-ignore
6
5
  // eslint-disable-next-line
@@ -8,20 +7,19 @@ import { IRow, Filters, SemanticType, IMeasure, IMutField, IFilterField } from '
8
7
  /* eslint import/no-webpack-loader-syntax:0 */
9
8
  // @ts-ignore
10
9
  // eslint-disable-next-line
11
- import ExplainerWorker from './workers/explainer.worker?worker&inline';
10
+ // import ExplainerWorker from './workers/explainer.worker?worker&inline';
12
11
  import FilterWorker from './workers/filter.worker?worker&inline';
13
12
  import TransformDataWorker from './workers/transform.worker?worker&inline';
14
13
  import ViewQueryWorker from './workers/viewQuery.worker?worker&inline';
15
- import { IExplaination, IMeasureWithStat } from './insights';
16
- import { IViewQuery, queryView } from './lib/viewQuery';
14
+ import { IViewQuery } from './lib/viewQuery';
17
15
 
18
- interface WorkerState {
19
- eWorker: Worker | null;
20
- }
16
+ // interface WorkerState {
17
+ // eWorker: Worker | null;
18
+ // }
21
19
 
22
- const workerState: WorkerState = {
23
- eWorker: null,
24
- }
20
+ // const workerState: WorkerState = {
21
+ // eWorker: null,
22
+ // }
25
23
 
26
24
  function workerService<T, R>(worker: Worker, data: R): Promise<T> {
27
25
  return new Promise<T>((resolve, reject) => {
@@ -38,72 +36,72 @@ function workerService<T, R>(worker: Worker, data: R): Promise<T> {
38
36
  });
39
37
  }
40
38
 
41
- interface ExplainParams {
42
- dimensions: string[];
43
- measures: string[];
44
- dataSource: IRow[];
45
- filters?: Filters;
46
- currentSpace: {
47
- dimensions: string[];
48
- measures: IMeasure[];
49
- };
50
- }
39
+ // interface ExplainParams {
40
+ // dimensions: string[];
41
+ // measures: string[];
42
+ // dataSource: IRow[];
43
+ // filters?: Filters;
44
+ // currentSpace: {
45
+ // dimensions: string[];
46
+ // measures: IMeasure[];
47
+ // };
48
+ // }
51
49
  export interface IVisSpace {
52
50
  dataView: IRow[];
53
51
  schema: Specification;
54
52
  }
55
- interface ExplainReturns {
56
- explainations: IExplaination[];
57
- valueExp: IMeasureWithStat[];
58
- visSpaces: IVisSpace[];
59
- fieldsWithSemanticType: Array<{ key: string; type: SemanticType }>;
60
- }
61
- export async function getExplaination(props: ExplainParams) {
62
- const worker = workerState.eWorker;
63
- if (worker === null) throw new Error('init worker first.')
64
- let result: ExplainReturns = {
65
- explainations: [],
66
- valueExp: [],
67
- visSpaces: [],
68
- fieldsWithSemanticType: [],
69
- };
70
- try {
71
- result = await workerService<ExplainReturns, { type: string; data: ExplainParams }>(
72
- worker,
73
- {
74
- type: 'getExplaination',
75
- data: props
76
- }
77
- );
78
- return result;
79
- } catch (error) {
80
- console.error(error);
81
- }
82
- return result;
83
- }
53
+ // interface ExplainReturns {
54
+ // explainations: IExplaination[];
55
+ // valueExp: IMeasureWithStat[];
56
+ // visSpaces: IVisSpace[];
57
+ // fieldsWithSemanticType: Array<{ key: string; type: SemanticType }>;
58
+ // }
59
+ // export async function getExplaination(props: ExplainParams) {
60
+ // const worker = workerState.eWorker;
61
+ // if (worker === null) throw new Error('init worker first.')
62
+ // let result: ExplainReturns = {
63
+ // explainations: [],
64
+ // valueExp: [],
65
+ // visSpaces: [],
66
+ // fieldsWithSemanticType: [],
67
+ // };
68
+ // try {
69
+ // result = await workerService<ExplainReturns, { type: string; data: ExplainParams }>(
70
+ // worker,
71
+ // {
72
+ // type: 'getExplaination',
73
+ // data: props
74
+ // }
75
+ // );
76
+ // return result;
77
+ // } catch (error) {
78
+ // console.error(error);
79
+ // }
80
+ // return result;
81
+ // }
84
82
 
85
83
  interface PreAnalysisParams {
86
84
  fields: IMutField[];
87
85
  dataSource: IRow[];
88
86
  }
89
- export async function preAnalysis(props: PreAnalysisParams) {
90
- if (workerState.eWorker !== null) {
91
- workerState.eWorker.terminate();
92
- }
93
- try {
94
- workerState.eWorker = new ExplainerWorker() as Worker;
95
- const tmp = await workerService<boolean, { type: string; data: PreAnalysisParams}>(workerState.eWorker, { type: 'preAnalysis', data: props });
96
- } catch (error) {
97
- console.error(error)
98
- }
99
- }
87
+ // export async function preAnalysis(props: PreAnalysisParams) {
88
+ // if (workerState.eWorker !== null) {
89
+ // workerState.eWorker.terminate();
90
+ // }
91
+ // try {
92
+ // workerState.eWorker = new ExplainerWorker() as Worker;
93
+ // const tmp = await workerService<boolean, { type: string; data: PreAnalysisParams}>(workerState.eWorker, { type: 'preAnalysis', data: props });
94
+ // } catch (error) {
95
+ // console.error(error)
96
+ // }
97
+ // }
100
98
 
101
- export function destroyWorker() {
102
- if (workerState.eWorker) {
103
- workerState.eWorker.terminate();
104
- workerState.eWorker = null;
105
- }
106
- }
99
+ // export function destroyWorker() {
100
+ // if (workerState.eWorker) {
101
+ // workerState.eWorker.terminate();
102
+ // workerState.eWorker = null;
103
+ // }
104
+ // }
107
105
 
108
106
  let filterWorker: Worker | null = null;
109
107
  let filterWorkerAutoTerminator: NodeJS.Timeout | null = null;
@@ -1,15 +1,12 @@
1
1
  import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } from "mobx";
2
2
  import produce from "immer";
3
3
  import { v4 as uuidv4 } from "uuid";
4
- import { Specification } from "visual-insights";
5
- import { DataSet, DraggableFieldState, IExpression, IFilterRule, IViewField, IVisSpec, IVisualConfig } from "../interfaces";
4
+ import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig, Specification } from "../interfaces";
6
5
  import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";
7
- import { makeBinField, makeLogField } from "../utils/normalization";
8
6
  import { VisSpecWithHistory } from "../models/visSpecHistory";
9
7
  import { IStoInfo, dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
10
8
  import { CommonStore } from "./commonStore";
11
9
  import { createCountField } from "../utils";
12
- import { IViewQuery } from "../lib/viewQuery";
13
10
 
14
11
  function getChannelSizeLimit(channel: string): number {
15
12
  if (typeof CHANNEL_LIMIT[channel] === "undefined") return Infinity;
@@ -649,6 +646,7 @@ export class VizSpecStore {
649
646
  // thi
650
647
  // const [xField, yField, ] = spec.position;
651
648
  this.clearState();
649
+ this.setVisualConfig('defaultAggregated', Boolean(spec.aggregate));
652
650
  if ((spec.geomType?.length ?? 0) > 0) {
653
651
  this.setVisualConfig(
654
652
  "geoms",
@@ -1,4 +1,4 @@
1
- import { ISemanticType } from "visual-insights";
1
+ import { ISemanticType } from "../interfaces";
2
2
 
3
3
  /**
4
4
  *
@@ -1,5 +1,4 @@
1
- import { IRow } from "visual-insights";
2
- import { IMutField } from "../interfaces";
1
+ import { IMutField, IRow } from "../interfaces";
3
2
 
4
3
  function updateRowKeys(data: IRow[], keyEncodeList: {from: string; to: string}[]): IRow[] {
5
4
  return data.map((row) => {
@@ -40,6 +40,7 @@ interface ReactVegaProps {
40
40
  shape?: IViewField;
41
41
  theta?: IViewField;
42
42
  radius?: IViewField;
43
+ details?: Readonly<IViewField[]>;
43
44
  showActions: boolean;
44
45
  layoutMode: string;
45
46
  width: number;
@@ -97,6 +98,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
97
98
  height,
98
99
  selectEncoding,
99
100
  brushEncoding,
101
+ details = [],
100
102
  themeKey = 'vega',
101
103
  dark = 'media'
102
104
  } = props;
@@ -189,6 +191,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
189
191
  column: colFacetField,
190
192
  xOffset: NULL_FIELD,
191
193
  yOffset: NULL_FIELD,
194
+ details,
192
195
  defaultAggregated: defaultAggregate,
193
196
  stack,
194
197
  geomType,
@@ -257,6 +260,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
257
260
  column: colFacetField,
258
261
  xOffset: NULL_FIELD,
259
262
  yOffset: NULL_FIELD,
263
+ details,
260
264
  defaultAggregated: defaultAggregate,
261
265
  stack,
262
266
  geomType,
@@ -368,6 +372,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
368
372
  brushEncoding,
369
373
  crossFilterTriggerIdx,
370
374
  themeConfig,
375
+ details
371
376
  ]);
372
377
 
373
378
  useImperativeHandle(ref, () => ({
@@ -14,6 +14,7 @@ export interface IEncodeProps {
14
14
  column: IViewField;
15
15
  theta: IViewField;
16
16
  radius: IViewField;
17
+ details: Readonly<IViewField[]>;
17
18
  }
18
19
  function availableChannels(geomType: string): Set<string> {
19
20
  if (geomType === 'arc') {
@@ -1,4 +1,4 @@
1
- import { ISemanticType } from "visual-insights";
1
+ import { ISemanticType } from "../../interfaces";
2
2
 
3
3
  /**
4
4
  *
@@ -0,0 +1,16 @@
1
+ import { IViewField } from "../../interfaces";
2
+
3
+ export function addTooltipEncode (encoding: {[key: string]: any}, details: Readonly<IViewField[]> = []) {
4
+ const encs = Object.keys(encoding).filter(ck => ck !== 'tooltip').map(ck => {
5
+ return {
6
+ field: encoding[ck].field,
7
+ type: encoding[ck].type,
8
+ title: encoding[ck].title
9
+ }
10
+ }).concat(details.map(f => ({
11
+ field: f.fid,
12
+ title: f.name,
13
+ type: f.semanticType
14
+ })))
15
+ encoding.tooltip = encs
16
+ }
@@ -1,15 +1,14 @@
1
- import { ISemanticType } from 'visual-insights';
2
- import { IStackMode, IViewField } from '../../interfaces';
1
+ import { ISemanticType, IStackMode, IViewField } from '../../interfaces';
3
2
  import { autoMark } from './mark';
4
3
  import { NULL_FIELD } from './field';
5
4
  import { channelAggregate } from './aggregate';
6
5
  import { IEncodeProps, channelEncode } from './encode';
7
- import { channelStack } from './stack'
6
+ import { channelStack } from './stack';
7
+ import { addTooltipEncode } from './tooltip';
8
8
 
9
9
  const BRUSH_SIGNAL_NAME = '__gw_brush__';
10
10
  const POINT_SIGNAL_NAME = '__gw_point__';
11
11
  export interface SingleViewProps extends IEncodeProps {
12
-
13
12
  defaultAggregated: boolean;
14
13
  stack: IStackMode;
15
14
  enableCrossFilter: boolean;
@@ -32,6 +31,7 @@ export function getSingleView(props: SingleViewProps) {
32
31
  column,
33
32
  xOffset,
34
33
  yOffset,
34
+ details,
35
35
  defaultAggregated,
36
36
  stack,
37
37
  geomType,
@@ -70,27 +70,25 @@ export function getSingleView(props: SingleViewProps) {
70
70
  yOffset,
71
71
  theta,
72
72
  radius,
73
+ details
73
74
  });
75
+ addTooltipEncode(encoding, details)
74
76
  if (defaultAggregated) {
75
77
  channelAggregate(encoding, fields);
76
78
  }
77
79
  channelStack(encoding, stack);
80
+ const mark = {
81
+ type: markType,
82
+ opacity: 0.96,
83
+ tooltip: { content: 'data' }
84
+ };
78
85
  if (!enableCrossFilter || (brushEncoding === 'none' && selectEncoding === 'none')) {
79
86
  return {
80
87
  config,
81
- mark: {
82
- type: markType,
83
- opacity: 0.96,
84
- tooltip: true,
85
- },
88
+ mark,
86
89
  encoding,
87
90
  };
88
91
  }
89
- const mark = {
90
- type: markType,
91
- opacity: 0.96,
92
- tooltip: true,
93
- };
94
92
 
95
93
  if (brushEncoding !== 'none') {
96
94
  return {