-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
59 lines (53 loc) · 1.88 KB
/
test.js
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
People = new Meteor.Collection("people");
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
if (Meteor.isClient) {
Template.hello.rendered = function() {
var chart = nv.models.lineChart()
.margin({left: 100}) //Adjust chart margins to give the x-axis some breathing room.
.useInteractiveGuideline(true) //We want nice looking tooltips and a guideline!
.transitionDuration(350) //how fast do you want the lines to transition?
.showLegend(true) //Show the legend, allowing users to turn on/off line series.
.showYAxis(true) //Show the y-axis
.showXAxis(true) //Show the x-axis
;
nv.addGraph(function() {
chart.xAxis.axisLabel('Person number').tickFormat(d3.format('d'));
chart.yAxis.axisLabel('Age (years)').tickFormat(d3.format('d'));
d3.select('#chart svg').datum(
[{ values: People.find().fetch(), key: 'Age' }]
).call(chart);
nv.utils.windowResize(function() { chart.update(); });
return chart;
});
this.autorun(function () {
d3.select('#chart svg').datum(
[{ values: People.find().fetch(), key: 'Age' }]
).call(chart);
chart.update();
});
};
Template.hello.events({
'click #addDataButton': function() {
var age = getRandomInt(13, 89);
var lastPerson = People.findOne({}, {fields:{x:1},sort:{x:-1},limit:1,reactive:false});
if (lastPerson) {
People.insert({x:(lastPerson.x + 1), y:age});
} else {
People.insert({x:1, y:age});
}
},
'click #removeDataButton': function() {
var lastPerson = People.findOne({}, {fields:{x:1},sort:{x:-1},limit:1,reactive:false});
if (lastPerson) {
People.remove(lastPerson._id);
}
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}