Skip to content

Commit

Permalink
feat: v2 engine to webworker
Browse files Browse the repository at this point in the history
  • Loading branch information
ObservedObserver committed Sep 28, 2021
1 parent 284413a commit 994fe2f
Show file tree
Hide file tree
Showing 22 changed files with 787 additions and 342 deletions.
13 changes: 13 additions & 0 deletions packages/frontend/public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,18 @@
"default_group": "group distribution",
"default_trend": "trend"
}
},
"lts": {
"autoAnalysis": "Auto Analysis",
"computing": "computing",
"title": "Visual Insights",
"hintMain": "Here are some interesting patterns and insights found by Rath. If you are interested in some of them, try to use 'summary' to know more details about current view and use 'associate' to explore relative visualizations.",
"summary": "Summary",
"associate": "Associate",
"asso": {
"T1": "Associated Measures",
"T2": "Associated Dimensions",
"hint": "Associated Measures refers to keep the dimensions similar, find correlated measures. Associated Dimensions refers to keep the measures similar, find correlated dimensions."
}
}
}
13 changes: 13 additions & 0 deletions packages/frontend/public/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,18 @@
"default_group": "组间分布差异",
"default_trend": "趋势"
}
},
"lts": {
"autoAnalysis": "自动分析",
"computing": "计算中",
"title": "洞察推荐",
"hintMain": "洞察推荐板块展示了Rath自动化挖掘数据时发现的有趣的规律和洞察,如果你对其中的某些图表感兴趣,尝试使用'概览'来获取更多细节或使用'联想'来探索与当前图表相关的内容。",
"summary": "概览",
"associate": "联想",
"asso": {
"T1": "关联度量",
"T2": "关联维度",
"hint": "『关联度量』是指探索和当前图表中,度量/指标关联程度更高的图表,这可以帮你研究哪些指标的表现和当前关注的指标相近。『关联维度』是指探索和当前图表中,维度相关度更高的图表,这可以帮助你研究对于当前的度量下,相似维度对度量分布的划分差异。"
}
}
}
10 changes: 10 additions & 0 deletions packages/frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ h2, h3 {
color: #323130;
font-weight: 500;
}
.state-header{
display: block;
font-size: 1.5em;
margin-block-start: 0.83em;
margin-block-end: 0.83em;
margin-inline-start: 0px;
margin-inline-end: 0px;
color: #323130;
font-weight: 500;
}
.state-description{
margin-top: 10px;
font-weight: 360;
Expand Down
11 changes: 10 additions & 1 deletion packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import intl from 'react-intl-universal';
import { useGlobalStore, StoreWrapper } from './store/index'
import { Pivot, PivotItem } from "office-ui-fabric-react";
import { useComposeState } from "./utils/index";
import { useComposeState } from "./hooks/index";
import "./App.css";

import Gallery from "./pages/gallery/index";
Expand All @@ -15,6 +15,8 @@ import SupportPage from './pages/support/index';
import LTSPage from './pages/lts';
import UserSettings from './components/userSettings';
import { observer } from "mobx-react-lite";
import { useEffect } from "react";
import { destroyRathWorker, initRathWorker } from "./service";

// FIXME: 这两代码好像没什么用
require('intl/locale-data/jsonp/en.js')
Expand Down Expand Up @@ -48,6 +50,13 @@ function App() {
})
}

useEffect(() => {
initRathWorker();
return () => {
destroyRathWorker();
}
}, [])

const [pageStatus, setPageStatus] = useComposeState<PageStatus>({
show: {
insightBoard: false,
Expand Down
91 changes: 91 additions & 0 deletions packages/frontend/src/components/vizPreference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useCallback } from "react";
import { observer } from 'mobx-react-lite';
import { PrimaryButton, Stack, Checkbox, Panel, PanelType, ComboBox, Label } from "office-ui-fabric-react";
import { Aggregator } from "../global";
import { useGlobalStore } from "../store";
const checkboxStyles = () => {
return {
root: {
marginTop: "10px",
},
};
};

// todo: import aggregators list from cube-core
const aggregationList: Array<{ key: Aggregator; text: string }> = [
{ key: "sum", text: "Sum" },
{ key: "count", text: "Count" },
{ key: "mean", text: "Mean" },
];

const PreferencePanel: React.FC = () => {
const { exploreStore } = useGlobalStore()
const { visualConfig, showPreferencePannel } = exploreStore;

const { aggregator, defaultAggregated, defaultStack } = visualConfig;

const closeVisualPannel = useCallback(() => {
exploreStore.setShowPreferencePannel(false);
}, [])

const onRenderFooterContent = () => (
<div>
<PrimaryButton
onClick={closeVisualPannel}
>
Save
</PrimaryButton>
</div>
);

return (
<Panel
isOpen={showPreferencePannel}
type={PanelType.smallFixedFar}
onDismiss={closeVisualPannel}
headerText="Preference"
closeButtonAriaLabel="Close"
onRenderFooterContent={onRenderFooterContent}
>
<Label>Preference</Label>
<Stack verticalFill tokens={{ childrenGap: 50, padding: 6 }}>
<ComboBox
selectedKey={aggregator}
label="Aggregator"
allowFreeform={true}
autoComplete="on"
options={aggregationList}
onChange={(e, option) => {
if (option) {
exploreStore.setVisualConig(config => {
config.aggregator = option.key as Aggregator;
})
}
}}
/>
<Checkbox
styles={checkboxStyles}
label="measurement aggregation"
checked={defaultAggregated}
onChange={(e, isChecked) => {
exploreStore.setVisualConig(config => {
visualConfig.defaultAggregated = isChecked || false;
})
}}
/>
<Checkbox
styles={checkboxStyles}
label="measurement stack"
checked={defaultStack}
onChange={(e, isChecked) => {
exploreStore.setVisualConig(config => {
visualConfig.defaultStack = isChecked || false;
})
}}
/>
</Stack>
</Panel>
);
};

export default observer(PreferencePanel);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type StateUpdater<S> = (draftState: Draft<S>) => void
* })
* ```
*/
export default function useComposeState<S>(initState: S): [S, (stateUpdater: StateUpdater<S>) => void] {
export function useComposeState<S>(initState: S): [S, (stateUpdater: StateUpdater<S>) => void] {
const [state, setState] = useState<S>(initState)
const updateState = useCallback((stateUpdater: StateUpdater<S>) => {
setState(state => {
Expand All @@ -26,4 +26,4 @@ export default function useComposeState<S>(initState: S): [S, (stateUpdater: Sta
})
}, [setState])
return [state, updateState]
}
}
10 changes: 8 additions & 2 deletions packages/frontend/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// define new interfaces here, global.ts is no longer maintained.
import { BIField, BIFieldType, FieldType } from "./global";
import { Aggregator, BIField, BIFieldType, FieldType } from "./global";

export interface IRow {
[key: string]: number | string | boolean | null | undefined;
Expand Down Expand Up @@ -35,4 +35,10 @@ export enum IComputeMode {
worker = 'worker'
}

export type IAnalyticType = 'dimension' | 'measure';
export type IAnalyticType = 'dimension' | 'measure';

export interface PreferencePanelConfig {
aggregator: Aggregator;
defaultAggregated: boolean;
defaultStack: boolean;
}
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/dashBoard/combinedChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo, useEffect, useState } from "react";
import { DashBoard } from "../../service";
import { DataSource, Field } from "../../global";
import { specification } from "visual-insights";
import { useComposeState } from "../../utils/index";
import { useComposeState } from "../../hooks/index";
import { IconButton } from "office-ui-fabric-react";
import IndicatorCard from "./indicatorCard";
import ReactVega from '../../components/react-vega';
Expand Down
5 changes: 2 additions & 3 deletions packages/frontend/src/pages/dataSource/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { useCallback, useEffect } from "react";
import intl from 'react-intl-universal'
import { useComposeState } from '../../utils/index';
import { useComposeState } from '../../hooks/index';
import { ComboBox, PrimaryButton, Stack, DefaultButton } from 'office-ui-fabric-react';
// import DataTable from '../../components/table';
import DataTable from './dataTable/index';
import { CleanMethod, useCleanMethodList } from './clean';
import Selection from './selection/index';
import { BIFieldType, Record } from "../../global";
import { Record } from "../../global";
import { observer } from 'mobx-react-lite';
import { useGlobalStore } from "../../store";
import { IRawField } from "../../interfaces";
interface PageStatus {
show: {
insightBoard: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PreferencePanel, {
import BaseChart from "../../visBuilder/vegaBase";
import { Position } from "office-ui-fabric-react/lib/utilities/positioning";

import { useComposeState } from '../../utils';
import { useComposeState } from '../../hooks/index';
import SimpleTick from '../../components/simpleTick';
import RadarChart from '../../components/radarChart';
import { observer } from 'mobx-react-lite';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Gallery: React.FC = props => {
)}
{pivotIndex === pivotList[0].itemKey && (
<div>
<h2 style={{ marginBottom: 0 }}>
<h2 className="state-header" style={{ marginBottom: 0 }}>
{intl.get('explore.title')}
<IconButton
iconProps={{ iconName: 'Settings' }}
Expand Down
105 changes: 56 additions & 49 deletions packages/frontend/src/pages/lts/association/assCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
import React from "react";
// import VisDescription from "../../../plugins/visSummary/description";
// import useDigDimension, { DigDimensionProps } from "./digDimension";
import BaseChart from "../../../visBuilder/vegaBase";
import { FieldSummary, Subspace } from "../../../service";
// import { IconButton, Stack } from "office-ui-fabric-react";
import { FieldSummary } from "../../../service";
import { IInsightSpace, Specification } from "visual-insights";
import { PreferencePanelConfig } from "../../../components/preference";
import { IRow } from "../../../interfaces";

import { IconButton } from "office-ui-fabric-react";
import intl from 'react-intl-universal';
export interface IVizSpace extends IInsightSpace {
schema: Specification;
dataView: IRow[]
}

interface AssociationProps {
visualConfig: PreferencePanelConfig;
// subspaceList: Subspace[];
vizList: IVizSpace[];
fieldScores: FieldSummary[];
dataSource: IRow[];
onSelectView: (index: number) => void
visualConfig: PreferencePanelConfig;
// subspaceList: Subspace[];
vizList: IVizSpace[];
fieldScores: FieldSummary[];
dataSource: IRow[];
onSelectView: (viz: IVizSpace) => void
}
const AssociationCharts: React.FC<AssociationProps> = props => {
const { vizList, onSelectView, visualConfig, fieldScores, dataSource } = props;
// const { dataSource, fieldScores } = digDimensionProps;
// const relatedCharts = useDigDimension(digDimensionProps);
const fieldFeatures = fieldScores.map(f => ({
name: f.fieldName,
type: f.type
}));
//className="ms-Grid"
return (
<div style={{ border: "solid 1px #bfbfbf", marginTop: '2em' }}>
const { vizList, onSelectView, visualConfig, fieldScores, dataSource } = props;
// const { dataSource, fieldScores } = digDimensionProps;
// const relatedCharts = useDigDimension(digDimensionProps);
const fieldFeatures = fieldScores.map(f => ({
name: f.fieldName,
type: f.type
}));
//className="ms-Grid"
return (
<div style={{ border: "solid 1px #bfbfbf", marginTop: '2em', backgroundColor: '#e7e7e7' }}>

<div style={{ display: 'flex', flexWrap: 'wrap', overflow: 'auto' }}>
{vizList.map((view, i) => {
return (
<div key={`associate-row-${i}`}
// className="ms-Grid-row"
dir="ltr"
style={{
// border: "solid 1px #bfbfbf",
margin: "1em",
padding: "1em"
}}
>
<BaseChart
fixedWidth={false}
aggregator={visualConfig.aggregator}
defaultAggregated={view.schema.geomType && view.schema.geomType.includes("point") ? false : true}
defaultStack={visualConfig.defaultStack}
dimensions={view.dimensions}
measures={view.measures}
dataSource={dataSource}
schema={view.schema}
fieldFeatures={fieldFeatures}
/>
<div style={{ display: 'flex', flexWrap: 'wrap', overflow: 'auto' }}>
{vizList.map((view, i) => {
return (
<div key={`associate-row-${i}`}
// className="ms-Grid-row"
dir="ltr"
style={{
// border: "solid 1px #bfbfbf",
backgroundColor:'#fff',
margin: "1em",
padding: "1em"
}}
>
<BaseChart
fixedWidth={false}
aggregator={visualConfig.aggregator}
defaultAggregated={view.schema.geomType && view.schema.geomType.includes("point") ? false : true}
defaultStack={visualConfig.defaultStack}
dimensions={view.dimensions}
measures={view.measures}
dataSource={dataSource}
schema={view.schema}
fieldFeatures={fieldFeatures}
/>
<IconButton
iconProps={{ iconName: 'Lightbulb' }}
title={intl.get('explore.digIn')}
ariaLabel={intl.get('explore.digIn')}
onClick={() => {
onSelectView(view);
}}
/>
</div>
);
})}
</div>
);
})}
</div>
</div>
);
</div>
);
};

export default AssociationCharts;
Loading

0 comments on commit 994fe2f

Please sign in to comment.