From bb24161f4b0849ac760792ef112d982c80dcc0af Mon Sep 17 00:00:00 2001 From: Lorenz Padberg Date: Mon, 27 Jun 2022 18:11:11 +0200 Subject: [PATCH] with real data from store --- .../src/components/circle/CircleDiagram.vue | 37 +++++++++++++++---- client/src/views/CircleView.vue | 4 +- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/client/src/components/circle/CircleDiagram.vue b/client/src/components/circle/CircleDiagram.vue index b6167af9..1963227e 100644 --- a/client/src/components/circle/CircleDiagram.vue +++ b/client/src/components/circle/CircleDiagram.vue @@ -2,6 +2,7 @@ import * as d3 from "d3"; import {useCircleStore} from '@/stores/circle'; import {onMounted} from "vue"; +import * as _ from 'underscore' const props = defineProps<{ @@ -40,15 +41,35 @@ const props = defineProps<{ width: { default: 500, type: number, + required: false + }, height: { default: 500, type: number, + required: false }, }>() + +function calculatePieData(circle){ + let learningSequences = _.filter(circle.children, (child) => { return child.type === 'learnpath.LearningSequence'; }) + let pieWeights = new Array(Math.max(learningSequences.length, 1)).fill(1) + let pieGenerator = d3.pie() + let pieData = pieGenerator(pieWeights) + console.log(pieData) + _.forEach(pieData, (pie) => { + pie.title = learningSequences[parseInt(pie.index)].title + pie.icon = learningSequences[parseInt(pie.index)].icon + }) + return pieData +} + onMounted(async () => { - const data = [5, 5, 5, 5, 5] + + + + let pieData = calculatePieData(props.circleData) const width = 500, height = 500, @@ -89,15 +110,15 @@ onMounted(async () => { .outerRadius(radius * 1.16) //Generate groups - const wedgesGroup = g.selectAll('arc').data(pie(data)).enter().append('g').attr('class', 'arc') + const wedgesGroup = g.selectAll('arc').data(pieData).enter().append('g').attr('class', 'arc') wedgesGroup.append('path').attr('fill', sky400).attr('d', wedge) const learningSequenceText = wedgesGroup .append('text') .attr('fill', blue900) - .style('font-size', 19) - .text((d) => {return 'segment'}) + .style('font-size', 15) + .text((d) => {return d.title}) .attr("transform", function(d) { let translate = wedge.centroid(d) translate = [translate[0], translate[1] + 20] @@ -106,9 +127,9 @@ onMounted(async () => { .style('text-anchor', 'middle') const learningSequenceIcon = wedgesGroup.append("svg:image") - .attr("xlink:href", "/static/icons/icon-ls-network.svg") - .attr("width", 40) - .attr("height", 40) + .attr("xlink:href", (d) => {return "/static/icons/"+d.icon.replace("it-", "")+".svg"}) + .attr("width", 30) + .attr("height", 30) .attr("transform", function(d) { let translate = wedge.centroid(d) translate = [translate[0]-20, translate[1] - 35] @@ -118,7 +139,7 @@ onMounted(async () => { //Generate groups const arrows = g .selectAll('arrow') - .data(pie(data)) + .data(pieData) .enter() .append('g') .attr('class', 'arrow') diff --git a/client/src/views/CircleView.vue b/client/src/views/CircleView.vue index 88fae2d5..6f58b0a6 100644 --- a/client/src/views/CircleView.vue +++ b/client/src/views/CircleView.vue @@ -45,8 +45,8 @@ onMounted(async () => { {{ circleStore.circleData.title }} -
- +
+