-
Notifications
You must be signed in to change notification settings - Fork 119
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
Changes from 14 commits
f784b2b
e71ac18
f4eafa5
f7a1aa0
a0c8839
d6fb645
f263fbf
d5abfd7
591c603
dc9a38f
efce9bf
60664b9
af7c506
935e64a
4976be7
1b76c69
5037110
1d888f7
ead2e9e
c5ac664
4e88447
054c088
55bf6ee
6ba6751
9aa1329
4952e6b
8a9739c
594c6f6
a63b9eb
9ed79f0
506bf0b
d0ff3c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 type TickFormatterOptions = { | ||
timeZone?: string; | ||
}; | ||
|
||
export type TickFormatter = (value: any, options?: TickFormatterOptions) => string; | ||
|
||
export interface AxisStyle { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Why we need this in the scale option? the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
const defaultScaleOptions: ScaleOptions = { | ||
bandwidth: 0, | ||
|
@@ -149,6 +151,7 @@ const defaultScaleOptions: ScaleOptions = { | |
ticks: 10, | ||
isSingleValueHistogram: false, | ||
integersOnly: false, | ||
duplicateTicks: false, | ||
}; | ||
export class ScaleContinuous implements Scale { | ||
readonly bandwidth: number; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. */ | ||
|
||
import React from 'react'; | ||
import { Axis, Chart, LineSeries, Position, ScaleType, niceTimeFormatter } from '../../src/'; | ||
import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana'; | ||
import { boolean } from '@storybook/addon-knobs'; | ||
import { DateTime } from 'luxon'; | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Weirdly, utc+1 wasn't aligning but |
||
.toMillis(); | ||
const oneDay = 1000 * 60 * 60 * 24; | ||
const formatter = niceTimeFormatter([now, now + oneDay * 31]); | ||
const duplicateTicksInAxis = boolean('Show duplicate ticks in x axis', false); | ||
return ( | ||
<Chart className="story-chart"> | ||
<Axis id="bottom" position={Position.Bottom} tickFormat={formatter} duplicateTicks={duplicateTicksInAxis} /> | ||
<Axis | ||
id="left" | ||
title={KIBANA_METRICS.metrics.kibana_os_load[0].metric.title} | ||
position={Position.Left} | ||
tickFormat={(d) => `${Number(d).toFixed(1)}`} | ||
/> | ||
<LineSeries | ||
id="lines" | ||
xScaleType={ScaleType.Time} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
data={[ | ||
{ x: now, y: 2 }, | ||
{ x: now + oneDay, y: 3 }, | ||
{ x: now + oneDay * 2, y: 3 }, | ||
{ x: now + oneDay * 3, y: 4 }, | ||
{ x: now + oneDay * 4, y: 8 }, | ||
{ x: now + oneDay * 5, y: 6 }, | ||
]} | ||
/> | ||
</Chart> | ||
); | ||
}; |
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!