@kanaries/graphic-walker 0.2.11 → 0.2.12

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 (54) hide show
  1. package/dist/App.d.ts +6 -3
  2. package/dist/assets/explainer.worker-8428eb12.js.map +1 -1
  3. package/dist/components/button/base.d.ts +6 -0
  4. package/dist/components/button/default.d.ts +4 -0
  5. package/dist/components/button/primary.d.ts +4 -0
  6. package/dist/dataSource/utils.d.ts +1 -1
  7. package/dist/graphic-walker.es.js +17671 -18577
  8. package/dist/graphic-walker.es.js.map +1 -1
  9. package/dist/graphic-walker.umd.js +134 -134
  10. package/dist/graphic-walker.umd.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/interfaces.d.ts +8 -0
  13. package/dist/lib/inferMeta.d.ts +20 -0
  14. package/dist/store/commonStore.d.ts +1 -1
  15. package/dist/store/index.d.ts +0 -1
  16. package/dist/store/visualSpecStore.d.ts +5 -5
  17. package/dist/utils/dataPrep.d.ts +6 -0
  18. package/dist/utils/index.d.ts +2 -2
  19. package/dist/utils/normalization.d.ts +1 -1
  20. package/dist/utils/save.d.ts +3 -3
  21. package/dist/utils/throttle.d.ts +1 -1
  22. package/dist/vis/temporalFormat.d.ts +10 -0
  23. package/package.json +1 -1
  24. package/src/App.tsx +27 -10
  25. package/src/components/button/base.ts +7 -0
  26. package/src/components/button/default.tsx +17 -0
  27. package/src/components/button/primary.tsx +17 -0
  28. package/src/dataSource/dataSelection/csvData.tsx +8 -10
  29. package/src/dataSource/dataSelection/publicData.tsx +4 -4
  30. package/src/dataSource/index.tsx +10 -12
  31. package/src/dataSource/table.tsx +33 -20
  32. package/src/dataSource/utils.ts +30 -35
  33. package/src/fields/datasetFields/dimFields.tsx +1 -5
  34. package/src/fields/datasetFields/meaFields.tsx +1 -5
  35. package/src/fields/obComponents/obFContainer.tsx +1 -5
  36. package/src/index.tsx +3 -4
  37. package/src/interfaces.ts +9 -0
  38. package/src/lib/inferMeta.ts +88 -0
  39. package/src/locales/en-US.json +6 -0
  40. package/src/locales/zh-CN.json +6 -0
  41. package/src/main.tsx +1 -1
  42. package/src/store/commonStore.ts +8 -3
  43. package/src/store/index.tsx +0 -2
  44. package/src/store/visualSpecStore.ts +245 -183
  45. package/src/utils/autoMark.ts +14 -14
  46. package/src/utils/dataPrep.ts +44 -0
  47. package/src/utils/index.ts +140 -128
  48. package/src/utils/normalization.ts +59 -51
  49. package/src/utils/save.ts +22 -21
  50. package/src/utils/throttle.ts +5 -1
  51. package/src/vis/react-vega.tsx +6 -10
  52. package/src/vis/temporalFormat.ts +66 -0
  53. package/dist/pitch/dnd-offset.d.ts +0 -2
  54. package/src/pitch/dnd-offset.ts +0 -64
package/src/index.tsx CHANGED
@@ -3,7 +3,7 @@ import { StyleSheetManager } from 'styled-components';
3
3
  import root from 'react-shadow';
4
4
  import { DOM } from '@kanaries/react-beautiful-dnd';
5
5
  import { observer } from 'mobx-react-lite';
6
- import App, { EditorProps } from './App';
6
+ import App, { IGWProps } from './App';
7
7
  import { StoreWrapper } from './store/index';
8
8
  import { FieldsContextWrapper } from './fields/fieldsContext';
9
9
 
@@ -14,10 +14,9 @@ import style from './index.css?inline';
14
14
 
15
15
  export const ShadowDomContext = createContext<{ root: ShadowRoot | null }>({ root: null });
16
16
 
