Skip to content

Commit

Permalink
chore: 添加 vue 的使用示例 (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue authored Sep 4, 2023
1 parent cba5702 commit 1fea0c1
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/f2-vue/examples/vite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
7 changes: 7 additions & 0 deletions packages/f2-vue/examples/vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vue 3 + Vite

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
13 changes: 13 additions & 0 deletions packages/f2-vue/examples/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions packages/f2-vue/examples/vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "vite",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@antv/f2": "^5.0.0",
"@antv/f-engine": "1.x",
"@antv/f-vue": "1.x",
"vue": "^3.2.25"
},
"devDependencies": {
"@babel/plugin-transform-react-jsx": "^7.17.3",
"@rollup/plugin-babel": "^5.3.1",
"@vitejs/plugin-vue": "^2.3.2",
"@vitejs/plugin-vue-jsx": "^1.3.10",
"vite": "^2.9.7"
}
}
61 changes: 61 additions & 0 deletions packages/f2-vue/examples/vite/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<script lang='jsx'>
import { toRaw } from 'vue';
import Canvas from '@antv/f-vue';
import { Chart, Interval, Axis } from '@antv/f2';
import Grahpic from './graphic';
const data1 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];
const data2 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 20 },
{ genre: 'Shooter', sold: 50 },
{ genre: 'Other', sold: 50 },
];
export default {
name: 'App',
data() {
return {
year: '2021',
chartData: data1,
}
},
mounted() {
setTimeout(() => {
this.year = '2022';
this.chartData = data2;
}, 1000);
},
render() {
const { year, chartData } = this;
return (
<div className="container">
<Canvas pixelRatio={ window.devicePixelRatio }>
<Chart data={ toRaw(chartData) }>
<Grahpic year={ year } />
<Axis field="genre"/>
<Axis field="sold"/>
<Interval x="genre" y="sold" color="genre" />
</Chart>
</Canvas>
</div>
);
},
};
</script>

<style>
.container {
width: 500px;
height: 300px;
}
</style>

24 changes: 24 additions & 0 deletions packages/f2-vue/examples/vite/src/graphic.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function View(props) {
const { coord, year } = props;
const { left, top, width, height } = coord;
const x = left + width / 2;
const y = top + height / 2;
return (
<group>
<text
attrs={{
x,
y,
text: year,
textAlign: 'center',
// textBaseline: 'bottom',
fontSize: '80px',
// fontWeight: 'bold',
fill: '#ddd',
}}
/>
</group>
);
}

export default View;
4 changes: 4 additions & 0 deletions packages/f2-vue/examples/vite/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue';
import App from './App.vue';

createApp(App).mount('#app');
23 changes: 23 additions & 0 deletions packages/f2-vue/examples/vite/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { babel } from '@rollup/plugin-babel';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
babel({
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
runtime: 'automatic',
importSource: '@antv/f-engine',
},
],
],
}),
vue(),
vueJsx(),
],
});
3 changes: 3 additions & 0 deletions packages/f2-vue/examples/vue3/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@vue/cli-plugin-babel/preset'],
};
29 changes: 29 additions & 0 deletions packages/f2-vue/examples/vue3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "vue-3",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@antv/f2": "^5.0.0",
"@antv/f-engine": "1.x",
"@antv/f-vue": "1.x",
"vue": "^3.2.25"
},
"devDependencies": {
"@babel/plugin-transform-react-jsx": "~7.17.3",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0-0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"keywords": [],
"description": ""
}
66 changes: 66 additions & 0 deletions packages/f2-vue/examples/vue3/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script lang="jsx">
import { toRaw } from 'vue';
import Canvas from '@antv/f-vue';
import { Chart, Interval, Axis, Tooltip } from '@antv/f2';
import Grahpic from './graphic';
const data1 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];
const data2 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 20 },
{ genre: 'Shooter', sold: 50 },
{ genre: 'Other', sold: 50 },
];
export default {
name: 'App',
data() {
return {
year: '2021',
chartData: data1,
}
},
mounted() {
setTimeout(() => {
this.year = '2022';
this.chartData = data2;
}, 1000);
setTimeout(() => {
this.year = '2021';
this.chartData = data1;
}, 3000);
},
render() {
const { year, chartData } = this;
return (
<div className="container">
<Canvas pixelRatio={ window.devicePixelRatio }>
<Chart data={ toRaw(chartData) }>
<Grahpic year={ year } />
<Axis field="genre"/>
<Axis field="sold"/>
<Interval x="genre" y="sold" color="genre" />
<Tooltip />
</Chart>
</Canvas>
</div>
);
},
};
</script>

<style>
.container {
width: 500px;
height: 300px;
}
</style>

24 changes: 24 additions & 0 deletions packages/f2-vue/examples/vue3/src/graphic.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function View(props) {
const { coord, year } = props;
const { left, top, width, height } = coord;
const x = left + width / 2;
const y = top + height / 2;
return (
<group>
<text
attrs={{
x,
y,
text: year,
textAlign: 'center',
// textBaseline: 'bottom',
fontSize: '80px',
// fontWeight: 'bold',
fill: '#ddd',
}}
/>
</group>
);
}

export default View;
4 changes: 4 additions & 0 deletions packages/f2-vue/examples/vue3/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue';
import App from './App.vue';

createApp(App).mount('#app');
24 changes: 24 additions & 0 deletions packages/f2-vue/examples/vue3/vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
chainWebpack: (config) => {
config.module
.rule('F2')
.test((path) => {
// Only transform FEngine JSX in .jsx files.
return /\.jsx$/.test(path) && !/\.vue\.jsx$/.test(path);
})
.use('babel')
.loader('babel-loader')
.options({
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
runtime: 'automatic',
importSource: '@antv/f-engine',
},
],
],
})
.end();
},
};
14 changes: 14 additions & 0 deletions packages/f2-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@antv/f2-vue",
"private": true,
"version": "5.0.30",
"homepage": "https://github.com/antvis/f2",
"bugs": {
"url": "https://github.com/antvis/f2/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/antvis/f2"
},
"author": "https://github.com/orgs/antvis/people"
}

0 comments on commit 1fea0c1

Please sign in to comment.