import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Inject, Input, NgZone, PLATFORM_ID, ViewChild, } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { BarHorizontal2DComponent, BarVertical2DComponent, BaseChartComponent, LegendPosition, } from '@swimlane/ngx-charts';
import { ChartDataModel } from '../ChartDataModel';
import { dataWithSeriesToCsv } from '../ExportDataFormat';
import { TapVariableDataPopupComponent } from '../tap-variable-data-popup/tap-variable-data-popup.component';
import * as i0 from "@angular/core";
import * as i1 from "@ionic/angular";
import * as i2 from "@angular/common";
import * as i3 from "@swimlane/ngx-charts";
import * as i4 from "../../ui-directive/export-data.directive";
export class BarChartStackedComponent extends BaseChartComponent {
    constructor(myChartElement, zone, cd, platformId, modalController) {
        super(myChartElement, zone, cd, platformId);
        this.modalController = modalController;
        this.legendPosition = LegendPosition.Below;
        this.showExportButton = false;
        this.legend = true;
        this.colorScheme = {
            domain: [
                '#5DADE2',
                '#9B59B6',
                '#F39C12',
                '#5AA454',
                '#A10A28',
                '#C7B42C',
                '#AAAAAA',
            ],
        };
        this.orientation = 'vertical';
        this.showDetails = false;
        this.noBarWhenZero = false;
        this.showXAxis = true;
        this.showYAxis = true;
        this.history = false;
        this.valueCountLimit = 10;
        this.results = [
            {
                name: '---',
                series: [
                    {
                        name: '---',
                        value: 0,
                        extra: 0,
                    },
                ],
            },
        ];
        this.scrollableChart = false;
        this.chartModel = new ChartDataModel();
    }
    set label(indexOrArray) {
        this.chartModel.initLabel(indexOrArray);
    }
    set data(results) {
        this.results = results;
    }
    createExportedData() {
        return dataWithSeriesToCsv(this.results);
    }
    onSelect(event) {
        if (typeof event === 'object') {
            if (this.showDetails) {
                this.chartModel
                    .showDetail(event, this.modalController, TapVariableDataPopupComponent)
                    .catch((err) => {
                    console.log(err);
                });
            }
        }
    }
    ngAfterViewChecked() {
        if (!this.scrollableChart) {
            this.widthChart = this.divContainer.nativeElement.offsetWidth;
            this.heightChart = this.divContainer.nativeElement.offsetHeight;
        }
        this.cd.detectChanges();
    }
    resizeToScroll(size, seriesSize) {
        if (this.orientation === 'vertical') {
            if (this.divContainer.nativeElement.offsetWidth <=
                size * 50 * seriesSize) {
                this.barChartVer.view = [
                    size * 50 * seriesSize,
                    this.divContainer.nativeElement.offsetHeight,
                ];
            }
        }
        else if (this.orientation === 'horizontal') {
            if (this.divContainer.nativeElement.offsetHeight <=
                size * 50 * seriesSize) {
                this.barChartHor.view = [
                    this.divContainer.nativeElement.offsetWidth,
                    size * 50 * seriesSize,
                ];
            }
        }
    }
    ngOnDestroy() {
        this.subscription?.unsubscribe();
        this.chartModel.destroyCurrentSub();
    }
}
/** @nocollapse */ BarChartStackedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BarChartStackedComponent, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }, { token: PLATFORM_ID }, { token: i1.ModalController }], target: i0.ɵɵFactoryTarget.Component });
/** @nocollapse */ BarChartStackedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: BarChartStackedComponent, selector: "iotize-dashboard-bar-chart-stacked", inputs: { orientation: "orientation", showDetails: "showDetails", noBarWhenZero: "noBarWhenZero", showXAxis: "showXAxis", showYAxis: "showYAxis", history: "history", valueCountLimit: "valueCountLimit", label: "label", data: "data", scrollableChart: "scrollableChart" }, viewQueries: [{ propertyName: "divContainer", first: true, predicate: ["containerRef"], descendants: true }, { propertyName: "barChartHor", first: true, predicate: ["barChartHor"], descendants: true }, { propertyName: "barChartVer", first: true, predicate: ["barChartVer"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<div\n  [ngClass]=\"\n    scrollableChart\n      ? orientation === 'vertical'\n        ? 'verticalContainer'\n        : 'horizontalContainer'\n      : {}\n  \"\n>\n  <div\n    #containerRef\n    [ngClass]=\"\n      legendPosition === 'below' && legend ? 'belowLegend' : 'rightLegend'\n    \"\n    [ngSwitch]=\"orientation\"\n    style=\"position: relative\"\n  >\n    <ngx-charts-bar-horizontal-stacked\n      *ngSwitchCase=\"'horizontal'\"\n      #barChartHor\n      [view]=\"[containerRef.offsetWidth, containerRef.offsetHeight]\"\n      [scheme]=\"colorScheme\"\n      [results]=\"results\"\n      [legend]=\"legend\"\n      [legendPosition]=\"legendPosition\"\n      [xAxis]=\"showXAxis\"\n      [noBarWhenZero]=\"noBarWhenZero\"\n      [yAxis]=\"showYAxis\"\n      (select)=\"onSelect($event)\"\n    >\n    </ngx-charts-bar-horizontal-stacked>\n    <ngx-charts-bar-vertical-stacked\n      *ngSwitchCase=\"'vertical'\"\n      #barChartVer\n      [view]=\"[containerRef.offsetWidth, containerRef.offsetHeight]\"\n      [scheme]=\"colorScheme\"\n      [results]=\"results\"\n      [legend]=\"legend\"\n      [legendPosition]=\"legendPosition\"\n      [noBarWhenZero]=\"noBarWhenZero\"\n      [xAxis]=\"showXAxis\"\n      [yAxis]=\"showYAxis\"\n      (select)=\"onSelect($event)\"\n    >\n    </ngx-charts-bar-vertical-stacked>\n    <ion-fab-button\n      id=\"exportFabButton\"\n      size=\"small\"\n      tapExportData\n      *ngIf=\"showExportButton\"\n      [dataToExport]=\"createExportedData.bind(this)\"\n      [exportedFileName]=\"exportedFileName\"\n    >\n      <ion-icon name=\"download\"></ion-icon>\n    </ion-fab-button>\n  </div>\n</div>\n", styles: ["::ng-deep .horizontal-legend{overflow:auto!important}.belowLegend{max-height:50vh;width:100%;min-width:100%;margin-bottom:60px}.rightLegend{max-height:50vh;width:100%}#exportFabButton{position:absolute;top:10px;right:10px}@media (prefers-color-scheme: dark){::ng-deep span.legend-label-text{color:#ccc!important}::ng-deep span.legend-label-text:hover{color:#fff!important}::ng-deep .ngx-charts text{fill:#fff!important}}.verticalContainer{overflow-y:hidden;overflow-x:auto;max-height:60vh}.horizontalContainer{overflow-x:hidden;overflow-y:auto;max-height:60vh}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i3.BarHorizontalStackedComponent, selector: "ngx-charts-bar-horizontal-stacked", inputs: ["legend", "legendTitle", "legendPosition", "xAxis", "yAxis", "showXAxisLabel", "showYAxisLabel", "xAxisLabel", "yAxisLabel", "tooltipDisabled", "gradient", "showGridLines", "activeEntries", "schemeType", "trimXAxisTicks", "trimYAxisTicks", "rotateXAxisTicks", "maxXAxisTickLength", "maxYAxisTickLength", "xAxisTickFormatting", "yAxisTickFormatting", "xAxisTicks", "yAxisTicks", "barPadding", "roundDomains", "xScaleMax", "showDataLabel", "dataLabelFormatting", "noBarWhenZero", "wrapTicks"], outputs: ["activate", "deactivate"] }, { kind: "component", type: i3.BarVerticalStackedComponent, selector: "ngx-charts-bar-vertical-stacked", inputs: ["legend", "legendTitle", "legendPosition", "xAxis", "yAxis", "showXAxisLabel", "showYAxisLabel", "xAxisLabel", "yAxisLabel", "tooltipDisabled", "gradient", "showGridLines", "activeEntries", "schemeType", "trimXAxisTicks", "trimYAxisTicks", "rotateXAxisTicks", "maxXAxisTickLength", "maxYAxisTickLength", "xAxisTickFormatting", "yAxisTickFormatting", "xAxisTicks", "yAxisTicks", "barPadding", "roundDomains", "yScaleMax", "showDataLabel", "dataLabelFormatting", "noBarWhenZero", "wrapTicks"], outputs: ["activate", "deactivate"] }, { kind: "component", type: i1.IonFabButton, selector: "ion-fab-button", inputs: ["activated", "closeIcon", "color", "disabled", "download", "href", "mode", "rel", "routerAnimation", "routerDirection", "show", "size", "target", "translucent", "type"] }, { kind: "component", type: i1.IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "directive", type: i4.ExportDataDirective, selector: "[tapExportData]", inputs: ["exportedFileName", "dataToExport", "format"], outputs: ["exportDataError"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BarChartStackedComponent, decorators: [{
            type: Component,
            args: [{ selector: 'iotize-dashboard-bar-chart-stacked', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n  [ngClass]=\"\n    scrollableChart\n      ? orientation === 'vertical'\n        ? 'verticalContainer'\n        : 'horizontalContainer'\n      : {}\n  \"\n>\n  <div\n    #containerRef\n    [ngClass]=\"\n      legendPosition === 'below' && legend ? 'belowLegend' : 'rightLegend'\n    \"\n    [ngSwitch]=\"orientation\"\n    style=\"position: relative\"\n  >\n    <ngx-charts-bar-horizontal-stacked\n      *ngSwitchCase=\"'horizontal'\"\n      #barChartHor\n      [view]=\"[containerRef.offsetWidth, containerRef.offsetHeight]\"\n      [scheme]=\"colorScheme\"\n      [results]=\"results\"\n      [legend]=\"legend\"\n      [legendPosition]=\"legendPosition\"\n      [xAxis]=\"showXAxis\"\n      [noBarWhenZero]=\"noBarWhenZero\"\n      [yAxis]=\"showYAxis\"\n      (select)=\"onSelect($event)\"\n    >\n    </ngx-charts-bar-horizontal-stacked>\n    <ngx-charts-bar-vertical-stacked\n      *ngSwitchCase=\"'vertical'\"\n      #barChartVer\n      [view]=\"[containerRef.offsetWidth, containerRef.offsetHeight]\"\n      [scheme]=\"colorScheme\"\n      [results]=\"results\"\n      [legend]=\"legend\"\n      [legendPosition]=\"legendPosition\"\n      [noBarWhenZero]=\"noBarWhenZero\"\n      [xAxis]=\"showXAxis\"\n      [yAxis]=\"showYAxis\"\n      (select)=\"onSelect($event)\"\n    >\n    </ngx-charts-bar-vertical-stacked>\n    <ion-fab-button\n      id=\"exportFabButton\"\n      size=\"small\"\n      tapExportData\n      *ngIf=\"showExportButton\"\n      [dataToExport]=\"createExportedData.bind(this)\"\n      [exportedFileName]=\"exportedFileName\"\n    >\n      <ion-icon name=\"download\"></ion-icon>\n    </ion-fab-button>\n  </div>\n</div>\n", styles: ["::ng-deep .horizontal-legend{overflow:auto!important}.belowLegend{max-height:50vh;width:100%;min-width:100%;margin-bottom:60px}.rightLegend{max-height:50vh;width:100%}#exportFabButton{position:absolute;top:10px;right:10px}@media (prefers-color-scheme: dark){::ng-deep span.legend-label-text{color:#ccc!important}::ng-deep span.legend-label-text:hover{color:#fff!important}::ng-deep .ngx-charts text{fill:#fff!important}}.verticalContainer{overflow-y:hidden;overflow-x:auto;max-height:60vh}.horizontalContainer{overflow-x:hidden;overflow-y:auto;max-height:60vh}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [PLATFORM_ID]
                }] }, { type: i1.ModalController }]; }, propDecorators: { divContainer: [{
                type: ViewChild,
                args: ['containerRef']
            }], barChartHor: [{
                type: ViewChild,
                args: ['barChartHor']
            }], barChartVer: [{
                type: ViewChild,
                args: ['barChartVer']
            }], orientation: [{
                type: Input
            }], showDetails: [{
                type: Input
            }], noBarWhenZero: [{
                type: Input
            }], showXAxis: [{
                type: Input
            }], showYAxis: [{
                type: Input
            }], history: [{
                type: Input
            }], valueCountLimit: [{
                type: Input
            }], label: [{
                type: Input
            }], data: [{
                type: Input
            }], scrollableChart: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 