17
- export const GraphicWalker: React.FC<EditorProps> = observer(props => {
17
+ export const GraphicWalker: React.FC<IGWProps> = observer(props => {
18
18
  const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(null);
19
19
  const rootRef = useRef<HTMLDivElement>(null);
20
- const fixContainer = props.fixContainer ?? false;
21
20
 
22
21
  useEffect(() => {
23
22
  if (rootRef.current) {
@@ -38,7 +37,7 @@ export const GraphicWalker: React.FC<EditorProps> = observer(props => {
38
37
  <style>{style}</style>
39
38
  {shadowRoot && (
40
39
  <StyleSheetManager target={shadowRoot}>
41
- <StoreWrapper keepAlive={props.keepAlive} rootContainer={fixContainer ? rootRef.current : null}>
40
+ <StoreWrapper keepAlive={props.keepAlive}>
42
41
  <FieldsContextWrapper>
43
42
  <ShadowDomContext.Provider value={{ root: shadowRoot }}>
44
43
  <App {...props} />
package/src/interfaces.ts CHANGED
@@ -27,6 +27,15 @@ export interface IMutField {
27
27
  analyticType: IAnalyticType;
28
28
  };
29
29
 
30
+ export interface IUncertainMutField {
31
+ fid: string;
32
+ key?: string;
33
+ name?: string;
34
+ disable?: boolean;
35
+ semanticType: ISemanticType | '?';
36
+ analyticType: IAnalyticType | '?';
37
+ }
38
+
30
39
  export interface IField {
31
40
  /**
32
41
  * fid: key in data record
@@ -0,0 +1,88 @@
1
+ import { IAnalyticType, ISemanticType, UnivariateSummary } from "visual-insights";
2
+ import { IMutField, IRow, IUncertainMutField } from "../interfaces";
3
+
4
+ const COMMON_TIME_FORMAT: RegExp[] = [
5
+ /^\d{4}-\d{2}-\d{2}$/, // YYYY-MM-DD
6
+ /^\d{2}\/\d{2}\/\d{4}$/, // MM/DD/YYYY
7
+ /^\d{2}\/\d{2}\/\d{4}$/, // DD/MM/YYYY
8
+ /^\d{4}\/\d{2}\/\d{2}$/, // YYYY/MM/DD
9
+ /^\d{4}\.\d{2}\.\d{2}$/, // YYYY.MM.DD
10
+ /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/, // YYYY-MM-DD HH:MM:SS
11
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/ // YYYY-MM-DDTHH:MM:SS (ISO-8601)
12
+ ];
13
+
14
+ /**
15
+ * check if this array is a date time array based on some common date format
16
+ * @param data string array
17
+ * @returns
18
+ */
19
+ export function isDateTimeArray(data: string[]): boolean {
20
+ let isDateTime = true;
21
+ for (let d of data) {
22
+ let isDateTimeItem = false;
23
+ for (let r of COMMON_TIME_FORMAT) {
24
+ if (r.test(d)) {
25
+ isDateTimeItem = true;
26
+ break;
27
+ }
28
+ }
29
+ if (!isDateTimeItem) {
30
+ isDateTime = false;
31
+ break;
32
+ }
33
+ }
34
+ return isDateTime;
35
+ }
36
+
37
+ function inferAnalyticTypeFromSemanticType(semanticType: ISemanticType): IAnalyticType {
38
+ switch (semanticType) {
39
+ case 'quantitative':
40
+ return 'measure';
41
+ default:
42
+ return 'dimension';
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 这里目前暂时包一层,是为了解耦具体的推断实现。后续这里要调整推断的逻辑。
48
+ * 需要讨论这一层是否和交互层有关,如果没有关系,这一层包裹可以不存在这里,而是在visual-insights中。
49
+ * @param data 原始数据
50
+ * @param fid 字段id
51
+ * @returns semantic type 列表
52
+ */
53
+ export function inferSemanticType(data: IRow[], fid: string): ISemanticType {
54
+ let st = UnivariateSummary.getFieldType(data, fid);
55
+ if (st === 'nominal') {
56
+ if (isDateTimeArray(data.map((row) => row[fid]))) st = 'temporal';
57
+ } else if (st === 'ordinal') {
58
+ const valueSet: Set<number> = new Set();
59
+ let _max = -Infinity;
60
+ let _min = Infinity;
61
+ for (let v of valueSet) {
62
+ _max = Math.max(_max, v);
63
+ _min = Math.max(_min, v);
64
+ }
65
+ if (_max - _min + 1 !== valueSet.size) {
66
+ st = 'quantitative';
67
+ }
68
+ }
69
+ return st;
70
+ }
71
+
72
+ export function inferMeta (props: { dataSource: IRow[]; fields: IUncertainMutField[] }): IMutField[] {
73
+ const { dataSource, fields } = props;
74
+ const finalFieldMetas: IMutField[] = []
75
+ for (let field of fields) {
76
+ let semanticType: ISemanticType = field.semanticType === '?' ? inferSemanticType(dataSource, field.fid) : field.semanticType;
77
+ let analyticType: IAnalyticType = inferAnalyticTypeFromSemanticType(semanticType);
78
+
79
+ finalFieldMetas.push({
80
+ fid: field.fid,
81
+ key: field.key ? field.key : field.fid,
82
+ name: field.name ? field.name : field.fid,
83
+ analyticType,
84
+ semanticType,
85
+ })
86
+ }
87
+ return finalFieldMetas
88
+ }
@@ -5,6 +5,12 @@
5
5
  "dimension": "dimension",
6
6
  "measure": "measure"
7
7
  },
8
+ "semantic_type": {
9
+ "nominal": "nominal",
10
+ "ordinal": "ordinal",
11
+ "temporal": "temporal",
12
+ "quantitative": "quantitative"
13
+ },
8
14
  "mark_type": {
9
15
  "__enum__": "Mark Type",
10
16
  "auto": "Auto",
@@ -5,6 +5,12 @@
5
5
  "dimension": "维度",
6
6
  "measure": "度量"
7
7
  },
8
+ "semantic_type": {
9
+ "nominal": "类别类型",
10
+ "ordinal": "有序类型",
11
+ "temporal": "时间类型",
12
+ "quantitative": "数值类型"
13
+ },
8
14
  "mark_type": {
9
15
  "__enum__": "标记类型",
10
16
  "auto": "自动",
package/src/main.tsx CHANGED
@@ -9,7 +9,7 @@ inject();
9
9
 
10
10
  ReactDOM.render(
11
11
  <React.StrictMode>
12
- <GraphicWalker />
12
+ <GraphicWalker />
13
13
  </React.StrictMode>,
14
14
  document.getElementById("root")
15
15
  );
@@ -13,7 +13,6 @@ export class CommonStore {
13
13
  public showDSPanel: boolean = false;
14
14
  public showInsightBoard: boolean = false;
15
15
  public vizEmbededMenu: { show: boolean; position: [number, number] } = { show: false, position: [0, 0] };
16
- public rootContainer: HTMLDivElement | null = null;
17
16
 
18
17
  public filters: Filters = {};
19
18
  constructor () {
@@ -22,8 +21,7 @@ export class CommonStore {
22
21
  makeAutoObservable(this, {
23
22
  dataSources: observable.ref,
24
23
  tmpDataSource: observable.ref,
25
- filters: observable.ref,
26
- rootContainer: false
24
+ filters: observable.ref
27
25
  });
28
26
  }
29
27
  public get currentDataset (): DataSet {
@@ -75,6 +73,13 @@ export class CommonStore {
75
73
  }
76
74
  }
77
75
 
76
+ public updateTempFieldSemanticType (fieldKey: string, semanticType: IMutField['semanticType']) {
77
+ const field = this.tmpDSRawFields.find(f => f.fid === fieldKey);
78
+ if (field) {
79
+ field.semanticType = semanticType;
80
+ }
81
+ }
82
+
78
83
  public updateTempName (name: string) {
79
84
  this.tmpDSName = name;
80
85
  }
@@ -31,7 +31,6 @@ export function rebootGWStore() {
31
31
 
32
32
  interface StoreWrapperProps {
33
33
  keepAlive?: boolean;
34
- rootContainer?: HTMLDivElement | null;
35
34
  }
36
35
  export class StoreWrapper extends React.Component<StoreWrapperProps> {
37
36
  constructor(props: StoreWrapperProps) {
@@ -46,7 +45,6 @@ export class StoreWrapper extends React.Component<StoreWrapperProps> {
46
45
  }
47
46
  }
48
47
  render() {
49
- initStore.commonStore.rootContainer = this.props.rootContainer ?? null;
50
48
  return <StoreContext.Provider value={initStore}>
51
49
  { this.props.children }
52
50
  </StoreContext.Provider>