Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit d494ac5

Browse files
authored
Merge pull request #46 from peller/ref-dataframe
Fix #33 #44 #45
2 parents 9ffb85d + 934bf49 commit d494ac5

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

urth-viz-explorer.html

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
<urth-core-dataframe
105105
ref$="{{ref}}"
106106
value="{{df}}"
107-
limit="{{limit}}"
108107
row-as-object="true"
109108
on-rows-changed="_rowsChanged"
110109
on-columns-changed="_selectDefaults"
@@ -129,7 +128,7 @@
129128
<paper-item name="circle">Scatter Chart</paper-item>
130129
</paper-listbox>
131130
</paper-dropdown-menu>
132-
<paper-input label="Limit" value="{{limit}}"></paper-input>
131+
<paper-input label="Limit" type="number" value="{{limit}}"></paper-input>
133132
</paper-card-collapse>
134133

135134
<!-- select viz properties -->
@@ -149,7 +148,7 @@
149148

150149
<!-- dataframe query -->
151150
<paper-card-collapse class="viz-explorer-controls-section" heading="Query">
152-
<content id="viz-query" select="urth-viz-query"></content>
151+
<content select="urth-viz-query"></content>
153152
</paper-card-collapse>
154153
</iron-collapse>
155154

@@ -234,7 +233,8 @@
234233
* @private
235234
*/
236235
options: {
237-
type: Array
236+
type: Array,
237+
value: function() { return []; }
238238
},
239239

240240
/**
@@ -395,39 +395,50 @@
395395
var dataframe = event.target,
396396
types = dataframe.value.columnTypes.map(function(datatype) { return this._columnType(datatype); }, this);
397397

398-
var independentIndex, dependentIndex;
398+
// in case value-changed hasn't fired yet, this.df will be needed by observers
399+
this.df = dataframe.value;
399400

400-
// regenerate both dropdown label based on latest listbox items
401+
// regenerate both dropdown label based on latest listbox items where current selection is no longer valid
401402

402-
this.options && this.options.some(function(option, i) {
403+
var independentOption, dependentOption;
404+
405+
this.options.some(function(option, i) {
403406
if (option.prop === 'x') {
404-
independentIndex = 'options.' + i + '.index';
407+
independentOption = i;
405408
return true;
406409
}
407-
}) && this.set(independentIndex, null);
410+
});
408411

409-
this.options && this.options.some(function(option, i) {
412+
this.options.some(function(option, i) {
410413
if (option.prop === 'y') {
411-
dependentIndex = 'options.' + i + '.index';
414+
dependentOption = i;
412415
return true;
413416
}
414-
}) && this.set(dependentIndex, null);
417+
});
415418

416-
this.async(function() {
419+
if (independentOption !== undefined
420+
&& dataframe.value.columns.indexOf(this.get('options.' + independentOption + '.column')) == -1) {
417421
var independent = types.indexOf('temporal');
418422
if (independent == -1) independent = types.indexOf('quantitative');
419423
if (independent == -1) independent = 0;
420424
types[independent] = null;
421-
this.set('xOption.index', independent);
422-
if (independentIndex !== undefined) this.set(independentIndex, independent);
425+
this.set('options.' + independentOption + '.index', null);
426+
this.async(function() {
427+
this.set('options.' + independentOption + '.index', independent);
428+
});
429+
}
423430

431+
if (dependentOption !== undefined
432+
&& dataframe.value.columns.indexOf(this.get('options.' + dependentOption + '.column')) == -1) {
424433
var dependent = types.indexOf('quantitative');
425434
if (dependent == -1) dependent = 0;
426435
if (dependent == independent) dependent++;
427436
types[dependent] = null;
428-
this.set('yOption.index', dependent);
429-
if (dependentIndex !== undefined) this.set(dependentIndex, dependent);
430-
});
437+
this.set('options.' + dependentOption + '.index', null);
438+
this.async(function() {
439+
this.set('options.' + dependentOption + '.index', dependent);
440+
});
441+
}
431442
},
432443

433444
_rowsChanged: function(event) {
@@ -472,29 +483,45 @@
472483
this.options = this._optionsMap[this.type];
473484

474485
if (this.ref) {
475-
// Move template-generated query/dataframe to content
476-
//TODO: not ready until template dom-if is complete. Is there a callback for this?
477-
this.async(function() { this.$['viz-query'].appendChild(this.$$('urth-viz-query')); }, 1000);
486+
// template not ready until dom-if is stamped, so use microtask
487+
this.async(function() {
488+
// Move template-generated dataframe from shadow DOM to content DOM
489+
Polymer.dom(this).appendChild(this.$$('urth-viz-query'));
490+
491+
// Call ready() directly to bind to new DOM document
492+
var dataframe = this.querySelector('urth-core-dataframe');
493+
dataframe.ready();
494+
495+
dataframe.limit = this.limit;
496+
497+
// Bind limit to dataframe, but coerce to Number
498+
this.addEventListener('limit-changed', function(event) {
499+
dataframe.limit = +event.detail.value;
500+
});
501+
});
478502
} else {
479-
// If no dataframe instance is specified with `ref`, look instead for a child dataframe
480-
// and bind that value to df whenever it changes,
503+
// If no dataframe instance is specified with `ref`, look instead for a provided child dataframe
481504
var dataframe = this.querySelector('urth-core-dataframe');
482505

483-
// manually bind values to 'df' property if using child
484506
if (dataframe) {
507+
// manually bind values to 'df'
485508
this.df = dataframe.value;
509+
510+
// and set up properties and events
486511
dataframe.rowAsObject = true;
487512
dataframe.limit = this.limit;
488-
this.addEventListener('limit-changed', function(event) {
489-
dataframe.limit = event.detail.value;
490-
});
491513
dataframe.addEventListener('value-changed', this._dataChanged.bind(this));
492514
dataframe.addEventListener('columns-changed', function (event) {
493515
this.async(this._selectDefaults.bind(this, event));
494516
}.bind(this));
495517
dataframe.addEventListener('rows-changed', function(event) {
496518
this.async(this._rowsChanged.bind(this, event));
497519
}.bind(this));
520+
521+
// Bind limit to dataframe, but coerce to Number
522+
this.addEventListener('limit-changed', function(event) {
523+
dataframe.limit = +event.detail.value;
524+
});
498525
}
499526
}
500527
}

urth-viz-query.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ <h3 class="query-label">Filters (matches all):</h3>
191191
// n-element array with shape to fit query form
192192
filters: {
193193
type: Array,
194-
value: function() { return [{ col: null, op: null, val: null }]; }
194+
value: function() { return []; }
195195
},
196196

197197
groups: {
198198
type: Array,
199-
value: function() { return [{ col: null, aggregators: [] }]; }
199+
value: function() { return []; }
200200
}
201201
},
202202

0 commit comments

Comments
 (0)