Skip to content

Commit

Permalink
Merge pull request #2200 from plotly/polar
Browse files Browse the repository at this point in the history
Polar 2.0
  • Loading branch information
etpinard authored Jan 16, 2018
2 parents ef181da + 18a3a0d commit 70f3f70
Show file tree
Hide file tree
Showing 101 changed files with 11,751 additions and 668 deletions.
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.
*/
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

0 comments on commit 70f3f70

Please sign in to comment.