altair icon indicating copy to clipboard operation
altair copied to clipboard

Add more docs examples for offset encoding

Open joelostblom opened this issue 2 years ago • 4 comments

It would be nice if we could add a page about the new offset encoding that contained common examples. In addition to the offset barplot in the VegaLite docs, I think these examples would be nice:

import altair as alt
from vega_datasets import data

source = data.barley.url

alt.Chart(source).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset='year:N',
    color='year:N',
)

image

alt.Chart(source).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset=alt.XOffset('offset:Q', scale=alt.Scale(domain=(0, 3)))
).transform_calculate(
    offset='random()'
)

image

alt.Chart(source, width=alt.Step(40)).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset=alt.XOffset('offset:Q', scale=alt.Scale(domain=(0, 10))),
    color='year:N'
).transform_calculate(
    offset="datum.year == 1932 ? 5 + random() : 0 + random()"
)

image

joelostblom avatar May 17 '22 03:05 joelostblom

In case it's helpful, here are two short offset examples that I put together a few months ago: https://github.com/ChristopherDavisUCI/altair/commit/af0c3b4c1d27c366fb66fb6743aa15d5d30a56ce

ChristopherDavisUCI avatar May 17 '22 13:05 ChristopherDavisUCI

I saw that you already added sections for every transform and are in the process of adding the same for every mark which is great, I really think this lifts the documentation to a new level! Not everyone will feel comfortable going to the vega-lite documentation and translating the content themselves and many users might not even be aware that this could be done.

Is the same also planed for the encoding sections? I don't think I have the time right now to work on this so I'm just curious to hear your thoughts :) Maybe I could do some pages in a few weeks, depending on what your release schedule is for 5.0?

binste avatar Oct 17 '22 19:10 binste

I don't think we have anything planned currently for the encoding section so please feel free to start a PR on that. In case you want to work on the encoding section and have time it might make sense that you take over work on https://github.com/altair-viz/altair/pull/2607 as well to get familiar with the format of those doc sections? I left some comments there that needs to be addressed but other than that I think it is close to a merge and I am happy to review as soon as possible after you make changes. Any of the things we have discussed that you are interested in and have time for would be a welcome contribution, just let me know what you prefer when you start working on it so that we don't work onthe same thing separately (although I will likely not get to working on that PR until after Christmas myself).

Regarding a 5.0 release, there is no date planned for this yet, so you likely have time

joelostblom avatar Oct 17 '22 20:10 joelostblom

Thanks for the explanations! I'll work on #2696 next and would let you know in case I find time over the coming weeks to work on the other topics.

binste avatar Oct 18 '22 15:10 binste

Just so you are aware, I will work on the encoding pages next, expanding the current one and potentially adding separate ones for certain concepts similar to the vega-lite docs. I will also clarify the distinction between value and datum as discussed in #2572

binste avatar Dec 01 '22 10:12 binste

Just to check @binste, I could not find the documentation in the encoding channel options on x/yOffset in https://binste.github.io/altair-docs/user_guide/encodings/channel_options.html.

I think it be as included as follow:

XOffset and YOffset
~~~~~~~~~~~~~~~~~~~

 The :class:`XOffset` and :class:`YOffset` encodings accept the following options:

 .. altair-object-table:: OffsetDef

mattijn avatar Dec 27 '22 20:12 mattijn