Skip to content

Commit

Permalink
simplify scatter and add scatter_jitter template (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
dberenbaum authored Feb 16, 2023
1 parent 2aa47c8 commit b3c2dd8
Showing 1 changed file with 48 additions and 80 deletions.
128 changes: 48 additions & 80 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,89 +385,56 @@ class ScatterTemplate(Template):
"title": Template.anchor("title"),
"width": 300,
"height": 300,
"layer": [
{
"encoding": {
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
"y": {
"field": Template.anchor("y"),
"type": "quantitative",
"title": Template.anchor("y_label"),
"scale": {"zero": False},
},
"color": {
"field": "rev",
"type": "nominal",
},
},
"layer": [
{"mark": "point"},
{
"selection": {
"label": {
"type": "single",
"nearest": True,
"on": "mouseover",
"encodings": ["x"],
"empty": "none",
"clear": "mouseout",
}
},
"mark": "point",
"encoding": {
"opacity": {
"condition": {
"selection": "label",
"value": 1,
},
"value": 0,
}
},
},
],
"mark": {"type": "point", "tooltip": {"content": "data"}},
"encoding": {
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
{
"transform": [{"filter": {"selection": "label"}}],
"layer": [
{
"encoding": {
"text": {
"type": "quantitative",
"field": Template.anchor("y"),
},
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
},
"y": {
"field": Template.anchor("y"),
"type": "quantitative",
},
},
"layer": [
{
"mark": {
"type": "text",
"align": "left",
"dx": 5,
"dy": -5,
},
"encoding": {
"color": {
"type": "nominal",
"field": "rev",
}
},
}
],
}
],
"y": {
"field": Template.anchor("y"),
"type": "quantitative",
"title": Template.anchor("y_label"),
},
"color": {
"field": "rev",
"type": "nominal",
},
},
}


class ScatterJitterTemplate(Template):
DEFAULT_NAME = "scatter_jitter"

DEFAULT_CONTENT = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"values": Template.anchor("data")},
"title": Template.anchor("title"),
"width": 300,
"height": 300,
"transform": [
{"calculate": "random()", "as": "randomX"},
{"calculate": "random()", "as": "randomY"},
],
"mark": {"type": "point", "tooltip": {"content": "data"}},
"encoding": {
"x": {
"field": Template.anchor("x"),
"title": Template.anchor("x_label"),
},
"y": {
"field": Template.anchor("y"),
"title": Template.anchor("y_label"),
},
"color": {
"field": "rev",
"type": "nominal",
},
"xOffset": {"field": "randomX", "type": "quantitative"},
"yOffset": {"field": "randomY", "type": "quantitative"},
},
}


Expand Down Expand Up @@ -587,6 +554,7 @@ class SimpleLinearTemplate(Template):
ConfusionTemplate,
NormalizedConfusionTemplate,
ScatterTemplate,
ScatterJitterTemplate,
SmoothLinearTemplate,
BarHorizontalSortedTemplate,
BarHorizontalTemplate,
Expand Down

0 comments on commit b3c2dd8

Please sign in to comment.