Skip to content

Commit

Permalink
chartClick - no refresh data
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Alloza committed Nov 21, 2023
1 parent da4bc5a commit ef652fa
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ eda/eda_api/config/SMPT.config.json
eda/eda_api/config/SMPT.config.json.sample
eda/eda_api/lib/module/uploads/users
eda/eda_api/chromium_dependencies.txt

eda/eda_api/config/*

#APP

Expand All @@ -37,3 +37,4 @@ eda/sda_api/package-lock.json
eda/eda_api/config/SCRM
eda/eda_api/config
eda/eda_app/src/app/config
eda/eda_app/config/*
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class EdaChartComponent implements OnInit, AfterViewInit {
@ViewChild('edaChart') edaChart: BaseChartDirective;
@Output() onClick: EventEmitter<any> = new EventEmitter<any>();
@Input() inject: EdaChart;
@Output() onClick: EventEmitter<any> = new EventEmitter();

public update: boolean;
public chartPlugins = [ ChartDataLabels ];
Expand Down Expand Up @@ -73,17 +74,30 @@ export class EdaChartComponent implements OnInit, AfterViewInit {
return;
}

<<<<<<< HEAD
=======
ngAfterViewInit(): void {
this.edaChart.chart.options.onClick = (evt, activeEls, chart) => {
if (activeEls.length === 0 || chart.getElementsAtEventForMode(<any>evt, 'nearest', { intersect: true }, true).length === 0) {
return;
}

>>>>>>> 6bff99f (chartClick - no refresh data)
activeEls.forEach(point => {
const filterBy = chart.data.datasets[point.datasetIndex].label;
const label = chart.data.labels[point.index];
const value = chart.data.datasets[point.datasetIndex].data[point.index];
this.onClick.emit({ inx: point.index, label, value, filterBy })
<<<<<<< HEAD

if (this.inject.linkedDashboardProps) {
const props = this.inject.linkedDashboardProps;
const url = window.location.href.substr( 0, window.location.href.indexOf('/dashboard')) +`/dashboard/${props.dashboardID}?${props.table}.${props.col}=${label}`
window.open(url, "_blank");
}
=======
console.log('onCLick');
>>>>>>> 6bff99f (chartClick - no refresh data)
})
}
}
Expand Down Expand Up @@ -120,7 +134,10 @@ export class EdaChartComponent implements OnInit, AfterViewInit {
}

updateChart() {
console.log(this.edaChart);
this.edaChart.chart.update();
if (this.edaChart.chart) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class ChartDialogComponent extends EdaDialogAbstract {
const newDatasets = [];
const dataset = this.chart.chartDataset;

<<<<<<< HEAD

for (let i = 0, n = dataset.length; i < n; i += 1) {
if (dataset[i].label === event.label) {
Expand Down Expand Up @@ -173,6 +174,32 @@ export class ChartDialogComponent extends EdaDialogAbstract {
}

this.chart.chartDataset = newDatasets;
=======
let inx = this.chart.chartLabels.findIndex((label: string) => event.label === label);
if (inx >= 0) {
for (let i = 0, n = dataset.length; i < n; i += 1) {
if (dataset[i].label === event.label) {
//dataset[i].hoverBackgroundColor = this.hex2rgb(event.bg, 90);
//dataset[i].hoverBorderColor = 'rgb(255,255,255)';
dataset[i].backgroundColor = this.hex2rgb(event.bg, 90);
dataset[i].borderColor = this.hex2rgb(event.bg, 100);
this.chart.chartColors[i] = _.pick(dataset[i], [ 'backgroundColor', 'borderColor']);
} else if (dataset[i].data[inx]) {
dataset[i].backgroundColor[inx] = this.hex2rgb(event.bg, 90);
dataset[i].borderColor[inx] = this.hex2rgb(event.bg, 100);
this.chart.chartColors[i] = _.pick(dataset[i], [ 'backgroundColor', 'borderColor']);
} else {
//dataset[i].hoverBackgroundColor = this.chart.chartColors[i].backgroundColor;
//dataset[i].hoverBorderColor = 'rgb(255,255,255)';
dataset[i].backgroundColor = this.chart.chartColors[i].backgroundColor;
dataset[i].borderColor = this.chart.chartColors[i].backgroundColor;
this.chart.chartColors[i] = _.pick(dataset[i], [ 'backgroundColor', 'borderColor']);
}
newDatasets.push(dataset[i]);
}
this.chart.chartDataset = newDatasets;
}
>>>>>>> 6bff99f (chartClick - no refresh data)
} else {
if (this.chart.chartLabels) {
const labels = this.chart.chartLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ <h6 id="p-header" class="panel-title" style="cursor: default">
<!-- Body of Panel -->
<div class="panel-body" [ngClass]="{'spinner-panel': display_v.minispinner === true}">
<div *ngIf="display_v.saved_panel" class="p-1" style="height: 100%">
<<<<<<< HEAD
<panel-chart class="component" #PanelChartComponent [props]="panelChartConfig" (configUpdated)="setChartProperties()" (onChartClick)="onChartClick($event)"
style="height: 100%; width: 100%; display:block">
=======
<panel-chart #PanelChartComponent
[props]="panelChartConfig"
(configUpdated)="setChartProperties()"
(onChartClick)="onChartClick($event)"
class="component" style="height: 100%; width: 100%; display:block">
>>>>>>> 6bff99f (chartClick - no refresh data)
</panel-chart>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export class EdaBlankPanelComponent implements OnInit {
@Input() inject: InjectEdaPanel;
@Output() remove: EventEmitter<any> = new EventEmitter();
@Output() duplicate: EventEmitter<any> = new EventEmitter();
<<<<<<< HEAD
@Output() action: EventEmitter<IPanelAction> = new EventEmitter<IPanelAction>();
=======
@Output() action: EventEmitter<IPanelAction> = new EventEmitter();
>>>>>>> 6bff99f (chartClick - no refresh data)

/** propietats que s'injecten al dialog amb les propietats específiques de cada gràfic. */
public configController: EdaDialogController;
Expand Down Expand Up @@ -407,6 +411,7 @@ export class EdaBlankPanelComponent implements OnInit {
const config = output.styles ? new ChartConfig(output.styles) : new ChartConfig(output.config);
this.changeChartType(content.chart, content.edaChart, config);
this.chartForm.patchValue({ chart: this.chartUtils.chartTypes.find(o => o.subValue === content.edaChart) });
console.log('Reload content', this.display_v.saved_panel);
}

