Skip to content

Commit 21b5411

Browse files
committed
Merge pull request #230 from plotly/split-up-axes
Split up axes module
2 parents 473016c + 4758fe3 commit 21b5411

15 files changed

+1083
-914
lines changed

src/components/colorbar/defaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
'use strict';
1111

12-
var Axes = require('../../plots/cartesian/axes');
1312
var Lib = require('../../lib');
13+
var handleTickValueDefaults = require('../../plots/cartesian/tick_value_defaults');
14+
var handleTickDefaults = require('../../plots/cartesian/tick_defaults');
1415

1516
var attributes = require('./attributes');
1617

@@ -49,9 +50,9 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
4950
coerce('borderwidth');
5051
coerce('bgcolor');
5152

52-
Axes.handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
53+
handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
5354

54-
Axes.handleTickDefaults(colorbarIn, colorbarOut, coerce, 'linear',
55+
handleTickDefaults(colorbarIn, colorbarOut, coerce, 'linear',
5556
{outerTicks: false, font: layout.font, noHover: true});
5657

5758
coerce('title');

src/components/colorbar/draw.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
var d3 = require('d3');
1313

1414
var Plotly = require('../../plotly');
15+
var Plots = require('../../plots/plots');
16+
var Axes = require('../../plots/cartesian/axes');
17+
var Fx = require('../../plots/cartesian/graph_interact');
18+
var Lib = require('../../lib');
19+
var Drawing = require('../drawing');
20+
var Color = require('../color');
21+
22+
var handleAxisDefaults = require('../../plots/cartesian/axis_defaults');
23+
var handleAxisPositionDefaults = require('../../plots/cartesian/position_defaults');
24+
var axisLayoutAttrs = require('../../plots/cartesian/layout_attributes');
1525

1626
var attributes = require('./attributes');
1727

@@ -163,23 +173,19 @@ module.exports = function draw(gd, id) {
163173
// Coerce w.r.t. Axes layoutAttributes:
164174
// re-use axes.js logic without updating _fullData
165175
function coerce(attr, dflt) {
166-
return Plotly.Lib.coerce(cbAxisIn, cbAxisOut,
167-
Plotly.Axes.layoutAttributes,
168-
attr, dflt);
176+
return Lib.coerce(cbAxisIn, cbAxisOut, axisLayoutAttrs, attr, dflt);
169177
}
170178

171179
// Prepare the Plotly axis object
172-
Plotly.Axes.handleAxisDefaults(cbAxisIn, cbAxisOut,
173-
coerce, axisOptions);
174-
Plotly.Axes.handleAxisPositioningDefaults(cbAxisIn, cbAxisOut,
175-
coerce, axisOptions);
180+
handleAxisDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);
181+
handleAxisPositionDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);
176182

177183
cbAxisOut._id = 'y' + id;
178184
cbAxisOut._td = gd;
179185

180186
// position can't go in through supplyDefaults
181187
// because that restricts it to [0,1]
182-
cbAxisOut.position = opts.x+xpadFrac+thickFrac;
188+
cbAxisOut.position = opts.x + xpadFrac + thickFrac;
183189

