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

Improve tooltips when aggregating data #143

Merged
merged 3 commits into from
Mar 28, 2018

Conversation

pluehne
Copy link
Contributor

@pluehne pluehne commented Mar 27, 2018

This implements multiple improvements to the tooltips that are shown when hovering data points in views displaying aggregated data.

First, the tooltips now show the date range of the period of time over which the data has been aggregated (and not just the first date of the range). An exception to this are the first and last aggregation methods (which only pick the first or last value from the available time range), where the respective date is shown instead.

For reasons of clarity, the date format was changed to show abbreviated month names instead of full ones.

Second, the applied aggregation method is shown in parentheses next to the date range. This makes it easier to understand how to interpret the data. Again, this excludes the first and last aggregation methods, where the date itself already provides all the information needed.

Implementation-wise, new auxiliary columns were introduced. These are distinguished from regular columns with a leading underscore character and subsequently ignored from the chart rendering. This mechanism is useful for annotating data, currently with information for showing the tooltips.

I also updated Moment.js to 2.21.0 because of an issue with how UTC timestamps are handled.

Closes #130.


screenshot-weekly-sum


screenshot-weekly-first


screenshot-daily

@pluehne pluehne added the bug label Mar 27, 2018
@pluehne pluehne self-assigned this Mar 27, 2018
@@ -63,7 +63,7 @@ const timeSeriesChartDefaults =
time:
{
format: 'YYYY-MM-DD',
tooltipFormat: 'D MMMM YYYY',
tooltipFormat: 'D MMM YYYY',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is format used? I wonder if the formats should match...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is the default tooltip configuration if you haven’t set a tooltip callback.

Having it spelled out here is mostly a defensive measure now that we have a callback. But I agree that it’s not really necessary anymore. Depends mostly on whether we can reuse that default configuration at a later point in time or not.


const suffix = (dataPoint.infoText === undefined)
? ''
: ' (' + dataPoint.infoText + ')';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Wouldn't is be more straight forward to set row['_infoText'] = ''? Then you don't need this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I’d rather decouple the presentation (putting the info text in parentheses after the title) from the data itself. This keeps the data array rather clean I think even if this conditional is the consequence.

: ' (' + dataPoint.infoText + ')';

if (dateRange === undefined)
return moment(date).utc().format('D MMM YYYY') + suffix;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to define the tooltip format as some kind of global constant? We replicate it 5 times in this PR.

Copy link
Contributor Author

@pluehne pluehne Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought about this. However, the interface of Moments.js doesn’t look like this could be extracted.

I would have expected Moments.js to work like this:

moment.utc().format('D MMM YYYY')(1234567890);

This would have enabled us to extract the formatting function like this:

const formatDate = moment.utc().format('D MMM YYYY');
formatDate(1234567890);

However, as you can see, the interface isn’t like this. Yes, we could move the format into a global configuration, but then there’s still the UTC part that’s replicated everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now thinking of this, let me have a quick look whether there is another interface that would do the trick.

Copy link
Contributor Author

@pluehne pluehne Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also simply write a wrapper function:

function formatDate(date)
{
    return moment(date).utc().format('D MMM YYYY');
}

Would you prefer it in this way?

This implements multiple improvements to the tooltips that are shown
when hovering data points in views displaying aggregated data.

First, the tooltips now show the date range of the period of time over
which the data has been aggregated (and not just the first date of the
range). An exception to this are the “first” and “last” aggregation
methods (which only pick the first or last value from the available time
range), where the respective date is shown instead.

For reasons of clarity, the date format was changed to show abbreviated
month names instead of full ones.

Second, the applied aggregation method is shown in parentheses next to
the date range. This makes it easier to understand how to interpret the
data. Again, this excludes the “first” and “last” aggregation methods,
where the date itself already provides all the information needed.

Implementation-wise, new auxiliary columns were introduced. These are
distinguished from regular columns with a leading underscore character
and subsequently ignored from the chart rendering. This mechanism is
useful for annotating data, currently with information for showing the
tooltips.
This wraps the Moment.js date formatting calls in a separate function
to avoid code duplication.
@pluehne pluehne force-pushed the patrick/show-date-ranges-in-tooltips branch from bc91102 to 1db89be Compare March 28, 2018 10:18
@codecov-io
Copy link

Codecov Report

Merging #143 into master will increase coverage by 0.06%.
The diff coverage is 19.23%.

@pluehne
Copy link
Contributor Author

pluehne commented Mar 28, 2018

@larsxschneider: I addressed your feedback concerning code duplication with date formatting in 1db89be. Please have a look at the changes 🙂.

@larsxschneider larsxschneider merged commit bb29f3d into master Mar 28, 2018
@larsxschneider larsxschneider deleted the patrick/show-date-ranges-in-tooltips branch March 28, 2018 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants