Skip to content

Commit

Permalink
Customizing hover content using default content (fixes #179).
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Apr 14, 2013
1 parent b9f53a8 commit 67caadb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
7 changes: 4 additions & 3 deletions examples/decimal-custom-hover.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ <h1>Decimal Data</h1>
ykeys: ['y'],
labels: ['sin(x)'],
parseTime: false,
hoverCallback: function (index, options) {
hoverCallback: function (index, options, default_content) {
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>
</body>
21 changes: 10 additions & 11 deletions lib/morris.bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,17 @@ class Morris.Bar extends Morris.Grid
#
# @private
hoverContentForRow: (index) ->
row = @data[index]
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
for y, j in row.y
content += """
<div class='morris-hover-point' style='color: #{@colorFor(row, j, 'label')}'>
#{@options.labels[j]}:
#{@yLabelFormat(y)}
</div>
"""
if typeof @options.hoverCallback is 'function'
content = @options.hoverCallback(index, @options)
else
row = @data[index]
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
for y, j in row.y
content += """
<div class='morris-hover-point' style='color: #{@colorFor(row, j, 'label')}'>
#{@options.labels[j]}:
#{@yLabelFormat(y)}
</div>
"""
content = @options.hoverCallback(index, @options, content)
x = @left + (index + 0.5) * @width / @data.length
[content, x]

Expand Down
19 changes: 9 additions & 10 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ class Morris.Line extends Morris.Grid
# @private
hoverContentForRow: (index) ->
row = @data[index]
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
for y, j in row.y
content += """
<div class='morris-hover-point' style='color: #{@colorFor(row, j, 'label')}'>
#{@options.labels[j]}:
#{@yLabelFormat(y)}
</div>
"""
if typeof @options.hoverCallback is 'function'
content = @options.hoverCallback(index, @options)
else
content = "<div class='morris-hover-row-label'>#{row.label}</div>"
for y, j in row.y
content += """
<div class='morris-hover-point' style='color: #{@colorFor(row, j, 'label')}'>
#{@options.labels[j]}:
#{@yLabelFormat(y)}
</div>
"""
content = @options.hoverCallback(index, @options, content)
[content, row._x, row._ymax]


Expand Down
32 changes: 15 additions & 17 deletions morris.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion morris.min.js

Large diffs are not rendered by default.

0 comments on commit 67caadb

Please sign in to comment.