Skip to content

Add barpolar traces #2954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
347979c
expose setGroupPositions from bar/set_positions.js
etpinard Aug 2, 2018
8ca4101
don't set undefined class names via Lib.ensureSingle
etpinard Aug 28, 2018
52ed444
:hocho: now useless _module.style loop
etpinard Aug 15, 2018
d35d13b
DRY up polar mock cartesian axis 'range' logic
etpinard Aug 15, 2018
eb9307e
rename Polar.prototype.isPtWithinSector -> isPtInside
etpinard Aug 24, 2018
4d20388
move a few things to lib/angles.js + add isPtInsideSector
etpinard Aug 24, 2018
95119c4
move polar polygon logic to polar/helper.js
etpinard Aug 24, 2018
facb2f8
mv arc/sector/annular path fn to angles.js
etpinard Aug 24, 2018
5ea3d52
update polar baselines post pathSector/pathArc cleanup
etpinard Aug 27, 2018
a328b1a
add barpolar :tada:
etpinard Jul 24, 2018
dcdd6b5
fix 'date' radial polar axes
etpinard Aug 28, 2018
6edd45e
:lock: barpolar on funky subplots
etpinard Aug 28, 2018
7ae3b7c
bullet-proof barpolar hover
etpinard Aug 28, 2018
0f62c0f
add barpolar mock to svg mock list
etpinard Aug 28, 2018
235b425
add barpolar hover tests
etpinard Aug 28, 2018
6b5895f
add barpolar select test
etpinard Aug 23, 2018
296f088
fixup jsDoc header
etpinard Aug 27, 2018
a32484a
do not .classed() layers in ensureSingle if className not given
etpinard Aug 31, 2018
e938974
standardize API of polar internal routine
etpinard Aug 31, 2018
cd05d3d
confirm use of tip-of-bar/mid-angle pt for selection and hover labels
etpinard Aug 31, 2018
971c6f6
make reversed-radial-axis hover logic more readable
etpinard Aug 31, 2018
e6c4dad
align hover label to the left for negative radial coords
etpinard Aug 31, 2018
01e15b4
improve barpolar attribute descriptions
etpinard Aug 31, 2018
160f742
:hocho: comment of rounding up bar borders
etpinard Aug 31, 2018
6494302
change polar bargap 0.2 -> 0.2
etpinard Sep 4, 2018
183b734
set miter-limit to 2 + :lock: in polar_bar-overlay mock
etpinard Sep 4, 2018
452e792
compute bar corners p0/p1/s0/s1 in crossTraceCalc
etpinard Sep 5, 2018
e792bc8
add 1e-15 tolerance in isFullCircle
etpinard Sep 5, 2018
8575b27
replace wrap360 with Lib.mod & wrap180 with new Lib.modHalf
etpinard Sep 5, 2018
939bdad
use mod to compute angle delta
etpinard Sep 5, 2018
d2484f3
make modHalf restrict output to "half" of Math.abs(input)
etpinard Sep 5, 2018
235fe5b
fixup doc for Lib.modHalf
etpinard Sep 5, 2018
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
14 changes: 12 additions & 2 deletions src/traces/bar/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,22 +683,32 @@ function collectExtents(calcTraces, pa) {
return String(Math.round(roundFactor * (p - pMin)));
};

var poffset, poffsetIsArray;

for(i = 0; i < calcTraces.length; i++) {
cd = calcTraces[i];
cd[0].t.extents = extents;
poffset = cd[0].t.poffset;
poffsetIsArray = Array.isArray(poffset);

for(j = 0; j < cd.length; j++) {
var di = cd[j];
var p0 = di[posLetter] - di.w / 2;

if(isNumeric(p0)) {
var p1 = di[posLetter] + di.w / 2;
var pVal = round(di.p);
if(extents[pVal]) {
extents[pVal] = [Math.min(p0, extents[pVal][0]), Math.max(p1, extents[pVal][1])];
}
else {
} else {
extents[pVal] = [p0, p1];
}
}

di.p0 = di.p + ((poffsetIsArray) ? poffset[j] : poffset);
di.p1 = di.p0 + di.w;
di.s0 = di.b;
di.s1 = di.s0 + di.s;
}
}
}
Expand Down
25 changes: 8 additions & 17 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
var bartraces = Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function(cd) {
var plotGroup = d3.select(this);
var cd0 = cd[0];
var t = cd0.t;
var trace = cd0.trace;

if(!plotinfo.isRangePlot) cd0.node3 = plotGroup;

var poffset = t.poffset;
var poffsetIsArray = Array.isArray(poffset);

var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');

var bars = pointGroup.selectAll('g.point').data(Lib.identity);
Expand All @@ -62,26 +58,21 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
// clipped xf/yf (2nd arg true): non-positive
// log values go off-screen by plotwidth
// so you see them continue if you drag the plot
var p0 = di.p + ((poffsetIsArray) ? poffset[i] : poffset),
p1 = p0 + di.w,
s0 = di.b,
s1 = s0 + di.s;

var x0, x1, y0, y1;
if(trace.orientation === 'h') {
y0 = ya.c2p(p0, true);
y1 = ya.c2p(p1, true);
x0 = xa.c2p(s0, true);
x1 = xa.c2p(s1, true);
y0 = ya.c2p(di.p0, true);
y1 = ya.c2p(di.p1, true);
x0 = xa.c2p(di.s0, true);
x1 = xa.c2p(di.s1, true);

// for selections
di.ct = [x1, (y0 + y1) / 2];
}
else {
x0 = xa.c2p(p0, true);
x1 = xa.c2p(p1, true);
y0 = ya.c2p(s0, true);
y1 = ya.c2p(s1, true);
x0 = xa.c2p(di.p0, true);
x1 = xa.c2p(di.p1, true);
y0 = ya.c2p(di.s0, true);
y1 = ya.c2p(di.s1, true);

// for selections
di.ct = [(x0 + x1) / 2, y1];
Expand Down
33 changes: 7 additions & 26 deletions src/traces/barpolar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ module.exports = function plot(gd, subplot, cdbar) {
var barLayer = subplot.layers.frontplot.select('g.barlayer');

Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function(cd) {
var cd0 = cd[0];
var plotGroup = cd0.node3 = d3.select(this);
var t = cd0.t;

var poffset = t.poffset;
var poffsetIsArray = Array.isArray(poffset);

var plotGroup = cd[0].node3 = d3.select(this);
var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
var bars = pointGroup.selectAll('g.point').data(Lib.identity);

Expand All @@ -41,26 +35,13 @@ module.exports = function plot(gd, subplot, cdbar) {

bars.exit().remove();

bars.each(function(di, i) {
bars.each(function(di) {
var bar = d3.select(this);

// TODO move this block to Bar.setPositions?
//
// now display the bar
// clipped xf/yf (2nd arg true): non-positive
// log values go off-screen by plotwidth
// so you see them continue if you drag the plot
//
// this gets reused in ./hover.js
var p0 = di.p0 = di.p + ((poffsetIsArray) ? poffset[i] : poffset);
var p1 = di.p1 = p0 + di.w;
var s0 = di.s0 = di.b;
var s1 = di.s1 = s0 + di.s;

var rp0 = di.rp0 = radialAxis.c2p(s0);
var rp1 = di.rp1 = radialAxis.c2p(s1);
var thetag0 = di.thetag0 = angularAxis.c2g(p0);
var thetag1 = di.thetag1 = angularAxis.c2g(p1);
var rp0 = di.rp0 = radialAxis.c2p(di.s0);
var rp1 = di.rp1 = radialAxis.c2p(di.s1);
var thetag0 = di.thetag0 = angularAxis.c2g(di.p0);
var thetag1 = di.thetag1 = angularAxis.c2g(di.p1);

var dPath;

Expand All @@ -74,7 +55,7 @@ module.exports = function plot(gd, subplot, cdbar) {
dPath = 'M0,0Z';
} else {
// this 'center' pt is used for selections and hover labels
var rg1 = radialAxis.c2g(s1);
var rg1 = radialAxis.c2g(di.s1);
var thetagMid = (thetag0 + thetag1) / 2;
di.ct = [
xa.c2p(rg1 * Math.cos(thetagMid)),
Expand Down
10 changes: 6 additions & 4 deletions src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,17 @@ module.exports = function calc(gd, trace) {
b: 0
};

// pts and p0/p1 don't seem to make much sense for cumulative distributions
// setup hover and event data fields,
// N.B. pts and "hover" positions ph0/ph1 don't seem to make much sense
// for cumulative distributions
if(!cumulativeSpec.enabled) {
cdi.pts = inputPoints[i];
if(uniqueValsPerBin) {
cdi.p0 = cdi.p1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
cdi.ph0 = cdi.ph1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @alexcjohnson I hope you don't mind.

The bar corners p0/p1/s0/s1 are now set during Bar.crossTraceCalc (moved from Bar.plot) so that we don't have to duplicate logic in BarPolar.plot. In turn, we needed to rename histogram p0/p1 to not break histogram hover.

}
else {
cdi.p0 = roundFn(binEdges[i]);
cdi.p1 = roundFn(binEdges[i + 1], true);
cdi.ph0 = roundFn(binEdges[i]);
cdi.ph1 = roundFn(binEdges[i + 1], true);
}
}
cd.push(cdi);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/histogram/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
if(!trace.cumulative.enabled) {
var posLetter = trace.orientation === 'h' ? 'y' : 'x';

pointData[posLetter + 'Label'] = hoverLabelText(pointData[posLetter + 'a'], di.p0, di.p1);
pointData[posLetter + 'Label'] = hoverLabelText(pointData[posLetter + 'a'], di.ph0, di.ph1);
}

return pts;
Expand Down
60 changes: 30 additions & 30 deletions test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('Test histogram', function() {
var out = calc(gd, fullTrace);
delete out[0].trace;

// this is dumb - but some of the `p0` values are `-0` which doesn't match `0`
// this is dumb - but some of the `ph0` values are `-0` which doesn't match `0`
// even though -0 === 0
out.forEach(function(cdi) {
for(var key in cdi) {
Expand Down Expand Up @@ -238,10 +238,10 @@ describe('Test histogram', function() {
expect(out).toEqual([
// full calcdata has x and y too (and t in the first one),
// but those come later from crossTraceCalc.
{i: 0, b: 0, p: d70, s: 2, pts: [0, 1], p0: d70, p1: d70},
{i: 1, b: 0, p: d71, s: 1, pts: [2], p0: d71, p1: d71},
{i: 2, b: 0, p: d72, s: 0, pts: [], p0: d72, p1: d72},
{i: 3, b: 0, p: d73, s: 1, pts: [3], p0: d73, p1: d73}
{i: 0, b: 0, p: d70, s: 2, pts: [0, 1], ph0: d70, ph1: d70},
{i: 1, b: 0, p: d71, s: 1, pts: [2], ph0: d71, ph1: d71},
{i: 2, b: 0, p: d72, s: 0, pts: [], ph0: d72, ph1: d72},
{i: 3, b: 0, p: d73, s: 1, pts: [3], ph0: d73, ph1: d73}
]);

// All data on exact months: shift so bin center is on (31-day months)
Expand All @@ -255,10 +255,10 @@ describe('Test histogram', function() {
var d70mar = Date.UTC(1970, 2, 2, 12);
var d70apr = Date.UTC(1970, 3, 1);
expect(out).toEqual([
{i: 0, b: 0, p: d70, s: 2, pts: [0, 1], p0: d70, p1: d70},
{i: 1, b: 0, p: d70feb, s: 1, pts: [2], p0: d70feb, p1: d70feb},
{i: 2, b: 0, p: d70mar, s: 0, pts: [], p0: d70mar, p1: d70mar},
{i: 3, b: 0, p: d70apr, s: 1, pts: [3], p0: d70apr, p1: d70apr}
{i: 0, b: 0, p: d70, s: 2, pts: [0, 1], ph0: d70, ph1: d70},
{i: 1, b: 0, p: d70feb, s: 1, pts: [2], ph0: d70feb, ph1: d70feb},
{i: 2, b: 0, p: d70mar, s: 0, pts: [], ph0: d70mar, ph1: d70mar},
{i: 3, b: 0, p: d70apr, s: 1, pts: [3], ph0: d70apr, ph1: d70apr}
]);

// data on exact days: shift so each bin goes from noon to noon
Expand All @@ -272,11 +272,11 @@ describe('Test histogram', function() {

expect(out).toEqual([
// dec 31 12:00 -> jan 31 12:00, middle is jan 16
{i: 0, b: 0, p: Date.UTC(1970, 0, 16), s: 2, pts: [0, 1], p0: Date.UTC(1970, 0, 1), p1: Date.UTC(1970, 0, 31)},
{i: 0, b: 0, p: Date.UTC(1970, 0, 16), s: 2, pts: [0, 1], ph0: Date.UTC(1970, 0, 1), ph1: Date.UTC(1970, 0, 31)},
// jan 31 12:00 -> feb 28 12:00, middle is feb 14 12:00
{i: 1, b: 0, p: Date.UTC(1970, 1, 14, 12), s: 1, pts: [2], p0: Date.UTC(1970, 1, 1), p1: Date.UTC(1970, 1, 28)},
{i: 2, b: 0, p: Date.UTC(1970, 2, 16), s: 0, pts: [], p0: Date.UTC(1970, 2, 1), p1: Date.UTC(1970, 2, 31)},
{i: 3, b: 0, p: Date.UTC(1970, 3, 15, 12), s: 1, pts: [3], p0: Date.UTC(1970, 3, 1), p1: Date.UTC(1970, 3, 30)}
{i: 1, b: 0, p: Date.UTC(1970, 1, 14, 12), s: 1, pts: [2], ph0: Date.UTC(1970, 1, 1), ph1: Date.UTC(1970, 1, 28)},
{i: 2, b: 0, p: Date.UTC(1970, 2, 16), s: 0, pts: [], ph0: Date.UTC(1970, 2, 1), ph1: Date.UTC(1970, 2, 31)},
{i: 3, b: 0, p: Date.UTC(1970, 3, 15, 12), s: 1, pts: [3], ph0: Date.UTC(1970, 3, 1), ph1: Date.UTC(1970, 3, 30)}
]);
});

Expand All @@ -292,10 +292,10 @@ describe('Test histogram', function() {
x3 = x2 + oneDay;

expect(out).toEqual([
{i: 0, b: 0, p: x0, s: 2, pts: [0, 1], p0: x0, p1: x0},
{i: 1, b: 0, p: x1, s: 1, pts: [2], p0: x1, p1: x1},
{i: 2, b: 0, p: x2, s: 0, pts: [], p0: x2, p1: x2},
{i: 3, b: 0, p: x3, s: 1, pts: [3], p0: x3, p1: x3}
{i: 0, b: 0, p: x0, s: 2, pts: [0, 1], ph0: x0, ph1: x0},
{i: 1, b: 0, p: x1, s: 1, pts: [2], ph0: x1, ph1: x1},
{i: 2, b: 0, p: x2, s: 0, pts: [], ph0: x2, ph1: x2},
{i: 3, b: 0, p: x3, s: 1, pts: [3], ph0: x3, ph1: x3}
]);
});

Expand All @@ -319,7 +319,7 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 3, s: 3, width1: 2, pts: [0, 1, 2], p0: 2, p1: 3.9}
{i: 0, b: 0, p: 3, s: 3, width1: 2, pts: [0, 1, 2], ph0: 2, ph1: 3.9}
]);
});

Expand All @@ -332,7 +332,7 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 1.1, s: 3, width1: 0.5, pts: [0, 1, 2], p0: 1.1, p1: 1.1}
{i: 0, b: 0, p: 1.1, s: 3, width1: 0.5, pts: [0, 1, 2], ph0: 1.1, ph1: 1.1}
]);
});

Expand All @@ -345,7 +345,7 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 17, s: 2, width1: 2, pts: [2, 4], p0: 17, p1: 17}
{i: 0, b: 0, p: 17, s: 2, width1: 2, pts: [2, 4], ph0: 17, ph1: 17}
]);
});

Expand All @@ -358,7 +358,7 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 13, s: 2, width1: 8, pts: [1, 3], p0: 13, p1: 13}
{i: 0, b: 0, p: 13, s: 2, width1: 8, pts: [1, 3], ph0: 13, ph1: 13}
]);
});

