-
Notifications
You must be signed in to change notification settings - Fork 121
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(axis): option to hide duplicate axes #370
Changes from 1 commit
37808ff
e07b954
f306a93
add9661
37c4f0b
1f27b60
2474776
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ import { inject, observer } from 'mobx-react'; | |
import { ContainerConfig } from 'konva'; | ||
import { Layer, Rect, Stage } from 'react-konva'; | ||
|
||
import { AnnotationId, AxisId } from '../../utils/ids'; | ||
import { AnnotationId } from '../../utils/ids'; | ||
import { isLineAnnotation, isRectAnnotation, AxisSpec } from '../../chart_types/xy_chart/utils/specs'; | ||
import { LineAnnotationStyle, RectAnnotationStyle, mergeGridLineConfigs } from '../../utils/themes/theme'; | ||
import { | ||
|
@@ -37,8 +37,8 @@ interface ReactiveChartState { | |
}; | ||
} | ||
|
||
interface AxisConfig { | ||
id: AxisId; | ||
interface AxisProps { | ||
key: string; | ||
axisSpec: AxisSpec; | ||
axisTicksDimensions: AxisTicksDimensions; | ||
axisPosition: Dimensions; | ||
|
@@ -163,20 +163,20 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> { | |
]; | ||
}; | ||
|
||
getAxes = (): AxisConfig[] => { | ||
getAxes = (): AxisProps[] => { | ||
const { axesVisibleTicks, axesSpecs, axesTicksDimensions, axesPositions } = this.props.chartStore!; | ||
const ids = [...axesVisibleTicks.keys()]; | ||
|
||
return ids | ||
.map((id) => ({ | ||
id, | ||
key: `axis-${id}`, | ||
ticks: axesVisibleTicks.get(id), | ||
axisSpec: axesSpecs.get(id), | ||
axisTicksDimensions: axesTicksDimensions.get(id), | ||
axisPosition: axesPositions.get(id), | ||
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. you can map this to something that respect the props of 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. see 2474776 |
||
})) | ||
.filter( | ||
(config: Partial<AxisConfig>): config is AxisConfig => { | ||
(config: Partial<AxisProps>): config is AxisProps => { | ||
const { ticks, axisSpec, axisTicksDimensions, axisPosition } = config; | ||
|
||
return Boolean(ticks && axisSpec && axisTicksDimensions && axisPosition); | ||
|
@@ -188,17 +188,8 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> { | |
const { chartTheme, debug, chartDimensions } = this.props.chartStore!; | ||
const axes = this.getAxes(); | ||
|
||
return axes.map(({ id, ticks, axisSpec, axisTicksDimensions, axisPosition }) => ( | ||
<Axis | ||
key={`axis-${id}`} | ||
axisSpec={axisSpec} | ||
axisTicksDimensions={axisTicksDimensions} | ||
axisPosition={axisPosition} | ||
ticks={ticks} | ||
chartTheme={chartTheme} | ||
debug={debug} | ||
chartDimensions={chartDimensions} | ||
/> | ||
return axes.map(({ key, ...axisProps }) => ( | ||
<Axis {...axisProps} key={key} chartTheme={chartTheme} debug={debug} chartDimensions={chartDimensions} /> | ||
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. Have you extracted the key a bit more explicit on the code? 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. Sorry what do you mean by this? I tried spreading the props with the key included and I get a linting error not adding the key 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. yes, sorry :( 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 comment
The reason will be displayed to describe this comment to others. Learn more.
it's a double equal here if we want to mark as duplicate if one title is null and the other undefined (that in our case we can threat as no value)
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.
The value cannot be
null
based on the types correct?Nonetheless, I also don't like double equals in javascript because it is loose equality, and generally a bad practice. It also can cause unwanted conversions producing inaccurate results. I'd like to enforce this throughout the code eventually.
I think the explicit equality adding twice the code to clearly indicate the comparison is worth it.
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.
yep that value cannot be null, but I was thinking on the case the chart used in a JS world (people can do strange things there).
You are right about the loose equality, I use that only in rare case checking when checking for null and undefined, in that case you are right, we can get some strange results. So please ignore my comment here
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.
To your point about people using this library in javaScript and not minding the types.
I 100% agree, but I think if we want to address that there are numerous places where we assume values to be provided/required. I think the
Theme
is a perfect example where we assume options are provided on the type were in js they may not.