Skip to content
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

Polar 2.0 #2200

Merged
merged 73 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
58d53e8
move (old) polar code to legacy/ folder
etpinard Nov 20, 2017
853581e
introduce scatterpolar attributes
etpinard Dec 11, 2017
3c8ae5b
introduce polar subplot attributes
etpinard Dec 11, 2017
ca8081b
introduce angles helper module
etpinard Dec 11, 2017
46fe066
first cut polar subplot defaults and draw routines
etpinard Dec 11, 2017
0826ee7
first cut scatterpolar calc/defaults/plot/style/hover
etpinard Dec 11, 2017
9770f2c
misc things to get scatterpolar traces to show up
etpinard Dec 11, 2017
0b85af2
init categories stashes for polar axes
etpinard Dec 11, 2017
cbf19c1
allow ticksuffix dflt to be passed via option
etpinard Dec 11, 2017
86204a6
get polar axis updates to work
etpinard Dec 11, 2017
0027f53
add legacy deprecation warnings
etpinard Dec 11, 2017
4cdc301
remove obsolete check for polar in registry
etpinard Dec 11, 2017
a5a719c
get snapshot redraw function right for (new) polar
etpinard Dec 11, 2017
da720aa
improve scatterpolar hover
etpinard Dec 11, 2017
04a886b
use subplot ref in scatterternary hover pointData
etpinard Dec 11, 2017
22cf4ba
expose a few things out of cartesian dragbox for :recycle:
etpinard Dec 11, 2017
122dd0b
uber wip polar main drag interaction
etpinard Dec 11, 2017
689414c
add radial axis drag interactions
etpinard Dec 11, 2017
543b615
first cut polar mocks!
etpinard Dec 11, 2017
54b3f1c
Merge branch 'master' into polar
etpinard Dec 15, 2017
17503cb
make scatter{ternary,polar,carpet} Scatter.style reuse straight-up
etpinard Dec 14, 2017
7b0f718
add test for commit 86204a6 (ternary ax tickfont relayouts)
etpinard Dec 14, 2017
fbea869
:palm_tree: domain attributes
etpinard Dec 14, 2017
1e769f0
make non-zero radialaxis.range[0] work
etpinard Dec 14, 2017
f53495e
make radial/angular axis visible: false cases work
etpinard Dec 14, 2017
c5a3a72
1st pass isPtWithinSector algo
etpinard Dec 15, 2017
61e155c
warn -> log for polar deprecation
etpinard Dec 15, 2017
258600d
:hocho: special polygon logic from scatterpolar/plot
etpinard Dec 18, 2017
0a41da5
implement {angular,radial}axis.layer
etpinard Dec 18, 2017
f3a2379
:palm_tree: make filter-visible work for calcdata containers
etpinard Dec 19, 2017
3f5e77b
first cut radial axis drag intractions
etpinard Dec 19, 2017
65b717d
get `polar.sector` working on category angular axes
etpinard Dec 19, 2017
13568a3
fixup isPtWithinSector
etpinard Dec 20, 2017
797fec1
add support for 'log' radial axes
etpinard Dec 20, 2017
0a9278c
fixup axis autotype logic for visible: false traces
etpinard Dec 22, 2017
07a3af7
make sure that angular setting relayout call propagate to tick labels
etpinard Dec 22, 2017
a263c1c
solid zoombox try + some pan work and radial drag fixups
etpinard Dec 22, 2017
765d2b7
pretty solid zoom/pan interactions
etpinard Dec 23, 2017
909d134
make polar ticks relayout more robust
etpinard Dec 27, 2017
3e1e4dd
:palm_tree: calcMarkerSize logic
etpinard Dec 28, 2017
a96131d
fix hoveron fill hover label placement edge case
etpinard Dec 28, 2017
b35d7ec
update ticks when panning sectors using new wrap180 routine
etpinard Dec 28, 2017
5751de5
make marker.size bump radial autorange results
etpinard Dec 28, 2017
86067a6
:palm_tree: cartesian/ternary/polar line/grid default logic
etpinard Dec 29, 2017
5422da9
coerce 'cliponaxis' only when markers and/or text are present
etpinard Dec 29, 2017
b4af46f
clear ternary axis titles when ternary subplots are removed
etpinard Jan 3, 2018
20b17e5
set radialaxis.rangemode dflt to 'tozero' + add support for -ve r ranges
etpinard Jan 4, 2018
cb78d19
implement radialaxis.title
etpinard Jan 4, 2018
25b4e7b
even more robust relayout
etpinard Jan 4, 2018
1e81039
large commit of attribute name & dflt changes
etpinard Jan 4, 2018
e5d238d
remove crispEdges for all polar subplot paths
etpinard Jan 4, 2018
0146c2f
Merge branch 'master' into polar
etpinard Jan 4, 2018
c94423b
adapt polar to clean-subplots improvements
etpinard Jan 4, 2018
4d5a1bd
fixups for domain attrs
etpinard Jan 10, 2018
d4c7d2c
default *rotation* to 90 for clockwise *direction*
etpinard Jan 10, 2018
8b4c2b5
do not implement 'date' angular axes (for now)
etpinard Jan 10, 2018
5357501
clear polar radial range viewInitial during log <-> linear relayout
etpinard Jan 10, 2018
9a71ba3
set limit of 100 for num2frac denominator
etpinard Jan 10, 2018
f714449
extend line & fills to polar center when pts < radialaxis.range[0]
etpinard Jan 10, 2018
cde7369
fixup radial axis drag rotate logic
etpinard Jan 10, 2018
9c4c9bf
Merge branch 'master' into polar
etpinard Jan 11, 2018
b365374
more strict check for polar subplot existence
etpinard Jan 11, 2018
a72ce55
adapt polar main drag to dragElement updates (+ tests)
etpinard Jan 11, 2018
473643c
AJ-proof latest additions
etpinard Jan 12, 2018
c2da23e
replace dragmode: 'pan' with annulus-shaped dragger
etpinard Jan 11, 2018
974740b
improve zoom dragbox behavior
etpinard Jan 11, 2018
e8aec86
un-rotate markers and text pts during angular drag
etpinard Jan 12, 2018
e8865bc
add scatterpolar hover label tests
etpinard Dec 22, 2017
8a33b89
add scatterpolar select test
etpinard Jan 12, 2018
c7a7f59
add polar drag interaction tests
etpinard Jan 15, 2018
7f7193d
a few small tweaks
etpinard Jan 15, 2018
816be51
misc. polar fixup after AJ's review:
etpinard Jan 16, 2018
18a3a0d
add clampFn option to dragElement & use it for radial drag box
etpinard Jan 16, 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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ dist
build

