-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[TIP] Fix barchart legend rendering issue #142268
[TIP] Fix barchart legend rendering issue #142268
Conversation
- set minimum width - vertically align context menu button
iconType="boxesHorizontal" | ||
iconSize="s" | ||
size="xs" | ||
onClick={() => setPopover(!isPopoverOpen)} |
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.
Hey, in this particular situation, the recommended approach is to use https://reactjs.org/docs/hooks-reference.html#functional-updates
- check it out :)
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.
Also, maybe we could extract this handler with useCallback
?
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 I wasn't aware of the functional updates, it's cool as it prevent rerendering if the value is identical!
It seems to me that the useCallback here is overkill. We're not really rendering a complex component, just a EuiContextPanel with 3 icons and 3 texts... No?
</EuiToolTip> | ||
} | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setPopover(false)} |
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.
useCallback
would work better here as well
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, with some minor notes. Apply the changes or skip them, I think the performance needs a deeper dive anyway around the entire plugin, but these useCallbacks
are a low hanging fruit that does not hurt I guess 👯
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.
overall good improvement, couple of questions to the chart library itself on which we can kick off a discussion with the team owning it
@@ -52,6 +53,7 @@ export const IndicatorsBarChart: VFC<IndicatorsBarChartProps> = ({ | |||
showLegend | |||
showLegendExtra |
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.
Took a look at the charts documentation. It's quite weird that the legend is controlled only through the Settings component. My suggestion is to remove the showLegendExtra
from the settings because values in the legend in my opinion don't bring any value, only confusion. Tbh the current behaviour of the legend looks to my more like a UX bug than a feature, especially when combined with a tooltip on hower on each bar. Does it makes sense to consult with the team owning the chart library and ask how would they suggest to implement such a feature - showing the accumulated values in the legend
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.
found this issue that is related to the problem elastic/elastic-charts#561
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.
yeah good point on removing the showLegendExtra
, I really don't see what value it provide at the moment as we have the tooltip that's way more convenient.
I'll reach out to the charts
team and ask them about the accumulated values in legend!
|
||
export const useStyles = () => { | ||
const contextMenu: CSSObject = { | ||
'margin-top': '-2px', |
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.
this is quite weird that we need to do this hacks to align the components that are built in. Does it makes sense to also reach out to the team to check if it is a bug they are aware of.
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 agree I hated overriding some default values, but hated even more the -2px.
After investigating more by playing with the elastic-charts repo, the problem is actually with the use of the EuiTooltip
. Removing it fixes the alignment issue. I posted on their channel , let's see it I'm doing something wrong.
For now I decided to remove the EuiToolTip
, it will take 30 seconds to add it back once we figure out how to do it properly...
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.
well actually with the help of the charts team I think we have a better hack
for now. We're using style={{ height: '100%' }}
on the EuiButtonIcon. It's either that or we don't use EuButtonIcon and have to style everything ourselves, like they do in the elastic-charts Storybook here.
The charts team isn't really testing their components with Eui components so it's not the first time they're seeing those weird UI issues...
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.
created a bug ticket on the elastic-charts repo for traceability
# Conflicts: # x-pack/plugins/threat_intelligence/public/modules/indicators/components/barchart/legend_action/legend_action.tsx # x-pack/plugins/threat_intelligence/public/modules/indicators/components/barchart/legend_action/styles.ts
…ue shown in legend
b9dd471
to
2e1ffcc
Compare
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
* [TIP] Fix barchart legend rendering issue - set minimum width - vertically align context menu button - remove value displayed in legend
Summary
Our Indicators barchart legend component was cutting off names too aggressively.
Also as seen in the screenshot above, the 3-dot button used to display the context menu for actions wasn't properly aligned with the rest of the legend.
This PR:
legendSize
prop as a min-size)Render after fix:
Fixes https://github.com/elastic/security-team/issues/5117