Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Update x and width as well to make boxplot responsive #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ d3.box = function() {
center.transition()
.duration(duration)
.style("opacity", 1)
.attr("x1", width / 2)
.attr("x2", width / 2)
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1]); });

center.exit().transition()
.duration(duration)
.style("opacity", 1e-6)
.attr("x1", width / 2)
.attr("x2", width / 2)
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1]); })
.remove();
Expand All @@ -99,8 +103,11 @@ d3.box = function() {
box.transition()
.duration(duration)
.attr("y", function(d) { return x1(d[2]); })
.attr("width", width)
.attr("height", function(d) { return x1(d[0]) - x1(d[2]); });



// Update median line.
var medianLine = g.selectAll("line.median")
.data([quartileData[1]]);
Expand All @@ -118,6 +125,8 @@ d3.box = function() {

medianLine.transition()
.duration(duration)
.attr("x1", 0)
.attr("x2", width)
.attr("y1", x1)
.attr("y2", x1);

Expand All @@ -140,6 +149,8 @@ d3.box = function() {

whisker.transition()
.duration(duration)
.attr("x1", 0)
.attr("x2", width)
.attr("y1", x1)
.attr("y2", x1)
.style("opacity", 1);
Expand Down Expand Up @@ -168,6 +179,7 @@ d3.box = function() {

outlier.transition()
.duration(duration)
.attr("cx", width / 2)
.attr("cy", function(i) { return x1(d[i]); })
.style("opacity", 1);

Expand Down Expand Up @@ -199,6 +211,8 @@ d3.box = function() {
boxTick.transition()
.duration(duration)
.text(format)
.attr("dx", function(d, i) { return i & 1 ? 6 : -6; })
.attr("x", function(d, i) { return i & 1 ? width : 0; })
.attr("y", x1);

// Update whisker ticks. These are handled separately from the box
Expand All @@ -223,6 +237,8 @@ d3.box = function() {
whiskerTick.transition()
.duration(duration)
.text(format)
.attr("dx", 6)
.attr("x", width)
.attr("y", x1)
.style("opacity", 1);

Expand Down