1. Simon Cross
  2. distri

Commits

Simon Cross  committed 6d7ba9b

Chart title and footer setting.

  • Participants
  • Parent commits 6298e87
  • Branches default

Comments (0)

Files changed (2)

File lib/stats.js

View file
         var plot = distri.plots.all[opts.initial];
         plot.init({
             chart: chart,
-            coeffs: opts.coeffs
+            coeffs: opts.coeffs,
+            chart_title: opts.chart_title,
+            chart_footer: opts.chart_footer,
         });
         plot.update();
     }
 
         self.name = name;
         self.title = opts.title || name;
+        self.footer = opts.footer || "";
         self.setup_chart = opts.setup_chart;
         self.setup_coeffs = opts.setup_coeffs;
         self.data = opts.data;
 
         self.init = function(opts) {
             self.chart = opts.chart;
+            self.setup_chart_title(opts.chart_title);
+            self.setup_chart_footer(opts.chart_footer);
             self.setup_chart(self.chart);
+
             self.$coeffs = opts.coeffs;
             self.$coeffs.empty;
             self.coeffs = [];
             self.setup_coeffs(self);
         };
 
+        self.setup_chart_title = function(chart_title) {
+            chart_title.empty();
+            chart_title.text(self.title);
+        };
+
+        self.setup_chart_footer = function(chart_footer) {
+            chart_footer.empty();
+            chart_footer.html(self.footer);
+        };
+
         self.setup_coeff = function(coeff) {
             coeff = _.defaults(coeff, {
                 label_id: "label_" + coeff.name,
 
 })(distri.plots = {});
 
-// binomial plot
+// plot: binomial distribution
 
 (function() {
     new distri.plots.Plot("binomial", {
         title: "Binomial distribution",
+        footer: 'See <a href="http://en.wikipedia.org/wiki/Binomial_distribution">Wikipedia</a> for details.',
         setup_chart: function(chart) {
             var x = chart.addCategoryAxis("x", "trials");
             x.addOrderRule("trials");
         }
     });
 })();
+
+// plot: kingmans formula
+
+(function() {
+    new distri.plots.Plot("kingmans", {
+        title: "Kingman's formula",
+        setup_chart: function(chart) {
+            var x_rho = chart.addCategoryAxis("x", "rho");
+            x_rho.addOrderRule("rho");
+            var y_wait = chart.addMeasureAxis("y", "wait");
+            chart.addSeries(null, dimple.plot.line, [x_rho, y_wait]);
+        },
+        setup_coeffs: function(plot) {
+            plot.setup_coeff({
+                name: "tau",
+                min: 1,
+                max: 50,
+                step: 1,
+                initial: 15
+            });
+        },
+        data: function(tau) {
+            var data = [];
+            var kingman = function(rho) {
+                return (rho / (1 - rho));
+            };
+            var rho = 0.0, rho_step = 1.0 / 100;
+            for (var i = 0; i <= 95; i++) {
+                rho += rho_step;
+                data[i] = {
+                    rho: rho,
+                    wait: kingman(rho)
+                }
+            }
+            return data;
+        }
+    });
+})();

File stats.html

View file
   <script src="lib/stats.js"></script>
 </head>
 <body>
-  <h1>Binomial distribution</h1>
+  <h1 id="chart_title">Unset</h1>
 
   <div style="width: 100%">
 
     <div id="column-1" style="padding: 0px; margin: 0px; float: left;">
-      <div id="chart"></div>
-      <div>See <a href="http://en.wikipedia.org/wiki/Binomial_distribution">Wikipedia</a> for details.</div>
+      <div id="chart_plot"></div>
+      <div id="chart_footer"></div>
     </div>
 
     <div id="column-2" style="padding: 0px; margin: 0px; float: left;">
       <h2>Co-efficients:</h2>
-      <div id="coeffs">
+      <div id="chart_coeffs">
       </div>
       <h2>Charts:</h2>
       <div id="chart_selector"></div>
   <script type="text/javascript">
     $(function () {
         distri.attach({
-            chart: "#chart",
-            coeffs: $("#coeffs"),
+            chart: "#chart_plot",
+            coeffs: $("#chart_coeffs"),
             chart_selector: $("#chart_selector"),
+            chart_title: $("#chart_title"),
+            chart_footer: $("#chart_footer"),
             initial: "binomial"
         });
     });