File: ia\factories\AreaBreakdownPieLegendFactory.js
/**
* Factory for creating pie legends.
*
* @author J Clare
* @class ia.AreaBreakdownPieLegendFactory
* @param {ia.ComponentConfig} config The component config.
* @param {ia.Report} report The report object.
* @param {Object} componentGroup Hash table containing the Data and Interaction Groups that the component belongs to:
* {dataGroup:ia.DataGroup, interactionGroup:ia.InteractionGroup, comparisonInteractionGroup:ia.InteractionGroup}.
*/
ia.AreaBreakdownPieLegendFactory = function(config, report, componentGroup)
{
var me = this;
// Data and Interaction groups that the components belongs to.
var interactionGroup = componentGroup.interactionGroup;
var dataGroup = componentGroup.dataGroup;
var comparisonInteractionGroup = componentGroup.comparisonInteractionGroup;
// This code executes every time the data groups data has changed.
dataGroup.addEventListener(ia.DataEvent.DATA_CHANGED, function(event)
{
me.update();
me.render();
});
// Panel.
var panel = report.getWidget(config.id);
// Legend.
var legend;
/**
* Builds the component.
*
* @method build
* @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
*/
this.build = function(callbackFunction)
{
// Empty panel.
panel.content.empty();
// Legend.
legend = new ia.DiscreteLegend(config.id);
legend.interactive = false;
panel.append(legend.container);
interactionGroup.addComponent(legend);
report.addComponent(config.id, legend);
if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
};
/**
* Updates the component.
*
* @method update
* @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
*/
this.update = function(callbackFunction)
{
if (config.getProperty("layout")) legend.layout = config.getProperty("layout");
var chart = report.getComponent("areaBreakdownPieChart"+dataGroup.suffix);
if (chart) legend.thematic = chart.thematic;
if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
};
/**
* Renders the component.
*
* @method render
* @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
*/
this.render = function(callbackFunction)
{
var chart = report.getComponent("areaBreakdownPieChart"+dataGroup.suffix);
if (chart) legend.render();
if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
};
};