Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more flexible formatters #107

Closed
ehq opened this issue Nov 5, 2012 · 1 comment
Closed

Provide more flexible formatters #107

ehq opened this issue Nov 5, 2012 · 1 comment

Comments

@ehq
Copy link

ehq commented Nov 5, 2012

Here: https://github.com/oesmith/morris.js/blob/master/lib/morris.donut.coffee#L97

The parameter passed to the formatter is the value itself, but ideally the formatter should be aware of the complete segment data object.

This would be useful if I want to use my own non-js helpers, instead of replicating them as js formatters. With Ruby, an example would be:

module FooHelpers
  def foo_format(value)
    # Some code...
  end
end

Now if I wanted to use that helper as the formatter, I could pass it in the segment data:

<script type="text/javascript">
  Morris.Donut({
    element: 'foobar',
    data: <%= [
      { label: "Baz",
        value: my_value,
        formatted_value: foo_format(my_value) 
    } ].to_json %>,
    formatter: function(segment) { return segment.formatted_value }
  });
</script>

❗ Not having this functionality is kind of a deal breaker for me, as I have lots of formatting helpers made with Ruby, and replicating all that logic as morris.js formatters would be redundant and too costly for my project.

If adding this functionality makes sense to you guys, I'd be more than happy to submit a pull request with the necessary changes.

@oesmith oesmith closed this as completed in c279b9b Nov 5, 2012
oesmith added a commit that referenced this issue Nov 5, 2012
Fixes #107, passes data row to formatter function as second param
@ehq
Copy link
Author

ehq commented Nov 5, 2012

Awesome! Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants