Skip to content
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

Make charts responsive #145

Open
domoritz opened this issue Aug 8, 2019 · 6 comments
Open

Make charts responsive #145

domoritz opened this issue Aug 8, 2019 · 6 comments

Comments

@domoritz
Copy link
Member

domoritz commented Aug 8, 2019

By adding a signal to listen to changes of https://vega.github.io/vega/docs/expressions/#containerSize or (probably better) use autosize: 'fit'.

@josesaranda
Copy link

To support parent container resize detector you can't do it with vega-spec. As you said in the previous link explain how to adjust size to window size but not to the container size.

@domoritz
Copy link
Member Author

domoritz commented Aug 8, 2019

I'm not following.

containerSize gives you the size of the container.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 400,
  "height": 200,
  "padding": 5,
  "signals": [
    {
      "name": "size",
      "update": "containerSize()",
      "on": [
        {
          "events": {
            "source": "window",
            "type": "resize"
          },
          "update": "containerSize()"
        }
      ]
    }
  ],

  "marks": [
    {
      "type": "text",
      "encode": {
        "enter": {
          "align": {"value": "center"},
          "baseline": {"value": "bottom"},
          "fill": {"value": "black"}
        },
        "update": {
          "x": {"signal": "width", "mult": 0.5},
          "y": {"signal": "height", "mult": 0.5},
          "text": {"signal": "'size: ' + size"}
        }
      }
    }
  ]
}

Having said that, a better option may be to just use the autosize feature with fit ( https://vega.github.io/vega/docs/specification/).

@josesaranda
Copy link

What's about that? vega/vega#755 (comment)
You try to do that without javascript code but in your comment in another issue you said that it is necessary.

@josesaranda
Copy link

I tried before without any kind of javascript code using only containerSize as described in vega but it not work for me.

@domoritz
Copy link
Member Author

domoritz commented Aug 8, 2019

I think that was before containerSize and better support for autosize: 'fit'. I think the latter should work. Have you tried it?

If it doesn't work we can use JavaScript but I'd like to avoid it. Does this sound like a good plan to you?

@josesaranda
Copy link

Yes i tried the latter but won't work. I don't like to do that using Javascript but i think there isn't another way to do that. Please approve it! You make my life easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants