-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
How to define a fixed label on the edge of an axis? #714
Comments
You can introduce an additional text mark for custom labels. For example: {
"type": "text",
"encode": {
"enter": {
"x": {"signal": "width"},
"y": {"signal": "height"},
"text": {"value": "Now"},
"fontWeight": {"value": "bold"},
"fontSize": {"value": 10}
}
}
} Then adjust the positioning, align, baseline, etc as desired. |
The problem with this approach is that the Is that possible to avoid this collision? Shall I use an ordinal scale and calculate all the axis labels myself? |
This is what I was (obliquely) referring to about adjusting positioning, etc. There are various means of further positioning the label. One simple approach is to add a constant offset with the text |
Sorry, I probably didn't explain myself clearly. P.S. Thanks a lot for a super fast response! |
I see. If you happen to know the actual value of 'Now' you can override that label like so within your axis definition: "axes": [
{
"orient": "bottom",
"scale": "x",
"encode": {
"labels": {
"update": {
"text": {"signal": "datum.label === '9am' ? 'Now' : datum.label"}
}
}
}
}
] Of course, you would need to replace |
Sorry, but that's not what I want. |
Here's a different example that hides axis labels near the end of the scale range, configurable via the {
"width": 400,
"height": 100,
"signals": [
{
"name": "threshold",
"value": 0.925
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": [1484286340567, 1484372740567],
"range": "width"
}
],
"axes": [
{
"orient": "bottom",
"scale": "x",
"encode": {
"labels": {
"update": {
"opacity": {"signal": "(datum.value - domain('x')[0]) / span(domain('x')) > threshold ? 0 : 1"}
}
}
}
}
],
"marks": [
{
"type": "text",
"encode": {
"update": {
"x": {"signal": "width"},
"y": {"signal": "height + 8"},
"text": {"value": "Now"},
"align": {"value": "center"},
"fontSize": {"value": 10},
"fontWeight": {"value": "bold"},
"baseline": {"value": "top"}
}
}
}
]
} |
I have the following spec:
that generates:
In my case, the scale domain will always be
[now - 1day, now]
, so I'd like to always display the labelNow
at the right end of the axis:How could I achieve that? Example will be appreciated.
I use vega@3.0.0-beta.14.
The text was updated successfully, but these errors were encountered: