@kanaries/graphic-walker 0.2.17 → 0.2.19

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.
@@ -128,7 +128,6 @@ export interface IFilterField extends IViewField {
128
128
  rule: IFilterRule | null;
129
129
  }
130
130
  export interface DraggableFieldState {
131
- fields: IViewField[];
132
131
  dimensions: IViewField[];
133
132
  measures: IViewField[];
134
133
  rows: IViewField[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanaries/graphic-walker",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "scripts": {
5
5
  "dev:front_end": "vite --host",
6
6
  "dev": "npm run dev:front_end",
@@ -43,6 +43,7 @@
43
43
  "immer": "^9.0.15",
44
44
  "mobx": "^6.3.3",
45
45
  "mobx-react-lite": "^3.2.1",
46
+ "nanoid": "^4.0.2",
46
47
  "postcss": "^8.3.7",
47
48
  "postinstall-postinstall": "^2.1.0",
48
49
  "re-resizable": "^6.9.8",
@@ -17,7 +17,7 @@ const syntaxHighlight = (json: any) => {
17
17
  .replace(/>/g, ">")
18
18
  .replace(/\n/g, "<br>")
19
19
  .replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;")
20
- .replace(/\s/g, "&nbsp;&nbsp;");
20
+ .replace(/\s/g, "&nbsp;");
21
21
  return json.replace(
22
22
  /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
23
23
  function (match) {
@@ -84,8 +84,8 @@ const CodeExport: React.FC = observer((props) => {
84
84
  }}
85
85
  />
86
86
  {tabKey === "graphic-walker" && (
87
- <div className="text-sm px-6 max-h-56 overflow-auto">
88
- <div dangerouslySetInnerHTML={{ __html: syntaxHighlight(code) }} />
87
+ <div className="text-sm px-6 max-h-96 overflow-auto">
88
+ <code dangerouslySetInnerHTML={{ __html: syntaxHighlight(code) }} />
89
89
  </div>
90
90
  )}
91
91
  <div className="mt-4 flex justify-start">
package/src/config.ts CHANGED
@@ -53,5 +53,4 @@ export const CHANNEL_LIMIT = {
53
53
  export const MetaFieldKeys: Array<keyof DraggableFieldState> = [
54
54
  'dimensions',
55
55
  'measures',
56
- 'fields'
57
56
  ]
@@ -40,7 +40,6 @@ export const FieldsContextWrapper: React.FC = props => {
40
40
  export default FieldsContextWrapper;
41
41
 
42
42
  export const DRAGGABLE_STATE_KEYS: Readonly<IDraggableStateKey[]> = [
43
- { id: 'fields', mode: 0 },
44
43
  { id: 'columns', mode: 0 },
45
44
  { id: 'rows', mode: 0 },
46
45
  { id: 'color', mode: 1 },
package/src/interfaces.ts CHANGED
@@ -149,7 +149,6 @@ export interface IFilterField extends IViewField {
149
149
  }
150
150
 
151
151
  export interface DraggableFieldState {
152
- fields: IViewField[];
153
152
  dimensions: IViewField[];
154
153
  measures: IViewField[];
155
154
  rows: IViewField[];
package/src/main.tsx CHANGED
@@ -1,11 +1,13 @@
1
- import React, { useEffect } from "react";
1
+ import React from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import { GraphicWalker } from "./index";
4
4
 
5
5
  import { inject } from "@vercel/analytics";
6
6
  import "./index.css";
7
7
 
8
- inject();
8
+ if (!import.meta.env.DEV) {
9
+ inject();
10
+ }
9
11
 
10
12
  ReactDOM.render(
11
13
  <React.StrictMode>
@@ -1,21 +1,26 @@
1
1
  import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } from "mobx";
2
2
  import produce from "immer";
3
- import { v4 as uuidv4 } from "uuid";
4
3
  import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig, Specification } from "../interfaces";
5
4
  import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";
6
5
  import { VisSpecWithHistory } from "../models/visSpecHistory";
7
6
  import { IStoInfo, dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
8
7
  import { CommonStore } from "./commonStore";
9
8
  import { createCountField } from "../utils";
9
+ import { nanoid } from "nanoid";
10
10
 
11
11
  function getChannelSizeLimit(channel: string): number {
12
12
  if (typeof CHANNEL_LIMIT[channel] === "undefined") return Infinity;
13
13
  return CHANNEL_LIMIT[channel];
14
14
  }
15
15
 
16
+ function uniqueId(): string {
17
+ return "gw_" + nanoid(4);
18
+ }
19
+
16
20
  function geomAdapter(geom: string) {
17
21
  switch (geom) {
18
22
  case "interval":
23
+ case "bar":
19
24
  return "bar";
20
25
  case "line":
21
26
  return "line";
@@ -43,7 +48,6 @@ export function initEncoding(): DraggableFieldState {
43
48
  return {
44
49
  dimensions: [],
45
50
  measures: [],
46
- fields: [],
47
51
  rows: [],
48
52
  columns: [],
49
53
  color: [],
@@ -143,7 +147,7 @@ export class VizSpecStore {
143
147
  this.visList.push(
144
148
  new VisSpecWithHistory({
145
149
  name: 'Chart 1',
146
- visId: uuidv4(),
150
+ visId: uniqueId(),
147
151
  config: this.visualConfig,
148
152
  encodings: this.draggableFieldState,
149
153
  })
@@ -298,7 +302,7 @@ export class VizSpecStore {
298
302
  this.visList.push(
299
303
  new VisSpecWithHistory({
300
304
  name,
301
- visId: uuidv4(),
305
+ visId: uniqueId(),
302
306
  config: initVisualConfig(),
303
307
  encodings: initEncoding(),
304
308
  })
@@ -323,19 +327,10 @@ export class VizSpecStore {
323
327
  public initMetaState(dataset: DataSet) {
324
328
  const countField = createCountField();
325
329
  this.useMutable(({ encodings }) => {
326
- encodings.fields = dataset.rawFields.map((f) => ({
327
- dragId: uuidv4(),
328
- fid: f.fid,
329
- name: f.name || f.fid,
330
- aggName: f.analyticType === "measure" ? "sum" : undefined,
331
- analyticType: f.analyticType,
332
- semanticType: f.semanticType,
333
- }))//.concat(countField);
334
- encodings.fields.push(countField);
335
330
  encodings.dimensions = dataset.rawFields
336
331
  .filter((f) => f.analyticType === "dimension")
337
332
  .map((f) => ({
338
- dragId: uuidv4(),
333
+ dragId: uniqueId(),
339
334
  fid: f.fid,
340
335
  name: f.name || f.fid,
341
336
  semanticType: f.semanticType,
@@ -344,7 +339,7 @@ export class VizSpecStore {
344
339
  encodings.measures = dataset.rawFields
345
340
  .filter((f) => f.analyticType === "measure")
346
341
  .map((f) => ({
347
- dragId: uuidv4(),
342
+ dragId: uniqueId(),
348
343
  fid: f.fid,
349
344
  name: f.name || f.fid,
350
345
  analyticType: f.analyticType,
@@ -435,7 +430,7 @@ export class VizSpecStore {
435
430
  // use a different dragId
436
431
  movingField = {
437
432
  ...toJS(encodings[sourceKey][sourceIndex]), // toJS will NOT shallow copy a object here
438
- dragId: uuidv4(),
433
+ dragId: uniqueId(),
439
434
  };
440
435
  } else {
441
436
  [movingField] = encodings[sourceKey].splice(sourceIndex, 1);
@@ -479,7 +474,7 @@ export class VizSpecStore {
479
474
  this.useMutable(({ encodings }) => {
480
475
  encodings.filters.splice(index, 0, {
481
476
  ...toJS(data),
482
- dragId: uuidv4(),
477
+ dragId: uniqueId(),
483
478
  rule: null,
484
479
  });
485
480
  this.editingFilterIdx = index;
@@ -507,7 +502,7 @@ export class VizSpecStore {
507
502
  public createBinField(stateKey: keyof DraggableFieldState, index: number, binType: 'bin' | 'binCount') {
508
503
  this.useMutable(({ encodings }) => {
509
504
  const originField = encodings[stateKey][index];
510
- const newVarKey = uuidv4();
505
+ const newVarKey = uniqueId();
511
506
  const binField: IViewField = {
512
507
  fid: newVarKey,
513
508
  dragId: newVarKey,
@@ -536,7 +531,7 @@ export class VizSpecStore {
536
531
 
537
532
  this.useMutable(({ encodings }) => {
538
533
  const originField = encodings[stateKey][index];
539
- const newVarKey = uuidv4();
534
+ const newVarKey = uniqueId();
540
535
  const logField: IViewField = {
541
536
  fid: newVarKey,
542
537
  dragId: newVarKey,
@@ -634,7 +629,7 @@ export class VizSpecStore {
634
629
 
635
630
  this.useMutable(({ encodings }) => {
636
631
  const cloneField = { ...toJS(field) };
637
- cloneField.dragId = uuidv4();
632
+ cloneField.dragId = uniqueId();
638
633
  encodings[destinationKey].push(cloneField);
639
634
  });
640
635
  }
@@ -642,7 +637,7 @@ export class VizSpecStore {
642
637
  const tab = this.visList[this.visIndex];
643
638
 
644
639
  if (tab) {
645
- const fields = tab.encodings.fields;
640
+ const fields = tab.encodings.dimensions.concat(tab.encodings.measures);
646
641
  // thi
647
642
  // const [xField, yField, ] = spec.position;
648
643
  this.clearState();