Skip to content

Remove some refs to internal Plotly #237

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

Merged
merged 4 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 3 additions & 3 deletions src/traces/bar/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

var Plotly = require('../../plotly');
var Axes = require('../../plots/cartesian/axes');
var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleCalc = require('../../components/colorscale/calc');

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

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

Expand Down
17 changes: 9 additions & 8 deletions src/traces/bar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

'use strict';

var Plotly = require('../../plotly');
var Fx = require('../../plots/cartesian/graph_interact');
var ErrorBars = require('../../components/errorbars');
var Color = require('../../components/color');


Expand All @@ -32,25 +33,25 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
dx = function(di){
// add a gradient so hovering near the end of a
// bar makes it a little closer match
return Plotly.Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b);
return Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b);
};
dy = function(di){
var centerPos = barPos(di) - yval;
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
return Fx.inbox(centerPos - barDelta, centerPos + barDelta);
};
}
else {
dy = function(di){
return Plotly.Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b);
return Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b);
};
dx = function(di){
var centerPos = barPos(di) - xval;
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
return Fx.inbox(centerPos - barDelta, centerPos + barDelta);
};
}

var distfn = Plotly.Fx.getDistanceFunction(hovermode, dx, dy);
Plotly.Fx.getClosest(cd, distfn, pointData);
var distfn = Fx.getDistanceFunction(hovermode, dx, dy);
Fx.getClosest(cd, distfn, pointData);

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

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

Plotly.ErrorBars.hoverInfo(di, trace, pointData);
ErrorBars.hoverInfo(di, trace, pointData);

return [pointData];
};
30 changes: 14 additions & 16 deletions src/traces/bar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

'use strict';

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');

var layoutAttributes = require('./layout_attributes');
Expand All @@ -23,36 +24,33 @@ module.exports = function(layoutIn, layoutOut, fullData) {
var hasBars = false,
shouldBeGapless = false,
gappedAnyway = false,
usedSubplots = {},
i,
trace,
subploti;

for(i = 0; i < fullData.length; i++) {
trace = fullData[i];
if(Plotly.Plots.traceIs(trace, 'bar')) hasBars = true;
usedSubplots = {};

for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];
if(Plots.traceIs(trace, 'bar')) hasBars = true;
else continue;

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

if(trace.visible && trace.type==='histogram') {
var pa = Plotly.Axes.getFromId({_fullLayout:layoutOut},
trace[trace.orientation==='v' ? 'xaxis' : 'yaxis']);
if(pa.type!=='category') shouldBeGapless = true;
if(trace.visible && trace.type === 'histogram') {
var pa = Axes.getFromId({_fullLayout: layoutOut},
trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);
if(pa.type !== 'category') shouldBeGapless = true;
}
}

if(!hasBars) return;

var mode = coerce('barmode');
if(mode!=='overlay') coerce('barnorm');
if(mode !== 'overlay') coerce('barnorm');

coerce('bargap', shouldBeGapless && !gappedAnyway ? 0 : 0.2);
coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
coerce('bargroupgap');
};
66 changes: 35 additions & 31 deletions src/traces/bar/set_positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

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

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');

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

