PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/visualize/public/examples/pie.html

http://github.com/jspears/bobamo
HTML | 91 lines | 84 code | 7 blank | 0 comment | 0 complexity | 8c582219cf2adf2760b4594f7116e194 MD5 | raw file
Possible License(s): Apache-2.0
  1. <html>
  2. <head>
  3. <title>Backbone.d3 - Pie 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/pie.js" type="text/javascript"></script>
  7. <script type="text/javascript">
  8. $(function() {
  9. var DataPoint = Backbone.Model.extend({
  10. initialize: function(value) {
  11. this.set(value);
  12. }
  13. });
  14. var DataSeries = Backbone.d3.PlotCollection.extend({
  15. model : DataPoint,
  16. url : "data",
  17. plottype: "pie",
  18. fetch: function(){
  19. // No op
  20. console.log('fetching is a no op in this example');
  21. }
  22. });
  23. var series = new DataSeries();
  24. var plot = new Backbone.d3.Canned.Pie.View(series, {
  25. div:'#plot1',
  26. name: 'PLOT1',
  27. radius: 85
  28. });
  29. series.reset([new DataPoint({id: 1, value: 2}),
  30. new DataPoint({id: 2, value: 1}),
  31. new DataPoint({id: 3, value: 1}),
  32. new DataPoint({id: 4, value: 2})]);
  33. var newValues = [1, 2, 2, 1];
  34. _.each(_.range(1,5), function(i, ii, l) {
  35. setTimeout(function() {
  36. var m = plot.collection.get(i);
  37. m.set({value: newValues[ii]});
  38. }, i * 1000);
  39. })
  40. var dynamicSeries = new DataSeries();
  41. var dynamicPlot = new Backbone.d3.Canned.Pie.View(dynamicSeries, {
  42. div:'#plot2',
  43. name: 'PLOT2',
  44. radius: 85
  45. });
  46. dynamicSeries.reset([new DataPoint({id: 1, value: 1}),
  47. new DataPoint({id: 2, value: 2})]);
  48. setTimeout(function() {
  49. dynamicSeries.add(new DataPoint({id: 3, value: 4}));
  50. }, 1000);
  51. setTimeout(function() {
  52. dynamicSeries.add(new DataPoint({id: 4, value: 2}));
  53. }, 2000);
  54. setTimeout(function() {
  55. dynamicSeries.remove(3);
  56. }, 3000);
  57. setTimeout(function() {
  58. dynamicSeries.add(new DataPoint({id: 5, value: 1}));
  59. }, 4000);
  60. });
  61. </script>
  62. </head>
  63. <body>
  64. <div id="container">
  65. <h1>Pie charts</h1>
  66. <p>Backbone-d3 currently supports simple pie charts with transitions.
  67. Changing values in a collection causes the pie chart to update to the
  68. new ratios. Adding a value adds a new segment to the pie chart, and
  69. removing a value removes that segment.</p>
  70. <hr/>
  71. <table width="100%">
  72. <tr>
  73. <td width="50%" align="center">
  74. <h3>Fixed length series<div id="plot1"></div></h3>
  75. </td>
  76. <td width="50%" align="center">
  77. <h3>Variable length series<div id="plot2"></div></h3>
  78. </td>
  79. </tr>
  80. </table>
  81. <div id="footer"></div>
  82. </div>
  83. </body>
  84. </html>