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
32 changes: 9 additions & 23 deletions src/lib/angles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,14 @@

'use strict';

var mod = require('./mod').mod;

var PI = Math.PI;
var twoPI = 2 * PI;

function deg2rad(deg) {
return deg / 180 * PI;
}

function rad2deg(rad) {
return rad / PI * 180;
}
function deg2rad(deg) { return deg / 180 * PI; }

function wrap360(deg) {
var out = deg % 360;
return out < 0 ? out + 360 : out;
}

function wrap180(deg) {
if(Math.abs(deg) > 180) deg -= Math.round(deg / 360) * 360;
return deg;
}
function rad2deg(rad) { return rad / PI * 180; }

/**
* is sector a full circle?
Expand Down Expand Up @@ -84,12 +72,12 @@ function isAngleInsideSector(a, aBnds) {
s1 = aBnds[0];
}

s0 = wrap360(rad2deg(s0));
s1 = wrap360(rad2deg(s1));
if(s0 > s1) s1 += 360;
s0 = mod(s0, twoPI);
s1 = mod(s1, twoPI);
if(s0 > s1) s1 += twoPI;

var a0 = wrap360(rad2deg(a));
var a1 = a0 + 360;
var a0 = mod(a, twoPI);
var a1 = a0 + twoPI;

return (a0 >= s0 && a0 <= s1) || (a1 >= s0 && a1 <= s1);
}
Expand Down Expand Up @@ -237,8 +225,6 @@ function pathAnnulus(r0, r1, a0, a1, cx, cy) {
module.exports = {
deg2rad: deg2rad,
rad2deg: rad2deg,
wrap360: wrap360,
wrap180: wrap180,
angleDelta: angleDelta,
angleDist: angleDist,
isFullCircle: isFullCircle,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var colorscaleNames = Object.keys(require('../components/colorscale/scales'));
var nestedProperty = require('./nested_property');
var counterRegex = require('./regex').counter;
var DESELECTDIM = require('../constants/interactions').DESELECTDIM;
var wrap180 = require('./angles').wrap180;
var modHalf = require('./mod').modHalf;
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;

exports.valObjectMeta = {
Expand Down Expand Up @@ -186,7 +186,7 @@ exports.valObjectMeta = {
coerceFunction: function(v, propOut, dflt) {
if(v === 'auto') propOut.set('auto');
else if(!isNumeric(v)) propOut.set(dflt);
else propOut.set(wrap180(+v));
else propOut.set(modHalf(+v, 180));
}
},
subplotid: {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
var mod = require('./mod');
var mod = require('./mod').mod;

var constants = require('../constants/numerical');
var BADNUM = constants.BADNUM;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/geometry2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

var mod = require('./mod');
var mod = require('./mod').mod;

/*
* look for intersection of two line segments
Expand Down
7 changes: 4 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ lib.nestedProperty = require('./nested_property');
lib.keyedContainer = require('./keyed_container');
lib.relativeAttr = require('./relative_attr');
lib.isPlainObject = require('./is_plain_object');
lib.mod = require('./mod');
lib.toLogRange = require('./to_log_range');
lib.relinkPrivateKeys = require('./relink_private');
lib.ensureArray = require('./ensure_array');

var modModule = require('./mod');
lib.mod = modModule.mod;
lib.modHalf = modModule.modHalf;

var isArrayModule = require('./is_array');
lib.isTypedArray = isArrayModule.isTypedArray;
lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray;
Expand Down Expand Up @@ -86,8 +89,6 @@ lib.apply2DTransform2 = matrixModule.apply2DTransform2;
var anglesModule = require('./angles');
lib.deg2rad = anglesModule.deg2rad;
lib.rad2deg = anglesModule.rad2deg;
lib.wrap360 = anglesModule.wrap360;
lib.wrap180 = anglesModule.wrap180;
lib.angleDelta = anglesModule.angleDelta;
lib.angleDist = anglesModule.angleDist;
lib.isFullCircle = anglesModule.isFullCircle;
Expand Down
18 changes: 17 additions & 1 deletion src/lib/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@
* sanitized modulus function that always returns in the range [0, d)
* rather than (-d, 0] if v is negative
*/
module.exports = function mod(v, d) {
function mod(v, d) {
var out = v % d;
return out < 0 ? out + d : out;
}

/**
* sanitized modulus function that always returns in the range [-1.5*d, 1.5*d]
* rather than (-d, 0] if v is negative
*/
function modHalf(v, d) {
var d2 = 2 * d;
return Math.abs(v) > d ?
v - Math.round(v / d2) * d2 :
v;
}

module.exports = {
mod: mod,
modHalf: modHalf
};
9 changes: 4 additions & 5 deletions src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ var constants = require('./constants');
var helpers = require('./helpers');

var _ = Lib._;
var mod = Lib.mod;
var deg2rad = Lib.deg2rad;
var rad2deg = Lib.rad2deg;
var wrap360 = Lib.wrap360;
var wrap180 = Lib.wrap180;

function Polar(gd, id) {
this.id = id;
Expand Down Expand Up @@ -375,7 +374,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
var cx = _this.cx;
var cy = _this.cy;
var radialLayout = polarLayout.radialaxis;
var a0 = wrap360(polarLayout.sector[0]);
var a0 = mod(polarLayout.sector[0], 360);
var ax = _this.radialAxis;

_this.fillViewInitialKey('radialaxis.angle', radialLayout.angle);
Expand Down Expand Up @@ -1122,7 +1121,7 @@ proto.updateAngularDrag = function(fullLayout) {
});

// update rotation -> range -> _m,_b
angularAxis.rotation = wrap180(rot1);
angularAxis.rotation = Lib.modHalf(rot1, 180);
angularAxis.setGeometry();
angularAxis.setScale();

Expand Down Expand Up @@ -1238,7 +1237,7 @@ function computeSectorBBox(sector) {
var s0 = sector[0];
var s1 = sector[1];
var arc = s1 - s0;
var a0 = wrap360(s0);
var a0 = mod(s0, 360);
var a1 = a0 + arc;

var ax0 = Math.cos(deg2rad(a0));
Expand Down
4 changes: 2 additions & 2 deletions src/traces/scattermapbox/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
var lonlat = d.lonlat;
if(lonlat[0] === BADNUM) return Infinity;

var lon = Lib.wrap180(lonlat[0]);
var lon = Lib.modHalf(lonlat[0], 180);
var lat = lonlat[1];
var pt = subplot.project([lon, lat]);
var dx = pt.x - xa.c2p([xval2, lat]);
Expand All @@ -52,7 +52,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {

var di = cd[pointData.index];
var lonlat = di.lonlat;
var lonlatShifted = [Lib.wrap180(lonlat[0]) + lonShift, lonlat[1]];
var lonlatShifted = [Lib.modHalf(lonlat[0], 180) + lonShift, lonlat[1]];

// shift labels back to original winded globe
var xc = xa.c2p(lonlatShifted);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scattermapbox/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function selectPoints(searchInfo, polygon) {
var lonlat = di.lonlat;

if(lonlat[0] !== BADNUM) {
var lonlat2 = [Lib.wrap180(lonlat[0]), lonlat[1]];
var lonlat2 = [Lib.modHalf(lonlat[0], 180), lonlat[1]];
var xy = [xa.c2p(lonlat2), ya.c2p(lonlat2)];

if(polygon.contains(xy)) {
Expand Down