Scale - color range based on field value

Hi there

in schema
and have this dataset named teams_legend:

then i have scale

      "name": "color2",
      "type": "ordinal",
      "domain": {"data": "teams_legend", "fields": [{"data": "teams_legend", "field": "pracovnik_full"}]},
          #756bb1","#e65b16","#3182bd","#31a354","#636363",#9e9ac8","#fd8d3c","#6baed6","#74c476","#bcbddc", "#fdae6b","#9ecae1","#a1d99b","#bdbdbd","#dadaeb","#fdd0a2","#c6dbef","#c7e9c0","#d9d9d9"

I want to add some kind of conditioning to this scale:
when legend == 0, then color should be white, else use color from range.
Is it even possible to change it here?

Final vizualization should looks similar to this:

Thank you



You could put your color palette in a signal (like "signals": [{"name": "colorPalette", "value": ["red", "blue", "purple"]}] ). then you could go into your scale and write it as: "range": {"signal": "data('teams_legend').legend == 0 ? 'white' : colorPalette"}. I'm not entirely sure that that will work right, but please give it a whirl and let me know if it works.


Hi Midas
I tried this solution in previous work - it works fine but don't exactly fulfill my needs.
I managed to solve this problem by usage of production rules in legend. Its little bit more complex (combinated with signals), but maybe it can help other seekers :

  "legends": [
  "clipHeight": 30,
  "title": "Zaměstnanci",
  "orient": "none",
  "padding": {"value": -250},
  "fill": "color",
  "gridAlign": "none",
  "encode": {
    "title": {
      "update": {
        "fontSize": {"value": 14},
        "fill": {"signal": "Zobrazení === 'Po zaměstnancích' ? 'black' : 'white'"}
    "labels": {
      "interactive": true,
      "update": {
        "fontSize": {"value": 10},
        "fill": [
          {"test": "!indata('teams_empty','pracovnik_full',datum.value)", "value": "black"},
          {"value": "grey"}
        "opacity": {"signal": "Zobrazení === 'Po zaměstnancích' ? 1 : 0"}
    "symbols": {
      "update": {
        "stroke": {"signal": "datum.legend == 0 ? 'black' : 'transparent'"},
        "fill": [
            "test": "!indata('teams_empty','pracovnik_full',datum.value)",
            "scale": "color",
            "field": "value"
          {"value": "white"}
        "size": {"signal": "Zobrazení === 'Po zaměstnancích' ? 50 : 0"}
    "legend": {"update": {"x": {"signal": "width", "offset": 5}, "y": {"value": 250}}}
} ]

I highly appreciate your help :slight_smile:


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.