StephanWagner / svgMap

svgMap is a JavaScript library that lets you easily create an interactable world map comparing customizable data for each country.
MIT License
256 stars 42 forks source link

[bug] Countries in map flash black on load #120

Open tipsy opened 3 months ago

tipsy commented 3 months ago

Steps to reproduce

Current workaround

<div id="svgMap" class="unloaded"></div>
.unloaded .svgMap-map-wrapper .svgMap-country {
    fill: var(--desired-starting-color);
}
const map = new svgMap(...);
document.querySelector(".unloaded").classList.remove("unloaded");
m1rm commented 2 weeks ago

@StephanWagner I dug a little into this issue and the simplest fix I came up with is (based on the workaround) to add a $colorMin css-variable in variables.scss and then use it in map.scss to set the initial fill color for .svgMap-map-wrapper and .svgMap-country. The initial color then is the same as the transition initial color and thus there is no visible flash of black anymore.

variables.scss $colorMin: #ffaa11 !default; // just sth. bright to try out

map.scss

.svgMap-map-wrapper {
  fill: $colorMin;
  [...]
}
[...]
  .svgMap-country {
    fill: $colorMin;
    [...]
}
[...]

But this would be a breaking change because $colorMin then is sth. you need to set when initializing the map, just like the $colorOcean (for example) and users who do not set it this way would fallback to the default.

I also thought about a refactoring so that the map is not first initialized and then the colors are applied (which I think is leading to the flashing black).

I'd be glad to open a MR for any solution you'd prefer :slightly_smiling_face: