Protovis.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var Protovis = new Class({
  2. Implements : [Options],
  3. options : {
  4. data : [],
  5. width : 'auto',
  6. height : 'auto',
  7. bottom : 20,
  8. left : 20,
  9. right : 10,
  10. top : 5,
  11. colors : ['#9edae5', '#17becf', '#dbdb8d', '#bcbd22']
  12. },
  13. initialize : function(el,options){
  14. this.setOptions(options);
  15. this.el = el;
  16. pv.Panel.$dom = el;
  17. },
  18. setScale : function(){
  19. var size = this.el.getParent().getParent().getSize();
  20. if(this.options.width == 'auto' || this.options.height == 'auto'){
  21. this.width = size.x -5;
  22. this.height = size.y - 5;
  23. } else {
  24. this.width = this.options.width;
  25. this.height = this.options.height;
  26. }
  27. this.width -= (this.options.left + this.options.right);
  28. this.height -= (this.options.top + this.options.bottom);
  29. },
  30. makeGraph : function(){
  31. this.graph = new pv.Panel()
  32. .width(this.width)
  33. .height(this.height)
  34. .bottom(this.options.bottom)
  35. .left(this.options.left)
  36. .right(this.options.right)
  37. .top(this.options.top);
  38. },
  39. makePanel : function(){
  40. this.panel = this.graph.add(pv.Panel)
  41. .data(this.data);
  42. },
  43. refresh : function(options){
  44. this.setOptions(options);
  45. this.destroy();
  46. this.setScale();
  47. this.makeGraph();
  48. this.render();
  49. },
  50. render : function(){
  51. this.graph.render();
  52. },
  53. destroy : function(){
  54. $(this.el.getElement('svg').getParent()).dispose();
  55. }
  56. });