Vega: Handle no height/width with autosize=none (#16696)
This works around the issue described in https://github.com/vega/vega/issues/1146 With this patch, users will be able to set autosize=none, while at the same time rely on Kibana to set width/height. This will only be done when width & height are not set. Testing code: ```hjson { $schema: https://vega.github.io/schema/vega/v3.0.json autosize: none padding: {left: 32, bottom: 24, top: 10, right: 6} background: "#dbb" scales: [ { name: x type: band range: width domain: ["a", "b"] paddingOuter: 0.05 paddingInner: 0.95 } { name: y type: linear range: height domain: [0, 100] } ] data: [ { name: edges values: [ {x1: "a", x2: "b", y1: 50, y2: 50, value: 100} ] transform: [ { type: linkpath orient: horizontal shape: {signal: "'diagonal'"} sourceY: {expr: "scale('y', datum.y1)"} sourceX: {expr: "scale('x', datum.x1) + bandwidth('x')"} targetY: {expr: "scale('y', datum.y2)"} targetX: {expr: "scale('x', datum.x2)"} } { type: formula expr: range('y')[0]-scale('y', datum.value) as: strokeWidth } ] } ] axes: [ {orient: "bottom", scale: "x", zindex: 1} {orient: "left", scale: "y", zindex: 1} ] marks: [ { type: path name: edgeMark from: {data: "edges"} encode: { update: { strokeWidth: {field: "strokeWidth"} path: {field: "path"} } } } ] } ```
This commit is contained in:
parent
d250e661f3
commit
9062f116f2
|
@ -102,7 +102,17 @@ export class VegaParser {
|
|||
* @private
|
||||
*/
|
||||
_calcSizing() {
|
||||
this.useResize = !this.useMap && (this.spec.autosize === 'fit' || this.spec.autosize.type === 'fit');
|
||||
this.useResize = false;
|
||||
if (!this.useMap) {
|
||||
// when useResize is true, vega's canvas size will be set based on the size of the container,
|
||||
// and will be automatically updated on resize events.
|
||||
// We delete width & height if the autosize is set to "fit"
|
||||
// We also set useResize=true in case autosize=none, and width & height are not set
|
||||
const autosize = this.spec.autosize.type || this.spec.autosize;
|
||||
if (autosize === 'fit' || (autosize === 'none' && !this.spec.width && !this.spec.height)) {
|
||||
this.useResize = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Padding is not included in the width/height by default
|
||||
this.paddingWidth = 0;
|
||||
|
|
Loading…
Reference in a new issue