Skip to content

Commit ebc4d8b

Browse files
committed
🔪 my zeroed-out 3D pie code
apparently I got a lot farther than just defining attributes (deleted in #1152)
1 parent d2756f1 commit ebc4d8b

File tree

2 files changed

+9
-60
lines changed

2 files changed

+9
-60
lines changed

src/traces/pie/plot.js

+8-59
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,10 @@ module.exports = function plot(gd, cdpie) {
3737
var pieGroup = d3.select(this);
3838
var cd0 = cd[0];
3939
var trace = cd0.trace;
40-
var tiltRads = 0; // trace.tilt * Math.PI / 180,
41-
var depthLength = (trace.depth||0) * cd0.r * Math.sin(tiltRads) / 2;
42-
var tiltAxis = trace.tiltaxis || 0;
43-
var tiltAxisRads = tiltAxis * Math.PI / 180;
44-
var depthVector = [
45-
depthLength * Math.sin(tiltAxisRads),
46-
depthLength * Math.cos(tiltAxisRads)
47-
];
48-
var rSmall = cd0.r * Math.cos(tiltRads);
49-
50-
var pieParts = pieGroup.selectAll('g.part')
51-
.data(trace.tilt ? ['top', 'sides'] : ['top']);
52-
53-
pieParts.enter().append('g').attr('class', function(d) {
54-
return d + ' part';
55-
});
56-
pieParts.exit().remove();
57-
pieParts.order();
5840

5941
setCoords(cd);
6042

61-
pieGroup.selectAll('.top').each(function() {
43+
pieGroup.each(function() {
6244
var slices = d3.select(this).selectAll('g.slice').data(cd);
6345

6446
slices.enter().append('g')
@@ -83,8 +65,8 @@ module.exports = function plot(gd, cdpie) {
8365

8466
quadrants[pt.pxmid[1] < 0 ? 0 : 1][pt.pxmid[0] < 0 ? 0 : 1].push(pt);
8567

86-
var cx = cd0.cx + depthVector[0];
87-
var cy = cd0.cy + depthVector[1];
68+
var cx = cd0.cx;
69+
var cy = cd0.cy;
8870
var sliceTop = d3.select(this);
8971
var slicePath = sliceTop.selectAll('path.surface').data([pt]);
9072
var hasHoverData = false;
@@ -201,7 +183,7 @@ module.exports = function plot(gd, cdpie) {
201183
pt.cyFinal = cy;
202184

203185
function arc(start, finish, cw, scale) {
204-
return 'a' + (scale * cd0.r) + ',' + (scale * rSmall) + ' ' + tiltAxis + ' ' +
186+
return 'a' + (scale * cd0.r) + ',' + (scale * cd0.r) + ' 0 ' +
205187
pt.largeArc + (cw ? ' 1 ' : ' 0 ') +
206188
(scale * (finish[0] - start[0])) + ',' + (scale * (finish[1] - start[1]));
207189
}
@@ -269,7 +251,6 @@ module.exports = function plot(gd, cdpie) {
269251
.call(svgTextUtils.convertToTspans, gd);
270252

271253
// position the text relative to the slice
272-
// TODO: so far this only accounts for flat
273254
var textBB = Drawing.bBox(sliceText.node());
274255
var transform;
275256

@@ -566,7 +547,7 @@ function scootLabels(quadrants, trace) {
566547
function scalePies(cdpie, plotSize) {
567548
var scaleGroups = [];
568549

569-
var pieBoxWidth, pieBoxHeight, i, j, cd0, trace, tiltAxisRads,
550+
var pieBoxWidth, pieBoxHeight, i, j, cd0, trace,
570551
maxPull, scaleGroup, minPxPerValUnit;
571552

572553
// first figure out the center and maximum radius for each pie
@@ -575,7 +556,6 @@ function scalePies(cdpie, plotSize) {
575556
trace = cd0.trace;
576557
pieBoxWidth = plotSize.w * (trace.domain.x[1] - trace.domain.x[0]);
577558
pieBoxHeight = plotSize.h * (trace.domain.y[1] - trace.domain.y[0]);
578-
tiltAxisRads = trace.tiltaxis * Math.PI / 180;
579559

580560
maxPull = trace.pull;
581561
if(Array.isArray(maxPull)) {
@@ -585,10 +565,7 @@ function scalePies(cdpie, plotSize) {
585565
}
586566
}
587567

588-
cd0.r = Math.min(
589-
pieBoxWidth / maxExtent(trace.tilt, Math.sin(tiltAxisRads), trace.depth),
590-
pieBoxHeight / maxExtent(trace.tilt, Math.cos(tiltAxisRads), trace.depth)
591-
) / (2 + 2 * maxPull);
568+
cd0.r = Math.min(pieBoxWidth, pieBoxHeight) / (2 + 2 * maxPull);
592569

593570
cd0.cx = plotSize.l + plotSize.w * (trace.domain.x[1] + trace.domain.x[0]) / 2;
594571
cd0.cy = plotSize.t + plotSize.h * (2 - trace.domain.y[1] - trace.domain.y[0]) / 2;
@@ -624,14 +601,12 @@ function scalePies(cdpie, plotSize) {
624601
function setCoords(cd) {
625602
var cd0 = cd[0];
626603
var trace = cd0.trace;
627-
var tilt = trace.tilt;
628604
var currentAngle = trace.rotation * Math.PI / 180;
629605
var angleFactor = 2 * Math.PI / cd0.vTotal;
630606
var firstPt = 'px0';
631607
var lastPt = 'px1';
632608

633-
var tiltAxisRads, tiltAxisSin, tiltAxisCos, tiltRads, crossTilt,
634-
inPlane, i, cdi, currentCoords;
609+
var i, cdi, currentCoords;
635610

636611
if(trace.direction === 'counterclockwise') {
637612
for(i = 0; i < cd.length; i++) {
@@ -645,26 +620,8 @@ function setCoords(cd) {
645620
lastPt = 'px0';
646621
}
647622

648-
if(tilt) {
649-
tiltRads = tilt * Math.PI / 180;
650-
tiltAxisRads = trace.tiltaxis * Math.PI / 180;
651-
crossTilt = Math.sin(tiltAxisRads) * Math.cos(tiltAxisRads);
652-
inPlane = 1 - Math.cos(tiltRads);
653-
tiltAxisSin = Math.sin(tiltAxisRads);
654-
tiltAxisCos = Math.cos(tiltAxisRads);
655-
}
656-
657623
function getCoords(angle) {
658-
var xFlat = cd0.r * Math.sin(angle);
659-
var yFlat = -cd0.r * Math.cos(angle);
660-
661-
if(!tilt) return [xFlat, yFlat];
662-
663-
return [
664-
xFlat * (1 - inPlane * tiltAxisSin * tiltAxisSin) + yFlat * crossTilt * inPlane,
665-
xFlat * crossTilt * inPlane + yFlat * (1 - inPlane * tiltAxisCos * tiltAxisCos),
666-
Math.sin(tiltRads) * (yFlat * tiltAxisCos - xFlat * tiltAxisSin)
667-
];
624+
return [cd0.r * Math.sin(angle), -cd0.r * Math.cos(angle)];
668625
}
669626

670627
currentCoords = getCoords(currentAngle);
@@ -687,11 +644,3 @@ function setCoords(cd) {
687644
cdi.largeArc = (cdi.v > cd0.vTotal / 2) ? 1 : 0;
688645
}
689646
}
690-
691-
function maxExtent(tilt, tiltAxisFraction, depth) {
692-
if(!tilt) return 1;
693-
var sinTilt = Math.sin(tilt * Math.PI / 180);
694-
return Math.max(0.01, // don't let it go crazy if you tilt the pie totally on its side
695-
depth * sinTilt * Math.abs(tiltAxisFraction) +
696-
2 * Math.sqrt(1 - sinTilt * sinTilt * tiltAxisFraction * tiltAxisFraction));
697-
}

src/traces/pie/style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function style(gd) {
2020

2121
traceSelection.style({opacity: trace.opacity});
2222

23-
traceSelection.selectAll('.top path.surface').each(function(pt) {
23+
traceSelection.selectAll('path.surface').each(function(pt) {
2424
d3.select(this).call(styleOne, pt, trace);
2525
});
2626
});

0 commit comments

Comments
 (0)