Changing the domain of a scale without shifting the entire plot

家住魔仙堡 提交于 2021-01-28 07:05:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!