['v','h'].forEach(function(dir){
['v', 'h'].forEach(function(dir){
var bl = [],
pLetter = {v:'x',h:'y'}[dir],
sLetter = {v:'y',h:'x'}[dir],
pLetter = {v:'x', h:'y'}[dir],
sLetter = {v:'y', h:'x'}[dir],
pa = plotinfo[pLetter](),
sa = plotinfo[sLetter]();

gd._fullData.forEach(function(trace,i) {
if(trace.visible === true &&
Plotly.Plots.traceIs(trace, 'bar') &&
Plots.traceIs(trace, 'bar') &&
trace.orientation === dir &&
trace.xaxis === xa._id &&
trace.yaxis === ya._id) {
bl.push(i);
}
});

if(!bl.length) return;

// bar position offset and width calculation
Expand All @@ -53,9 +55,9 @@ module.exports = function setPositions(gd, plotinfo) {
function barposition(bl1) {
// find the min. difference between any points
// in any traces in bl1
var pvals=[];
var pvals = [];
bl1.forEach(function(i){
gd.calcdata[i].forEach(function(v){ pvals.push(v.p); });
gd.calcdata[i].forEach(function(v) { pvals.push(v.p); });
});
var dv = Lib.distinctVals(pvals),
pv2 = dv.vals,
Expand All @@ -65,7 +67,8 @@ module.exports = function setPositions(gd, plotinfo) {
// if so, let them have full width even if mode is group
var overlap = false,
comparelist = [];
if(fullLayout.barmode==='group') {

if(fullLayout.barmode === 'group') {
bl1.forEach(function(i) {
if(overlap) return;
gd.calcdata[i].forEach(function(v) {
Expand All @@ -82,36 +85,37 @@ module.exports = function setPositions(gd, plotinfo) {
}

// check forced minimum dtick
Plotly.Axes.minDtick(pa, barDiff, pv2[0], overlap);
Axes.minDtick(pa, barDiff, pv2[0], overlap);

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

// bar widths and position offsets
barDiff *= 1-fullLayout.bargap;
if(overlap) barDiff/=bl.length;
barDiff *= 1 - fullLayout.bargap;
if(overlap) barDiff /= bl.length;

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

for(var i=0; i<bl1.length; i++){
for(var i = 0; i < bl1.length; i++){
var t = gd.calcdata[bl1[i]][0].t;
t.barwidth = barDiff*(1-fullLayout.bargroupgap);
t.poffset = ((overlap ? (2*i+1-bl1.length)*barDiff : 0) -
t.barwidth)/2;
t.barwidth = barDiff * (1 - fullLayout.bargroupgap);
t.poffset = ((overlap ? (2 * i + 1 - bl1.length) * barDiff : 0) -
t.barwidth) / 2;
t.dbar = dv.minDiff;

// store the bar center in each calcdata item
barCenter = t.poffset + t.barwidth/2;
barCenter = t.poffset + t.barwidth / 2;
gd.calcdata[bl1[i]].forEach(setBarCenter);
}
}
if(fullLayout.barmode==='overlay') {

if(fullLayout.barmode === 'overlay') {
bl.forEach(function(bli){ barposition([bli]); });
}
else barposition(bl);

var stack = fullLayout.barmode==='stack',
var stack = (fullLayout.barmode === 'stack'),
norm = fullLayout.barnorm;

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

// make sure if p is different only by rounding,
// we still stack
sumround = gd.calcdata[bl[0]][0].t.barwidth/100,
sumround = gd.calcdata[bl[0]][0].t.barwidth / 100,
sv = 0,
padded = true,
barEnd,
ti,
scale;

for(i=0; i<bl.length; i++){ // trace index
for(i = 0; i<bl.length; i++){ // trace index
Copy link
Contributor

Choose a reason for hiding this comment

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

the < too?

ti = gd.calcdata[bl[i]];
for(j=0; j<ti.length; j++) {
sv = Math.round(ti[j].p/sumround);
var previousSum = sums[sv]||0;
for(j = 0; j<ti.length; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

sv = Math.round(ti[j].p / sumround);
var previousSum = sums[sv] || 0;
if(stack) ti[j].b = previousSum;
barEnd = ti[j].b+ti[j].s;
barEnd = ti[j].b + ti[j].s;
sums[sv] = previousSum + ti[j].s;

// store the bar top in each calcdata item
Expand All @@ -160,9 +164,9 @@ module.exports = function setPositions(gd, plotinfo) {
tiny = top/1e9; // in case of rounding error in sum
sMin = 0;
sMax = stack ? top : 0;
for(i=0; i<bl.length; i++){ // trace index
for(i = 0; i < bl.length; i++){ // trace index
ti = gd.calcdata[bl[i]];
for(j=0; j<ti.length; j++) {
for(j = 0; j < ti.length; j++) {
scale = top / sums[Math.round(ti[j].p/sumround)];
ti[j].b *= scale;
ti[j].s *= scale;
Expand All @@ -183,16 +187,16 @@ module.exports = function setPositions(gd, plotinfo) {
}
}

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

for(i=0; i<bl.length; i++){
Plotly.Axes.expand(sa, gd.calcdata[bl[i]].map(fs),
for(i = 0; i < bl.length; i++){
Axes.expand(sa, gd.calcdata[bl[i]].map(fs),
{tozero: true, padded: true});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/traces/bar/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Color = require('../../components/color');
var Drawing = require('../../components/drawing');


module.exports = function style(gd) {
Expand All @@ -21,7 +21,7 @@ module.exports = function style(gd) {
fullLayout = gd._fullLayout;

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

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

d3.select(this).selectAll('path').each(function(d) {
// allow all marker and marker line colors to be scaled
Expand Down
8 changes: 4 additions & 4 deletions src/traces/box/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

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

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');

module.exports = function calc(gd, trace) {
// outlier definition based on http://www.physics.csbsju.edu/stats/box2.html
var xa = Plotly.Axes.getFromId(gd, trace.xaxis||'x'),
ya = Plotly.Axes.getFromId(gd, trace.yaxis||'y'),
var xa = Axes.getFromId(gd, trace.xaxis||'x'),
Copy link
Contributor

Choose a reason for hiding this comment

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

||'s

ya = Axes.getFromId(gd, trace.yaxis||'y'),
orientation = trace.orientation,
cd = [],
valAxis, valLetter, val, valBinned,
Expand All @@ -39,7 +39,7 @@ module.exports = function calc(gd, trace) {

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

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