mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Fixed problem with performance improvement
- Relabelled variables to make them more meaningful - Fixed bug with the way that the pointsPerPixel was calculated
This commit is contained in:
parent
bfb1e71193
commit
16db900413
@ -148,17 +148,17 @@ class Morris.Line
|
|||||||
# draw x axis labels
|
# draw x axis labels
|
||||||
prevLabelMargin = null
|
prevLabelMargin = null
|
||||||
xLabelMargin = 50 # make this an option?
|
xLabelMargin = 50 # make this an option?
|
||||||
xstep = width / @xvals.length
|
pointsPerPixel = (Math.floor(@xmax) - Math.ceil(@xmin)) / width
|
||||||
next_x = null
|
nextPoint = null
|
||||||
for i in [Math.ceil(@xmin)..Math.floor(@xmax)]
|
for i in [Math.ceil(@xmin)..Math.floor(@xmax)]
|
||||||
if xstep < 1 or null == next_x or i >= next_x
|
if null == nextPoint or i >= nextPoint
|
||||||
labelText = if @options.parseTime then i else @columnLabels[@columnLabels.length-i-1]
|
labelText = if @options.parseTime then i else @columnLabels[@columnLabels.length-i-1]
|
||||||
label = @r.text(transX(i), @options.marginTop + height + @options.marginBottom / 2, labelText)
|
label = @r.text(transX(i), @options.marginTop + height + @options.marginBottom / 2, labelText)
|
||||||
.attr('font-size', @options.gridTextSize)
|
.attr('font-size', @options.gridTextSize)
|
||||||
.attr('fill', @options.gridTextColor)
|
.attr('fill', @options.gridTextColor)
|
||||||
labelBox = label.getBBox()
|
labelBox = label.getBBox()
|
||||||
# Calculate the next value of i to use
|
# Calculate the next value of i to use
|
||||||
next_x = (labelBox.x + labelBox.width + xLabelMargin) * xstep
|
nextPoint = (labelBox.x + labelBox.width + xLabelMargin) * pointsPerPixel
|
||||||
# ensure a minimum of `xLabelMargin` pixels between labels
|
# ensure a minimum of `xLabelMargin` pixels between labels
|
||||||
if prevLabelMargin is null or prevLabelMargin <= labelBox.x
|
if prevLabelMargin is null or prevLabelMargin <= labelBox.x
|
||||||
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin
|
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin
|
||||||
|
10
morris.js
10
morris.js
@ -105,7 +105,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Line.prototype.redraw = function() {
|
Line.prototype.redraw = function() {
|
||||||
var c, circle, columns, coords, dx, dy, firstY, height, hideHover, hilight, hover, hoverHeight, hoverMargins, hoverSet, i, label, labelBox, labelText, lastY, left, lineY, maxYLabelWidth, next_x, path, pointGrow, pointShrink, prevHilight, prevLabelMargin, s, seriesCoords, seriesPoints, touchHandler, transX, transY, updateHilight, updateHover, v, width, x, xLabel, xLabelMargin, xstep, y, yInterval, yLabel, yLabels, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7,
|
var c, circle, columns, coords, dx, dy, firstY, height, hideHover, hilight, hover, hoverHeight, hoverMargins, hoverSet, i, label, labelBox, labelText, lastY, left, lineY, maxYLabelWidth, nextPoint, path, pointGrow, pointShrink, pointsPerPixel, prevHilight, prevLabelMargin, s, seriesCoords, seriesPoints, touchHandler, transX, transY, updateHilight, updateHover, v, width, x, xLabel, xLabelMargin, y, yInterval, yLabel, yLabels, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7,
|
||||||
_this = this;
|
_this = this;
|
||||||
this.el.empty();
|
this.el.empty();
|
||||||
this.r = new Raphael(this.el[0]);
|
this.r = new Raphael(this.el[0]);
|
||||||
@ -136,14 +136,14 @@
|
|||||||
}
|
}
|
||||||
prevLabelMargin = null;
|
prevLabelMargin = null;
|
||||||
xLabelMargin = 50;
|
xLabelMargin = 50;
|
||||||
xstep = width / this.xvals.length;
|
pointsPerPixel = (Math.floor(this.xmax) - Math.ceil(this.xmin)) / width;
|
||||||
next_x = null;
|
nextPoint = null;
|
||||||
for (i = _ref = Math.ceil(this.xmin), _ref2 = Math.floor(this.xmax); _ref <= _ref2 ? i <= _ref2 : i >= _ref2; _ref <= _ref2 ? i++ : i--) {
|
for (i = _ref = Math.ceil(this.xmin), _ref2 = Math.floor(this.xmax); _ref <= _ref2 ? i <= _ref2 : i >= _ref2; _ref <= _ref2 ? i++ : i--) {
|
||||||
if (xstep < 1 || null === next_x || i >= next_x) {
|
if (null === nextPoint || i >= nextPoint) {
|
||||||
labelText = this.options.parseTime ? i : this.columnLabels[this.columnLabels.length - i - 1];
|
labelText = this.options.parseTime ? i : this.columnLabels[this.columnLabels.length - i - 1];
|
||||||
label = this.r.text(transX(i), this.options.marginTop + height + this.options.marginBottom / 2, labelText).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor);
|
label = this.r.text(transX(i), this.options.marginTop + height + this.options.marginBottom / 2, labelText).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor);
|
||||||
labelBox = label.getBBox();
|
labelBox = label.getBBox();
|
||||||
next_x = (labelBox.x + labelBox.width + xLabelMargin) * xstep;
|
nextPoint = (labelBox.x + labelBox.width + xLabelMargin) * pointsPerPixel;
|
||||||
if (prevLabelMargin === null || prevLabelMargin <= labelBox.x) {
|
if (prevLabelMargin === null || prevLabelMargin <= labelBox.x) {
|
||||||
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
|
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
|
||||||
} else {
|
} else {
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user