palantir / plottable

:bar_chart: A library of modular chart components built on D3
http://plottablejs.org/
MIT License
2.97k stars 223 forks source link

Support for 24 hour time format #3542

Closed upsteer closed 4 years ago

upsteer commented 4 years ago

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

Sopwafel commented 4 years ago

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.

upsteer commented 4 years ago

Thank you, that worked wonders!