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

formatters for JS charts #4003

Merged
merged 4 commits into from Sep 23, 2015
Merged

formatters for JS charts #4003

merged 4 commits into from Sep 23, 2015

Conversation

himdel
Copy link
Contributor

@himdel himdel commented Aug 21, 2015

JS implementation of MiqReport::Formatting#format_*, meant to be used by code from #3894.

Curried so that we can say things like axis.x.tick.formatter = ManageIQ.charts.formatters.boolean({ format: 't_f' });. (ManageIQ.charts.formatters.number_with_delimiter({ precision: 3, separator: '!', delimiter: '@' })(123456.7891) yields "123@456!789").

TODO:

  • remove the included yml fragments
  • write tests
  • fix test failures

Will do a separate PR addressing these issues later:

  • ruby tests
  • non-UTC time zone handling
  • datetime_range should not look at description and probably not column suffix either
  • test that we have the same functions in JS and Ruby

EDIT:
The date-related test failures will be gone after benjaminoakes/moment-strftime#15 .

@miq-bot
Copy link
Member

miq-bot commented Aug 25, 2015

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@dclarizio dclarizio added the ui label Aug 27, 2015
@miq-bot
Copy link
Member

miq-bot commented Sep 2, 2015

@miq-bot
Copy link
Member

miq-bot commented Sep 3, 2015

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@miq-bot miq-bot removed the wip label Sep 8, 2015
@chessbyte chessbyte changed the title [WIP] formatters for JS charts formatters for JS charts Sep 8, 2015
@himdel
Copy link
Contributor Author

himdel commented Sep 8, 2015

@martinpovolny depending on how the moment-strftime problem goes you may need to fix the version in the gemfile, but otherwise it should be ready

@dclarizio
Copy link

@martinpovolny There are some JS test failures, hopefully you can find someone to help fix them up while @himdel is out.

@himdel
Copy link
Contributor Author

himdel commented Sep 9, 2015

@dclarizio..They should be taken care of soon, it's just that the new release of moment-strftime included the old minified version instead of the new one (and rails assets picks just that file). (see the link in the top comment)

@martinpovolny
Copy link
Member

@JPrause : are you ok with these gems' inclusion?

@martinpovolny
Copy link
Member

Btw: thx! 🍻

@martinpovolny
Copy link
Member

@himdel : One small problem: jqplot calls the formatter with an extra argument: formatter(format_string, value)

wherefor I need something like this:

  window.ManageIQ.charts.orig_formatters = _.mapValues(format, _.curryRight);
  window.ManageIQ.charts.formatters = _.mapValues(window.ManageIQ.charts.orig_formatters,
      function(fun) { return function(_x, val, opts) { return fun(val, opts) }})  

but again the curried version. Can you fix that for me? There's _.rearg and _.restParam but that looks just too complicated to me there must be some simpler way ;-)

@martinpovolny martinpovolny mentioned this pull request Sep 15, 2015
@himdel
Copy link
Contributor Author

himdel commented Sep 15, 2015

I just wrote this.. but can't actually commit it because github&IE8...

Updated the ManageIQ.charts.formatters object so that you can pick between 3 function signatures:

  • formatters.foo will take value and options and return the result directly
  • formatters.foo.c3 will take options and return a function taking a value
  • formatters.foo.jqplot will do the same except the resulting function ignores it first argument and works with the second
  // .foo(opt, val) or .foo.c3(opt)(val) or .foo.jqplot(opt)(_, val)
  window.ManageIQ.charts.formatters = _.mapValues(format, function(fn) {
    fn.c3 = _.curryRight(fn);

    fn.jqplot = function(opt) {
      return function(_fmt, val) {
        return fn(val, opt);
      };
    };

    return fn;
  });

EDIT: commited, fixed and added tests; still waiting for a new moment-strftime release

…ntation for JS

including a js reimplementation of a few rails helper functions

registered moment-strftime in bower registry
add sprintf-js
add numeral.js
this adds specs and fixes various omissions from the previous commit
Updated the ManageIQ.charts.formatters object so that you can pick between 3 function signatures:

  * formatters.foo will take value and options and return the result directly
  * formatters.foo.c3 will take options and return a function taking a value
  * formatters.foo.jqplot will do the same except the resulting function ignores its first argument and works with the second

Also, tests.
@himdel
Copy link
Contributor Author

himdel commented Sep 23, 2015

Tests failures fixed by a new moment-strftime release, ready for merging :)

@martinpovolny martinpovolny added this to the Sprint 30 Ending Oct 5, 2015 milestone Sep 23, 2015
martinpovolny added a commit that referenced this pull request Sep 23, 2015
@martinpovolny martinpovolny merged commit bffbd30 into ManageIQ:master Sep 23, 2015
@miq-bot
Copy link
Member

miq-bot commented Sep 23, 2015

Checked commits https://github.com/himdel/manageiq/compare/a09b208a3ee4bd28732e362d1e1d898e9352d1f3~...07a37d65103a3be39dac0977741dcb5cfb0ada2f with ruby 1.9.3, rubocop 0.33.0, and haml-lint 0.13.0
2 files checked, 0 offenses detected
Everything looks good. 🍰

@himdel himdel deleted the formatters branch September 23, 2015 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants