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

scale domain/range should not place items in legend if they are not in plot #2802

Closed
jowens opened this issue Aug 7, 2017 · 12 comments
Closed

Comments

@jowens
Copy link

jowens commented Aug 7, 2017

This was an Altair graph. I wanted to assign colors to vendors using a domain/range Scale and make many graphs with that Scale. Some graphs do not have all vendors. I expected that only the vendors that appeared in the graph would appear in the legend. (Consider an uber-Scale that has hundreds of items in domain/range but only a few appear in any particular graph.)

In the JSON below (VL 2.0.0-beta.11) I see both AMD and NVIDIA in the legend, but only NVIDIA points appear in the graph, so I expect only NVIDIA should be in the legend.

{
  "mark": "point",
  "data": {
    "values": [
      {
        "Launch": "1995-09-01 00:00:00.000000000",
        "SM count": 1,
        "Vendor": "NVIDIA"
      },
      {
        "Launch": "1996-09-01 00:00:00.000000000",
        "SM count": 2,
        "Vendor": "NVIDIA"
      }
    ]
  },
  "encoding": {
    "y": {
      "field": "SM count",
      "type": "quantitative"
    },
    "color": {
      "field": "Vendor",
      "scale": {
        "domain": [
          "AMD",
          "NVIDIA"
        ],
        "range": [
          "#ff0000",
          "#76b900"
        ]
      },
      "type": "nominal"
    },
    "tooltip": {
      "field": "Model",
      "type": "nominal"
    },
    "x": {
      "field": "Launch",
      "type": "temporal"
    }
  }
}
@domoritz
Copy link
Member

domoritz commented Aug 8, 2017

There is no clean way to do this in Vega as far as I know. I remember that we talked about domain mapping that specifies what colors items in the domain should be mapped to but I can't find the reference right now. Either way, we need support in Vega first so I'm closing this issue here. Please file an issue in Vega first.

@domoritz domoritz closed this as completed Aug 8, 2017
@kanitw
Copy link
Member

kanitw commented Aug 8, 2017

@jowens Thanks for filing an issue. However, conceptually, legend is a visualization of the scale. Thus if you set the scale domain, it should appear on the legend by design. Doing something different is actually violating the concept.

However, a better alternative would to use a formula transform to derive a new field with specific color value and just the data value as the color.
This requires us to allow disabling scale (#2400), but for now you can actually start doing this in Vega by referring to a field without passing it through a scale.

Our previous discussion of a "replace" transform could be handy for this task as well #1761.

@domoritz
Copy link
Member

domoritz commented Aug 8, 2017

Yes, #1761 was what I was thinking of. Thanks @kanitw!

@jheer
Copy link
Member

jheer commented Aug 8, 2017

In Vega, you can control which values appear in a legend using the values property - overriding the scale domain in the process. It's basically a white list. For more, see https://vega.github.io/vega/docs/legends/

@kanitw
Copy link
Member

kanitw commented Aug 8, 2017

Oh yeah, if you want to manually change values for each plot (or edit the underlying to wire values to a signal based on your dataset) then it works.

What I mention above is more like what could work natively in Vega-Lite in the future :)

@domoritz
Copy link
Member

domoritz commented Aug 8, 2017

@kanitw Do you think we should wire up things in Vega-Lite to use the original domain of the scale to set the values of the legends? Even if you or I don't implement this right now, we could mark this as "help wanted".

@kanitw
Copy link
Member

kanitw commented Aug 9, 2017 via email

@kanitw
Copy link
Member

kanitw commented Aug 9, 2017

Actually I'm a bit wrong -- if we disable scale, then there would be no legend. Hmm, I'll re-open this for now then. Not sure what's the best solution yet.

@kanitw kanitw reopened this Aug 9, 2017
@jowens
Copy link
Author

jowens commented Aug 9, 2017

Thanks for always taking my issues seriously, whether they're good, bad, or weird.

@g3o2
Copy link
Contributor

g3o2 commented Aug 9, 2017

In the above example, I don't quite understand how it would be more tedious to provide a manual scale not based on the data than a manual values array for the legend. Does this mean that it would be programmatically possible to inject a custom scale but not a custom values array ?

@jowens
Copy link
Author

jowens commented Aug 9, 2017

@g3o2 My use case is one defined domain/range scale, many graphs. Consider if I have dozens of vendors and each one gets its own (custom) color, but any individual graph has only a small subset of the total number of vendors.

I can't address your question.

@kanitw kanitw modified the milestone: 2.x.x Features & Patches Aug 11, 2017
@kanitw
Copy link
Member

kanitw commented May 9, 2018

Closing as it appears to be no clear solution here. I think this is a bit too complicated to support natively in Vega-Lite -- better just do it in Vega or D3.

If you have a good proposal, please feel free to reopen and propose one.

@kanitw kanitw closed this as completed May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants