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

Introduce workaround for vega height bug #31461

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,49 @@ describe('VegaVisualizations', () => {

});

it('should add a small subpixel value to the height of the canvas to avoid getting it set to 0', async () => {
let vegaVis;
try {

vegaVis = new VegaVisualization(domNode, vis);
const vegaParser = new VegaParser(`{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"marks": [
{
"type": "text",
"encode": {
"update": {
"text": {
"value": "Test"
},
"align": {"value": "center"},
"baseline": {"value": "middle"},
"xc": {"signal": "width/2"},
"yc": {"signal": "height/2"}
fontSize: {value: "14"}
}
}
}
]
}`, new SearchCache());
await vegaParser.parseAsync();

domNode.style.width = '256px';
domNode.style.height = '256px';

await vegaVis.render(vegaParser, { data: true });
const vegaView = vegaVis._vegaView._view;
expect(vegaView.height()).to.be(250.00000001);

vegaView.height(250);
await vegaView.runAsync();
// as soon as this test fails, the workaround with the subpixel value can be removed.
expect(vegaView.height()).to.be(0);
} finally {
vegaVis.destroy();
}
});

});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ export class VegaBaseView {
const heightExtraPadding = 6;
const width = Math.max(0, this._$container.width() - this._parser.paddingWidth);
const height = Math.max(0, this._$container.height() - this._parser.paddingHeight) - heightExtraPadding;
if (view.width() !== width || view.height() !== height) {
view.width(width).height(height);
// Somehow the `height` signal in vega becomes zero if the height is set exactly to
// an even number. This is a dirty workaround for this.
// when vega itself is updated again, it should be checked whether this is still
// necessary.
const adjustedHeight = height + 0.00000001;
if (view.width() !== width || view.height() !== adjustedHeight) {
view.width(width).height(adjustedHeight);
return true;
}
return false;
Expand Down