ChartControl.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * Copyright IBM Corp. 2015
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define([
  11. "q",
  12. 'jquery',
  13. 'rave2',
  14. 'bi/commons/ui/View'
  15. ], function (Q, $, rave, View) {
  16. 'use strict';
  17. var ChartControl = View.extend({
  18. init: function(options){
  19. ChartControl.inherited('init', this, arguments);
  20. this.margin = {
  21. top: 20,
  22. right: 20,
  23. bottom: 40,
  24. left: 120
  25. };
  26. this.barHeight = 40;
  27. this.barSeparation = 10;
  28. this.data = [];
  29. $.extend(this, options);
  30. this.$el.empty();
  31. this.el = this.$el[0];
  32. this._colours = rave.scale.ordinal()
  33. .domain(['enabled', 'disabled'])
  34. .range(['#5AA700', '#AEB8B8']);
  35. this._setSizes();
  36. if (this.data) {
  37. this._draw(this.data);
  38. }
  39. },
  40. /**
  41. * Clear's the current chart
  42. */
  43. clear: function(){
  44. this.$el.empty();
  45. },
  46. redraw: function(data) {
  47. this.clear();
  48. this._setSizes();
  49. if(typeof data !== 'undefined') {
  50. this.data = data;
  51. }
  52. this._draw(this.data);
  53. },
  54. /* This must be overwritten */
  55. _draw: function (data) {
  56. },
  57. _setSizes: function() {
  58. this.width = ($(window).width() * 0.80) - this.margin.left - this.margin.right;
  59. this.height = this.barHeight * this.data.length;
  60. this.svgWidth = this.width + this.margin.left + this.margin.right;
  61. this.svgHeight = this.height + this.margin.top + this.margin.bottom;
  62. this.chart = rave.select(this.el)
  63. .attr("width", this.svgWidth)
  64. .attr("height", this.svgHeight);
  65. }
  66. });
  67. return ChartControl;
  68. });