palantir/plottable

Support for 24 hour time format

upsteer opened this issue · 2 comments

We have a situation with plottable.

Bug report

Steps to repro:

  1. Create any chart with time axis.
  2. Create a custom formatter for the time axis.
  3. The formatter doesn't work for the time axis.

Expected behavior

The formatter should work for the time axis.

Actual behavior

The formatter for the time axis is completely avoided when formatting the time axis.

Possible Solution

This could have been caused by the Time._DEFAULT_TIME_AXIS_CONFIGURATIONS
Since it only takes the default values, I would only like to have a variable so that the configs could be updated or rather, instead of defining my custom configs, I would simply like to add/modify these DEFAULT CONFIGURATIONS

  • Plottable version: Plottable 1.16.2
  • Browser name/version: Any browser
  • OS name/version: MacOS/Windows

I stumbled upon this problem too, but I McGyvered a solution:

myTimeAxis.axisConfigurations().forEach(tierConfiguration =>  
      tierConfiguration.forEach(function (row) {
        if(row.interval === "hour" || row.interval === "minute")  
          row.formatter = new Plottable.Formatters.time("%H:%M")  
      })  
 )  

With myTimeAxis being a Plottable.Axes.Time object.
I used http://plottablejs.org/tutorials/time-axes/ and https://github.com/d3/d3-time-format/blob/v2.2.3/README.md#isoFormat.

Thank you, that worked wonders!