Polymer 1.x: Data binding -
i want select states in <google-chart>
geo
map element shown in jsbin.
when select state, expect change color (to dark teal) instead, stays same color (light grey).
follow these steps recreate problem:
- open jsbin.
- in section
dom-module
><script>
>properties
>items
>value
, change array['alabama', 0]
['alabama', 1]
. - notice state of alabama changes color light grey dark teal.
- hover mouse on state of alabama.
- notice value of
select
variable1
state of alabama (and0
other states). - return value of array
['alabama', 0]
. - note previous step proves code generating geochart behaves expected when
items
property manually mutated. - here's trouble begins...
- click state of alabama.
- in console, notice value of
items[1]
array['alabama', 1]
. - notice
select
value0
(unlike case when manually changed above).
what problem here?
i'm uncertain but perhaps solution involves implementing advice?
when handling events generated
dom-repeat
template instance, want map element firing event model data generated item.
but how 1 implement solution in case? or solution?
what solution? please show working in jsbin.
http://jsbin.com/pilotazifa/edit?html,console,output<!doctype html> <head> <meta charset="utf-8"> <base href="https://polygit.org/components/"> <script src="webcomponentsjs/webcomponents-lite.min.js"></script> <link href="polymer/polymer.html" rel="import"> <link href="google-chart/google-chart.html" rel="import"> </head> <body> <dom-module id="x-element"> <template> <style> google-chart { width: 100%; max-height: 300px; } </style> <button on-tap="_show">show</button> <google-chart id="geochart" type="geo" options={{options}} data={{items}} on-google-chart-select="_ongooglechartselect" ></google-chart> </template> <script> (function(){ polymer({ is: 'x-element', properties: { items: { type: array, notify: true, reflecttoattribute: true, value: function() { return [['state', 'select'], ['alabama', 0], ['alaska', 0], ['arizona', 0], ['arkansas', 0], ['california', 0], ['colorado', 0], ['connecticut', 0], ['delaware', 0], ['florida', 0], ['georgia', 0], ['hawaii', 0], ['iowa', 0], ['idaho', 0], ['illinois', 0], ['indiana', 0], ['kansas', 0], ['kentucky', 0], ['louisiana', 0], ['massachusetts', 0], ['maryland', 0], ['maine', 0], ['michigan', 0], ['minnesota', 0], ['missouri', 0], ['mississippi', 0], ['montana', 0], ['north carolina', 0], ['north dakota', 0], ['nebraska', 0], ['new hampshire', 0], ['new jersey', 0], ['new mexico', 0], ['nevada', 0], ['new york', 0], ['ohio', 0], ['oklahoma', 0], ['oregon', 0], ['pennsylvania', 0], ['rhode island', 0], ['south carolina', 0], ['south dakota', 0], ['tennessee', 0], ['texas', 0], ['utah', 0], ['virginia', 0], ['vermont', 0], ['washington', 0], ['wisconsin', 0], ['west virginia', 0], ['wyoming', 0]]; } }, options: { type: object, notify: true, reflecttoattribute: true, value: function() { return { region: 'us', displaymode: 'regions', resolution: 'provinces', legend: 'none', defaultcolor: '#f5f5f5', coloraxis: { colors: ['#f5f5f5', '#455a64'], minvalue: 0, maxvalue: 1, } } } }, }, _ongooglechartselect: function(e) { var str = e.path[0].textcontent.split('select')[0].trim(), ar = this.items, = ar.length; while(i---1){ if(str === ar[i][0]){ this.set('items.' + + '.1', ar[i][1] ? 0 : 1); } } console.log(this.items); }, _show: function() { console.log(this.items); }, }); })(); </script> </dom-module> <x-element></x-element> </body> </html>
you have add function _ongooglechartselect in end after while. generate data again , draw chart.
this.$.geochart._datatable=this.$.geochart._createdatatable(this.items); this.$.geochart._chartobject.draw( this.$.geochart._datatable, this.$.geochart.options);
and can use
this.items[i]= ...
and not
// fire event every time , think in case dont need it. this.set(...)
because google-chart ask data ajax , data not binding. solution insert data functions draw chart.
Comments
Post a Comment