title: Meteor: How to Perform Calculations Client-Side on Mongo Data
body: <p>In my Meteor app, I've successfully published data server-side and subscribed to that data client-side. Now, rather than pushing raw data straight to the client's screen, I want to store it as a javascript object, perform some calculations on it (number crunching), and render the result on the client's screen (within an HTML5 canvas element). Every time Mongo is updated, the javascript code should re-run (i.e. the js object is re-set, calculations are performed again from that object, and the new results are rendered on the canvas).</p>
  
  <p>I can grab hold of Mongo data using the <code>Template.example.helpers</code> block and show that <em>directly</em> in the client as follows:</p>
  
  <hr>
  
  <pre><code>Meteor.subscribe('collection','query');
  
  Template.example.helpers({
    sampleData: function(){
      return Collection.findOne({query:`query`});
    }
  });
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;template name="example"&gt;
    &lt;div&gt;
      {{sampleData.last}}
    &lt;/div&gt;
    &lt;canvas id="test-canvas"&gt;&lt;/canvas&gt;
  &lt;/template&gt;
  </code></pre>
  
  <hr>
  
  <p>But what I'm trying to do is grab hold of this data before pushing to the client's screen, within the <code>Template.example.rendered</code> block:</p>
  
  <pre><code>Meteor.subscribe('collection','query');
  
  Template.example.rendered = function(){
    // define HTML5 canvas and context variables
    var canvas = $("#test-canvas")[0];
    var context = canvas.getContext("2d");
    // store Mongo data as Javascript variable
    // loop over this variable and perform calculations
      // draw results to the canvas
  }
  </code></pre>
  
  <p>Am I approaching this the right way? If so, how can I achieve it? Thanks!</p>