Expand All @@ -372,7 +372,7 @@ describe('Test histogram', function() {

var p = 1296691200000;
expect(out).toEqual([
{i: 0, b: 0, p: p, s: 2, width1: 2 * 24 * 3600 * 1000, pts: [1, 3], p0: p, p1: p}
{i: 0, b: 0, p: p, s: 2, width1: 2 * 24 * 3600 * 1000, pts: [1, 3], ph0: p, ph1: p}
]);
});

Expand All @@ -385,15 +385,15 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 97, s: 2, width1: 1, pts: [1, 3], p0: 97, p1: 97}
{i: 0, b: 0, p: 97, s: 2, width1: 1, pts: [1, 3], ph0: 97, ph1: 97}
]);
});

it('can tell the difference between single-bin and single-value histograms', function() {
var out = _calc({x: [1, 4]}, [], {barmode: 'overlay'});

expect(out).toEqual([
{i: 0, b: 0, p: 2, s: 2, width1: 5, pts: [0, 1], p0: 0, p1: 4}
{i: 0, b: 0, p: 2, s: 2, width1: 5, pts: [0, 1], ph0: 0, ph1: 4}
]);

// real single-valued trace inherits bar width from the simply single-bin trace
Expand All @@ -404,7 +404,7 @@ describe('Test histogram', function() {
});

expect(out).toEqual([
{i: 0, b: 0, p: 5, s: 1, width1: 5, pts: [0], p0: 5, p1: 5}
{i: 0, b: 0, p: 5, s: 1, width1: 5, pts: [0], ph0: 5, ph1: 5}
]);
});