/**
Expand Down Expand Up @@ -448,12 +453,22 @@ export class EdaBlankPanelComponent implements OnInit {
}
}

<<<<<<< HEAD
=======
/**
* Chart click event
*/
>>>>>>> 6bff99f (chartClick - no refresh data)
public onChartClick(event: any): void {
const config = this.panelChart.getCurrentConfig();
if (config?.chartType == 'doughnut') {
this.action.emit({ code: 'ADDFILTER', data: {...event, panel: this.panel} });
}
}
<<<<<<< HEAD
=======

>>>>>>> 6bff99f (chartClick - no refresh data)

/**
* Changes chart type
Expand All @@ -470,7 +485,7 @@ export class EdaBlankPanelComponent implements OnInit {
this.graficos.numberOfColumns = config && config.getConfig() ? config.getConfig()['numberOfColumns'] : null;

if (!_.isEqual(this.display_v.chart, 'no_data') && !allow.ngIf && !allow.tooManyData) {
this.panelChart.destroyComponent();
// this.panelChart.destroyComponent();
const _config = config || new ChartConfig(ChartsConfigUtils.setVoidChartConfig(type));
this.renderChart(this.currentQuery, this.chartLabels, this.chartData, type, subType, _config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class LinkDashboardsComponent extends EdaDialogAbstract {
}

onShow(): void {

console.log(this.controller)
this.oldLinked = this.controller.params.linkedDashboard ? this.controller.params.linkedDashboard.dashboardName : null;
if ((this.controller.params.charttype === 'parallelSets') && !this.controller.params.modeSQL) {

Expand All @@ -106,7 +106,9 @@ export class LinkDashboardsComponent extends EdaDialogAbstract {
let column = this.controller.params.query
.map((col, i) => { return { col: col.column_name, table: col.table_id, colname: col.display_name.default, index:i, column_type:col.column_type } })
.filter(col => (col.column_type === 'text' || col.column_type === 'date'))[0];
this.column = column.index === 0 ? column.colname : this.noValidColumn;

console.log(column)
this.column = column.index === 0 ? column.colname : this.noValidColumn;

if(column.index === 0){
this.initDashboards(column);
Expand Down Expand Up @@ -166,6 +168,7 @@ export class LinkDashboardsComponent extends EdaDialogAbstract {


for (let i = 0; i < dashboards.length; i++) {
<<<<<<< HEAD
let res;
try {
res = await this.dashboardService.getDashboard(dashboards[i]._id).toPromise();
Expand Down Expand Up @@ -215,6 +218,57 @@ export class LinkDashboardsComponent extends EdaDialogAbstract {

}
}
=======
let res;
try {
res = await this.dashboardService.getDashboard(dashboards[i]._id).toPromise();
} catch (err) {
console.log(dashboards[i]._id)
console.error(err);
}

if (res) {
/** If datasources are equal and dashboar has filters */
if (res.dashboard.config.ds._id === this.controller.params.datasource && res.dashboard.config.filters?.length > 0) {

let disable = true;

if (!this.controller.params.modeSQL) {

res.dashboard.config.filters.forEach(filter => {
if (filter.column.value.column_name === column.col && filter.table.value === column.table) {
disable = false;
}

this.targetColumn = column.col;
this.targetTable = column.table;

this.sourceColumn = column.col;
this.sourceTable = column.table;

});

if (!disable) {
this.dasboards.push({ label: dashboards[i].config.title, value: dashboards[i]._id });
}

} else {

this.sourceColumn = column.col;
this.sourceTable = column.table;

res.dashboard.config.filters.forEach(filter => {

filters.push({ colname: filter.column.value.column_name, dashboardID: dashboards[i]._id, table: filter.table.value });

});

this.dasboards.push({ label: dashboards[i].config.title, value: dashboards[i]._id });

}
}
}
>>>>>>> 6bff99f (chartClick - no refresh data)

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<template #chartComponent ></template>
<template #chartComponent></template>
<ng-container *ngIf="NO_DATA">
<div class="d-flex justify-content-center">
<img src="assets/images/nodata.png" style="width: 250px;" alt="no data" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<<<<<<< HEAD
import { filter } from 'rxjs/operators';
=======
>>>>>>> 6bff99f (chartClick - no refresh data)
import { EdaKnob } from './../../../eda-knob/edaKnob';
import { EdaKnobComponent } from './../../../eda-knob/eda-knob.component';
import { EdaScatter } from './../../../eda-scatter/eda-scatter.component';
Expand All @@ -19,7 +22,6 @@ import { ChartUtilsService, StyleConfig, StyleProviderService } from '@eda/servi

