From 0e2a8cc2e2175e7555da3c320b9e310cd9c70aac Mon Sep 17 00:00:00 2001 From: Lorenz Padberg Date: Thu, 9 Jun 2022 16:16:28 +0200 Subject: [PATCH] refactoring --- .../components/circle/SimpleCircleDiagram.vue | 72 ++++++++++++------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/client/src/components/circle/SimpleCircleDiagram.vue b/client/src/components/circle/SimpleCircleDiagram.vue index 7b7b254c..89034d4b 100644 --- a/client/src/components/circle/SimpleCircleDiagram.vue +++ b/client/src/components/circle/SimpleCircleDiagram.vue @@ -3,9 +3,11 @@ import * as d3 from 'd3'; export default { props: { - learningSequences: {required: false, - default: [{title: '', done: false}, {title: '', done: false}, {title: '', done: false}, {title: '', done: false}]}, - width: { + learningSequences: { + required: false, + default: [{title: '', done: false}, {title: '', done: false}, {title: '', done: false}, {title: '', done: false}] + }, + width: { default: 250, type: Number, }, @@ -15,68 +17,90 @@ export default { } }, computed: { - pieData () { - return new Array(Math.max(this.learningSequences.length, 1)).fill(1); + pieData() { + return new Array(Math.max(this.learningSequences.length, 1)).fill(1) }, viewBox() { - return `0 0 ${this.width} ${this.height}`; - } - + return `0 0 ${this.width} ${this.height}` + }, }, mounted() { console.log(this.pieData) - var data = this.pieData; + const data = this.pieData const width = this.width const height = this.height const radius = Math.min(width, height) / 2.5 + console.log(this.viewBox) - var svg = d3.select(this.$el) + const svg = d3.select(this.$el) .append('svg') .attr('width', width) .attr('height', height) - var g = svg.append('g').attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')'); + const g = svg.append('g').attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')') - var color = '#99C7E7'; // Generate the pie - var pie = d3.pie(); + const pie = d3.pie() // Generate the arcs - var arc = d3 + const arc = d3 .arc() .innerRadius(radius / 2) .padAngle(12 / 360) - .outerRadius(radius); + .outerRadius(radius) + //Generate groups - var arcs = g.selectAll("arc") + const arcs = g.selectAll('arc') .data(pie(data)) .enter() - .append("g") - .attr("class", "arc") + .append('g') + .attr('class', 'arc') + //Draw arc paths - arcs.append("path") - .attr("d", arc) + arcs.append('path') + .attr('d', arc) + + } }