Skip to content

Provide more flexible formatters #107

Closed
@ehq

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions