Skip to content

Commit

Permalink
Add original data to custom hover callback.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oesmith committed Nov 9, 2013
1 parent c072224 commit 68aa4c3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions examples/decimal-custom-hover.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ <h1>Decimal Data</h1>
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,
Expand Down
4 changes: 2 additions & 2 deletions lib/morris.bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion lib/morris.grid.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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]


Expand Down
12 changes: 7 additions & 5 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.

1 comment on commit 68aa4c3

@sudeepdk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can anyone help to get data from Sql server ans using C# .... so how can i show data using morris .... .. i have already user with JqWidgets its working ... fine but Bcoz IN MORRIS their is datatype element in JS file while using live Ex Solution so i can not use (Json Or CSV ) to get data and show in charts ...?

Thanks .
sudeep

Please sign in to comment.