Skip to content

Commit

Permalink
Pass size down to vega and trigger a resize. view API not working, so…
Browse files Browse the repository at this point in the history
… use brute force and redraw. jupyter-incubator#3

(c) Copyright IBM Corp. 2016
  • Loading branch information
peller committed Aug 17, 2016
1 parent def85d7 commit 7d8bcf7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
13 changes: 11 additions & 2 deletions urth-viz-explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="import" href="../polymer/polymer.html">

<link rel="import" href="../urth-core-behaviors/error-display-behavior.html">
<!-- <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html"> -->
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../urth-viz-behaviors/urth-viz-selection-behavior.html">

<link rel="import" href="../iron-collapse/iron-collapse.html">
Expand Down Expand Up @@ -347,11 +347,20 @@
],

behaviors: [
// Polymer.IronResizableBehavior,
Polymer.IronResizableBehavior,
Urth.DisplayErrorBehavior,
Urth.VizSelectionBehavior
],

listeners: {
'iron-resize': '_resize'
},

_resize: function() {
var vega = this.$$('urth-viz-vega');
if (vega) vega._resize();
},

_closeEditDialog: function(event) {
var specEditor = this.$['spec-editor'];
if (event.detail.confirmed) {
Expand Down
27 changes: 19 additions & 8 deletions urth-viz-vega.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@
},

_specChanged: function(newSpec) {
if (!this.isReady) { return; }
if (!this.view) { return; }

this.render();
},

_resize: function() {
if (!this.view) { return; }

// TODO
this.view.update();
if (!this.view || !this.spec) { return; }

// spec width/height represent plot area, not total canvas. Use fudge factor, for now,
// to account for labels, axes
var style = window.getComputedStyle(this.parentNode),
width = Math.max(200, parseInt(style.width) - 150),
height = Math.max(200, parseInt(style.height) - 150);
// this.view.width(width).height(height).update();
this.spec.width = width; this.spec.height = height; this.render();
},

created: function() {
Expand Down Expand Up @@ -129,14 +134,20 @@
}
},

ready: function() {
attached: function() {
var display = window.getComputedStyle(this).display;
if (display === 'none' || document.readyState !== 'complete') {
this.async(this.ready, 200);
this.async(this.attached, 200);
return;
}

this.isReady = true;
var style = window.getComputedStyle(this.$.container),
width = parseInt(style.width) || 200,
height = parseInt(style.height) || 200;

this.spec.width = Math.max(200, parseInt(style.width) - 150);
this.spec.height = Math.max(200, parseInt(style.height) - 150);

this.render();
},

Expand Down

0 comments on commit 7d8bcf7

Please sign in to comment.