feat: add x coordinates and links, use SVG

This commit is contained in:
Lin, Hung-Shin committed 2023-11-16 12:46:53 +08:00
1 parent e018e8dfe4
commit 7a8df716da
1 file changed
+23 -8
+23 -8
View File
@@ -14,16 +14,17 @@
<script setup> <script setup>
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { use, init } from 'echarts/core' import { use, init } from 'echarts/core'
import { GraphChart } from 'echarts/charts' import { GraphChart } from 'echarts/charts'
import { CanvasRenderer } from 'echarts/renderers' import { SVGRenderer } from 'echarts/renderers'
import { TitleComponent, TooltipComponent } from 'echarts/components' import { TitleComponent, TooltipComponent } from 'echarts/components'
import { DAG } from '@linux-odyssey/utils' import { DAG } from '@linux-odyssey/utils'
const chartContainer = ref(null) const chartContainer = ref(null)
let chartInstance = null let chartInstance = null
use([GraphChart, CanvasRenderer, TitleComponent, TooltipComponent]) use([GraphChart, SVGRenderer, TitleComponent, TooltipComponent])
const data = [ const data = [
{ {
@@ -46,16 +47,21 @@ const data = [
title: 'Learn to spell', title: 'Learn to spell',
requirements: ['helloworld'], requirements: ['helloworld'],
}, },
{
_id: 'move',
requirements: ['read', 'discover'],
},
] ]
const dag = new DAG(data) const dag = new DAG(data)
const nodes = dag.getNodes().map((node) => ({ const nodes = dag.getNodes().map((node) => ({
name: node._id, id: node._id,
x: 0, name: node.title,
x: 50 * node.index,
y: 100 * node.layer, y: 100 * node.layer,
})) }))
const edges = dag.getEdges().map((edge) => ({ const edges = dag.getEdgesArray().map((edge) => ({
source: edge[0], source: edge[0],
target: edge[1], target: edge[1],
})) }))
@@ -64,7 +70,7 @@ const option = {
title: { title: {
text: 'Quest Map', text: 'Quest Map',
}, },
rendener: 'canvas', rendener: 'svg',
tooltip: {}, tooltip: {},
animationDurationUpdate: 1500, animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut', animationEasingUpdate: 'quinticInOut',
@@ -93,12 +99,21 @@ const option = {
}, },
], ],
} }
const router = useRouter()
function initChart() { function initChart() {
console.log('initChart', chartContainer.value) console.log('initChart', chartContainer.value)
chartInstance = init(chartContainer.value) chartInstance = init(chartContainer.value)
chartInstance.setOption(option) chartInstance.setOption(option)
console.log(dag.getNodes()) chartInstance.on('click', (params) => {
console.log(dag.getEdges()) console.log('click', params)
const {
data: { id },
} = params
router.push({ name: 'game', params: { questId: id } })
})
} }
onMounted(() => { onMounted(() => {