-
Notifications
You must be signed in to change notification settings - Fork 22
fix(data-analysis): charts update functionality and extras update #3614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| /* eslint-disable max-len */ | ||
| import { AfterViewInit, ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, OnInit, Pipe, PipeTransform, QueryList, ViewChild, ViewChildren } from '@angular/core'; | ||
| import { IgxChartIntegrationDirective, IgxContextMenuDirective, OPTIONS_TYPE, CHART_TYPE } from 'igniteui-angular-extras'; | ||
| import { AfterViewInit, ChangeDetectorRef, ViewContainerRef, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, OnInit, Pipe, PipeTransform, QueryList, ViewChild, ViewChildren, TemplateRef } from '@angular/core'; | ||
| import { IgxChartIntegrationDirective, IgxConditionalFormattingDirective, IgxContextMenuDirective, OPTIONS_TYPE, CHART_TYPE, IDeterminedChartTypesArgs } from 'igniteui-angular-extras'; | ||
| import { IgcDockManagerLayout, IgcDockManagerPaneType, IgcSplitPane, IgcSplitPaneOrientation } from 'igniteui-dockmanager'; | ||
| import { FinancialData } from '../../data/financialData'; | ||
| import { FloatingPanesService } from '../../services/floating-panes.service'; | ||
| import { DockSlotComponent } from './dock-slot/dock-slot.component'; | ||
| import { IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxDividerDirective, IgxBadgeComponent } from 'igniteui-angular'; | ||
| import { IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxDividerDirective, IgxBadgeComponent, IColumnSelectionEventArgs } from 'igniteui-angular'; | ||
| import { NgClass, DecimalPipe, TitleCasePipe, CurrencyPipe } from '@angular/common'; | ||
| import { debounceTime } from 'rxjs/operators'; | ||
|
|
||
| @Pipe({ | ||
| name: 'filterType' | ||
|
|
@@ -53,10 +54,12 @@ export class HastDuplicateLayouts implements PipeTransform { | |
| templateUrl: './data-analysis-dock-manager.component.html', | ||
| styleUrls: ['./data-analysis-dock-manager.component.scss'], | ||
| providers: [FloatingPanesService], | ||
| imports: [IgxGridComponent, IgxChartIntegrationDirective, IgxContextMenuDirective, IgxBadgeComponent, IgxColumnComponent, IgxCellTemplateDirective, NgClass, IgxDividerDirective, DockSlotComponent, DecimalPipe, TitleCasePipe, CurrencyPipe, FilterTypePipe, HastDuplicateLayouts], | ||
| imports: [IgxGridComponent, IgxConditionalFormattingDirective, IgxChartIntegrationDirective, IgxContextMenuDirective, IgxBadgeComponent, IgxColumnComponent, IgxCellTemplateDirective, NgClass, IgxDividerDirective, DockSlotComponent, DecimalPipe, TitleCasePipe, CurrencyPipe, FilterTypePipe, HastDuplicateLayouts], | ||
| schemas: [CUSTOM_ELEMENTS_SCHEMA] | ||
| }) | ||
| export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | ||
| export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | ||
| @ViewChild('grid', { read: IgxGridComponent, static: true }) | ||
| public grid: IgxGridComponent; | ||
|
|
||
| @ViewChild('dock', { read: ElementRef }) | ||
| public dockManager: ElementRef<HTMLIgcDockmanagerElement>; | ||
|
|
@@ -67,6 +70,10 @@ export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | |
| @ViewChildren(DockSlotComponent) | ||
| public dockSlots: QueryList<DockSlotComponent>; | ||
|
|
||
| @ViewChild('template', { read: TemplateRef }) | ||
| public emptyChartTemplate: TemplateRef<any>; | ||
|
|
||
| public availableCharts: CHART_TYPE[] = []; | ||
| public allCharts: CHART_TYPE[] = []; | ||
| public data; | ||
| public chartData = []; | ||
|
|
@@ -81,7 +88,7 @@ export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | |
| } | ||
|
|
||
| public ngAfterViewInit() { | ||
| this.allCharts = this.chartIntegration.getAvailableCharts(); | ||
| this.allCharts = this.chartIntegration.getAllChartTypes(); | ||
| this.cdr.detectChanges(); | ||
| const pieChartOptions = { | ||
| labelsPosition: 4, | ||
|
|
@@ -96,6 +103,30 @@ export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | |
| chart.indexOf('Bar') === -1 || | ||
| chart !== CHART_TYPE.PIE) | ||
| .forEach(chart => this.chartIntegration.setChartComponentOptions(chart, OPTIONS_TYPE.X_AXIS, { labelAngle: 30 })); | ||
|
|
||
| this.chartIntegration.onChartTypesDetermined.subscribe((args: IDeterminedChartTypesArgs) => { | ||
| if (args.chartsAvailability.size === 0 || args.chartsForCreation.length === 0) { | ||
| this.chartIntegration.disableCharts(this.allCharts); | ||
| } else { | ||
| args.chartsAvailability.forEach((isAvailable, chart) => { | ||
| if (args.chartsForCreation.indexOf(chart) === -1) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's just style preference - maybe includes would be easier to read. |
||
| this.chartIntegration.disableCharts([chart]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am not sure what is the implementation of disable/enableCharts function in chartIntegration package. Possibly it would be more effective and concise, if the method is called once for all charts to enable/disable. |
||
| } else { | ||
| this.chartIntegration.enableCharts([chart]); | ||
| } | ||
| }); | ||
| } | ||
| this.availableCharts = this.chartIntegration.getAvailableCharts(); | ||
| }); | ||
| this.cdr.detectChanges(); | ||
|
|
||
| this.grid.rangeSelected.subscribe(range => { | ||
| this.createChartCommonLogic(); | ||
| }); | ||
|
|
||
| this.grid.columnSelectionChanging.pipe(debounceTime(100)).subscribe((args: IColumnSelectionEventArgs) => { | ||
| this.createChartCommonLogic(); | ||
| }); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/member-ordering | ||
|
|
@@ -163,12 +194,47 @@ export class DataAnalysisDockManagerComponent implements OnInit, AfterViewInit { | |
| this.paneService.appendPane(splitPane); | ||
| const chartHost = this.getChartHostFromSlot(type); | ||
| chartHost.viewContainerRef.clear(); | ||
| this.chartIntegration.chartFactory | ||
| const chart = this.chartIntegration.chartFactory(type, chartHost.viewContainerRef); | ||
|
|
||
| this.dockManager.nativeElement.layout.floatingPanes.push(splitPane); | ||
| this.docLayout = { ...this.dockManager.nativeElement.layout }; | ||
| this.selectedCharts[type] = chart; | ||
| this.cdr.detectChanges(); | ||
| } | ||
| } | ||
|
|
||
| public createChartCommonLogic() { | ||
| if (Object.keys(this.selectedCharts).length !== 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if is not needed. Drop the if and document the setTimeout usage. |
||
| setTimeout(() => { | ||
| Object.keys(this.selectedCharts).forEach((c: CHART_TYPE) => { | ||
| const chartHost = this.getChartHostFromSlot(c); | ||
| if (this.availableCharts.indexOf(c) !== -1) { | ||
| if (c !== CHART_TYPE.PIE && typeof this.selectedCharts[c] === 'object') { | ||
| this.selectedCharts[c] = this.chartIntegration.chartFactory(c, null, this.selectedCharts[c]); | ||
| } else { | ||
| chartHost.viewContainerRef.clear(); | ||
| this.selectedCharts[c] = this.chartIntegration.chartFactory(c, chartHost.viewContainerRef); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Export the this.selectedCharts[c] into a constant. This is the third usage in few lines. |
||
| } | ||
| } else { | ||
| this.clearViewContainer(chartHost.viewContainerRef); | ||
| const embeddedView = chartHost.viewContainerRef.createEmbeddedView(this.emptyChartTemplate); | ||
| embeddedView.detectChanges(); | ||
| this.selectedCharts[c] = 'Empty'; | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private clearViewContainer(viewContainerRef: ViewContainerRef) { | ||
| for (let i = viewContainerRef.length -1; i >= 0; i--) { | ||
| const viewRef = viewContainerRef.get(i); | ||
| if (viewRef) { | ||
| const componentInstance = (viewRef as any).context; | ||
| if (componentInstance && (componentInstance as any).destroy) { | ||
| (componentInstance as any).destroy(); | ||
| } | ||
| } | ||
| } | ||
| viewContainerRef.clear(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,10 @@ | |
|
|
||
| .main { | ||
| width: calc(100% - 300px); | ||
| igx-navbar { | ||
| position: relative; | ||
| z-index: 0; | ||
| } | ||
| } | ||
|
|
||
| .content { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly use includes, better readibility in the template