-
- Downloads
Format Pie Chart Legend Labels as Month, YYYY (#24890)
* Format Pie Chart Legend Labels as Month, YYYY On the backend, the pie chart legend is not rendered in the javascript, it is instead re-created server side as a set of html elements. This means "YYYY-MM-DD" formatted dates do not get passed through the frontend code responsible for formatting date times (I believe this is done with a library called 'moment.js'). And, since the SVG cannot contain html foreignObjects (the backend SVG renederer 'batik' ignores foreign objects), the legend is left as a responsiblility for Clojure land. This PR adds a `format-month` function to handle this case. Current caveats with this approach: - doesn't consider localization (yet) - adjusted the html to use a table instead of a div full of spans and the formatting could use some tweaks - assumes any string that is parse-able into a Jave DateTime object will be displayed in this Month, Year format, - which might not be true in all cases * Improve label formatting by using viz-settings transform fns * Rework Static Pie Chart legend Try to make it look a bit nicer: - splits legends into 2 tables if there are more than 8 entries - larger colored circle - use tables to help lay things out more evenly (CSS flexbox doesn't seem to work) - handle some legend label formatting cases beyond just timestamps (eg weeks of year, yearly quarters) Also fixed the failing test * Adding a month formatter. Sometimes, the label values are not passed in as timestamps, but just numbers (as strings). In these cases, the Datetime formatters won't be useful, so there are some cases built to handle these. * Remove print statement * Change temporal format fns to more closely follow viz-settings Various changes are made to improve static-viz's use of viz-settings from the frontend. - abbreviation is considered (eg. so "January" is rendered as "Jan" when setting is true) - abbreviation also works for Days of week - x-of-y cases are handled a bit better - separator settings are properly reflected (eg. 2022/05 becomes 2022-05 if separator changed to "-") * Remove unused key from the let * Fix some failing tests * Adding more tests * Prevent non-temporal legend labels from being rendered via datetime If a legend's label is some string, we want to pass it unmodified. If it's a number or a timestamp, we can pass it through to the date time render function to format the string to match the viz-settings/column units * Add missed docstring * Don't lowercase 'D' format, pass correct lowercase 'd' before 'D' format = day of year, which in most human-readable formats is not what we want, but it IS what we want in a :day-of-year case. Instead of always lowercasing, just make sure the lowercase 'd' is in the defaults/overrides * Better way to handle day of week and month of year Also got rid of bad use of read-string by using parse-long * Use a java lib. to format ordinal numbers, respecting site locale
Showing
- src/metabase/pulse/render/body.clj 59 additions, 21 deletionssrc/metabase/pulse/render/body.clj
- src/metabase/pulse/render/datetime.clj 75 additions, 23 deletionssrc/metabase/pulse/render/datetime.clj
- test/metabase/pulse/render/body_test.clj 3 additions, 3 deletionstest/metabase/pulse/render/body_test.clj
- test/metabase/pulse/render/datetime_test.clj 51 additions, 8 deletionstest/metabase/pulse/render/datetime_test.clj
- test/metabase/pulse/render_test.clj 1 addition, 1 deletiontest/metabase/pulse/render_test.clj
Please register or sign in to comment