Skip to content

Commit 7b8510f

Browse files
committed
Merge pull request #237 from plotly/byebye-internal-plotly
Remove some refs to internal Plotly
2 parents 75026fa + 347ff55 commit 7b8510f

38 files changed

+277
-261
lines changed

Diff for: src/traces/bar/calc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
var isNumeric = require('fast-isnumeric');
1313

14-
var Plotly = require('../../plotly');
14+
var Axes = require('../../plots/cartesian/axes');
1515
var hasColorscale = require('../../components/colorscale/has_colorscale');
1616
var colorscaleCalc = require('../../components/colorscale/calc');
1717

@@ -22,8 +22,8 @@ module.exports = function calc(gd, trace) {
2222
// note: this logic for choosing orientation is
2323
// duplicated in graph_obj->setstyles
2424

25-
var xa = Plotly.Axes.getFromId(gd, trace.xaxis||'x'),
26-
ya = Plotly.Axes.getFromId(gd, trace.yaxis||'y'),
25+
var xa = Axes.getFromId(gd, trace.xaxis||'x'),
26+
ya = Axes.getFromId(gd, trace.yaxis||'y'),
2727
orientation = trace.orientation || ((trace.x && !trace.y) ? 'h' : 'v'),
2828
pos, size, i;
2929

Diff for: src/traces/bar/hover.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
12+
var Fx = require('../../plots/cartesian/graph_interact');
13+
var ErrorBars = require('../../components/errorbars');
1314
var Color = require('../../components/color');
1415

1516

@@ -32,25 +33,25 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
3233
dx = function(di){
3334
// add a gradient so hovering near the end of a
3435
// bar makes it a little closer match
35-
return Plotly.Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b);
36+
return Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b);
3637
};
3738
dy = function(di){
3839
var centerPos = barPos(di) - yval;
39-
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
40+
return Fx.inbox(centerPos - barDelta, centerPos + barDelta);
4041
};
4142
}
4243
else {
4344
dy = function(di){
44-
return Plotly.Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b);
45+
return Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b);
4546
};
4647
dx = function(di){
4748
var centerPos = barPos(di) - xval;
48-
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
49+
return Fx.inbox(centerPos - barDelta, centerPos + barDelta);
4950
};
5051
}
5152

52-
var distfn = Plotly.Fx.getDistanceFunction(hovermode, dx, dy);
53-
Plotly.Fx.getClosest(cd, distfn, pointData);
53+
var distfn = Fx.getDistanceFunction(hovermode, dx, dy);
54+
Fx.getClosest(cd, distfn, pointData);
5455

5556
// skip the rest (for this trace) if we didn't find a close point
5657
if(pointData.index===false) return;
@@ -82,7 +83,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
8283

8384
if(di.tx) pointData.text = di.tx;
8485

85-
Plotly.ErrorBars.hoverInfo(di, trace, pointData);
86+
ErrorBars.hoverInfo(di, trace, pointData);
8687

8788
return [pointData];
8889
};

Diff for: src/traces/bar/layout_defaults.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
12+
var Plots = require('../../plots/plots');
13+
var Axes = require('../../plots/cartesian/axes');
1314
var Lib = require('../../lib');
1415