184190
// save for other callers to access this axis
185191
component.axis = cbAxisOut;
@@ -196,14 +202,14 @@ module.exports = function draw(gd, id) {
196202
cbAxisOut.tick0 = opts.levels.start;
197203
var dtick = opts.levels.size;
198204
// expand if too many contours, so we don't get too many ticks
199-
var autoNtick = Plotly.Lib.constrain(
205+
var autoNtick = Lib.constrain(
200206
(yBottomPx-yTopPx)/50, 4, 15) + 1,
201207
dtFactor = (zrange[1]-zrange[0]) /
202208
((opts.nticks||autoNtick)*dtick);
203209
if(dtFactor>1) {
204210
var dtexp = Math.pow(10,Math.floor(
205211
Math.log(dtFactor)/Math.LN10));
206-
dtick *= dtexp*Plotly.Lib.roundUp(dtFactor/dtexp,[2,5,10]);
212+
dtick *= dtexp * Lib.roundUp(dtFactor/dtexp,[2,5,10]);
207213
// if the contours are at round multiples, reset tick0
208214
// so they're still at round multiples. Otherwise,
209215
// keep the first label on the first contour level
@@ -269,7 +275,7 @@ module.exports = function draw(gd, id) {
269275
parseInt(titleText.style('font-size'), 10) * 1.3;
270276
}
271277
if(mathJaxNode) {
272-
titleHeight = Plotly.Drawing.bBox(mathJaxNode).height;
278+
titleHeight = Drawing.bBox(mathJaxNode).height;
273279
if(titleHeight>lineSize) {
274280
// not entirely sure how mathjax is doing
275281
// vertical alignment, but this seems to work.
@@ -278,7 +284,7 @@ module.exports = function draw(gd, id) {
278284
}
279285
else if(titleText.node() &&
280286
!titleText.classed('js-placeholder')) {
281-
titleHeight = Plotly.Drawing.bBox(
287+
titleHeight = Drawing.bBox(
282288
titleGroup.node()).height;
283289
}
284290
if(titleHeight) {
@@ -351,7 +357,7 @@ module.exports = function draw(gd, id) {
351357
.attr('d','M'+xLeft+',' +
352358
(Math.round(cbAxisOut.c2p(d))+(opts.line.width/2)%1) +
353359
'h'+thickPx)
354-
.call(Plotly.Drawing.lineGroupStyle,
360+
.call(Drawing.lineGroupStyle,
355361
opts.line.width, linecolormap(d), opts.line.dash);
356362
});
357363

@@ -363,7 +369,7 @@ module.exports = function draw(gd, id) {
363369
(opts.outlinewidth||0)/2 - (opts.ticks==='outside' ? 1 : 0);
364370
cbAxisOut.side = 'right';
365371

366-
return Plotly.Axes.doTicks(gd, cbAxisOut);
372+
return Axes.doTicks(gd, cbAxisOut);
367373
}
368374

369375
function positionCB(){
@@ -372,7 +378,7 @@ module.exports = function draw(gd, id) {
372378
// TODO: why are we redrawing multiple times now with this?
373379
// I guess autoMargin doesn't like being post-promise?
374380
var innerWidth = thickPx + opts.outlinewidth/2 +
375-
Plotly.Drawing.bBox(cbAxisOut._axislayer.node()).width;
381+
Drawing.bBox(cbAxisOut._axislayer.node()).width;
376382
titleEl = titleCont.select('text');
377383
if(titleEl.node() && !titleEl.classed('js-placeholder')) {
378384
var mathJaxNode = titleCont
@@ -381,15 +387,15 @@ module.exports = function draw(gd, id) {
381387
titleWidth;
382388
if(mathJaxNode &&
383389
['top','bottom'].indexOf(opts.titleside)!==-1) {
384-
titleWidth = Plotly.Drawing.bBox(mathJaxNode).width;
390+
titleWidth = Drawing.bBox(mathJaxNode).width;
385391
}
386392
else {
387393
// note: the formula below works for all titlesides,
388394
// (except for top/bottom mathjax, above)
389395
// but the weird fullLayout._size.l is because the titleunshift
390396
// transform gets removed by Drawing.bBox
391397
titleWidth =
392-
Plotly.Drawing.bBox(titleCont.node()).right -
398+
Drawing.bBox(titleCont.node()).right -
393399
xLeft - fullLayout._size.l;
394400
}
395401
innerWidth = Math.max(innerWidth,titleWidth);
@@ -406,8 +412,8 @@ module.exports = function draw(gd, id) {
406412
width: Math.max(outerwidth,2),
407413
height: Math.max(outerheight + 2*yExtraPx,2)
408414
})
409-
.call(Plotly.Color.fill, opts.bgcolor)
410-
.call(Plotly.Color.stroke, opts.bordercolor)
415+
.call(Color.fill, opts.bgcolor)
416+
.call(Color.stroke, opts.bordercolor)
411417
.style({'stroke-width': opts.borderwidth});
412418

413419
container.selectAll('.cboutline').attr({
@@ -417,7 +423,7 @@ module.exports = function draw(gd, id) {
417423
width: Math.max(thickPx,2),
418424
height: Math.max(outerheight - 2*opts.ypad - titleHeight, 2)
419425
})
420-
.call(Plotly.Color.stroke, opts.outlinecolor)
426+
.call(Color.stroke, opts.outlinecolor)
421427
.style({
422428
fill: 'None',
423429
'stroke-width': opts.outlinewidth
@@ -430,7 +436,7 @@ module.exports = function draw(gd, id) {
430436
'translate('+(fullLayout._size.l-xoffset)+','+fullLayout._size.t+')');
431437

432438
//auto margin adjustment
433-
Plotly.Plots.autoMargin(gd, id,{
439+
Plots.autoMargin(gd, id,{
434440
x: opts.x,
435441
y: opts.y,
436442
l: outerwidth*({right:1, center:0.5}[opts.xanchor]||0),
@@ -440,10 +446,10 @@ module.exports = function draw(gd, id) {
440446
});
441447
}
442448

443-
var cbDone = Plotly.Lib.syncOrAsync([
444-
Plotly.Plots.previousPromises,
449+
var cbDone = Lib.syncOrAsync([
450+
Plots.previousPromises,
445451
drawAxis,
446-
Plotly.Plots.previousPromises,
452+
Plots.previousPromises,
447453
positionCB
448454
], gd);
449455

@@ -455,29 +461,29 @@ module.exports = function draw(gd, id) {
455461
xf,
456462
yf;
457463

458-
Plotly.Fx.dragElement({
464+
Fx.dragElement({
459465
element: container.node(),
460466
prepFn: function() {
461467
t0 = container.attr('transform');
462-
Plotly.Fx.setCursor(container);
468+
Fx.setCursor(container);
463469
},
464470
moveFn: function(dx, dy) {
465471
var gs = gd._fullLayout._size;
466472

467473
container.attr('transform',
468474
t0+' ' + 'translate('+dx+','+dy+')');
469475

470-
xf = Plotly.Fx.dragAlign(xLeftFrac + (dx/gs.w), thickFrac,
476+
xf = Fx.dragAlign(xLeftFrac + (dx/gs.w), thickFrac,
471477
0, 1, opts.xanchor);
472-
yf = Plotly.Fx.dragAlign(yBottomFrac - (dy/gs.h), lenFrac,
478+
yf = Fx.dragAlign(yBottomFrac - (dy/gs.h), lenFrac,
473479
0, 1, opts.yanchor);
474480

475-
var csr = Plotly.Fx.dragCursors(xf, yf,
481+
var csr = Fx.dragCursors(xf, yf,
476482
opts.xanchor, opts.yanchor);
477-
Plotly.Fx.setCursor(container, csr);
483+
Fx.setCursor(container, csr);
478484
},
479485
doneFn: function(dragged) {
480-
Plotly.Fx.setCursor(container);
486+
Fx.setCursor(container);
481487

482488
if(dragged && xf!==undefined && yf!==undefined) {
483489
var idNum = id.substr(2),
@@ -507,8 +513,8 @@ module.exports = function draw(gd, id) {
507513

508514
// setter - for multi-part properties,
509515
// set only the parts that are provided
510-
opts[name] = Plotly.Lib.isPlainObject(opts[name]) ?
511-
Plotly.Lib.extendFlat(opts[name], v) :
516+
opts[name] = Lib.isPlainObject(opts[name]) ?
517+
Lib.extendFlat(opts[name], v) :
512518
v;
513519

514520
return component;

0 commit comments

Comments
 (0)