Show:

File: ia\factories\PieChartFactory.js

  1. /**
  2. * Factory for creating pie charts.
  3. *
  4. * @author J Clare
  5. * @class ia.PieChartFactory
  6. * @param {ia.ComponentConfig} config The component config.
  7. * @param {ia.Report} report The report object.
  8. * @param {Object} componentGroup Hash table containing the Data and Interaction Groups that the component belongs to:
  9. * {dataGroup:ia.DataGroup, interactionGroup:ia.InteractionGroup, comparisonInteractionGroup:ia.InteractionGroup}.
  10. */
  11. ia.PieChartFactory = function(config, report, componentGroup)
  12. {
  13. var me = this;
  14.  
  15. // Data and Interaction groups that the components belongs to.
  16. var interactionGroup = componentGroup.interactionGroup;
  17. var dataGroup = componentGroup.dataGroup;
  18. var comparisonInteractionGroup = componentGroup.comparisonInteractionGroup;
  19.  
  20. // Event handlers.
  21.  
  22. // This code executes every time the data groups data has changed.
  23. dataGroup.addEventListener(ia.DataEvent.DATA_CHANGED, function(event)
  24. {
  25. me.update()
  26. me.render();
  27. });
  28.  
  29. // This code executes every time the data groups thematic has changed.
  30. // The thematic will change after any data change so only render
  31. // here to avoid multiple rendering.
  32. dataGroup.addEventListener(ia.Event.THEMATIC_CHANGED, function(event)
  33. {
  34. me.update()
  35. me.render();
  36. });
  37.  
  38. // Components.
  39.  
  40. // Panel.
  41. var panel = report.getWidget(config.id);
  42. panel.exportFunction = function() {chart.exportData(report.config.getProperty("saveImageText"));};
  43.  
  44. // Chart.
  45. var chart;
  46. var layer;
  47.  
  48. /**
  49. * Builds the component.
  50. *
  51. * @method build
  52. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  53. */
  54. this.build = function(callbackFunction)
  55. {
  56. // Empty panel.
  57. panel.content.empty();
  58. // Chart.
  59. chart = new ia.PieChart(config.id);
  60. panel.append(chart.container);
  61. report.addComponent(config.id, chart);
  62.  
  63. // Layer.
  64. layer = new ia.PieLayer();
  65. layer.thematic = dataGroup.thematic;
  66. layer.setVisible(true);
  67. layer.interactive = true;
  68. layer.highlightColor = report.highlightColor;
  69. layer.selectionColor = report.selectionColor;
  70. chart.addLayer(layer);
  71. interactionGroup.addComponent(layer);
  72.  
  73. // Wait till charts ready before returning.
  74. chart.addEventListener(ia.Event.MAP_READY, function()
  75. {
  76. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  77. });
  78. };
  79.  
  80. /**
  81. * Updates the component.
  82. *
  83. * @method update
  84. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  85. */
  86. this.update = function(callbackFunction)
  87. {
  88. layer.tip = config.getProperty("tip");
  89.  
  90. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  91. };
  92.  
  93. /**
  94. * Renders the component.
  95. *
  96. * @method render
  97. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  98. */
  99. this.render = function(callbackFunction)
  100. {
  101. if (dataGroup.thematic.numericClassifier.classificationName === ia.Thematic.CONTINUOUS)
  102. {
  103. // Hide.
  104. chart.hide();
  105. panel.text(config.getProperty("notAvailableText"));
  106. }
  107. else
  108. {
  109. // Show.
  110. panel.text("");
  111. chart.show();
  112. chart.render();
  113. }
  114. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  115. };
  116. };