mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-14 07:41:11 +01:00
Customizing hover content using default content (fixes #179).
This commit is contained in:
parent
b9f53a8fdb
commit
67caadb600
5 changed files with 39 additions and 42 deletions
|
@ -27,11 +27,12 @@ window.m = Morris.Line({
|
||||||
ykeys: ['y'],
|
ykeys: ['y'],
|
||||||
labels: ['sin(x)'],
|
labels: ['sin(x)'],
|
||||||
parseTime: false,
|
parseTime: false,
|
||||||
hoverCallback: function (index, options) {
|
hoverCallback: function (index, options, default_content) {
|
||||||
var row = options.data[index];
|
var row = options.data[index];
|
||||||
return "1.5 + 1.5 sin(" + row.x + ") = " + row.y;
|
return default_content.replace("sin(x)", "1.5 + 1.5 sin(" + row.x + ")");
|
||||||
},
|
},
|
||||||
xLabelMargin: 10
|
xLabelMargin: 10,
|
||||||
|
integerYLabels: true
|
||||||
});
|
});
|
||||||
</pre>
|
</pre>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -147,9 +147,6 @@ class Morris.Bar extends Morris.Grid
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
hoverContentForRow: (index) ->
|
hoverContentForRow: (index) ->
|
||||||
if typeof @options.hoverCallback is 'function'
|
|
||||||
content = @options.hoverCallback(index, @options)
|
|
||||||
else
|
|
||||||
row = @data[index]
|
row = @data[index]
|
||||||
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
|
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
|
||||||
for y, j in row.y
|
for y, j in row.y
|
||||||
|
@ -159,6 +156,8 @@ class Morris.Bar extends Morris.Grid
|
||||||
#{@yLabelFormat(y)}
|
#{@yLabelFormat(y)}
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
if typeof @options.hoverCallback is 'function'
|
||||||
|
content = @options.hoverCallback(index, @options, content)
|
||||||
x = @left + (index + 0.5) * @width / @data.length
|
x = @left + (index + 0.5) * @width / @data.length
|
||||||
[content, x]
|
[content, x]
|
||||||
|
|
||||||
|
|
|
@ -103,9 +103,6 @@ class Morris.Line extends Morris.Grid
|
||||||
# @private
|
# @private
|
||||||
hoverContentForRow: (index) ->
|
hoverContentForRow: (index) ->
|
||||||
row = @data[index]
|
row = @data[index]
|
||||||
if typeof @options.hoverCallback is 'function'
|
|
||||||
content = @options.hoverCallback(index, @options)
|
|
||||||
else
|
|
||||||
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
|
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
|
||||||
for y, j in row.y
|
for y, j in row.y
|
||||||
content += """
|
content += """
|
||||||
|
@ -114,6 +111,8 @@ class Morris.Line extends Morris.Grid
|
||||||
#{@yLabelFormat(y)}
|
#{@yLabelFormat(y)}
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
if typeof @options.hoverCallback is 'function'
|
||||||
|
content = @options.hoverCallback(index, @options, content)
|
||||||
[content, row._x, row._ymax]
|
[content, row._x, row._ymax]
|
||||||
|
|
||||||
|
|
||||||
|
|
10
morris.js
10
morris.js
|
@ -754,15 +754,14 @@
|
||||||
Line.prototype.hoverContentForRow = function(index) {
|
Line.prototype.hoverContentForRow = function(index) {
|
||||||
var content, j, row, y, _i, _len, _ref;
|
var content, j, row, y, _i, _len, _ref;
|
||||||
row = this.data[index];
|
row = this.data[index];
|
||||||
if (typeof this.options.hoverCallback === 'function') {
|
|
||||||
content = this.options.hoverCallback(index, this.options);
|
|
||||||
} else {
|
|
||||||
content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
|
content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
|
||||||
_ref = row.y;
|
_ref = row.y;
|
||||||
for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {
|
for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {
|
||||||
y = _ref[j];
|
y = _ref[j];
|
||||||
content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
|
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);
|
||||||
}
|
}
|
||||||
return [content, row._x, row._ymax];
|
return [content, row._x, row._ymax];
|
||||||
};
|
};
|
||||||
|
@ -1441,9 +1440,6 @@
|
||||||
|
|
||||||
Bar.prototype.hoverContentForRow = function(index) {
|
Bar.prototype.hoverContentForRow = function(index) {
|
||||||
var content, j, row, x, y, _i, _len, _ref;
|
var content, j, row, x, y, _i, _len, _ref;
|
||||||
if (typeof this.options.hoverCallback === 'function') {
|
|
||||||
content = this.options.hoverCallback(index, this.options);
|
|
||||||
} else {
|
|
||||||
row = this.data[index];
|
row = this.data[index];
|
||||||
content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
|
content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
|
||||||
_ref = row.y;
|
_ref = row.y;
|
||||||
|
@ -1451,6 +1447,8 @@
|
||||||
y = _ref[j];
|
y = _ref[j];
|
||||||
content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
|
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);
|
||||||
}
|
}
|
||||||
x = this.left + (index + 0.5) * this.width / this.data.length;
|
x = this.left + (index + 0.5) * this.width / this.data.length;
|
||||||
return [content, x];
|
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 a new issue