Skip to content

Instantly share code, notes, and snippets.

@chhib
Last active August 29, 2015 14:14
Show Gist options
  • Save chhib/17238814d4a1e1941d79 to your computer and use it in GitHub Desktop.
Save chhib/17238814d4a1e1941d79 to your computer and use it in GitHub Desktop.
chartHandlers = {};
Template.metric.rendered = function () {
var self = this;
self.myDeps = Deps.autorun(function () {
// Get data from db
var calculatedData = Aggregates.find().fetch();
// find the container to put the graph in
var element = self.$('.chart').first();
// Do the graph, save a handler to be able to re-render
chartHandlers[element.attr('id')] = Morris.Area({
element: element.attr('id'),
hideHover: 'always',
data: data,
xkey: 'ymd',
xLabels: 'day',
ykeys: ykey, //['a'],
lineColors: ['#D09898'],
grid: false,
pointSize: 0,
lineWidth: 5,
smooth: false,
yLabelFormat: function (y) { return ''; },
xLabelFormat: function (x) { return ''; }
});
});
}
Template.metric.destroyed = function () {
// Remove if switching to a different view
this.myDeps.stop();
};
// Redraw if user resizes the window
var lazyLayout = _.debounce(function () {
_.each(chartHandlers, function (chart, id) {
chart.redraw();
});
}, 100);
$(window).resize(lazyLayout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment