-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbound-layout.js
More file actions
76 lines (72 loc) · 1.69 KB
/
bound-layout.js
File metadata and controls
76 lines (72 loc) · 1.69 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import debug from 'debug';
const log = debug('ember-cli-plotly:plot-ly-component');
const n = Math.pow(2,16);
const x = new Array(n).fill(0).map((z,i) => 100*(2*i/(n-1)-1)); // [-10, ..., 10]
export default class BoundLayoutController extends Controller {
constructor() {
super(...arguments);
this.setProperties({
xaxis: {
min: -10,
max: 10
},
yaxis: {
min: -2,
max: 2
},
chartData: [{
name: 'Very long line',
x: [-1E6,1E6],
y: [1E6,-1E6]
},{
name: 'x',
x,
y: x
},{
name: '1/x',
x,
y: x.map(x => 1/x)
},{
name: 'normalized sinc',
x,
y: x.map(x => Math.sin(Math.PI*x)/(Math.PI*x))
},{
name: 'sin(1/x)',
x,
y: x.map(x => Math.sin(1/x))
},{
name: 'log2',
x,
y: x.map(x => Math.log2(x))
},{
name: '2^x',
x,
y: x.map(x => Math.pow(2,x))
}
]
});
}
@computed('xaxis.{min,max}', 'yaxis.{min,max}')
get chartLayout() {
log('computing chartLayout');
const getRange = (axisPropName) => {
let min = parseFloat(this.get(`${axisPropName}.min`));
if (typeof min !== 'number')
min = 0;
let max = parseFloat(this.get(`${axisPropName}.max`));
if (typeof max !== 'number')
max = min + 1;
return [min, max];
};
return {
xaxis: {
range: getRange('xaxis')
},
yaxis: {
range: getRange('yaxis')
}
};
}
}