File tree Expand file tree Collapse file tree 2 files changed +50
-2
lines changed
src/legacy/core_plugins/vega/public Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,49 @@ describe('VegaVisualizations', () => {
188188
189189 } ) ;
190190
191+ it ( 'should add a small subpixel value to the height of the canvas to avoid getting it set to 0' , async ( ) => {
192+ let vegaVis ;
193+ try {
194+
195+ vegaVis = new VegaVisualization ( domNode , vis ) ;
196+ const vegaParser = new VegaParser ( `{
197+ "$schema": "https://vega.github.io/schema/vega/v3.json",
198+ "marks": [
199+ {
200+ "type": "text",
201+ "encode": {
202+ "update": {
203+ "text": {
204+ "value": "Test"
205+ },
206+ "align": {"value": "center"},
207+ "baseline": {"value": "middle"},
208+ "xc": {"signal": "width/2"},
209+ "yc": {"signal": "height/2"}
210+ fontSize: {value: "14"}
211+ }
212+ }
213+ }
214+ ]
215+ }` , new SearchCache ( ) ) ;
216+ await vegaParser . parseAsync ( ) ;
217+
218+ domNode . style . width = '256px' ;
219+ domNode . style . height = '256px' ;
220+
221+ await vegaVis . render ( vegaParser , { data : true } ) ;
222+ const vegaView = vegaVis . _vegaView . _view ;
223+ expect ( vegaView . height ( ) ) . to . be ( 250.00000001 ) ;
224+
225+ vegaView . height ( 250 ) ;
226+ await vegaView . runAsync ( ) ;
227+ // as soon as this test fails, the workaround with the subpixel value can be removed.
228+ expect ( vegaView . height ( ) ) . to . be ( 0 ) ;
229+ } finally {
230+ vegaVis . destroy ( ) ;
231+ }
232+ } ) ;
233+
191234 } ) ;
192235
193236
Original file line number Diff line number Diff line change @@ -195,8 +195,13 @@ export class VegaBaseView {
195195 const heightExtraPadding = 6 ;
196196 const width = Math . max ( 0 , this . _$container . width ( ) - this . _parser . paddingWidth ) ;
197197 const height = Math . max ( 0 , this . _$container . height ( ) - this . _parser . paddingHeight ) - heightExtraPadding ;
198- if ( view . width ( ) !== width || view . height ( ) !== height ) {
199- view . width ( width ) . height ( height ) ;
198+ // Somehow the `height` signal in vega becomes zero if the height is set exactly to
199+ // an even number. This is a dirty workaround for this.
200+ // when vega itself is updated again, it should be checked whether this is still
201+ // necessary.
202+ const adjustedHeight = height + 0.00000001 ;
203+ if ( view . width ( ) !== width || view . height ( ) !== adjustedHeight ) {
204+ view . width ( width ) . height ( adjustedHeight ) ;
200205 return true ;
201206 }
202207 return false ;
You can’t perform that action at this time.
0 commit comments