diff --git a/addon/components/c3-chart.js b/addon/components/c3-chart.js index a0d1c83a..4cce2aa2 100644 --- a/addon/components/c3-chart.js +++ b/addon/components/c3-chart.js @@ -21,7 +21,7 @@ export default Component.extend({ // t/f data must by loaded after unload animation (400) // or chart will not properly render - later(this, function () { + later(() => { chart.load( // data, axis, color are only mutable elements get(this, 'data'), diff --git a/tests/dummy/app/controllers/events.js b/tests/dummy/app/controllers/events.js new file mode 100644 index 00000000..da14c31f --- /dev/null +++ b/tests/dummy/app/controllers/events.js @@ -0,0 +1,38 @@ +import Controller from '@ember/controller'; +import { computed } from '@ember/object'; +import { bind } from '@ember/runloop'; + +export default Controller.extend({ + message: null, + hover: null, + + data: computed('model', function () { + return { + columns: this.get('model'), + type: 'bar', + types: { + data3: 'spline', + data4: 'line', + }, + groups: [ + ['data1', 'data2'] + ], + + // https://balinterdi.com/blog/ember-dot-run-dot-bind/ + onclick: bind(this, this.get('actions.myClick')), + onmouseover: bind(this, this.get('actions.myMouseover')) + } + }), + + actions: { + myClick(d, i) { + this.set('message', `${d.name}, value: ${d.value}`); + if (d.name == 'data5') + alert(`Data 5 - you're a winner`); + }, + + myMouseover(d, i) { + this.set('hover', `${d.name}, value: ${d.value}`); + } + } +}); diff --git a/tests/dummy/app/routes/events.js b/tests/dummy/app/routes/events.js new file mode 100644 index 00000000..ee07a176 --- /dev/null +++ b/tests/dummy/app/routes/events.js @@ -0,0 +1,15 @@ +import Route from '@ember/routing/route'; + +export default Route.extend({ + model() { + return [ + ['data1', 30, 20, 50, 40, 60, 50], + ['data2', 200, 130, 90, 240, 130, 220], + ['data3', 130, 100, 140, 200, 150, 50], + ['data4', 300, 200, 160, 400, 250, 250], + ['data5', 200, 130, 90, 240, 130, 220], + ['data6', 130, 120, 150, 140, 160, 150], + ['data7', 90, 70, 20, 50, 60, 120], + ] + } +}); diff --git a/tests/dummy/app/templates/events.hbs b/tests/dummy/app/templates/events.hbs new file mode 100644 index 00000000..56a9bfb7 --- /dev/null +++ b/tests/dummy/app/templates/events.hbs @@ -0,0 +1,30 @@ +
+ +

Generated Chart

+

See the data in the JSON editor below.

+ +

Mouseover: {{hover}}

+

Mouse Click: {{message}}

+ {{c3-chart data=data}} + +

Usage In Ember

+

See example app source code on GitHub.

+
+ \{{c3-chart data=data}} +
+

You can edit the data for this chart in the editor below.

+ +
+ +

Chart Data Editor

+

+ Edit the data below, powered by + Ember JSONEditor, + to see the changes thanks to two-way data binding support. + The data below is from the + Combination Chart + in the C3 examples. +

+ {{json-editor json=model}} + +