-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcheckboxes.js
More file actions
51 lines (47 loc) · 1.47 KB
/
checkboxes.js
File metadata and controls
51 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { A } from '@ember/array';
import Controller from '@ember/controller';
import EmberObject from '@ember/object';
import { computed } from '@ember/object';
const n = 51;
const x = new Array(n).fill(0).map((z,i) => 10*(2*i/(n-1) - 1)); // [-10, ..., 10]
const noise = x.map(() => 10*(Math.random()-0.5));
export default class CheckBoxesController extends Controller {
constructor() {
super(...arguments);
// In this example the x & y arrays here should be considered static
// (that is, the `chartData` computed property is not "watching" them)
// Also note that use of A and EmberObject.create are only needed if
// EmberENV.EXTEND_PROTOTYPES === false
this.set('dataSets', A([{
name: 'absolute',
isPassedToPlotly: false,
x,y: x.map(Math.abs)
}, {
name: 'linear',
isPassedToPlotly: false,
x,y: x.map(x => x/2+1)
}, {
name: 'cosine',
isPassedToPlotly: true,
x,y: x.map(Math.cos)
}, {
name: 'cubic',
isPassedToPlotly: true,
x,y: x.map(x => (x-5)*(x)*(x+5)/100)
}, {
name: 'mod5',
isPassedToPlotly: false,
x,y: x.map(x => x%5)
}, {
name: 'noise',
isPassedToPlotly: false,
x,y: noise
}
].map(s => EmberObject.create(s))));
}
@computed('dataSets.@each.isPassedToPlotly')
get chartData() {
const dataSets = this.dataSets;
return dataSets.filterBy('isPassedToPlotly', true);
}
}