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

What is the best practice for resizing vega lite graph? #345

Open
mapringg opened this issue Dec 9, 2020 · 2 comments
Open

What is the best practice for resizing vega lite graph? #345

mapringg opened this issue Dec 9, 2020 · 2 comments

Comments

@mapringg
Copy link

mapringg commented Dec 9, 2020

The code below allows me to resize, but it fails if I use any graph that have a column property. Also, I feel like my current method is very hacky and may not be the correct method for resizing.

const [spec, setSpec] = useState({
  height: 'container',
  width: 'container',
  mark: {
    type: 'bar',
  },
  encoding: {
    // column: { field: 'brand', type: 'nominal', title: null },
    y: {
      field: 'sov',
      type: 'quantitative',
      title: null,
    },
    x: { field: 'date', type: 'ordinal', timeUnit: 'utcmonth', title: null },
    color: { field: 'brand', type: 'nominal' },
  },
  data: {
    name: 'multi',
  },
})
useEffect(() => {
  setSpec({ ...spec, height: size.height, width: size.width })
}, [size])
const handleResize = (e, data) => {
  const { width, height } = data.size
  setSize({
    width,
    height,
  })
}
<ResizableBox
  width={size.width}
  height={size.height}
  onResize={handleResize}
  >
  <VegaLite
      spec={spec}
      data={data}
      actions={false}
  />
</ResizableBox>

Update: Updating the width and height props of the vega lite component does not trigger a rerender, but an update to spec does.

@PhML
Copy link

PhML commented Mar 2, 2021

I use a similar method with Vega component and have similar issue when I use vconcat oh hconcat in a vega-lite spec.
@mapringg as a workaround I replace my Vega-Lite spec with its Vega compiled version (with a Vega component you can use either Vega or Vega-Lite spec).
Surprisingly, resizing is then possible.

@domoritz
Copy link
Member

domoritz commented Mar 2, 2021

Vega-Lite just compiles to Vega so the behavior should be exactly the same.

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

No branches or pull requests

3 participants