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

filled legend markers without filled path #383

Closed
hugovoerman opened this issue Nov 28, 2020 · 6 comments
Closed

filled legend markers without filled path #383

hugovoerman opened this issue Nov 28, 2020 · 6 comments

Comments

@hugovoerman
Copy link

I would like to be able to create solid colored markers. Right now (as I can find) it used the fill property to fill the marker, but that also creates an effect on the chart which I don't want. Is there a way to do this?

I derive this from uPlot.js

let indic = placeDiv(LEGEND_MARKER, label);
indic.style.borderColor = s.width ? s.stroke : i > 0 && s.points.width ? s.points.stroke : null;
indic.style.backgroundColor = s.fill || null;

So as an example I would like the blue transparant box to be solid blue, without creating fills in the chart itself.

image

@leeoniya
Copy link
Owner

this might be a useful setting to add.

until then...

since these legend markers are in the dom, you can use uPlot's init hook to to set their style.background to match their series.stroke. it will take a few lines of code but should not be very difficult.

@leeoniya leeoniya changed the title Create filled markers filled legend markers without filled path Nov 28, 2020
@leeoniya
Copy link
Owner

need to think about where to stick this api. probably:

opts.legend.marker: (self, seriesIdx) => {
  return {
    fill,
    stroke,
    width,
  };
  // or raw html or svg element...
  return document.createElement("div");
}

@hugovoerman
Copy link
Author

Using the commented code in legendAsTooltipPlugin in the init() it was indeed easy:

const idents = legendEl.querySelectorAll(".u-marker");

for (let i = 0; i < idents.length; i++)
    idents[i].style.backgroundColor = idents[i].style.borderColor;

did the trick. Thanks for the pointer in this direction!

@leeoniya
Copy link
Owner

leeoniya commented Dec 13, 2020

i ended up having to fix this after fixing series gradient strokes/fills, since they cannot be re-used for css backgroundColor or borderColor.

you can now explicitly define them via callbacks:

{
  legend: {
    stroke: (u, seriesIdx) => "red",
    fill: (u, seriesIdx) => "blue",
  }
}

it's also done similarly in the new demo: https://leeoniya.github.io/uPlot/demos/gradient-fill.html, which sounds like what you want:

{
  legend: {
    fill: (u, seriesIdx) => u.series[seriesIdx].stroke(u, seriesIdx),
  }
}

@bogdan-nourescu
Copy link

Since you added the ability to specify stroke and fill as a function, i would like to also specify width as a function.
The reasoning is so that i can change the width when you hover over a series with focus.
If i have width 1, and i have a lot of series, i can't clearly see it, so i would like to change the width to 3 on focus, using a function on the width

@leeoniya
Copy link
Owner

i'll think about it: #403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants