From 5543defabae1199b18b4a19affccbd34459c9549 Mon Sep 17 00:00:00 2001 From: da730 Date: Wed, 15 Nov 2023 14:59:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A8=E6=80=81=E6=9D=A1=E5=BD=A2?= =?UTF-8?q?=E5=9B=BE=E5=8A=A8=E7=94=BB=E4=BF=AE=E5=A4=8D&badcase=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + .../browser/src/constants/mockData.ts | 9 ++- .../__tests__/browser/src/pages/LeftInput.tsx | 71 ++++++++++++++++--- .../src/chart-generation/NLToChartPipe.ts | 2 +- .../vmind/src/chart-generation/constants.ts | 14 ++-- packages/vmind/src/chart-generation/pipes.ts | 4 ++ packages/vmind/src/chart-generation/utils.ts | 11 +++ .../src/chart-generation/vizDataToSpec.ts | 42 ++++++++--- 8 files changed, 128 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 703bb05a1..4af22cdcd 100644 --- a/.gitignore +++ b/.gitignore @@ -124,3 +124,5 @@ packages/wx-vchart/miniprogram/miniprogram_npm/ docs/public/documents docs/public/vchart/preview/failedPreviewLists.json packages/vchart/__tests__/runtime/node/**.png +# env files +.env.local diff --git a/packages/vmind/__tests__/browser/src/constants/mockData.ts b/packages/vmind/__tests__/browser/src/constants/mockData.ts index 600d66aab..16c16155c 100644 --- a/packages/vmind/__tests__/browser/src/constants/mockData.ts +++ b/packages/vmind/__tests__/browser/src/constants/mockData.ts @@ -3566,7 +3566,8 @@ export const mockUserInput9 = { Step1,100,1 Step2,80,1 Step3,60,1 -Step4,40,1` +Step4,40,1`, + input: '展示各个流程转化率' }; /** @@ -3580,7 +3581,8 @@ export const mockUserInput11 = { 周四,10,12 周五,13,15 周六,10,15 -周日,12,14` +周日,12,14`, + input: '展示男女早餐饭量不同' }; /** @@ -3657,5 +3659,6 @@ South Asia,9.4,10.06,10.75,11.56,12.5 Middle East & North Africa,9.54,10.6,11.05,11.5,11.92 Latin America & Caribbean,8.74,9.46,10.35,10.94,12.21 East Asia & Pacific,7.8,8.95,10.18,11.57,13.25 -Europe & Central Asia,9.52,10.39,10.93,11.69,12.63` +Europe & Central Asia,9.52,10.39,10.93,11.69,12.63`, + input: '看下各地区gdp情况' }; diff --git a/packages/vmind/__tests__/browser/src/pages/LeftInput.tsx b/packages/vmind/__tests__/browser/src/pages/LeftInput.tsx index af221761d..d5da3d7cb 100644 --- a/packages/vmind/__tests__/browser/src/pages/LeftInput.tsx +++ b/packages/vmind/__tests__/browser/src/pages/LeftInput.tsx @@ -1,6 +1,6 @@ import React, { useState, useCallback } from 'react'; import './index.scss'; -import { Avatar, Input, Divider, Button, InputNumber, Upload, Message } from '@arco-design/web-react'; +import { Avatar, Input, Divider, Button, InputNumber, Upload, Message, Select } from '@arco-design/web-react'; import { mockUserInput10, mockUserInput2, @@ -9,12 +9,26 @@ import { mockUserInput6, mockUserInput6Eng, mockUserInput8, - carSaleMockData + carSaleMockData, + mockUserInput15, + acceptRatioData, + mallSalesData, + hotWordsData, + mockUserInput4, + mockUserInput5, + mockUserInput9, + mockUserInput11, + mockUserInput12, + mockUserInput13, + mockUserInput14, + mockUserInput16 } from '../constants/mockData'; import { excel2csv } from '../../../../src/excel'; import VMind from '../../../../src/index'; const TextArea = Input.TextArea; +const Option = Select.Option; + type IPropsType = { onSpecGenerate: ( spec: any, @@ -24,21 +38,45 @@ type IPropsType = { } ) => void; }; - +const demoDataList: { [key: string]: any } = { + pie: mockUserInput2, + 'dynamic bar zh_cn': mockUserInput6, + line: mockUserInput8, + column: mockUserInput3, + column2: mockUserInput10, + wordcloud: hotWordsData, + wordcloud2: mockUserInput5, + 'scatter plot': mockUserInput4, + funnel: mockUserInput9, + 'dual-axis': mockUserInput11, + waterfall: mockUserInput12, + rose: mockUserInput13, + radar: mockUserInput14, + sankey: mockUserInput15, + 'box-plot': mockUserInput16, + 'Electric vehicle sales': carSaleMockData, + 'College entrance examination': acceptRatioData, + 'Shopping Mall Sales Performance': mallSalesData, + 'Global GDP': mockUserInput6Eng, + 'Sales of different drinkings': mockUserInput3Eng +}; export function LeftInput(props: IPropsType) { - const [describe, setDescribe] = useState(mockUserInput2.input); - const [csv, setCsv] = useState(mockUserInput2.csv); + const defaultDataKey = Object.keys(demoDataList)[0]; + const [describe, setDescribe] = useState(demoDataList[defaultDataKey].input); + const [csv, setCsv] = useState(demoDataList[defaultDataKey].csv); const [spec, setSpec] = useState(''); const [time, setTime] = useState(1000); const [loading, setLoading] = useState(false); - const vmind = new VMind(import.meta.OPENAI_KEY!); + const vmind = new VMind(import.meta.env.OPENAI_KEY!, { + url: import.meta.env.VITE_OPENAI_URL ?? undefined + }); const askGPT = useCallback(async () => { setLoading(true); const { spec, time } = await vmind.generateChart(csv, describe); props.onSpecGenerate(spec, time as any); setLoading(false); - }, [describe, csv]); + }, [vmind, csv, describe, props]); const isAcceptFile = useCallback((file, accept) => { if (accept && file) { @@ -68,6 +106,23 @@ export function LeftInput(props: IPropsType) { return (
+

@@ -78,7 +133,7 @@ export function LeftInput(props: IPropsType) {