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

[Maps] Apply styles to icon SVGs in legend via descendent selectors #129255

Merged
merged 9 commits into from
Apr 8, 2022

Conversation

nickpeihl
Copy link
Member

@nickpeihl nickpeihl commented Apr 1, 2022

Fixes #128846

The wildcard descendent selector to applies fill and stroke to all elements in the SVG. This was not necessary before because Maki icons always had a single path element. But we don't have control over the number of elements with custom icons, so we must apply and override any fill and stroke settings on sibling and nested elements.

The vector-effect: non-scaling-stroke property fixes the issue where the stroke was barely visible in the legend with large custom icons.

Additionally, the !important property force overrides any style attributes in descendant elements. It is still possible that an element may have a style attribute with !important that we can not override. Hopefully that is a rare case though.

To test this:

  • Open the [Flights] Origin Time Delayed map from the Sample flight data
  • In Map settings, add a custom icon using an SVG with a width/height or viewBox much greater than 15px that also has style attributes applied to the descendent elements. This Shoes walking is a good example.
  • Change the Flight Origin Location layer Symbol type to icon and select the custom icon
  • Change the Fill and Border colors to solid colors.
  • Verify the color in the Legend matches the selected colors.

The wildcard descendent selector to applies fill and stroke to all elements in the SVG. This was not necessary before because Maki icons always had a single path element. But we don't have control over the number of elements with custom icons, so we must override any style settings on sibling and nested elements.

The `non-scaling-stroke` property fixes the issue where the stroke was barely visible in the legend with large custom icons.
@nickpeihl nickpeihl added [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed v8.2.0 v8.3.0 labels Apr 1, 2022
@nickpeihl nickpeihl requested a review from a team as a code owner April 1, 2022 20:18
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-gis (Team:Geo)

style += `stroke-width:1;`;
}
if (style) svgXml.svg.$.style = style;
svgXml.svg.$.id = symbolId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the id a uuid so there can be no conflict.

if (style) svgXml.svg.$.style = style;
svgXml.svg.$.id = symbolId;
svgXml.svg.style = `
#${symbolId} * {
Copy link
Contributor

@nreese nreese Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about why css selector is needed, maybe something like
// Elements nested under svg root may define style attribute
// Wildcard descendent selector provides more specificity to ensure root svg style attribute is applied instead of children style attributes

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for fixing. Thanks for also moving custom icons to top of map settings and fixing issue where custom icon includes style attributes in children elements.

code review, tested in chrome

@nreese
Copy link
Contributor

nreese commented Apr 4, 2022

Actually, this creates problems for icons styled by a single color. In the screen shot below, notice how the shoe icon is black and not fill color of the layer

Screen Shot 2022-04-04 at 8 55 56 AM

@nreese nreese self-requested a review April 4, 2022 14:56
I incorrectly assumed the style element would override style attributes on descendants. This changes the specificity to the svg element and all descendents. It appears the scope of the style element is limited to the SVG and does not affect other SVGs.

Additionally, the !important property force overrides any style attributes in descendant elements. It is still possible that an element may have a style attribute with !important that we can not override. Hopefully that is a rare case though.
@nickpeihl
Copy link
Member Author

Actually, this creates problems for icons styled by a single color. In the screen shot below, notice how the shoe icon is black and not fill color of the layer

Screen Shot 2022-04-04 at 8 55 56 AM

8cb8a11 should fix this.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks for all the fixes.
code review, tested in chrome

@nickpeihl nickpeihl enabled auto-merge (squash) April 8, 2022 19:47
@nickpeihl
Copy link
Member Author

@elasticmachine merge upstream

@nickpeihl nickpeihl merged commit 7b64a54 into elastic:main Apr 8, 2022
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Test Failures

  • [job] [logs] OSS CI Group #11 / visualize app visualize ciGroup11 visual builder Time Series basics Clicking on the chart should create a filter for series with multiple split by terms fields one of which has formatting

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
maps 2.7MB 2.7MB +122.0B

History

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

@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.2

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation release_note:skip Skip the PR/issue when compiling release notes v8.2.0 v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Maps] Custom Icons appear faded in legend
5 participants