-
Notifications
You must be signed in to change notification settings - Fork 120
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
Conversation
Codecov Report
@@ 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.
|
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
stories/line/10_duplicate_ticks.tsx
Outdated
|
||
export const example = () => { | ||
const now = DateTime.fromISO('2019-01-11T00:00:00.000') | ||
.setZone('utc+1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
src/scales/scale_continuous.ts
Outdated
@@ -139,6 +139,8 @@ interface ScaleOptions { | |||
isSingleValueHistogram: boolean; | |||
/** Show only integer values **/ | |||
integersOnly?: boolean; | |||
/** Show duplicate tick values default to false */ | |||
duplicateTicks?: boolean; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
const oneDay = 1000 * 60 * 60 * 24; | |
const oneDay = moment.duration(1, 'day'); |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
jenkins, test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# [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))
🎉 This PR is included in version 18.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 18.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [18.1.0](elastic/elastic-charts@v18.0.0...v18.1.0) (2020-03-18) ### Bug Fixes * add unicorn eslint as dev dependency ([opensearch-project#591](elastic/elastic-charts#591)) ([7c7ccfe](elastic/elastic-charts@7c7ccfe)) ### Features * remove duplicate tick labels from axis ([opensearch-project#577](elastic/elastic-charts#577)) ([52c6921](elastic/elastic-charts@52c6921)), closes [opensearch-project#445](elastic/elastic-charts#445) * **api:** cleanup exposed types ([opensearch-project#593](elastic/elastic-charts#593)) ([0b964c6](elastic/elastic-charts@0b964c6)) * **partition:** general sunburst via slice show control ([opensearch-project#592](elastic/elastic-charts#592)) ([7240823](elastic/elastic-charts@7240823))
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#47045This 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
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [] Any consumer-facing exports were added tosrc/index.ts
(and stories only import from../src
except for test data & storybook)