|
104 | 104 | <urth-core-dataframe |
105 | 105 | ref$="{{ref}}" |
106 | 106 | value="{{df}}" |
107 | | - limit="{{limit}}" |
108 | 107 | row-as-object="true" |
109 | 108 | on-rows-changed="_rowsChanged" |
110 | 109 | on-columns-changed="_selectDefaults" |
|
129 | 128 | <paper-item name="circle">Scatter Chart</paper-item> |
130 | 129 | </paper-listbox> |
131 | 130 | </paper-dropdown-menu> |
132 | | - <paper-input label="Limit" value="{{limit}}"></paper-input> |
| 131 | + <paper-input label="Limit" type="number" value="{{limit}}"></paper-input> |
133 | 132 | </paper-card-collapse> |
134 | 133 |
|
135 | 134 | <!-- select viz properties --> |
|
149 | 148 |
|
150 | 149 | <!-- dataframe query --> |
151 | 150 | <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> |
153 | 152 | </paper-card-collapse> |
154 | 153 | </iron-collapse> |
155 | 154 |
|
|
234 | 233 | * @private |
235 | 234 | */ |
236 | 235 | options: { |
237 | | - type: Array |
| 236 | + type: Array, |
| 237 | + value: function() { return []; } |
238 | 238 | }, |
239 | 239 |
|
240 | 240 | /** |
|
395 | 395 | var dataframe = event.target, |
396 | 396 | types = dataframe.value.columnTypes.map(function(datatype) { return this._columnType(datatype); }, this); |
397 | 397 |
|
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; |
399 | 400 |
|
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 |
401 | 402 |
|
402 | | - this.options && this.options.some(function(option, i) { |
| 403 | + var independentOption, dependentOption; |
| 404 | + |
| 405 | + this.options.some(function(option, i) { |
403 | 406 | if (option.prop === 'x') { |
404 | | - independentIndex = 'options.' + i + '.index'; |
| 407 | + independentOption = i; |
405 | 408 | return true; |
406 | 409 | } |
407 | | - }) && this.set(independentIndex, null); |
| 410 | + }); |
408 | 411 |
|
409 | | - this.options && this.options.some(function(option, i) { |
| 412 | + this.options.some(function(option, i) { |
410 | 413 | if (option.prop === 'y') { |
411 | | - dependentIndex = 'options.' + i + '.index'; |
| 414 | + dependentOption = i; |
412 | 415 | return true; |
413 | 416 | } |
414 | | - }) && this.set(dependentIndex, null); |
| 417 | + }); |
415 | 418 |
|
416 | | - this.async(function() { |
| 419 | + if (independentOption !== undefined |
| 420 | + && dataframe.value.columns.indexOf(this.get('options.' + independentOption + '.column')) == -1) { |
417 | 421 | var independent = types.indexOf('temporal'); |
418 | 422 | if (independent == -1) independent = types.indexOf('quantitative'); |
419 | 423 | if (independent == -1) independent = 0; |
420 | 424 | 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 | + } |
423 | 430 |
|
| 431 | + if (dependentOption !== undefined |
| 432 | + && dataframe.value.columns.indexOf(this.get('options.' + dependentOption + '.column')) == -1) { |
424 | 433 | var dependent = types.indexOf('quantitative'); |
425 | 434 | if (dependent == -1) dependent = 0; |
426 | 435 | if (dependent == independent) dependent++; |
427 | 436 | 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 | + } |
431 | 442 | }, |
432 | 443 |
|
433 | 444 | _rowsChanged: function(event) { |
|
472 | 483 | this.options = this._optionsMap[this.type]; |
473 | 484 |
|
474 | 485 | 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 | + }); |
478 | 502 | } 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 |
481 | 504 | var dataframe = this.querySelector('urth-core-dataframe'); |
482 | 505 |
|
483 | | - // manually bind values to 'df' property if using child |
484 | 506 | if (dataframe) { |
| 507 | + // manually bind values to 'df' |
485 | 508 | this.df = dataframe.value; |
| 509 | + |
| 510 | + // and set up properties and events |
486 | 511 | dataframe.rowAsObject = true; |
487 | 512 | dataframe.limit = this.limit; |
488 | | - this.addEventListener('limit-changed', function(event) { |
489 | | - dataframe.limit = event.detail.value; |
490 | | - }); |
491 | 513 | dataframe.addEventListener('value-changed', this._dataChanged.bind(this)); |
492 | 514 | dataframe.addEventListener('columns-changed', function (event) { |
493 | 515 | this.async(this._selectDefaults.bind(this, event)); |
494 | 516 | }.bind(this)); |
495 | 517 | dataframe.addEventListener('rows-changed', function(event) { |
496 | 518 | this.async(this._rowsChanged.bind(this, event)); |
497 | 519 | }.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 | + }); |
498 | 525 | } |
499 | 526 | } |
500 | 527 | } |
|
0 commit comments