import { Column } from '@eda/models/model.index';
import { EdaChartComponent } from '@eda/components/eda-chart/eda-chart.component';
import ChartDataLabels from 'chartjs-plugin-datalabels';
import { EdaColumnDate } from '@eda/components/eda-table/eda-columns/eda-column-date';
import { EdaColumnNumber } from '@eda/components/eda-table/eda-columns/eda-column-number';
import { EdaColumnText } from '@eda/components/eda-table/eda-columns/eda-column-text';
Expand Down Expand Up @@ -71,7 +73,8 @@ export class PanelChartComponent implements OnInit, OnChanges, OnDestroy {
public histoGramDescTxt2: string = $localize`:@@histoGramDescTxt2:en este rango`;


constructor(public resolver: ComponentFactoryResolver,
constructor(
public resolver: ComponentFactoryResolver,
private chartUtils: ChartUtilsService,
@Self() private ownRef: ElementRef,
public styleProviderService: StyleProviderService) {
Expand All @@ -98,7 +101,6 @@ export class PanelChartComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnChanges(changes: SimpleChanges): void {

/**
* If data change chart type
*/
Expand Down Expand Up @@ -228,7 +230,7 @@ export class PanelChartComponent implements OnInit, OnChanges, OnDestroy {
dataDescription.otherColumns.push(newCol);
dataDescription.totalColumns++;

}
}

const chartData = this.chartUtils.transformDataQuery(this.props.chartType, this.props.edaChart, values, dataTypes, dataDescription, isbarline, cfg.numberOfColumns);

Expand Down Expand Up @@ -659,6 +661,12 @@ export class PanelChartComponent implements OnInit, OnChanges, OnDestroy {
}
}

public updateComponent() {
if (this.componentRef) {
this.componentRef.instance.updateChart();
}
}

/**
* Initializes table
* @param type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const QueryUtils = {
* @param globalFilters flag to apply when runQuery() is called from dashboard component.
*/
runQuery: async (ebp: EdaBlankPanelComponent, globalFilters: boolean) => {
<<<<<<< HEAD

/** gestiona las columnas duplicadas. Si tengo dos columnas con el mismo nombre le añado el sufijo _1, _2, _3.... etc */
let dup = [];
Expand All @@ -97,6 +98,8 @@ export const QueryUtils = {
}
})

=======
>>>>>>> 6bff99f (chartClick - no refresh data)
ebp.display_v.disablePreview = false;

if (!globalFilters) {
Expand All @@ -107,10 +110,11 @@ export const QueryUtils = {
ebp.panelChart.NO_DATA = false;
ebp.display_v.minispinner = true;
}
console.log(ebp);

try {

if (ebp.panelChart) ebp.panelChart.destroyComponent();
// if (ebp.panelChart) ebp.panelChart.destroyComponent();

const query = ebp.switchAndBuildQuery();
/**Add fake column if SQL mode and there isn't fields yet */
Expand All @@ -136,15 +140,13 @@ export const QueryUtils = {
ebp.spinnerService.off();

} else {

ebp.reloadContent();
ebp.display_v.minispinner = false;

}

ebp.spinnerService.off();
ebp.index = 1;
ebp.display_v.saved_panel = true;

} catch (err) {

ebp.alertService.addError(err);
Expand Down
Loading

0 comments on commit ef652fa

Please sign in to comment.