Skip to content

Commit c94423b

Browse files
committedJan 4, 2018
adapt polar to clean-subplots improvements
- use new get-subplot-data tools - adapt for new offset and selections in Axes.doTicks - 2018 header
1 parent 0146c2f commit c94423b

File tree

19 files changed

+40
-29
lines changed

19 files changed

+40
-29
lines changed
 

‎lib/scatterpolar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/lib/angles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/cartesian/line_grid_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/domain_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/plots.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,9 +2322,8 @@ plots.doCalcdata = function(gd, traces) {
23222322
trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);
23232323
}
23242324

2325-
// TODO maybe move this to Axes.list ??
2326-
// or better yet, make a more general Axes.list
2327-
var polarIds = plots.getSubplotIds(fullLayout, 'polar');
2325+
// add polar axes to axis list
2326+
var polarIds = fullLayout._subplots.polar || [];
23282327
for(i = 0; i < polarIds.length; i++) {
23292328
axList.push(
23302329
fullLayout[polarIds[i]].radialaxis,

‎src/plots/polar/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/polar/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/polar/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var Plots = require('../../plots/plots');
11+
var getSubplotCalcData = require('../get_data').getSubplotCalcData;
1212
var counterRegex = require('../../lib').counterRegex;
1313

1414
var createPolar = require('./polar');
@@ -35,11 +35,11 @@ attributes[attr] = {
3535
function plot(gd) {
3636
var fullLayout = gd._fullLayout;
3737
var calcData = gd.calcdata;
38-
var subplotIds = Plots.getSubplotIds(fullLayout, name);
38+
var subplotIds = fullLayout._subplots[name];
3939

4040
for(var i = 0; i < subplotIds.length; i++) {
4141
var id = subplotIds[i];
42-
var subplotCalcData = Plots.getSubplotCalcData(calcData, name, id);
42+
var subplotCalcData = getSubplotCalcData(calcData, name, id);
4343
var subplot = fullLayout[id]._subplot;
4444

4545
if(!subplot) {
@@ -52,7 +52,7 @@ function plot(gd) {
5252
}
5353

5454
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
55-
var oldIds = Plots.getSubplotIds(oldFullLayout, name);
55+
var oldIds = oldFullLayout._subplots[name] || [];
5656

5757
for(var i = 0; i < oldIds.length; i++) {
5858
var id = oldIds[i];

‎src/plots/polar/layout_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/polar/layout_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the
@@ -10,9 +10,9 @@
1010

1111
var Lib = require('../../lib');
1212
var Color = require('../../components/color');
13-
var Plots = require('../plots');
1413
var Registry = require('../../registry');
1514
var handleSubplotDefaults = require('../subplot_defaults');
15+
var getSubplotData = require('../get_data').getSubplotData;
1616

1717
var handleTickValueDefaults = require('../cartesian/tick_value_defaults');
1818
var handleTickMarkDefaults = require('../cartesian/tick_mark_defaults');
@@ -35,7 +35,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
3535
var sector = coerce('sector');
3636

3737
// could optimize, subplotData is not always needed!
38-
var subplotData = Plots.getSubplotData(opts.fullData, constants.name, opts.id);
38+
var subplotData = getSubplotData(opts.fullData, constants.name, opts.id);
3939
var layoutOut = opts.layoutOut;
4040
var axName;
4141

‎src/plots/polar/legacy/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/plots/polar/polar.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the
@@ -136,8 +136,12 @@ proto.updateLayers = function(fullLayout, polarLayout) {
136136
layers.bgcircle = sel.append('path');
137137
break;
138138
case 'radial-grid':
139+
sel.style('fill', 'none');
140+
sel.append('g').classed('x', 1);
141+
break;
139142
case 'angular-grid':
140143
sel.style('fill', 'none');
144+
sel.append('g').classed('angular', 1);
141145
break;
142146
case 'radial-line':
143147
sel.append('line').style('fill', 'none');
@@ -302,6 +306,11 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
302306
ax.tickangle = 180;
303307
}
304308

309+
// easier to set rotate angle with custom translate function
310+
ax._transfn = function(d) {
311+
return 'translate(' + ax.l2p(d.x) + ',0)';
312+
};
313+
305314
// set special grid path function
306315
ax._gridpath = function(d) {
307316
var r = ax.r2p(d.x);

‎src/traces/scatterpolar/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/traces/scatterpolar/calc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/traces/scatterpolar/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/traces/scatterpolar/hover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/traces/scatterpolar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎src/traces/scatterpolar/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2017, Plotly, Inc.
2+
* Copyright 2012-2018, Plotly, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under the MIT license found in the

‎test/jasmine/tests/polar_test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ describe('Test polar plots defaults:', function() {
6565
}];
6666

6767
layoutOut = {
68-
font: {color: 'red'}
68+
font: {color: 'red'},
69+
_subplots: {polar: ['polar']}
6970
};
7071

7172
Polar.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
@@ -338,7 +339,7 @@ describe('Test relayout on polar subplots:', function() {
338339
return toggle(
339340
'polar.angularaxis.showgrid',
340341
[true, false], [8, 0],
341-
'.angular-grid > path', assertCnt
342+
'.angular-grid > .angular > path', assertCnt
342343
);
343344
})
344345
.then(function() {
@@ -418,6 +419,8 @@ describe('Test relayout on polar subplots:', function() {
418419
it('should clean up its framework, clip paths and info layers when getting deleted', function(done) {
419420
var gd = createGraphDiv();
420421
var fig = Lib.extendDeep({}, require('@mocks/polar_scatter.json'));
422+
var traces = Lib.extendDeep([], fig.data);
423+
var inds = traces.map(function(_, i) { return i; });
421424

422425
function _assert(exp) {
423426
expect(d3.selectAll('g.polar').size()).toBe(exp.subplot, '# subplot layer');
@@ -433,12 +436,12 @@ describe('Test relayout on polar subplots:', function() {
433436
Plotly.plot(gd, fig).then(function() {
434437
_assert({subplot: 1, clip: 1, rtitle: 1});
435438

436-
return Plotly.restyle(gd, 'visible', false);
439+
return Plotly.deleteTraces(gd, inds);
437440
})
438441
.then(function() {
439442
_assert({subplot: 0, clip: 0, rtitle: 0});
440443

441-
return Plotly.restyle(gd, 'visible', true);
444+
return Plotly.addTraces(gd, traces);
442445
})
443446
.then(function() {
444447
_assert({subplot: 1, clip: 1, rtitle: 1});

0 commit comments

Comments
 (0)