1516
var layoutAttributes = require('./layout_attributes');
@@ -23,36 +24,33 @@ module.exports = function(layoutIn, layoutOut, fullData) {
2324
var hasBars = false,
2425
shouldBeGapless = false,
2526
gappedAnyway = false,
26-
usedSubplots = {},
27-
i,
28-
trace,
29-
subploti;
30-
31-
for(i = 0; i < fullData.length; i++) {
32-
trace = fullData[i];
33-
if(Plotly.Plots.traceIs(trace, 'bar')) hasBars = true;
27+
usedSubplots = {};
28+
29+
for(var i = 0; i < fullData.length; i++) {
30+
var trace = fullData[i];
31+
if(Plots.traceIs(trace, 'bar')) hasBars = true;
3432
else continue;
3533

3634
// if we have at least 2 grouped bar traces on the same subplot,
3735
// we should default to a gap anyway, even if the data is histograms
3836
if(layoutIn.barmode !== 'overlay' && layoutIn.barmode !== 'stack') {
39-
subploti = trace.xaxis + trace.yaxis;
37+
var subploti = trace.xaxis + trace.yaxis;
4038
if(usedSubplots[subploti]) gappedAnyway = true;
4139
usedSubplots[subploti] = true;
4240
}
4341

44-
if(trace.visible && trace.type==='histogram') {
45-
var pa = Plotly.Axes.getFromId({_fullLayout:layoutOut},
46-
trace[trace.orientation==='v' ? 'xaxis' : 'yaxis']);
47-
if(pa.type!=='category') shouldBeGapless = true;
42+
if(trace.visible && trace.type === 'histogram') {
43+
var pa = Axes.getFromId({_fullLayout: layoutOut},
44+
trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);
45+
if(pa.type !== 'category') shouldBeGapless = true;
4846
}
4947
}
5048

5149
if(!hasBars) return;
5250

5351
var mode = coerce('barmode');
54-
if(mode!=='overlay') coerce('barnorm');
52+
if(mode !== 'overlay') coerce('barnorm');
5553

56-
coerce('bargap', shouldBeGapless && !gappedAnyway ? 0 : 0.2);
54+
coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
5755
coerce('bargroupgap');
5856
};

Diff for: src/traces/bar/set_positions.js

+35-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
var isNumeric = require('fast-isnumeric');
1313

14-
var Plotly = require('../../plotly');
14+
var Plots = require('../../plots/plots');
15+
var Axes = require('../../plots/cartesian/axes');
1516
var Lib = require('../../lib');
1617

1718
/*
@@ -27,22 +28,23 @@ module.exports = function setPositions(gd, plotinfo) {
2728
ya = plotinfo.y(),
2829
i, j;
2930

30-
['v','h'].forEach(function(dir){
31+
['v', 'h'].forEach(function(dir){
3132
var bl = [],
32-
pLetter = {v:'x',h:'y'}[dir],
33-
sLetter = {v:'y',h:'x'}[dir],
33+
pLetter = {v:'x', h:'y'}[dir],
34+
sLetter = {v:'y', h:'x'}[dir],
3435
pa = plotinfo[pLetter](),
3536
sa = plotinfo[sLetter]();
3637

3738
gd._fullData.forEach(function(trace,i) {
3839
if(trace.visible === true &&
39-
Plotly.Plots.traceIs(trace, 'bar') &&
40+
Plots.traceIs(trace, 'bar') &&
4041
trace.orientation === dir &&
4142
trace.xaxis === xa._id &&
4243
trace.yaxis === ya._id) {
4344
bl.push(i);
4445
}
4546
});
47+
4648
if(!bl.length) return;
4749

4850
// bar position offset and width calculation
@@ -53,9 +55,9 @@ module.exports = function setPositions(gd, plotinfo) {
5355
function barposition(bl1) {
5456
// find the min. difference between any points
5557
// in any traces in bl1
56-
var pvals=[];
58+
var pvals = [];
5759
bl1.forEach(function(i){
58-
gd.calcdata[i].forEach(function(v){ pvals.push(v.p); });
60+
gd.calcdata[i].forEach(function(v) { pvals.push(v.p); });
5961
});
6062
var dv = Lib.distinctVals(pvals),
6163
pv2 = dv.vals,
@@ -65,7 +67,8 @@ module.exports = function setPositions(gd, plotinfo) {
6567
// if so, let them have full width even if mode is group
6668
var overlap = false,
6769
comparelist = [];
68-
if(fullLayout.barmode==='group') {
70+
71+
if(fullLayout.barmode === 'group') {
6972
bl1.forEach(function(i) {
7073
if(overlap) return;
7174
gd.calcdata[i].forEach(function(v) {
@@ -82,36 +85,37 @@ module.exports = function setPositions(gd, plotinfo) {
8285
}
8386

8487
// check forced minimum dtick
85-
Plotly.Axes.minDtick(pa, barDiff, pv2[0], overlap);
88+
Axes.minDtick(pa, barDiff, pv2[0], overlap);
8689

8790
// position axis autorange - always tight fitting
88-
Plotly.Axes.expand(pa, pv2, {vpad: barDiff/2});
91+
Axes.expand(pa, pv2, {vpad: barDiff / 2});
8992

9093
// bar widths and position offsets
91-
barDiff *= 1-fullLayout.bargap;
92-
if(overlap) barDiff/=bl.length;
94+
barDiff *= 1 - fullLayout.bargap;
95+
if(overlap) barDiff /= bl.length;
9396

9497
var barCenter;
9598
function setBarCenter(v) { v[pLetter] = v.p + barCenter; }
9699

97-
for(var i=0; i<bl1.length; i++){
100+
for(var i = 0; i < bl1.length; i++){
98101
var t = gd.calcdata[bl1[i]][0].t;
99-
t.barwidth = barDiff*(1-fullLayout.bargroupgap);
100-
t.poffset = ((overlap ? (2*i+1-bl1.length)*barDiff : 0) -
101-
t.barwidth)/2;
102+
t.barwidth = barDiff * (1 - fullLayout.bargroupgap);
103+
t.poffset = ((overlap ? (2 * i + 1 - bl1.length) * barDiff : 0) -
104+
t.barwidth) / 2;
102105
t.dbar = dv.minDiff;
103106

104107
// store the bar center in each calcdata item
105-
barCenter = t.poffset + t.barwidth/2;
108+
barCenter = t.poffset + t.barwidth / 2;
106109
gd.calcdata[bl1[i]].forEach(setBarCenter);
107110
}
108111
}
109-
if(fullLayout.barmode==='overlay') {
112+
113+
if(fullLayout.barmode === 'overlay') {
110114
bl.forEach(function(bli){ barposition([bli]); });
111115
}
112116
else barposition(bl);
113117

114-
var stack = fullLayout.barmode==='stack',
118+
var stack = (fullLayout.barmode === 'stack'),
115119
norm = fullLayout.barnorm;
116120

117121
// bar size range and stacking calculation
@@ -127,20 +131,20 @@ module.exports = function setPositions(gd, plotinfo) {
127131

128132
// make sure if p is different only by rounding,
129133
// we still stack
130-
sumround = gd.calcdata[bl[0]][0].t.barwidth/100,
134+
sumround = gd.calcdata[bl[0]][0].t.barwidth / 100,
131135
sv = 0,
132136
padded = true,
133137
barEnd,
134138
ti,
135139
scale;
136140

137-
for(i=0; i<bl.length; i++){ // trace index
141+
for(i = 0; i < bl.length; i++){ // trace index
138142
ti = gd.calcdata[bl[i]];
139-
for(j=0; j<ti.length; j++) {
140-
sv = Math.round(ti[j].p/sumround);
141-
var previousSum = sums[sv]||0;
143+
for(j = 0; j < ti.length; j++) {
144+
sv = Math.round(ti[j].p / sumround);
145+
var previousSum = sums[sv] || 0;
142146
if(stack) ti[j].b = previousSum;
143-
barEnd = ti[j].b+ti[j].s;
147+
barEnd = ti[j].b + ti[j].s;
144148
sums[sv] = previousSum + ti[j].s;
145149

146150
// store the bar top in each calcdata item
@@ -160,9 +164,9 @@ module.exports = function setPositions(gd, plotinfo) {
160164
tiny = top/1e9; // in case of rounding error in sum
161165
sMin = 0;
162166
sMax = stack ? top : 0;
163-
for(i=0; i<bl.length; i++){ // trace index
167+
for(i = 0; i < bl.length; i++){ // trace index
164168
ti = gd.calcdata[bl[i]];
165-
for(j=0; j<ti.length; j++) {
169+
for(j = 0; j < ti.length; j++) {
166170
scale = top / sums[Math.round(ti[j].p/sumround)];
167171
ti[j].b *= scale;
168172
ti[j].s *= scale;
@@ -183,16 +187,16 @@ module.exports = function setPositions(gd, plotinfo) {
183187
}
184188
}
185189

186-
Plotly.Axes.expand(sa, [sMin, sMax], {tozero: true, padded: padded});
190+
Axes.expand(sa, [sMin, sMax], {tozero: true, padded: padded});
187191
}
188192
else {
189193
// for grouped or overlaid bars, just make sure zero is
190194
// included, along with the tops of each bar, and store
191195
// these bar tops in calcdata
192-
var fs = function(v){ v[sLetter] = v.s; return v.s; };
196+
var fs = function(v) { v[sLetter] = v.s; return v.s; };
193197

194-
for(i=0; i<bl.length; i++){
195-
Plotly.Axes.expand(sa, gd.calcdata[bl[i]].map(fs),
198+
for(i = 0; i < bl.length; i++){
199+
Axes.expand(sa, gd.calcdata[bl[i]].map(fs),
196200
{tozero: true, padded: true});
197201
}
198202
}

Diff for: src/traces/bar/style.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
var d3 = require('d3');
1313

14-
var Plotly = require('../../plotly');
1514
var Color = require('../../components/color');
15+
var Drawing = require('../../components/drawing');
1616

1717

1818
module.exports = function style(gd) {
@@ -21,7 +21,7 @@ module.exports = function style(gd) {
2121
fullLayout = gd._fullLayout;
2222

2323
// trace styling
24-
s.style('opacity',function(d){ return d[0].trace.opacity; })
24+
s.style('opacity', function(d) { return d[0].trace.opacity; })
2525

2626
// for gapless (either stacked or neighboring grouped) bars use
2727
// crispEdges to turn off antialiasing so an artificial gap
@@ -41,8 +41,8 @@ module.exports = function style(gd) {
4141
marker = trace.marker,
4242
markerLine = marker.line,
4343
markerIn = (trace._input||{}).marker||{},
44-
markerScale = Plotly.Drawing.tryColorscale(marker, markerIn, ''),
45-
lineScale = Plotly.Drawing.tryColorscale(marker, markerIn, 'line.');
44+
markerScale = Drawing.tryColorscale(marker, markerIn, ''),
45+
lineScale = Drawing.tryColorscale(marker, markerIn, 'line.');
4646

4747
d3.select(this).selectAll('path').each(function(d) {
4848
// allow all marker and marker line colors to be scaled

Diff for: src/traces/box/calc.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
var isNumeric = require('fast-isnumeric');
1212

13-
var Plotly = require('../../plotly');
1413
var Lib = require('../../lib');
14+
var Axes = require('../../plots/cartesian/axes');
1515

16+
17+
// outlier definition based on http://www.physics.csbsju.edu/stats/box2.html
1618
module.exports = function calc(gd, trace) {
17-
// outlier definition based on http://www.physics.csbsju.edu/stats/box2.html
18-
var xa = Plotly.Axes.getFromId(gd, trace.xaxis||'x'),
19-
ya = Plotly.Axes.getFromId(gd, trace.yaxis||'y'),
19+
var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
20+
ya = Axes.getFromId(gd, trace.yaxis || 'y'),
2021
orientation = trace.orientation,
2122
cd = [],
2223
valAxis, valLetter, val, valBinned,
@@ -39,7 +40,7 @@ module.exports = function calc(gd, trace) {
3940

4041
// size autorange based on all source points
4142
// position happens afterward when we know all the pos
42-
Plotly.Axes.expand(valAxis, val, {padded: true});
43+
Axes.expand(valAxis, val, {padded: true});
4344

4445
// In vertical (horizontal) box plots:
4546
// if no x (y) data, use x0 (y0), or name

0 commit comments

Comments
 (0)