mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Add original data to custom hover callback.
Chart data points are sorted when using parseTime, so indices will not always match the original data ordering. Also fixes a couple of event triggers. Ref: #264.
This commit is contained in:
parent
c07222445c
commit
68aa4c36f2
@ -27,8 +27,7 @@ window.m = Morris.Line({
|
||||
ykeys: ['y'],
|
||||
labels: ['sin(x)'],
|
||||
parseTime: false,
|
||||
hoverCallback: function (index, options, default_content) {
|
||||
var row = options.data[index];
|
||||
hoverCallback: function (index, options, default_content, row) {
|
||||
return default_content.replace("sin(x)", "1.5 + 1.5 sin(" + row.x + ")");
|
||||
},
|
||||
xLabelMargin: 10,
|
||||
|
@ -143,7 +143,7 @@ class Morris.Bar extends Morris.Grid
|
||||
# @private
|
||||
onGridClick: (x, y) =>
|
||||
index = @hitTest(x)
|
||||
@fire 'click', index, @options.data[index], x, y
|
||||
@fire 'click', index, @data[index].src, x, y
|
||||
|
||||
# hover movement event handler
|
||||
#
|
||||
@ -173,7 +173,7 @@ class Morris.Bar extends Morris.Grid
|
||||
</div>
|
||||
"""
|
||||
if typeof @options.hoverCallback is 'function'
|
||||
content = @options.hoverCallback(index, @options, content)
|
||||
content = @options.hoverCallback(index, @options, content, row.src)
|
||||
x = @left + (index + 0.5) * @width / @data.length
|
||||
[content, x]
|
||||
|
||||
|
@ -152,7 +152,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
ymax = if ymax? then Math.max(ymax, maxGoal) else maxGoal
|
||||
|
||||
@data = for row, index in data
|
||||
ret = {}
|
||||
ret = {src: row}
|
||||
|
||||
ret.label = row[@options.xkey]
|
||||
if @options.parseTime
|
||||
|
@ -68,7 +68,7 @@ class Morris.Line extends Morris.Grid
|
||||
# @private
|
||||
onGridClick: (x, y) =>
|
||||
index = @hitTest(x)
|
||||
@fire 'click', index, @options.data[index], x, y
|
||||
@fire 'click', index, @data[index].src, x, y
|
||||
|
||||
# hover movement event handler
|
||||
#
|
||||
@ -109,7 +109,7 @@ class Morris.Line extends Morris.Grid
|
||||
</div>
|
||||
"""
|
||||
if typeof @options.hoverCallback is 'function'
|
||||
content = @options.hoverCallback(index, @options, content)
|
||||
content = @options.hoverCallback(index, @options, content, row.src)
|
||||
[content, row._x, row._ymax]
|
||||
|
||||
|
||||
|
12
morris.js
12
morris.js
@ -216,7 +216,9 @@
|
||||
_results = [];
|
||||
for (index = _i = 0, _len = data.length; _i < _len; index = ++_i) {
|
||||
row = data[index];
|
||||
ret = {};
|
||||
ret = {
|
||||
src: row
|
||||
};
|
||||
ret.label = row[this.options.xkey];
|
||||
if (this.options.parseTime) {
|
||||
ret.x = Morris.parseDate(ret.label);
|
||||
@ -799,7 +801,7 @@
|
||||
Line.prototype.onGridClick = function(x, y) {
|
||||
var index;
|
||||
index = this.hitTest(x);
|
||||
return this.fire('click', index, this.options.data[index], x, y);
|
||||
return this.fire('click', index, this.data[index].src, x, y);
|
||||
};
|
||||
|
||||
Line.prototype.onHoverMove = function(x, y) {
|
||||
@ -835,7 +837,7 @@
|
||||
content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
|
||||
}
|
||||
if (typeof this.options.hoverCallback === 'function') {
|
||||
content = this.options.hoverCallback(index, this.options, content);
|
||||
content = this.options.hoverCallback(index, this.options, content, row.src);
|
||||
}
|
||||
return [content, row._x, row._ymax];
|
||||
};
|
||||
@ -1563,7 +1565,7 @@
|
||||
Bar.prototype.onGridClick = function(x, y) {
|
||||
var index;
|
||||
index = this.hitTest(x);
|
||||
return this.fire('click', index, this.options.data[index], x, y);
|
||||
return this.fire('click', index, this.data[index].src, x, y);
|
||||
};
|
||||
|
||||
Bar.prototype.onHoverMove = function(x, y) {
|
||||
@ -1588,7 +1590,7 @@
|
||||
content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
|
||||
}
|
||||
if (typeof this.options.hoverCallback === 'function') {
|
||||
content = this.options.hoverCallback(index, this.options, content);
|
||||
content = this.options.hoverCallback(index, this.options, content, row.src);
|
||||
}
|
||||
x = this.left + (index + 0.5) * this.width / this.data.length;
|
||||
return [content, x];
|
||||
|
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