Skip to content

Commit 5df675a

Browse files
committed
fix demo/outside legend bug and null data autoscale bug
1 parent a0944ec commit 5df675a

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,16 @@ axes.expandBounds = function(ax,dr,data,serieslen,pad) {
265265
pad = pad || 0; // optional extra space to give these new data points
266266
serieslen = serieslen || data.length;
267267
dr[0] = aggNums(Math.min, $.isNumeric(dr[0]) ? dr[0] : null,
268-
data.map(function(v){return ax.c2l(v-pad)}), serieslen);
268+
data.map(function(v){return $.isNumeric(v) ? ax.c2l(v-pad) : null}), serieslen);
269269
dr[1] = aggNums(Math.max, $.isNumeric(dr[1]) ? dr[1] : null,
270-
data.map(function(v){return ax.c2l(v+pad)}), serieslen);
270+
data.map(function(v){return $.isNumeric(v) ? ax.c2l(v+pad) : null}), serieslen);
271271
}
272272

273273
// expand data range to include a tight zero (if the data all has one
274274
// sign and the axis is linear) and a padded opposite bound
275275
axes.expandWithZero = function(ax,data,serieslen,pad) {
276276
if(!ax.autorange) { return }
277277

278-
// if(ax==xa) { tight=xtight; padded=xpadded }
279-
// else { tight=ytight; padded=ypadded }
280-
281278
var dr = [null,null];
282279
axes.expandBounds(ax,dr,data,serieslen,pad);
283280

@@ -678,13 +675,11 @@ function numFormat(v,ax,fmtoverride,hover) {
678675
// make a dummy axis obj to get the auto rounding and exponent
679676
var ah = {exponentformat:ax.exponentformat, dtick:Math.abs(v), range:[0,v||1]}
680677
autoTickRound(ah);
681-
// console.log(ah);
682678
r = ah._tickround+2;
683679
d = ah._tickexponent;
684680
}
685681
var e = Math.pow(10,-r)/2; // 'epsilon' - rounding increment
686682

687-
// if(!$.isNumeric(d)) { d = ax._tickexponent } // if nonzero, use a common exponent 10^d
688683
// fmt codes:
689684
// 'e' (1.2e+6, default)
690685
// 'E' (1.2E+6)

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,9 @@ function plotAutoSize(gd,aobj) {
12691269
gd.layout.height = newheight;
12701270
gd.layout.width = newwidth;
12711271
}
1272-
else { // if there's no size change, update layout but only restyle (different element may get margin color)
1272+
// if there's no size change, update layout but only restyle (different
1273+
// element may get margin color)
1274+
else if(gd.layout.autosize!='initial') { // can't call layoutStyles for initial autosize
12731275
delete(aobj.autosize);
12741276
gd.layout.autosize = true;
12751277
layoutStyles(gd);
@@ -1329,6 +1331,16 @@ function newPlot(divid, layout) {
13291331
.style('position','relative');
13301332
}
13311333

1334+
// destroy calculated vars that may cause problems
1335+
// TODO: better way to do this? should I be storing these all in some other
1336+
// object that I can wipe, rather than directly in gd?
1337+
// I ignored the ones that are reset each time through plot()
1338+
gd.lw = undefined; // "legend width" for legends outside the plot area to increase margins
1339+
gd.undoqueue = undefined; // action queue
1340+
gd.undonum = undefined;
1341+
gd.autoplay = undefined; // are we doing an action that doesn't go in undo queue?
1342+
gd.axtypesok = undefined; // have we already deduced axis types, so we can skip?
1343+
13321344
// Get the layout info - take the default and update it with layout arg
13331345
gd.layout=updateObject(defaultLayout(),layout);
13341346

@@ -1337,11 +1349,12 @@ function newPlot(divid, layout) {
13371349

13381350
// initial autosize
13391351
if(gl.autosize=='initial') {
1340-
gd.paper=gd3.append('svg')
1341-
.attr('width',gl.width)
1342-
.attr('height',gl.height);
1352+
// gd.paperdiv=gd3.append('svg')
1353+
// .attr('width',gl.width)
1354+
// .attr('height',gl.height);
1355+
console.log('initial autosize');
13431356
plotAutoSize(gd,{});
1344-
gd.paper.remove();
1357+
// gd.paper.remove();
13451358
gl.autosize=true;
13461359
}
13471360
// Make the graph containers

0 commit comments

Comments
 (0)