8000 Scale minX and minY too · leetcode/flot-plugin-collection@6330b8f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6330b8f

Browse files
committed
Scale minX and minY too
1 parent 8ef0ab5 commit 6330b8f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/flot/jquery.flot.autoscale.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010
var optsY = plot.getYAxes()[0].options;
1111
var optsX = plot.getXAxes()[0].options;
1212
var data = plot.getData();
13-
var maxX = 0, maxY = 0;
13+
var maxX = 0, maxY = 0, minX = 0, minY = 0;
1414

1515
$.each(data, function (index, s) {
1616
var max = autoScale(plot, s, s.data, s.datapoints);
1717
maxX = Math.max(maxX, max['maxX']);
1818
maxY = Math.max(maxY, max['maxY']);
19+
minX = Math.max(minX, min['minX']);
20+
minY = Math.max(minY, min['minY']);
1921
});
2022

21-
optsX.min = 0;
23+
optsX.min = minX;
2224
optsX.max = maxX;
23-
optsY.min = 0;
25+
optsY.min = minY;
2426
optsY.max = maxY;
2527

2628
plot.setupGrid();
2729
plot.draw();
2830

2931
return {
30-
min: optsY.min,
31-
max: optsY.max
32+
minY: optsY.min,
33+
maxY: optsY.max,
34+
minX: optsX.min,
35+
maxX: optsX.max,
3236
};
3337
}
3438

@@ -39,20 +43,31 @@
3943
if (series.lines.show || series.points.show || series.bars.show) {
4044
var maxX = Number.NEGATIVE_INFINITY;
4145
var maxY = Number.NEGATIVE_INFINITY;
46+
var minX = Number.POSITIVE_INFINITY;
47+
var minY = Number.POSITIVE_INFINITY;
4248

4349
for (var i = 0; i < data.length; i++) {
4450
maxX = Math.max(maxX, data[i][0]);
4551
maxY = Math.max(maxY, data[i][1]);
52+
minX = Math.min(minX, data[i][0]);
53+
minY = Math.min(minY, data[i][1]);
4654
}
4755

4856
maxX += 2;
4957
maxY += maxY * options.yaxis.autoscaleMargin * 10;
58+
59+
minY -= 2;
60+
minY -= minY * options.yaxis.autoscaleMargin * 10;
5061
return {
62+
minX: minX,
63+
minY: minY,
5164
maxX: maxX,
5265
maxY: maxY
5366
};
5467
} else {
5568
return {
69+
minX: 0,
70+
minY: 0,
5671
maxX: 0,
5772
maxY: 0
5873
};

0 commit comments

Comments
 (0)
0