Last active
August 29, 2015 14:16
-
-
Save robfallows/9bd0e199fcbcf456d607 to your computer and use it in GitHub Desktop.
Simple tunguska:gauge example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0, width=device-width"> | |
</head> | |
<body> | |
{{> gauge id="demo" style="basic"}} | |
</body> | |
<template name="gauge"> | |
<div id="demo" style="display:inline-block;width:200px;height:200px;"></div> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GaugeData = new Mongo.Collection('gauge-data'); | |
Template.gauge.rendered = function() { | |
var self = this; | |
self.gauge = new TunguskaGauge({ | |
id: self.data.id, | |
theme: self.data.style | |
}); | |
self.subscribe('current-gauge-data', function() { // Uses new Meteor 1.0.4 Template.subscribe() method | |
self.autorun(function() { | |
self.gauge.set(GaugeData.findOne({_id:'demo'}).value); | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.publish('current-gauge-data', function() { | |
var init = false; | |
var self = this; | |
Meteor.setInterval(function() { | |
var ran = Math.floor(Math.random() * 101); | |
if (init) { | |
self.changed('gauge-data', 'test', {value:ran}); | |
} else { | |
self.added('gauge-data', 'test', {value:ran}); | |
} | |
self.ready(); | |
init = true; | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, this looks amazing!