Skip to content

Commit 2a04a23

Browse files
committed
Merge branch 'master' of github.com:jackparmer/streambed
2 parents 942ce9c + 39bc76d commit 2a04a23

File tree

3 files changed

+62
-57
lines changed

3 files changed

+62
-57
lines changed

shelly/shelly/templates/static/js/axes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function setType(gd,axletter){
4040
delete ax.isdate;
4141

4242
// delete category list, if there is one, so we start over
43-
// to be filled in later by convertToAxis
43+
// to be filled in later by convertToNums
4444
ax.categories = [];
4545

4646
// guess at axis type with the new property format
@@ -194,7 +194,7 @@ axes.convertToNums = function(o,ax){
194194
}
195195

196196
// setConvert: define the conversion functions for an axis
197-
// after convertToAxis turns all data to numbers, it's used in 3 ways:
197+
// after convertToNums turns all data to numbers, it's used in 3 ways:
198198
// c: calcdata numbers, not linearized
199199
// l: linearized - same as c except for log axes (and other mappings later?)
200200
// this is used by ranges, and when we need to know if it's *possible* to

shelly/shelly/templates/static/js/graph_obj.js

+30-31
Original file line numberDiff line numberDiff line change
@@ -1260,19 +1260,19 @@ function plotDo(gd,aobj,traces) {
12601260
}
12611261

12621262
function plotAutoSize(gd,aobj) {
1263-
var plotBB = gd.paper.node().getBoundingClientRect();
1263+
var plotBB = gd.paperdiv.node().getBoundingClientRect();
12641264
var gdBB = gd.getBoundingClientRect();
1265-
var ftBB = $('#filetab')[0].getBoundingClientRect();
1265+
var ftBB = $('#filetab').length ? $('#filetab')[0].getBoundingClientRect() : {width:0};
12661266
var newheight = Math.round(gdBB.bottom-plotBB.top);
12671267
var newwidth = Math.round((ftBB.width ? ftBB.left : gdBB.right) - plotBB.left);
12681268
if(Math.abs(gd.layout.width-newwidth)>1 || Math.abs(gd.layout.height-newheight)>1) {
12691269
gd.layout.height = newheight;
12701270
gd.layout.width = newwidth;
12711271
}
1272-
else { // if there's no size change, update layout but don't need to redraw
1272+
else { // if there's no size change, update layout but only restyle (different element may get margin color)
12731273
delete(aobj.autosize);
12741274
gd.layout.autosize = true;
1275-
newModeBar(gd);
1275+
layoutStyles(gd);
12761276
}
12771277
return aobj
12781278
}
@@ -1281,15 +1281,13 @@ function plotAutoSize(gd,aobj) {
12811281
function plotResize(gd) {
12821282
killPopovers();
12831283
if(gd && gd.tabtype=='plot' && $(gd).css('display')!='none') {
1284-
$(gd).find('.modebar').remove();
12851284
if(gd.redrawTimer) { clearTimeout(gd.redrawTimer) }
12861285
gd.redrawTimer = setTimeout(function(){
12871286
if($(gd).css('display')=='none') { return }
12881287
if(gd.layout && gd.layout.autosize) {
12891288
gd.autoplay = true; // don't include this relayout in the undo queue
12901289
relayout(gd, {autosize:true});
12911290
}
1292-
else { newModeBar(gd) }
12931291

12941292
if(LIT) {
12951293
hidebox();
@@ -1308,28 +1306,33 @@ function newPlot(divid, layout) {
13081306
// (for extension to multiple graphs per page)
13091307
// some callers send this in already by dom element
13101308

1311-
var gd=(typeof divid == 'string') ? document.getElementById(divid) : divid;
1309+
var gd=(typeof divid == 'string') ? document.getElementById(divid) : divid,
1310+
gd3=d3.select(gd);
13121311
if(!layout) layout={};
13131312
// test if this is on the main site or embedded
13141313
gd.mainsite=Boolean($('#plotlyMainMarker').length);
13151314

13161315
// destroy any plot that already exists in this div
13171316
// first check if we can save the toolbars
1318-
if(gd.mainsite ? ($(gd).children('.graphbar').length==1 &&
1319-
$(gd).children('.demobar').length==1 &&
1320-
$(gd).children('svg').length==1 &&
1321-
$(gd).children().length>=3) : /* 4th child is graph tips alert div, then modebar... */
1322-
($(gd).children('svg').length==1)
1323-
) { $(gd).children('svg').remove() }
1317+
if(($(gd).children('.svgcontainer').length==1) && (!gd.mainsite ||
1318+
($(gd).children('.graphbar').length==1 && $(gd).children('.demobar').length==1))) {
1319+
$(gd).children('.svgcontainer').children('svg').remove()
1320+
}
13241321
else { // not the right children (probably none, but in case something goes wrong redraw all)
1322+
// TODO - remove tooltips here
1323+
$(gd).find('[rel="tooltip"]').tooltip('destroy');
13251324
gd.innerHTML='';
1326-
if(gd.mainsite) graphbar(gd);
1325+
if(gd.mainsite) { graphbar(gd) }
1326+
// Make the outer graph container
1327+
gd.paperdiv = gd3.append('div')
1328+
.classed('svgcontainer',true)
1329+
.style('position','relative');
13271330
}
13281331

13291332
// Get the layout info - take the default and update it with layout arg
13301333
gd.layout=updateObject(defaultLayout(),layout);
13311334

1332-
var gl=gd.layout, gd3=d3.select(gd), xa=gl.xaxis, ya=gl.yaxis;
1335+
var gl=gd.layout, xa=gl.xaxis, ya=gl.yaxis;
13331336
Axes.setTypes(gd);
13341337

13351338
// initial autosize
@@ -1341,11 +1344,8 @@ function newPlot(divid, layout) {
13411344
gd.paper.remove();
13421345
gl.autosize=true;
13431346
}
1344-
13451347
// Make the graph containers
1346-
gd.paper = gd3.append('svg')
1347-
gd.paperbg = gd.paper.append('rect')
1348-
.style('fill','none')
1348+
gd.paper = gd.paperdiv.append('svg');
13491349
gd.plotbg = gd.paper.append('rect')
13501350
.attr('stroke-width',0);
13511351
gd.axlines = {
@@ -1399,8 +1399,6 @@ function newPlot(divid, layout) {
13991399
dragBox(gd, x2, y2+y1-y0, x1-x0, y0-y1,'n','e');
14001400
dragBox(gd, x0, y1, x1-x0, y0-y1,'s','w');
14011401
dragBox(gd, x2, y1, x1-x0, y0-y1,'s','e');
1402-
1403-
newModeBar(gd);
14041402
}
14051403

14061404
// layoutStyles: styling for plot layout elements
@@ -1423,20 +1421,19 @@ function layoutStyles(gd) {
14231421
gd.plotwidth=gl.width-gm.l-gm.r;
14241422
gd.plotheight=gl.height-gm.t-gm.b;
14251423

1426-
gd.paper
1427-
.call(setSize, gl.width, gl.height);
1428-
gd.paperbg
1429-
.call(setRect, 0, 0, gl.width, gl.height);
1424+
gd.paperdiv.style({width:gl.width+'px', height:gl.height+'px'});
1425+
gd.paper.call(setSize, gl.width, gl.height);
1426+
14301427
// plot background: color the whole div if it's autosized in the main site,
14311428
// so we don't always have a weird white strip with the "My Data" tab
1432-
// otherwise color the paperbg rect, so you see the plot the size it's meant to be.
1429+
// otherwise color the paperdiv, so you see the plot the size it's meant to be.
14331430
if(gl.autosize && gd.mainsite) {
14341431
d3.select(gd).style('background', gl.paper_bgcolor);
1435-
gd.paperbg.style('fill','none');
1432+
gd.paperdiv.style('background','transparent');
14361433
}
14371434
else {
14381435
d3.select(gd).style('background', '#fff');
1439-
gd.paperbg.call(fillColor, gl.paper_bgcolor);
1436+
gd.paperdiv.style('background', gl.paper_bgcolor);
14401437
}
14411438
gd.plotbg
14421439
.call(setRect, gm.l-gm.p, gm.t-gm.p, gd.plotwidth+2*gm.p, gd.plotheight+2*gm.p)
@@ -1460,6 +1457,8 @@ function layoutStyles(gd) {
14601457
.attr('stroke-width',ylw)
14611458
.call(strokeColor,ya.linecolor);
14621459
makeTitles(gd,'gtitle');
1460+
1461+
newModeBar(gd);
14631462
}
14641463

14651464
// ----------------------------------------------------
@@ -1544,7 +1543,7 @@ function makeTitles(gd,title) {
15441543
else { el.remove() }
15451544

15461545
// move labels out of the way, if possible, when tick labels interfere
1547-
var titlebb=el[0][0].getBoundingClientRect(), gdbb=gd.paper.node().getBoundingClientRect();
1546+
var titlebb=el[0][0].getBoundingClientRect(), gdbb=gd.paperdiv.node().getBoundingClientRect();
15481547
if(k=='xtitle'){
15491548
var labels=gd.paper.selectAll('text.xtick')[0], ticky=0;
15501549
for(var i=0;i<labels.length;i++){
@@ -1754,7 +1753,7 @@ function legend(gd) {
17541753
if(Math.abs(dy)<MINDRAG) { dy=0 }
17551754
if(dx||dy) { gd.dragged = true }
17561755
el3.call(setPosition, x0+dx, y0+dy);
1757-
var pbb = gd.paper.node().getBoundingClientRect();
1756+
var pbb = gd.paperdiv.node().getBoundingClientRect();
17581757

17591758
// drag to within a couple px of edge to take the legend outside the plot
17601759
if(e2.clientX>pbb.right-3*MINDRAG || (gd.lw>0 && dx>-MINDRAG)) { xf=100 }
@@ -1857,7 +1856,7 @@ function annotation(gd,index,opt,value) {
18571856

18581857
// get the paper and plot bounding boxes before adding pieces that go off screen
18591858
// firefox will include things that extend outside the original... can we avoid that?
1860-
var paperbb = gd.paper.node().getBoundingClientRect(),
1859+
var paperbb = gd.paperdiv.node().getBoundingClientRect(),
18611860
plotbb = d3.select(gd).select('.nsewdrag').node().getBoundingClientRect(),
18621861
x = plotbb.left-paperbb.left,
18631862
y = plotbb.top-paperbb.top;

shelly/shelly/templates/static/js/heatmap.js

+30-24
Original file line numberDiff line numberDiff line change
@@ -262,31 +262,37 @@ heatmap.margin = function(gd){
262262
function get_xy(gd,gdc){
263263
// Set any missing keys to defaults
264264
setDefaults(gdc,true);
265-
var y = gdc.y,
266-
m = gdc.z.length, // num rows
267-
ya = gd.layout.yaxis;
268-
if($.isArray(y) && (y.length==m+1) && (gdc.type!='histogram2d') && (ya.type!='category')) {
269-
y = convertToAxis(y,ya);
270-
}
271-
else {
272-
y=[];
273-
var y0 = (typeof(gdc.y0)=='number') ?
274-
gdc.y0 : convertToAxis(gdc.y0,ya);
275-
for(var i=0; i<=m; i++) { y.push(y0+gdc.dy*(i-0.5)) }
276-
}
277-
var x = gdc.x,
278-
n = gdc.z[0].length, // num cols
279-
xa = gd.layout.xaxis;
280-
if($.isArray(x) && (x.length!=n+1) && (gdc.type!='histogram2d') && (xa.type!='category')) {
281-
x = convertToAxis(x,xa);
282-
}
283-
else {
284-
x=[];
285-
var x0 = (typeof(gdc.x0)=='number') ?
286-
gdc.x0 : convertToAxis(gdc.x0,xa);
287-
for(var i=0; i<=n; i++) { x.push(x0+gdc.dx*(i-0.5)) }
265+
266+
function makeBoundArray(array_in,v0_in,dv_in,numbricks,ax) {
267+
if($.isArray(array_in) && (gdc.type!='histogram2d') && (ax.type!='category')) {
268+
array_in = Axes.convertToNums(array_in,ax);
269+
var len = array_in.length;
270+
if(len==numbricks) { // given vals are brick centers
271+
if(numbricks==1) { return [array_in[0]-.5,array_in[0]+.5] }
272+
else {
273+
var array_out = [1.5*array_in[0]-.5*array_in[1]];
274+
for(var i=1; i<len; i++) {
275+
array_out.push((array_in[i-1]+array_in[i])*.5)
276+
}
277+
array_out.push(1.5*array_in[len-1]-.5*array_in[len-2]);
278+
}
279+
}
280+
else { // hopefully length==numbricks+1, but do something regardless:
281+
// given vals are brick boundaries
282+
return array_in.slice(0,numbricks+1);
283+
}
284+
}
285+
else {
286+
var array_out = [],
287+
v0 = v0_in ? Axes.convertToNums(v0_in,ax) : 0,
288+
dv = dv_in || 1;
289+
for(var i=0; i<=numbricks; i++) { array_out.push(v0+dv*(i-0.5)) }
290+
}
291+
return array_out;
288292
}
289-
return {x:x,y:y};
293+
294+
return {x:makeBoundArray(gdc.x,gdc.x0,gdc.dx,gdc.z[0].length,gd.layout.xaxis),
295+
y:makeBoundArray(gdc.y,gdc.y0,gdc.dy,gdc.z.length,gd.layout.yaxis)};
290296
}
291297

292298
// if the heatmap data object is missing any keys, fill them in

0 commit comments

Comments
 (0)