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

[TIP] Fix barchart legend rendering issue #142268

Merged
merged 3 commits into from
Sep 30, 2022

Conversation

PhilippeOberti
Copy link
Contributor

Summary

Our Indicators barchart legend component was cutting off names too aggressively.

Screen Shot 2022-09-29 at 2 45 39 PM

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:

  • set minimum width to 200px (this is not ideal but the elastic-charts' legend component has a built-in logic that will make sure the legend can't be wider than 30% of the total width. I interpreted the legendSize prop as a min-size)
  • vertically align context menu button (this seems to be a problem with the elastic-charts' implementation itself (looking at their Storybook seems to have the same problem).

Render after fix:

Screen Shot 2022-09-29 at 2 45 29 PM

Fixes https://github.com/elastic/security-team/issues/5117

- set minimum width
- vertically align context menu button
iconType="boxesHorizontal"
iconSize="s"
size="xs"
onClick={() => setPopover(!isPopoverOpen)}
Copy link
Contributor

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 :)

Copy link
Contributor

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?

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 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)}
Copy link
Contributor

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

Copy link
Contributor

@lgestc lgestc left a 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 👯

Copy link
Contributor

@maxcold maxcold left a 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
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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',
Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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...

Copy link
Contributor Author

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
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
threatIntelligence 121.1KB 121.1KB +23.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@PhilippeOberti PhilippeOberti merged commit 1b09c82 into elastic:main Sep 30, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 30, 2022
@PhilippeOberti PhilippeOberti deleted the barchart-legend-width branch September 30, 2022 21:10
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 2, 2022
* [TIP] Fix barchart legend rendering issue

- set minimum width
- vertically align context menu button
- remove value displayed in legend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.5 candidate backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team: Protections Experience v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants