mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
Fix for broken Pie Diagram for d3 v6 upgrade
This commit is contained in:
@@ -85,7 +85,7 @@ export const draw = (txt, id) => {
|
|||||||
|
|
||||||
// Compute the position of each group on the pie:
|
// Compute the position of each group on the pie:
|
||||||
var pie = d3pie().value(function (d) {
|
var pie = d3pie().value(function (d) {
|
||||||
return d.value;
|
return d[1];
|
||||||
});
|
});
|
||||||
var dataReady = pie(Object.entries(data));
|
var dataReady = pie(Object.entries(data));
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ export const draw = (txt, id) => {
|
|||||||
.append('path')
|
.append('path')
|
||||||
.attr('d', arcGenerator)
|
.attr('d', arcGenerator)
|
||||||
.attr('fill', function (d) {
|
.attr('fill', function (d) {
|
||||||
return color(d.data.key);
|
return color(d.data[0]);
|
||||||
})
|
})
|
||||||
.attr('class', 'pieCircle');
|
.attr('class', 'pieCircle');
|
||||||
|
|
||||||
@@ -108,11 +108,11 @@ export const draw = (txt, id) => {
|
|||||||
// Use the centroid method to get the best coordinates.
|
// Use the centroid method to get the best coordinates.
|
||||||
svg
|
svg
|
||||||
.selectAll('mySlices')
|
.selectAll('mySlices')
|
||||||
.data(dataReady.filter((value) => value.data.value !== 0))
|
.data(dataReady)
|
||||||
.enter()
|
.enter()
|
||||||
.append('text')
|
.append('text')
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
return ((d.data.value / sum) * 100).toFixed(0) + '%';
|
return ((d.data[1] / sum) * 100).toFixed(0) + '%';
|
||||||
})
|
})
|
||||||
.attr('transform', function (d) {
|
.attr('transform', function (d) {
|
||||||
return 'translate(' + arcGenerator.centroid(d) + ')';
|
return 'translate(' + arcGenerator.centroid(d) + ')';
|
||||||
@@ -150,15 +150,15 @@ export const draw = (txt, id) => {
|
|||||||
.style('stroke', color);
|
.style('stroke', color);
|
||||||
|
|
||||||
legend
|
legend
|
||||||
.data(dataReady.filter((value) => value.data.value !== 0))
|
.data(dataReady)
|
||||||
.append('text')
|
.append('text')
|
||||||
.attr('x', legendRectSize + legendSpacing)
|
.attr('x', legendRectSize + legendSpacing)
|
||||||
.attr('y', legendRectSize - legendSpacing)
|
.attr('y', legendRectSize - legendSpacing)
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
if (parser.yy.getShowData() || conf.showData || conf.pie.showData) {
|
if (parser.yy.getShowData() || conf.showData || conf.pie.showData) {
|
||||||
return d.data.key + ' [' + d.data.value + ']';
|
return d.data[0] + ' [' + d.data[1]+ ']';
|
||||||
} else {
|
} else {
|
||||||
return d.data.key;
|
return d.data[0];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Reference in New Issue
Block a user