Expand Down Expand Up @@ -496,14 +496,14 @@ describe('Test histogram', function() {
it('makes the right base histogram', function() {
var baseOut = _calc(base);
expect(baseOut).toEqual([
{i: 0, b: 0, p: 2, s: 1, pts: [0], p0: 0, p1: 0},
{i: 1, b: 0, p: 7, s: 2, pts: [1, 4], p0: 5, p1: 5},
{i: 2, b: 0, p: 12, s: 3, pts: [2, 5, 7], p0: 10, p1: 10},
{i: 3, b: 0, p: 17, s: 4, pts: [3, 6, 8, 9], p0: 15, p1: 15},
{i: 0, b: 0, p: 2, s: 1, pts: [0], ph0: 0, ph1: 0},
{i: 1, b: 0, p: 7, s: 2, pts: [1, 4], ph0: 5, ph1: 5},
{i: 2, b: 0, p: 12, s: 3, pts: [2, 5, 7], ph0: 10, ph1: 10},
{i: 3, b: 0, p: 17, s: 4, pts: [3, 6, 8, 9], ph0: 15, ph1: 15},
]);
});

// p0, p1, and pts have been omitted from CDFs for now
// ph0, ph1, and pts have been omitted from CDFs for now
var CDFs = [
{p: [2, 7, 12, 17], s: [1, 3, 6, 10]},
{
Expand Down