Commit b12ffcdd authored by 郭铭瑶's avatar 郭铭瑶 🤘

调整&优化

parent 067bede7
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
<script> <script>
import RelationGraph from '@/util/useD3.js' import RelationGraph from '@/util/useD3.js'
import { ref } from '@vue/reactivity' import { nextTick, onMounted, watch, ref } from 'vue'
import { nextTick, onMounted, watch } from '@vue/runtime-core'
export default { export default {
name: 'D3', name: 'D3',
props: { props: {
...@@ -44,13 +43,21 @@ export default { ...@@ -44,13 +43,21 @@ export default {
</script> </script>
<style lang="stylus"> <style lang="stylus">
.relation-tooltip { .relation-tooltip
position: fixed; position fixed
padding: 0.5rem 1rem; padding 0.5rem 1rem
background-color: rgba(0,0,0,0.5); background-color rgba(0,0,0,0.5)
border-radius: 0.5rem; border-radius 0.3rem
color: #fff; color #fff
backdrop-filter: blur(0.5rem); backdrop-filter blur(0.5rem)
-webkit-backdrop-filter: blur(0.5rem); -webkit-backdrop-filter blur(0.5rem)
}
.menu-segment
cursor pointer
fill #2c3e50
&:hover
fill #58b2dc
.menu-icon
pointer-events none
</style> </style>
<template> <template>
<D3 <D3
:data="data" :data="mockData"
:config="config" :config="config"
style="background: #fff; width: 100%; height: 100vh" style="background: #fff; width: 100%; height: 100vh"
/> />
...@@ -10,37 +10,20 @@ ...@@ -10,37 +10,20 @@
import D3 from './d3.vue' import D3 from './d3.vue'
import mockData from '@/util/mock.js' import mockData from '@/util/mock.js'
import { ref } from 'vue' import { ref } from 'vue'
import RadialMenu from '@/util/menu.js'
export default { export default {
name: 'Main', name: 'Main',
components: { D3 }, components: { D3 },
setup() { setup() {
const data = ref(mockData)
const config = ref({ const config = ref({
config: { config: {
strokeColor: 'skyblue', strokeColor: 'skyblue',
}, },
}) })
return { return {
data, mockData,
config, config,
} }
}, },
} }
</script> </script>
<style lang="stylus">
.menu-segment {
cursor: pointer;
fill: #2c3e50;
}
.menu-segment:hover {
fill: #58b2dc;
}
.menu-icon {
pointer-events: none;
}
</style>
...@@ -9,15 +9,12 @@ export default function RadialMenu() { ...@@ -9,15 +9,12 @@ export default function RadialMenu() {
//#region Local Variables //#region Local Variables
// The following variables have getter/setter functions exposed so are configurable // The following variables have getter/setter functions exposed so are configurable
let data = [{}] const data = [{}]
let padding = 1 let padding = 1
let radius = 50 let radius = 50
let thickness = 20 let thickness = 20
let iconSize = 16 let iconSize = 16
let animationDuration = 250 // The duration to run animations for let animationDuration = 250 // The duration to run animations for
let onClick = function (a) {
alert(a)
}
// Private Variables // Private Variables
let offsetAngleDeg = -180 / data.length // Initial rotation angle designed to put centre the first segment at the top let offsetAngleDeg = -180 / data.length // Initial rotation angle designed to put centre the first segment at the top
...@@ -28,19 +25,6 @@ export default function RadialMenu() { ...@@ -28,19 +25,6 @@ export default function RadialMenu() {
//#endregion //#endregion
//#region Getter/Setter Accessors
/**
* The function to execute on a menu click
* @param {object} onClick - The function to execute on a menu click
* @returns {number} The function to execute on a menu click or the control
*/
control.onClick = function (_) {
if (!arguments.length) return onClick
onClick = _
return control
}
/** /**
* Time in ms to animate transitions * Time in ms to animate transitions
* @param {object} animationDuration - The time in ms to animate transitions * @param {object} animationDuration - The time in ms to animate transitions
...@@ -124,9 +108,7 @@ export default function RadialMenu() { ...@@ -124,9 +108,7 @@ export default function RadialMenu() {
// Create pie layout // Create pie layout
pie = d3 pie = d3
.pie() .pie()
.value(function (d) { .value(data.length)
return data.length
})
.padAngle((padding * Math.PI) / 180) .padAngle((padding * Math.PI) / 180)
// Create the arc function // Create the arc function
...@@ -142,12 +124,9 @@ export default function RadialMenu() { ...@@ -142,12 +124,9 @@ export default function RadialMenu() {
* @returns {object} The control * @returns {object} The control
*/ */
control.appendTo = function (target) { control.appendTo = function (target) {
// Convert the target into a valid D3 selection
// that we can append our menu into
target = d3.select(target)
// Create the visualiziation // Create the visualiziation
segmentLayer = target segmentLayer = d3
.select(target)
.append('g') .append('g')
.attr('transform', 'rotate(' + offsetAngleDeg + ')') .attr('transform', 'rotate(' + offsetAngleDeg + ')')
...@@ -158,10 +137,9 @@ export default function RadialMenu() { ...@@ -158,10 +137,9 @@ export default function RadialMenu() {
* Display the menu * Display the menu
* @returns {object} The control * @returns {object} The control
*/ */
control.show = function (_) { control.show = function (data) {
// Calculate the new offset angle based on the number of data items and // Calculate the new offset angle based on the number of data items and
// then rotate the menu to re-centre the first segment // then rotate the menu to re-centre the first segment
data = _
offsetAngleDeg = -180 / data.length offsetAngleDeg = -180 / data.length
segmentLayer.attr('transform', 'rotate(' + offsetAngleDeg + ')') segmentLayer.attr('transform', 'rotate(' + offsetAngleDeg + ')')
...@@ -219,7 +197,8 @@ export default function RadialMenu() { ...@@ -219,7 +197,8 @@ export default function RadialMenu() {
this._current = d this._current = d
}) // store the initial data value for later }) // store the initial data value for later
.on('click', function (e, d) { .on('click', function (e, d) {
console.log(d.data.action) const { action } = d.data
action && action(e, d)
}) })
.transition() .transition()
.duration(animationDuration) .duration(animationDuration)
...@@ -299,11 +278,14 @@ export default function RadialMenu() { ...@@ -299,11 +278,14 @@ export default function RadialMenu() {
return arc.innerRadius(innerTween(t)).outerRadius(outerTween(t))(a) return arc.innerRadius(innerTween(t)).outerRadius(outerTween(t))(a)
} }
}) })
// .each('end', function (d) { .remove()
// dataJoin.remove() // Remove all of the segment groups once the transition has completed
// }) let timer = setTimeout(() => {
dataJoin.remove() segmentLayer.remove()
segmentLayer.remove() clearTimeout(timer)
timer = null
}, animationDuration + 100)
return control return control
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment