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

feat: remove duplicate tick labels from axis #577

Merged
merged 32 commits into from
Mar 18, 2020

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Mar 3, 2020

Summary

Closes #445 and addresses related kibana issue elastic/kibana#47045

BREAKING CHANGE:
showDuplicateTicks is set to false by default - this changes current behavior as seen in elastic/kibana#47045

This PR removes duplicate tickLabels for an axis instead of taking into account unique tickValues. For instance, if the tickLabel on the axis is showing days, then millisecond differences in the tickValues should not generate duplicate tickLabels. However, if the consumer wants to show duplicate tickLabels, then this can be configured with the showDuplicateTicks config prop but isn't set to true by default.

There has been a story added within Axes - Axes - Duplicate Ticks

Mar-18-2020 13-57-55

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [] Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)

  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@codecov-io
Copy link

codecov-io commented Mar 4, 2020

Codecov Report

Merging #577 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #577   +/-   ##
=======================================
  Coverage   70.55%   70.55%           
=======================================
  Files         220      220           
  Lines        6412     6412           
  Branches     1230     1230           
=======================================
  Hits         4524     4524           
  Misses       1869     1869           
  Partials       19       19           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 506bf0b...506bf0b. Read the comment docs.

@rshen91 rshen91 marked this pull request as ready for review March 4, 2020 16:18
@rshen91 rshen91 added wip work in progress bug Something isn't working labels Mar 4, 2020
@rshen91 rshen91 removed the wip work in progress label Mar 10, 2020
@rshen91 rshen91 requested a review from markov00 March 10, 2020 17:46
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

I've added few comments that needs to be addressed before merging. Feature wise works fine

@@ -525,11 +525,14 @@ export interface AxisSpec extends Spec {
style?: AxisStyle;
/** Show only integar values **/
integersOnly?: boolean;
/** Remove duplicate ticks, default is false*/
duplicateTicks?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

@rshen91 Maybe we should introduce a breaking change and enabling this by default changing the name to enableDuplicatedTicks or something similar. What do you think?
@nickofthyme ideas?

Copy link
Contributor Author

@rshen91 rshen91 Mar 11, 2020

Choose a reason for hiding this comment

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

I like the naming a lot better - please see commit 5037110 for naming changes


export const example = () => {
const now = DateTime.fromISO('2019-01-11T00:00:00.000')
.setZone('utc+1')
Copy link
Member

Choose a reason for hiding this comment

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

if you are using a timezone here, you should also add it to the LineSeries if not, the ticks will be slightly off
Screenshot 2020-03-10 at 19 13 21

<LineSeries
        ...
        timeZone="utc+1"

Copy link
Contributor Author

@rshen91 rshen91 Mar 11, 2020

Choose a reason for hiding this comment

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

Weirdly, utc+1 wasn't aligning but timeZone="local" seems to do the trick. Not really sure how that is possible. Commit ead2e9e for reference

@@ -139,6 +139,8 @@ interface ScaleOptions {
isSingleValueHistogram: boolean;
/** Show only integer values **/
integersOnly?: boolean;
/** Show duplicate tick values default to false */
duplicateTicks?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Why we need this in the scale option? the getDuplicateTicks doesn't use that but use directly the AxisSpec props

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks for spotting this, I didn't remove this properly after enabling the feature - I'm removing this in commit 5037110

Comment on lines 465 to 479
if (axisSpec.duplicateTicks === false) {
const uniqueTickLabels: { value: any; label: string; position: number }[] = [];
allTicks.filter((value, index) => {
for (let i = 0; i < labels.length; i++) {
if (labels[i] === allTicks[index].label) {
uniqueTickLabels.push(allTicks[index]);
// once uniqueTickLabels has the unique label, remove the label from the labels array so it doesnt create a duplicate
labels.splice(i, 1);
}
}
});
return uniqueTickLabels;
} else {
return allTicks;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this code can be simplified a bit, let's chat on that directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a ton for your help with me on this. I added commit 594c6f6 which I think gets done what we discussed, but lmk what you think!

const now = DateTime.fromISO('2019-01-11T00:00:00.000')
.setZone('utc+1')
.toMillis();
const oneDay = 1000 * 60 * 60 * 24;
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should leverage packages to your advantage. Like using duration from moment.

Suggested change
const oneDay = 1000 * 60 * 60 * 24;
const oneDay = moment.duration(1, 'day');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! Pls see commit 55bf6ee for changes 💪

.setZone('utc+1')
.toMillis();
const oneDay = 1000 * 60 * 60 * 24;
const formatter = niceTimeFormatter([now, now + oneDay * 31]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better yet you could use moment's super easy and declarative API for this using .add and .subtract depending on what type of date niceTimeFormatter is expecting. If you need the value in mills you could use the duration.add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes in commit 55bf6ee thanks!

return enableDuplicatedTicks(axisSpec, scale, offset, tickFormatOptions);
}

export function enableDuplicatedTicks(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: enableX to me sounds like you are toggling a config option or something of that nature. Also, your config property and this method have the same name, these should usually be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out - changed the config property naming in commit
6ba6751

@@ -525,11 +525,14 @@ export interface AxisSpec extends Spec {
style?: AxisStyle;
/** Show only integar values **/
integersOnly?: boolean;
/** Remove duplicate ticks, default is false*/
enableDuplicatedTicks?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These properties are more like the current state of something. Say showGridLines as in a boolean, it wouldn't be enableGirdLines because it is not performing an action like that would imply.

@rshen91 rshen91 requested a review from markov00 March 17, 2020 20:33
@rshen91
Copy link
Contributor Author

rshen91 commented Mar 18, 2020

jenkins, test this please

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM

@markov00 markov00 changed the title fix: remove duplicate tick labels from axis feat: remove duplicate tick labels from axis Mar 18, 2020
@rshen91 rshen91 merged commit e8c89ec into elastic:master Mar 18, 2020
@rshen91 rshen91 deleted the duplicate-ticks branch March 18, 2020 20:25
markov00 pushed a commit that referenced this pull request Mar 18, 2020
# [18.1.0](v18.0.0...v18.1.0) (2020-03-18)

### Bug Fixes

* add unicorn eslint as dev dependency ([#591](#591)) ([30fd07c](30fd07c))

### Features

* remove duplicate tick labels from axis ([#577](#577)) ([e8c89ec](e8c89ec)), closes [#445](#445)
* **api:** cleanup exposed types ([#593](#593)) ([544b7cc](544b7cc))
* **partition:** general sunburst via slice show control ([#592](#592)) ([5e6a30b](5e6a30b))
@markov00
Copy link
Member

🎉 This PR is included in version 18.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Mar 18, 2020
@markov00
Copy link
Member

🎉 This PR is included in version 18.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @18.1.x released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove duplicated ticks on axis
4 participants