PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/visualize/public/examples/bar.html

http://github.com/jspears/bobamo
HTML | 154 lines | 144 code | 10 blank | 0 comment | 0 complexity | c25743113ca84ea524785edea4f0bfd8 MD5 | raw file
Possible License(s): Apache-2.0
  1. <html>
  2. <head>
  3. <title>Backbone.d3 - Bar charts</title>
  4. <link rel="stylesheet" href="style.css" type="text/css" />
  5. <script src="loader.js" type="text/javascript"></script>
  6. <script src="../visualisations/bar.js" type="text/javascript"></script>
  7. <script type="text/javascript">
  8. $(function() {
  9. var DataPoint = Backbone.Model.extend({
  10. initialize: function(point) {
  11. this.set({
  12. id: point.id,
  13. x: point.x,
  14. y: point.y
  15. });
  16. }
  17. });
  18. var DataSeries = Backbone.d3.PlotCollection.extend({
  19. model : DataPoint,
  20. url : "bardata.json",
  21. // Needed for scolling plots
  22. fetch: function(){
  23. // No op
  24. console.log('fetching is a no op in this example');
  25. }
  26. });
  27. var series1 = new DataSeries();
  28. var plot1 = new Backbone.d3.Canned.Bar.View(series1, {div:'#plot1'});
  29. series1.reset([
  30. new DataPoint({x:1, y:6, id:1}),
  31. new DataPoint({x:2, y:4, id:2}),
  32. new DataPoint({x:3, y:2, id:3}),
  33. new DataPoint({x:4, y:4, id:4}),
  34. new DataPoint({x:5, y:6, id:5})
  35. ]);
  36. // evolve the dataset
  37. _.each(_.range(1,6), function(i, ii, l) {
  38. setTimeout(function() {
  39. m = plot1.collection.get(i);
  40. m.set({y:2*i});
  41. }, i * 1000);
  42. })
  43. var series2 = new DataSeries();
  44. var plot2 = new Backbone.d3.Canned.Bar.View(series2, {div:'#plot2', scrolling:true});
  45. series2.reset([
  46. new DataPoint({x:1, y:5, id:1}),
  47. new DataPoint({x:2, y:4, id:2}),
  48. new DataPoint({x:3, y:3, id:3}),
  49. new DataPoint({x:4, y:2, id:4}),
  50. new DataPoint({x:5, y:1, id:5})
  51. ]);
  52. // evolve the dataset
  53. _.each(_.range(1,6), function(i, ii, l) {
  54. setTimeout(function() {
  55. plot2.collection.add(new DataPoint({x:i+5, y:i*2, id:i}));
  56. }, i * 1000);
  57. })
  58. var series3 = new DataSeries();
  59. var caption = "**figure 3:** caption on the view using some markdown to describe this *sweet plot*, yo";
  60. var plot3 = new Backbone.d3.Canned.Bar.View(series3, {div:'#plot3', scrolling:true, caption:caption});
  61. series3.reset([
  62. new DataPoint({x:1, y:5, id:1}),
  63. new DataPoint({x:2, y:4, id:2}),
  64. new DataPoint({x:3, y:3, id:3}),
  65. new DataPoint({x:4, y:2, id:4}),
  66. new DataPoint({x:5, y:1, id:5})
  67. ]);
  68. // evolve the dataset
  69. _.each(_.range(1,6), function(i, ii, l) {
  70. setTimeout(function() {
  71. plot3.collection.add(new DataPoint({x:i+5, y:i*2, id:i}));
  72. }, i * 1000);
  73. })
  74. var caption = "**figure 4:** caption on the collection using some markdown to describe this *sweet plot*, yo";
  75. var series4 = new DataSeries([], {caption:caption});
  76. var plot4 = new Backbone.d3.Canned.Bar.View(series4, {div:'#plot4', scrolling:true});
  77. series4.reset([
  78. new DataPoint({x:1, y:5, id:1}),
  79. new DataPoint({x:2, y:4, id:2}),
  80. new DataPoint({x:3, y:3, id:3}),
  81. new DataPoint({x:4, y:2, id:4}),
  82. new DataPoint({x:5, y:1, id:5})
  83. ]);
  84. // evolve the dataset
  85. _.each(_.range(1,6), function(i, ii, l) {
  86. setTimeout(function() {
  87. plot4.collection.add(new DataPoint({x:i+5, y:i*2, id:i}));
  88. }, i * 1000);
  89. })
  90. });
  91. </script>
  92. </head>
  93. <body>
  94. <div id="container">
  95. <h1>Bar charts</h1>
  96. <p>Backbone-d3 currently supports two classes of bar chart; static and
  97. scrolling. They only differ in how they behave when the collection is
  98. updated. Static bar charts will update in place and are good for when
  99. x-axis data is fixed. Scrolling bar charts are good for time series
  100. data - new data will appear on the right hand side and old will
  101. "drop-off" on the left.</p>
  102. <hr/>
  103. <table width="100%">
  104. <tr>
  105. <td width="25%" align="center" valign="top">
  106. <h3>Static plot</h3>
  107. </td>
  108. <td width="25%" align="center" valign="top">
  109. <h3>Scrolling plot</h3>
  110. </td>
  111. <td width="25%" align="center" valign="top">
  112. <h3>Captioned view</h3>
  113. </td>
  114. <td width="25%" align="center" valign="top">
  115. <h3>Captioned collection</h3>
  116. </td>
  117. </tr>
  118. <tr>
  119. <td width="25%" align="center" valign="top">
  120. <div class="chartcontainer">
  121. <div id="plot1"></div>
  122. </div>
  123. </td>
  124. <td width="25%" align="center" valign="top">
  125. <div class="chartcontainer">
  126. <div id="plot2"></div>
  127. </div>
  128. </td>
  129. <td width="25%" align="center" valign="top">
  130. <div class="chartcontainer">
  131. <div id="plot3"></div>
  132. </div>
  133. </td>
  134. <td width="25%" align="center" valign="top">
  135. <div class="chartcontainer">
  136. <div id="plot4"></div>
  137. </div>
  138. </td>
  139. </tr>
  140. </table>
  141. <div id="footer"></div>
  142. </div>
  143. </body>
  144. </html>