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
feat: default Vega-Lite-based renderer (#342) #438
Conversation
We can delete this before merging, but the nb should be useful for discussions
575e07e
to
3de1ba4
Compare
Vega-Lite vs. Draco specBelow I list my takeaways in a nutshell from implementing all the example charts from the docs (https://dig.cmu.edu/draco2/facts/examples.html) in Vega-Lite using Altair.
Questions regarding Draco's spec
{'field': [{'name': 'temperature', 'type': 'number'},
{'name': 'condition', 'type': 'string'}],
'number_rows': 100,
'view': [{'coordinates': 'polar',
'mark': [{'encoding': [{'aggregate': 'count',
'channel': 'y',
'stack': 'zero'},
{'channel': 'color', 'field': 'condition'}],
'type': 'bar'}],
'scale': [{'channel': 'y', 'type': 'linear', 'zero': 'true'},
{'channel': 'color', 'type': 'categorical'}]}]} While it is easy to infer that the
@JunranY, @Zehua-Zeng, @domoritz
|
This pull request introduces 1 alert when merging 932ed30 into 0bf09e5 - view on LGTM.com new alerts:
|
Hey @domoritz! While the code I pushed is indeed not really LGTM (as it is partial work full of quick & dirty experimenting), I believe the LGTM.com report above is not right:
|
Renders all the example charts
The previous version crashed for some cases including `Generic` types
maybe fixes failing CI job https://github.com/cmudig/draco2/actions/runs/3439166059/jobs/5736131475
…ault-renderer Needed to pull in CI fix
8ae9280
to
e78f11a
Compare
e78f11a
to
fc68609
Compare
Support on-demand concats
@domoritz could you please take a look at this PR? |
.github/workflows/codeql.yml
Outdated
@@ -1,4 +1,4 @@ | |||
name: "CodeQL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is in the diff. Do you need to rebase or merge main?
draco/renderer/altair_renderer.py
Outdated
represented as an `Altair <https://altair-viz.github.io/>`_ chart object. | ||
""" | ||
|
||
def __init__(self, concat_mode: Literal["hconcat", "vconcat"] | None = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to move the concat mode into the Draco spec itself. This would simplify and generalize the logic here.
draco/renderer/altair_renderer.py
Outdated
case "bar": | ||
encodes_x_and_y = all([e.channel in ["x", "y"] for e in encodings]) | ||
if encodes_x_and_y: | ||
return chart.mark_arc(stroke="#ffffff") + chart.mark_text( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we set the stroke here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mental notes I took when writing this piece of code was the following:
When rendering a bar chart in a polar coordinate system, we are essentially rendering a classical radial chart in a cartesian coordinate system, using theta
and radius
as the channels instead of the polar x
and y
channels.
TLDR: I added a stroke here so there is a visual separation between the slices, just as we would have gaps between bars in a bar chart.
Without Stroke
Open the Chart in the Vega Editor
With Stroke
draco/renderer/altair_renderer.py
Outdated
f"Unknown channel: {encoding.channel}" | ||
) # pragma: no cover | ||
|
||
def __get_field_type(self, fields: list[Field], field_name: FieldName) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this logic is correct. We should look at the scale type instead. The data type could be number but the scale could be categorical or continuous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meeting notes:
Scale type provides a cleaner mapping, as it makes it possible to differentiate between different number types such as numerical, ordinal, and categorical.
draco/types.py
Outdated
import pydantic.main as pydantic_main | ||
import pydantic.types as pydantic_types | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, this file is Vega specific and should be moved into the Vega renderer.
The failing workflows are most likely related to actions/setup-python#162. |
Attempts to fix "Explicit returns mixed with implicit (fall through) returns"
24a0a8d
to
76795ec
Compare
A spec has either top-level- or view-level scales or both.
Adds support for determining Vega-Lite field type based on a combination of the scale type and the field's raw data type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last comment.
"datetime": "temporal", | ||
"linear": { | ||
"number": "quantitative", | ||
"string": "nominal", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string and boolean are not supported for linear, no?
}, | ||
"log": { | ||
"number": "quantitative", | ||
"string": "nominal", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Goals
alt.VConcatChart | alt.HConcatChart | alt.FacetChart | alt.Chart
, ready to be displayed, exported, customized, etc.closes #342
spawns #449
spawns #455