var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/************************************************
Power Quality Event Location Gadget
************************************************/
var Dashboards;
(function (Dashboards) {
    var Models;
    (function (Models) {
        var PowerQualityEventLocationGadget = (function (_super) {
            __extends(PowerQualityEventLocationGadget, _super);
            function PowerQualityEventLocationGadget(gadgetOptions) {
                gadgetOptions.renderer = new Dashboards.Views.PowerQualityEventLocationRender();
                _super.call(this, gadgetOptions);
                this.noDataMessage = i18n.loc.unencoded('PowerQualityGadgets', 'PowerQualityEvents_NoEvents');
            }
            PowerQualityEventLocationGadget.CreateInstance = function (gadgetOptions) {
                var instance = new PowerQualityEventLocationGadget(gadgetOptions);
                return instance;
            };
            /* Gadget Data Overrides
            ******************************************************************************/
            PowerQualityEventLocationGadget.prototype.hasData = function () {
                var hasData = this.dataSet &&
                    _.isArray(this.dataSet) &&
                    this.dataSet.length == 6;
                if (hasData) {
                    hasData = _.any(this.dataSet, function (result) { return result.Value > 0; });
                }
                return hasData;
            };
            PowerQualityEventLocationGadget.prototype.formatData = function (data) {
                if (data && data.hasOwnProperty('Results') && _.isArray(data.Results)) {
                    data = data.Results;
                }
                return data;
            };
            PowerQualityEventLocationGadget.TypeId = "d7579525-6864-4b38-bcbc-643354538a00";
            return PowerQualityEventLocationGadget;
        }(Models.ViewPeriodGadget));
        Models.PowerQualityEventLocationGadget = PowerQualityEventLocationGadget;
    })(Models = Dashboards.Models || (Dashboards.Models = {}));
})(Dashboards || (Dashboards = {}));
var Dashboards;
(function (Dashboards) {
    var Views;
    (function (Views) {
        var PowerQualityEventLocationRender = (function (_super) {
            __extends(PowerQualityEventLocationRender, _super);
            function PowerQualityEventLocationRender() {
                _super.call(this);
            }
            /* Renderer Overrides
            ******************************************************************************/
            PowerQualityEventLocationRender.prototype.updateGadget = function (handler) {
                var pqData = this.gadget.dataSet;
                var $chartdiv = this.$getChart();
                var externalLikelyImpact = _.findWhere(pqData, { Name: 'External', EventType: 'LikelyImpact' });
                var externalNoImpact = _.findWhere(pqData, { Name: 'External', EventType: 'NoImpact' });
                var internalLikelyImpact = _.findWhere(pqData, { Name: 'Internal', EventType: 'LikelyImpact' });
                var internalNoImpact = _.findWhere(pqData, { Name: 'Internal', EventType: 'NoImpact' });
                var indLikelyImpact = _.findWhere(pqData, { Name: 'Indeterminate', EventType: 'LikelyImpact' });
                var indNoImpact = _.findWhere(pqData, { Name: 'Indeterminate', EventType: 'NoImpact' });
                var seriesData = [
                    {
                        type: 'column',
                        title: i18n.loc.unencoded('PowerQualityGadgets', 'LikelyProcessImpact'),
                        fillStyles: [Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.External), Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Internal),
                            Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Undetermined)],
                        data: [[i18n.loc.unencoded('PowerQualityGadgets', 'PowerQualityEventsLocationGadget_ImpactNoImpact'), externalLikelyImpact.Value],
                            [i18n.loc.unencoded('PowerQualityGadgets', 'PowerQualityEventsLocationGadget_ImpactNoImpact'), internalLikelyImpact.Value],
                            [i18n.loc.unencoded('PowerQualityGadgets', 'PowerQualityEventsLocationGadget_ImpactNoImpact'), indLikelyImpact.Value]]
                    },
                    {
                        type: 'column',
                        title: i18n.loc.unencoded('PowerQualityGadgets', 'NoProcessImpact'),
                        fillStyles: [Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.ExternalMuted), Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.InternalMuted),
                            Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.UndeterminedMuted)],
                        data: [[i18n.loc.unencoded('PowerQualityGadgets', 'External'), externalNoImpact.Value],
                            [i18n.loc.unencoded('PowerQualityGadgets', 'Internal'), internalNoImpact.Value],
                            [i18n.loc.unencoded('PowerQualityGadgets', 'Indeterminate'), indNoImpact.Value]]
                    }
                ];
                var chartOptions = Dashboards.Views.ChartHelper.GetDefaultChartOptions(this);
                this.applyCustomLegend(chartOptions.legend);
                var leftAxis = Dashboards.Views.ChartHelper.GetStandardLeftYAxis(this);
                leftAxis.title = i18n.loc.unencoded('PowerQualityGadgets', 'Incidents');
                chartOptions.axes = [Dashboards.Views.ChartHelper.GetStandardBottomXAxis(this), leftAxis];
                chartOptions.series = seriesData;
                var existingSeries = $chartdiv.jqChart('option', 'series');
                Views.ChartHelper.UpdateSeriesVisibility(seriesData, existingSeries);
                this.bindAxisFormat($chartdiv, ['left']);
                this.destroyChart(); // Destroy any previous chart instance
                // Create the chart            
                $chartdiv.jqChart(chartOptions);
                this.bindGroupedToolTipFormat();
            };
            PowerQualityEventLocationRender.prototype.bindAxisFormat = function ($gadgetRender, axisLocations) {
                if (!axisLocations)
                    axisLocations = [];
                $gadgetRender.bind('axisLabelCreating', function (e, data) {
                    if (axisLocations.indexOf(data.context.axis.location) >= 0) {
                        data.text = i18n.formatNumber(data.text, 0);
                        var diff = Math.abs(data.context.axis.actualInterval);
                        if (diff <= 1) {
                            data.context.axis.interval = 1;
                        }
                    }
                });
            };
            PowerQualityEventLocationRender.prototype.applyCustomLegend = function (legend) {
                legend.customItems = [
                    {
                        text: {
                            text: i18n.loc.unencoded('PowerQualityGadgets', 'ImpactTrend_Label_ExternalCost')
                        },
                        marker: {
                            strokeStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.External),
                            fillStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.External),
                            type: 'circle'
                        }
                    },
                    {
                        text: {
                            text: i18n.loc.unencoded('PowerQualityGadgets', 'ImpactTrend_Label_InternalCost')
                        },
                        marker: {
                            strokeStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Internal),
                            fillStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Internal),
                            type: 'circle'
                        }
                    },
                    {
                        text: {
                            text: i18n.loc.unencoded('PowerQualityGadgets', 'ImpactTrend_Label_UnknownCost')
                        },
                        marker: {
                            strokeStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Undetermined),
                            fillStyle: Dashboards.PowerQuality.PowerQualityHelper.GetDataSeriesColor(Dashboards.PowerQuality.DataSeriesColor.Undetermined),
                            type: 'circle'
                        }
                    }];
            };
            PowerQualityEventLocationRender.prototype.bindGroupedToolTipFormat = function () {
                var _this = this;
                this.$gadgetRender.bind('tooltipFormat', function (eventObject, data) {
                    var fontSize = Views.ChartHelper.GetToolTipFontSize(_this.renderSize);
                    var tooltip = '<div class="chartTooltip" style="font-size:' + fontSize + '"><div class="clear"></div>';
                    var displayVal = StringUtil.format("{0}: {1}", i18n.loc.s('PowerQualityGadgets', 'Incidents'), i18n.formatNumber(data.y, 0));
                    tooltip += data.series.title.encodeHtml();
                    tooltip += '<div class="clear"></div>';
                    tooltip += '<div style="font-weight:bold">' + displayVal + '</div>';
                    tooltip += '</div>';
                    return tooltip;
                });
            };
            return PowerQualityEventLocationRender;
        }(Views.ViewPeriodChartRender));
        Views.PowerQualityEventLocationRender = PowerQualityEventLocationRender;
    })(Views = Dashboards.Views || (Dashboards.Views = {}));
})(Dashboards || (Dashboards = {}));
// Register the gadget type
Dashboards.Controllers.GadgetType.RegisterDefinition({
    typeId: Dashboards.Models.PowerQualityEventLocationGadget.TypeId,
    create: Dashboards.Models.PowerQualityEventLocationGadget.CreateInstance,
    resourceSet: 'PowerQualityGadgets'
});
//# sourceMappingURL=PowerQualityEventsLocation.js.map