PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/visualize/public/examples/multi.html

http://github.com/jspears/bobamo
HTML | 97 lines | 90 code | 7 blank | 0 comment | 0 complexity | 4cdf20fda906f97ecd5a971309e6beac 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 src="../visualisations/scatter.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9. $(function() {
  10. var DataPoint = Backbone.Model.extend({
  11. initialize: function(point) {
  12. this.set({
  13. id: point.id,
  14. x: point.x,
  15. y: point.y
  16. });
  17. }
  18. });
  19. var DataSeries = Backbone.d3.PlotCollection.extend({
  20. model : DataPoint,
  21. url : "bardata.json",
  22. // Needed for scolling plots
  23. fetch: function(){
  24. // No op
  25. console.log('fetching is a no op in this example');
  26. }
  27. });
  28. var series1 = new DataSeries();
  29. var plot1 = new Backbone.d3.Canned.Bar.View(series1, {div:'#plot1'});
  30. var caption = "inverse of data";
  31. var plot2 = new Backbone.d3.Canned.Bar.View(series1, {div:'#plot2', scrolling:true, caption:caption});
  32. plot2.plotdata = function(){
  33. var data = [];
  34. this.collection.forEach(function(datapoint) {
  35. data.push({x:datapoint.get('x'), y:1/datapoint.get('y')});
  36. }
  37. )
  38. // Needed for scolling plots
  39. if (data.length > this.size){
  40. return _.last(data, this.size);
  41. } else {
  42. return data;
  43. }
  44. };
  45. series1.reset([
  46. new DataPoint({x:1, y:6, id:1}),
  47. new DataPoint({x:2, y:4, id:2}),
  48. new DataPoint({x:3, y:2, id:3}),
  49. new DataPoint({x:4, y:4, id:4}),
  50. new DataPoint({x:5, y:6, id:5})
  51. ]);
  52. // evolve the dataset
  53. _.each(_.range(1,6), function(i, ii, l) {
  54. setTimeout(function() {
  55. series1.add(new DataPoint({x:i+5, y:i*2, id:i}));
  56. }, i * 1000);
  57. })
  58. });
  59. </script>
  60. </head>
  61. <body>
  62. <div id="container">
  63. <h1>Multi charts</h1>
  64. <p>Since the visualisation is defined by the view collection reuse is
  65. possible and sometimes very useful. For instance you may want a pie
  66. chart (to show the breakdown of the data) and a time series of the
  67. build up of the data.</p>
  68. <hr/>
  69. <table width="100%">
  70. <tr>
  71. <td width="50%" align="center" valign="top">
  72. <h3>Bar plot</h3>
  73. </td>
  74. <td width="50%" align="center" valign="top">
  75. <h3>Scatter plot</h3>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td width="50%" align="center" valign="top">
  80. <div id="plot1"></div>
  81. </td>
  82. <td width="50%" align="center" valign="top">
  83. <div id="plot2"></div>
  84. </td>
  85. </tr>
  86. </table>
  87. <div id="footer"></div>
  88. </div>
  89. </body>
  90. </html>