mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-09-21 02:31:32 +02:00
Line chart working again.
This commit is contained in:
parent
3b5ff1a47e
commit
f6b1cfe7a0
@ -25,7 +25,7 @@ var day_data = [
|
||||
{"period": "2012-09-15", "licensed": 3201, "sorned": 656},
|
||||
{"period": "2012-09-10", "licensed": 3215, "sorned": 622}
|
||||
];
|
||||
line = Morris.Line({
|
||||
Morris.Line({
|
||||
element: 'graph',
|
||||
data: day_data,
|
||||
xkey: 'period',
|
||||
|
@ -56,10 +56,14 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
#
|
||||
setData: (data, redraw = true) ->
|
||||
# shallow copy data
|
||||
@options.data = data.slice()
|
||||
if @parseTime
|
||||
@options.data = $.map data, (row) =>
|
||||
if @options.parseTime
|
||||
$.extend {'__T': Morris.parseDate(row[@options.xkey])}, row
|
||||
else
|
||||
$.extend {}, row
|
||||
if @options.parseTime
|
||||
@options.data = @options.data.sort (a, b) =>
|
||||
(a[@options.xkey] < b[@options.xkey]) - (b[@options.xkey] < a[@options.xkey])
|
||||
(a['__T'] > b['__T']) - (b['__T'] > a['__T'])
|
||||
|
||||
# extract series data
|
||||
@series = []
|
||||
@ -74,9 +78,9 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
@series.push seriesData
|
||||
|
||||
# extract labels / x values
|
||||
@columnLabels = $.map @options.data, (d) => d[@options.xkey]
|
||||
@columnLabels = $.map @options.data, (row) => row[@options.xkey]
|
||||
if @options.parseTime
|
||||
@xvals = $.map @columnLabels, (x) -> Morris.parseDate x
|
||||
@xvals = $.map @options.data, (row) -> row['__T']
|
||||
if @options.dateFormat
|
||||
@columnLabels = $.map @xvals, (d) => @options.dateFormat d
|
||||
else
|
||||
|
@ -79,7 +79,7 @@ class Morris.Line extends Morris.Grid
|
||||
@drawXAxis()
|
||||
@drawSeries()
|
||||
@drawHover()
|
||||
@hilight(if @options.hideHover then null else 0)
|
||||
@hilight(if @options.hideHover then null else @options.data.length - 1)
|
||||
|
||||
# draw the x-axis labels
|
||||
#
|
||||
@ -111,8 +111,8 @@ class Morris.Line extends Morris.Grid
|
||||
for l in Morris.labelSeries(@xmin, @xmax, @width, @options.xLabels, @options.xLabelFormat)
|
||||
drawLabel(l[0], l[1])
|
||||
else
|
||||
for i in [0..@columnLabels.length]
|
||||
labelText = @columnLabels[@columnLabels.length - i - 1]
|
||||
for i in [0...@columnLabels.length]
|
||||
labelText = @columnLabels[i]
|
||||
drawLabel(labelText, i)
|
||||
|
||||
# draw the data series
|
||||
@ -120,7 +120,7 @@ class Morris.Line extends Morris.Grid
|
||||
# @private
|
||||
drawSeries: ->
|
||||
for i in [@seriesCoords.length-1..0]
|
||||
coords = @seriesCoords[i]
|
||||
coords = $.map @seriesCoords[i], (c) -> c
|
||||
smooth = @options.smooth is true or
|
||||
$.inArray(@options.ykeys[i], @options.smooth) > -1
|
||||
if coords.length > 1
|
||||
@ -250,10 +250,9 @@ class Morris.Line extends Morris.Grid
|
||||
# @private
|
||||
updateHilight: (x) =>
|
||||
x -= @el.offset().left
|
||||
for hoverIndex in [@hoverMargins.length..0]
|
||||
if hoverIndex == 0 || @hoverMargins[hoverIndex - 1] > x
|
||||
@hilight hoverIndex
|
||||
break
|
||||
for hoverIndex in [0...@hoverMargins.length]
|
||||
break if @hoverMargins[hoverIndex] > x
|
||||
@hilight hoverIndex
|
||||
|
||||
# @private
|
||||
colorForSeries: (index) ->
|
||||
|
44
morris.js
44
morris.js
@ -334,10 +334,18 @@
|
||||
if (redraw == null) {
|
||||
redraw = true;
|
||||
}
|
||||
this.options.data = data.slice();
|
||||
if (this.parseTime) {
|
||||
this.options.data = $.map(data, function(row) {
|
||||
if (_this.options.parseTime) {
|
||||
return $.extend({
|
||||
'__T': Morris.parseDate(row[_this.options.xkey])
|
||||
}, row);
|
||||
} else {
|
||||
return $.extend({}, row);
|
||||
}
|
||||
});
|
||||
if (this.options.parseTime) {
|
||||
this.options.data = this.options.data.sort(function(a, b) {
|
||||
return (a[_this.options.xkey] < b[_this.options.xkey]) - (b[_this.options.xkey] < a[_this.options.xkey]);
|
||||
return (a['__T'] > b['__T']) - (b['__T'] > a['__T']);
|
||||
});
|
||||
}
|
||||
this.series = [];
|
||||
@ -362,12 +370,12 @@
|
||||
}
|
||||
this.series.push(seriesData);
|
||||
}
|
||||
this.columnLabels = $.map(this.options.data, function(d) {
|
||||
return d[_this.options.xkey];
|
||||
this.columnLabels = $.map(this.options.data, function(row) {
|
||||
return row[_this.options.xkey];
|
||||
});
|
||||
if (this.options.parseTime) {
|
||||
this.xvals = $.map(this.columnLabels, function(x) {
|
||||
return Morris.parseDate(x);
|
||||
this.xvals = $.map(this.options.data, function(row) {
|
||||
return row['__T'];
|
||||
});
|
||||
if (this.options.dateFormat) {
|
||||
this.columnLabels = $.map(this.xvals, function(d) {
|
||||
@ -681,7 +689,7 @@
|
||||
this.drawXAxis();
|
||||
this.drawSeries();
|
||||
this.drawHover();
|
||||
return this.hilight(this.options.hideHover ? null : 0);
|
||||
return this.hilight(this.options.hideHover ? null : this.options.data.length - 1);
|
||||
};
|
||||
|
||||
Line.prototype.drawXAxis = function() {
|
||||
@ -714,8 +722,8 @@
|
||||
}
|
||||
} else {
|
||||
_results1 = [];
|
||||
for (i = _j = 0, _ref1 = this.columnLabels.length; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
|
||||
labelText = this.columnLabels[this.columnLabels.length - i - 1];
|
||||
for (i = _j = 0, _ref1 = this.columnLabels.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
|
||||
labelText = this.columnLabels[i];
|
||||
_results1.push(drawLabel(labelText, i));
|
||||
}
|
||||
return _results1;
|
||||
@ -725,7 +733,9 @@
|
||||
Line.prototype.drawSeries = function() {
|
||||
var c, circle, coords, i, path, smooth, _i, _j, _ref, _ref1, _results;
|
||||
for (i = _i = _ref = this.seriesCoords.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
|
||||
coords = this.seriesCoords[i];
|
||||
coords = $.map(this.seriesCoords[i], function(c) {
|
||||
return c;
|
||||
});
|
||||
smooth = this.options.smooth === true || $.inArray(this.options.ykeys[i], this.options.smooth) > -1;
|
||||
if (coords.length > 1) {
|
||||
path = this.createPath(coords, this.bottom, smooth);
|
||||
@ -877,18 +887,14 @@
|
||||
};
|
||||
|
||||
Line.prototype.updateHilight = function(x) {
|
||||
var hoverIndex, _i, _ref, _results;
|
||||
var hoverIndex, _i, _ref;
|
||||
x -= this.el.offset().left;
|
||||
_results = [];
|
||||
for (hoverIndex = _i = _ref = this.hoverMargins.length; _ref <= 0 ? _i <= 0 : _i >= 0; hoverIndex = _ref <= 0 ? ++_i : --_i) {
|
||||
if (hoverIndex === 0 || this.hoverMargins[hoverIndex - 1] > x) {
|
||||
this.hilight(hoverIndex);
|
||||
for (hoverIndex = _i = 0, _ref = this.hoverMargins.length; 0 <= _ref ? _i < _ref : _i > _ref; hoverIndex = 0 <= _ref ? ++_i : --_i) {
|
||||
if (this.hoverMargins[hoverIndex] > x) {
|
||||
break;
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return this.hilight(hoverIndex);
|
||||
};
|
||||
|
||||
Line.prototype.colorForSeries = function(index) {
|
||||
|
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