@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.
- package/dist/App.d.ts +6 -3
- package/dist/assets/explainer.worker-8428eb12.js.map +1 -1
- package/dist/components/button/base.d.ts +6 -0
- package/dist/components/button/default.d.ts +4 -0
- package/dist/components/button/primary.d.ts +4 -0
- package/dist/dataSource/utils.d.ts +1 -1
- package/dist/graphic-walker.es.js +17671 -18577
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +134 -134
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/interfaces.d.ts +8 -0
- package/dist/lib/inferMeta.d.ts +20 -0
- package/dist/store/commonStore.d.ts +1 -1
- package/dist/store/index.d.ts +0 -1
- package/dist/store/visualSpecStore.d.ts +5 -5
- package/dist/utils/dataPrep.d.ts +6 -0
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/normalization.d.ts +1 -1
- package/dist/utils/save.d.ts +3 -3
- package/dist/utils/throttle.d.ts +1 -1
- package/dist/vis/temporalFormat.d.ts +10 -0
- package/package.json +1 -1
- package/src/App.tsx +27 -10
- package/src/components/button/base.ts +7 -0
- package/src/components/button/default.tsx +17 -0
- package/src/components/button/primary.tsx +17 -0
- package/src/dataSource/dataSelection/csvData.tsx +8 -10
- package/src/dataSource/dataSelection/publicData.tsx +4 -4
- package/src/dataSource/index.tsx +10 -12
- package/src/dataSource/table.tsx +33 -20
- package/src/dataSource/utils.ts +30 -35
- package/src/fields/datasetFields/dimFields.tsx +1 -5
- package/src/fields/datasetFields/meaFields.tsx +1 -5
- package/src/fields/obComponents/obFContainer.tsx +1 -5
- package/src/index.tsx +3 -4
- package/src/interfaces.ts +9 -0
- package/src/lib/inferMeta.ts +88 -0
- package/src/locales/en-US.json +6 -0
- package/src/locales/zh-CN.json +6 -0
- package/src/main.tsx +1 -1
- package/src/store/commonStore.ts +8 -3
- package/src/store/index.tsx +0 -2
- package/src/store/visualSpecStore.ts +245 -183
- package/src/utils/autoMark.ts +14 -14
- package/src/utils/dataPrep.ts +44 -0
- package/src/utils/index.ts +140 -128
- package/src/utils/normalization.ts +59 -51
- package/src/utils/save.ts +22 -21
- package/src/utils/throttle.ts +5 -1
- package/src/vis/react-vega.tsx +6 -10
- package/src/vis/temporalFormat.ts +66 -0
- package/dist/pitch/dnd-offset.d.ts +0 -2
- 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, {
|
|
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<
|
|
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}
|
|
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
|
+
}
|
package/src/locales/en-US.json
CHANGED
package/src/locales/zh-CN.json
CHANGED
package/src/main.tsx
CHANGED
package/src/store/commonStore.ts
CHANGED
|
@@ -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
|
}
|
package/src/store/index.tsx
CHANGED
|
@@ -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>
|