test/jasmine/assets/jquery-1.8.3.min.js
src/plots/polar/micropolar.js
src/plots/polar/legacy/micropolar.js
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Plotly.register([
require('./contourcarpet'),

require('./ohlc'),
require('./candlestick')
require('./candlestick'),

require('./scatterpolar')
]);

// transforms
Expand Down
11 changes: 11 additions & 0 deletions lib/scatterpolar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/scatterpolar');
3 changes: 3 additions & 0 deletions src/components/calendars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ module.exports = {
// from yaxis if they only apply to x (rangeselector/rangeslider)
yaxis: {calendar: axisAttrs},
zaxis: {calendar: axisAttrs}
},
polar: {
radialaxis: {calendar: axisAttrs}
}
},
transforms: {
Expand Down
19 changes: 15 additions & 4 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ dragElement.unhoverRaw = unhover.raw;
* numClicks is how many clicks we've registered within
* a doubleclick time
* e is the original mousedown event
* clampFn (optional, function(dx, dy) return [dx2, dy2])
* Provide custom clamping function for small displacements.
* By default, clamping is done using `minDrag` to x and y displacements
* independently.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nicely done. And it works great to solve the radial/angular drag bug! 🎯

*/
dragElement.init = function init(options) {
var gd = options.gd;
Expand All @@ -99,6 +103,14 @@ dragElement.init = function init(options) {
element.onmousedown = onStart;
element.ontouchstart = onStart;

function _clampFn(dx, dy, minDrag) {
if(Math.abs(dx) < minDrag) dx = 0;
if(Math.abs(dy) < minDrag) dy = 0;
return [dx, dy];
}

var clampFn = options.clampFn || _clampFn;

function onStart(e) {
// make dragging and dragged into properties of gd
// so that others can look at and modify them
Expand Down Expand Up @@ -145,12 +157,11 @@ dragElement.init = function init(options) {

function onMove(e) {
var offset = pointerOffset(e);
var dx = offset[0] - startX;
var dy = offset[1] - startY;
var minDrag = options.minDrag || constants.MINDRAG;
var dxdy = clampFn(offset[0] - startX, offset[1] - startY, minDrag);
var dx = dxdy[0];
var dy = dxdy[1];

if(Math.abs(dx) < minDrag) dx = 0;
if(Math.abs(dy) < minDrag) dy = 0;
if(dx || dy) {
gd._dragged = true;
dragElement.unhover(gd);
Expand Down
4 changes: 4 additions & 0 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
var hasGL2D = fullLayout._has('gl2d');
var hasTernary = fullLayout._has('ternary');
var hasMapbox = fullLayout._has('mapbox');
var hasPolar = fullLayout._has('polar');

var groups = [];

Expand Down Expand Up @@ -121,6 +122,9 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
if(hasMapbox || hasGeo) {
dragModeGroup = ['pan2d'];
}
if(hasPolar) {
dragModeGroup = ['zoom2d'];
}
if(isSelectable(fullData)) {
dragModeGroup.push('select2d');
dragModeGroup.push('lasso2d');
Expand Down
34 changes: 25 additions & 9 deletions src/components/titles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var numStripRE = / [XY][0-9]* /;
* offset - shift up/down in the rotated frame (unused?)
* containerGroup - if an svg <g> element already exists to hold this
* title, include here. Otherwise it will go in fullLayout._infolayer
*
* @return {selection} d3 selection of title container group
*/
Titles.draw = function(gd, titleClass, options) {
var cont = options.propContainer;
Expand All @@ -63,13 +65,14 @@ Titles.draw = function(gd, titleClass, options) {
var group = options.containerGroup;

var fullLayout = gd._fullLayout;
var font = cont.titlefont.family;
var fontSize = cont.titlefont.size;
var fontColor = cont.titlefont.color;
var titlefont = cont.titlefont || {};
var font = titlefont.family;
var fontSize = titlefont.size;
var fontColor = titlefont.color;

var opacity = 1;
var isplaceholder = false;
var txt = cont.title.trim();
var txt = (cont.title || '').trim();

// only make this title editable if we positively identify its property
// as one that has editing enabled.
Expand Down Expand Up @@ -111,17 +114,28 @@ Titles.draw = function(gd, titleClass, options) {
.attr('class', titleClass);
el.exit().remove();

if(!elShouldExist) return;
if(!elShouldExist) return group;

function titleLayout(titleEl) {
Lib.syncOrAsync([drawTitle, scootTitle], titleEl);
}

function drawTitle(titleEl) {
titleEl.attr('transform', transform ?
'rotate(' + [transform.rotate, attributes.x, attributes.y] +
') translate(0, ' + transform.offset + ')' :
null);
var transformVal;

if(transform) {
transformVal = '';
if(transform.rotate) {
transformVal += 'rotate(' + [transform.rotate, attributes.x, attributes.y] + ')';
}
if(transform.offset) {
transformVal += 'translate(0, ' + transform.offset + ')';
}
} else {
transformVal = null;
}

titleEl.attr('transform', transformVal);

titleEl.style({
'font-family': font,
Expand Down Expand Up @@ -236,4 +250,6 @@ Titles.draw = function(gd, titleClass, options) {
});
}
el.classed('js-placeholder', isplaceholder);

return group;
};
29 changes: 29 additions & 0 deletions src/lib/angles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var PI = Math.PI;

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

exports.rad2deg = function(rad) {
return rad / PI * 180;
};

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

exports.wrap180 = function(deg) {
if(Math.abs(deg) > 180) deg -= Math.round(deg / 360) * 360;
return deg;
};
6 changes: 2 additions & 4 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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;

exports.valObjectMeta = {
data_array: {
Expand Down Expand Up @@ -182,10 +183,7 @@ exports.valObjectMeta = {
coerceFunction: function(v, propOut, dflt) {
if(v === 'auto') propOut.set('auto');
else if(!isNumeric(v)) propOut.set(dflt);
else {
if(Math.abs(v) > 180) v -= Math.round(v / 360) * 360;
propOut.set(+v);
}
else propOut.set(wrap180(+v));
}
},
subplotid: {
Expand Down
22 changes: 19 additions & 3 deletions src/lib/filter_visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

/** Filter out object items with visible !== true
Expand All @@ -17,13 +16,30 @@
*
*/
module.exports = function filterVisible(container) {
var filterFn = isCalcData(container) ? calcDataFilter : baseFilter;
var out = [];

for(var i = 0; i < container.length; i++) {
var item = container[i];

if(item.visible === true) out.push(item);
if(filterFn(item)) out.push(item);
}

return out;
};

function baseFilter(item) {
return item.visible === true;
}

function calcDataFilter(item) {
return item[0].trace.visible === true;
}

function isCalcData(cont) {
return (
Array.isArray(cont) &&
Array.isArray(cont[0]) &&
cont[0][0] &&
cont[0][0].trace
);
}
6 changes: 6 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ lib.rotationXYMatrix = matrixModule.rotationXYMatrix;
lib.apply2DTransform = matrixModule.apply2DTransform;
lib.apply2DTransform2 = matrixModule.apply2DTransform2;

var anglesModule = require('./angles');
lib.deg2rad = anglesModule.deg2rad;
lib.rad2deg = anglesModule.rad2deg;
lib.wrap360 = anglesModule.wrap360;
lib.wrap180 = anglesModule.wrap180;

var geom2dModule = require('./geometry2d');
lib.segmentsIntersect = geom2dModule.segmentsIntersect;
lib.segmentDistance = geom2dModule.segmentDistance;
Expand Down
22 changes: 19 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Queue = require('../lib/queue');
var Registry = require('../registry');
var PlotSchema = require('./plot_schema');
var Plots = require('../plots/plots');
var Polar = require('../plots/polar');
var Polar = require('../plots/polar/legacy');
var initInteractions = require('../plots/cartesian/graph_interact');

var Drawing = require('../components/drawing');
Expand Down Expand Up @@ -144,8 +144,11 @@ Plotly.plot = function(gd, data, layout, config) {

var fullLayout = gd._fullLayout;

// Polar plots
if(data && data[0] && data[0].r) return plotPolar(gd, data, layout);
// Legacy polar plots
if(!fullLayout._has('polar') && data && data[0] && data[0].r) {
Lib.log('Legacy polar charts are deprecated!');
return plotPolar(gd, data, layout);
}

// so we don't try to re-call Plotly.plot from inside
// legend and colorbar, if margins changed
Expand Down Expand Up @@ -1941,6 +1944,16 @@ function _relayout(gd, aobj) {
ax.range = (ax.range[1] > ax.range[0]) ? [1, 2] : [2, 1];
}

// clear polar view initial stash for radial range so that
// value get recomputed in correct units
if(Array.isArray(fullLayout._subplots.polar) &&
fullLayout._subplots.polar.length &&
fullLayout[p.parts[0]] &&
p.parts[1] === 'radialaxis'
) {
delete fullLayout[p.parts[0]]._subplot.viewInitial['radialaxis.range'];
}

// Annotations and images also need to convert to/from linearized coords
// Shapes do not need this :)
Registry.getComponentMethod('annotations', 'convertCoords')(gd, parentFull, vi, doextra);
Expand Down Expand Up @@ -2865,6 +2878,9 @@ function makePlotFramework(gd) {
// single cartesian layer for the whole plot
fullLayout._cartesianlayer = fullLayout._paper.append('g').classed('cartesianlayer', true);

// single polar layer for the whole plot
fullLayout._polarlayer = fullLayout._paper.append('g').classed('polarlayer', true);

// single ternary layer for the whole plot
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);

Expand Down
4 changes: 2 additions & 2 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var frameAttributes = require('../plots/frame_attributes');
var animationAttributes = require('../plots/animation_attributes');

// polar attributes are not part of the Registry yet
var polarAreaAttrs = require('../plots/polar/area_attributes');
var polarAxisAttrs = require('../plots/polar/axis_attributes');
var polarAreaAttrs = require('../plots/polar/legacy/area_attributes');
var polarAxisAttrs = require('../plots/polar/legacy/axis_attributes');

var editTypes = require('./edit_types');

Expand Down
Loading