问题
I am working on a realtime simulation. I generate an hour of data, but I only want to present a portion of that, and scroll the plot when I get close to the right edge. I define two signals:
"signals": [
{
"name": "timeStart",
"init":0
},
{
"name": "timeEnd",
"init": 480000 }
],
and a scale
"scales": [
{
"name": "x",
"type": "time",
"range": "width",
"nice": "minute",
"domainMin": {"signal": "timeStart"},
"domainMax": {"signal": "timeEnd"},
"zero": false
}
I have a filter in the marks to make sure I only display the inrange data.
In my javascript, I update the values of timeStart and timeEnd, and the plot now contains the subset of the data I want, but the entire plot is shifted right by the amount of time I've added to timeStart and timeEnd. Not what I want. Putting offsets on the axis doesn't work. What am I missing?
回答1:
I figured out what I was missing. Adding
"padding": {"left":100, "right": 100, "top": 50, "bottom":100},
fixed the problem.
回答2:
Would you mind sharing the portion of your code that performs filtering? The Vega 3 code I wrote like this, works for one spec with symbols marks but not for another spec with line marks.
data: [
{
name: 'table',
transform: [
{ type: 'filter', expr: 'datum.l >= timeStart && datum.l <= timeEnd' }
],
values: [blah blah]
}
]
In https://github.com/vega/vega/issues/113, kjavia mentions a "tearing" effect which I see in my spec with line marks.
来源:https://stackoverflow.com/questions/44421951/changing-the-domain-of-a-scale-without-shifting-the-entire-plot