Merged PR 66: Enhanced directives functionality and chartFactory options...
ca192d78
Dobromir Tsvetkov
authored and
Zdravko Kolev
committed
succeeded
7 changed files
context-menu.component.html
/projects/igniteui-angular-extras/src/lib/context-menu/context-menu.component.html-1+1
/projects/igniteui-angular-extras/src/lib/context-menu/context-menu.component.html
Add comment 31 </div>
Add comment 32 </igx-tab-content>
Add comment 33 </igx-tab-item>
Add comment 34 Minus   <igx-tab-item [disabled]="!chartTypes.length">
Add comment 34 Plus   <igx-tab-item *ngIf="displayCreationTab" [disabled]="!chartTypes.length">
Add comment 35 <igx-tab-header>
Add comment 36 <span igxTabHeaderLabel>Create Chart</span>
Add comment 37 </igx-tab-header>
context-menu.component.ts
/projects/igniteui-angular-extras/src/lib/context-menu/context-menu.component.ts-1+24
/projects/igniteui-angular-extras/src/lib/context-menu/context-menu.component.ts
Add comment 1 import { AfterViewInit, Component, ElementRef, ViewChild, ViewContainerRef, OnDestroy, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
Add comment 2 Minus  import { CommonModule, NgFor } from '@angular/common';
Add comment 2 Plus  import { CommonModule, NgFor, NgIf } from '@angular/common';
Add comment 3 import { Subject } from 'rxjs';
Add comment 4 import { takeUntil } from 'rxjs/operators';
Add comment 5 import {
Add comment 43 imports: [
Add comment 44 CommonModule,
Add comment 45 NgFor,
Add comment 46 Plus   NgIf,
Add comment 46 47 SvgPipe,
Add comment 47 48 IgxToggleDirective,
Add comment 48 49 IgxIconComponent,
Add comment 79 80 public textFormatters = [];
Add comment 80 81 public currentChartType;
Add comment 81 82 public currentFormatter;
Add comment 83 Plus   public displayCreationTab = true;
Add comment 82 84 private destroy$ = new Subject<any>();
Add comment 83 85 private _dialogId;
Add comment 84 86 private _chartDialogOS: OverlaySettings = { closeOnOutsideClick: false };
Add comment 124 126 public ngAfterViewInit() {
Add comment 125 127 this.chartTypes = this.contextDirective.charts;
Add comment 126 128 this.textFormatters = this.contextDirective.formatters;
Add comment 129 Plus   this.displayCreationTab = this.contextDirective.displayCreationTab;
Add comment 127 130
Add comment 128 131 if (this.contextDirective.chartsDirective) {
Add comment 129 132 this.contextDirective.chartsDirective.onChartTypesDetermined.pipe(takeUntil(this.destroy$))
Add comment 158 161 instance.currentChartType = this.currentChartType;
Add comment 159 162 instance.allCharts = this.chartTypes;
Add comment 160 163 instance.chartDirective = this.contextDirective.chartsDirective;
Add comment 164 Plus   // TODO: This code handles resizing for a fullscreen dialog when the chart dialog resize event is triggered.
Add comment 165 Plus   // Currently, it determines the visible child element by filtering based on visibility and CSS classes,
Add comment 166 Plus   // which is not a reliable or optimal approach. Instead, this should be improved by properly handling
Add comment 167 Plus   // when elements in the overlay are detached and ensuring chart dialog is only available.
Add comment 168 Plus   instance.chartDialogResizeNotify?.subscribe(resizedContentArgs => {
Add comment 169 Plus   if ((this.overlayService as any)._overlayElement) {
Add comment 170 Plus   const overlayElement = (this.overlayService as any)._overlayElement;
Add comment 171 Plus   const visibleChild = Array.from(overlayElement.children).find(
Add comment 172 Plus   (child: HTMLElement) =>
Add comment 173 Plus   getComputedStyle(child).visibility !== 'hidden' &&
Add comment 174 Plus   child.classList.contains('igx-overlay__wrapper--flex')
Add comment 175 Plus   ) as HTMLElement | null;
Add comment 176 Plus   if (visibleChild) {
Add comment 177 Plus   const targetElement = visibleChild.children[0] as HTMLElement | null;
Add comment 178 Plus   if (targetElement && targetElement.style) {
Add comment 179 Plus   targetElement.style.width = resizedContentArgs[0].contentRect.width + 'px';
Add comment 180 Plus   }
Add comment 181 Plus   }
Add comment 182 Plus   }
Add comment 183 Plus   });
Add comment 161 184 instance.onClose?.subscribe(() => this.closeDialog());
Add comment 162 185 }
Add comment 163 186 });
igx-context-menu.directive.ts
/projects/igniteui-angular-extras/src/lib/context-menu/igx-context-menu.directive.ts-1+2
/projects/igniteui-angular-extras/src/lib/context-menu/igx-context-menu.directive.ts
Add comment 3 Directive,
Add comment 4 EventEmitter,
Add comment 5 Output,
Add comment 6 Plus   Input,
Add comment 6 7 OnInit,
Add comment 7 8 OnDestroy,
Add comment 8 9 Optional,
Add comment 28 29 selector: '[igxContextMenu]',
Add comment 29 30 })
Add comment 30 31 export class IgxContextMenuDirective implements OnInit, AfterViewInit, OnDestroy {
Add comment 31 Minus  
Add comment 32 Plus   @Input() public displayCreationTab: boolean = true;
Add comment 32 33 @Output() public onButtonClose = new EventEmitter<any>();
Add comment 33 34
Add comment 34 35 public formatters = [];
chart-integration.directive.ts
/projects/igniteui-angular-extras/src/lib/directives/chart-integration/chart-integration.directive.ts-9+19
/projects/igniteui-angular-extras/src/lib/directives/chart-integration/chart-integration.directive.ts
Add comment 13 IgxPieChartInitializer, IgxStackedDataChartInitializer, IOptions } from './initializers';
Add comment 14
Add comment 15 export interface IDeterminedChartTypesArgs {
Add comment 16 Minus   chartsAvailabilty: Map<CHART_TYPE, boolean>;
Add comment 16 Plus   chartsAvailability: Map<CHART_TYPE, boolean>;
Add comment 17 chartsForCreation: CHART_TYPE[];
Add comment 18 }
Add comment 19
Add comment 33 this._valueMemberPaths = Object.keys(dataModel).filter(key => typeof dataModel[key] === 'number');
Add comment 34 this._chartData = selectedData.map((dataRecord, index) => this.addIndexMemberPath(dataRecord, index + 1));
Add comment 35 const args: IDeterminedChartTypesArgs = {
Add comment 36 Minus   chartsAvailabilty: new Map<CHART_TYPE, boolean>(),
Add comment 36 Plus   chartsAvailability: new Map<CHART_TYPE, boolean>(),
Add comment 37 chartsForCreation: []
Add comment 38 };
Add comment 39
Add comment 68 charts.delete(CHART_TYPE.SCATTER_BUBBLE);
Add comment 69 }
Add comment 70
Add comment 71 Minus   args.chartsAvailabilty = this.chartTypesAvailability;
Add comment 71 Plus   args.chartsAvailability = this.chartTypesAvailability;
Add comment 72 args.chartsForCreation = [...charts];
Add comment 73 this.onChartTypesDetermined.emit(args);
Add comment 74 }
Add comment 188 }
Add comment 189 }
Add comment 190
Add comment 191 Plus   public getAllChartTypes() {
Add comment 192 Plus   return Array.from(this._dataChartTypes);
Add comment 193 Plus   }
Add comment 194 Plus  
Add comment 191 195 public getAvailableCharts() {
Add comment 192 196 const res = [];
Add comment 193 197 this.chartTypesAvailability.forEach((isAvailable, chartType) => {
Add comment 214 218 });
Add comment 215 219 }
Add comment 216 220
Add comment 217 Minus   public chartFactory(type: CHART_TYPE, viewContainerRef: ViewContainerRef) {
Add comment 221 Plus   public chartFactory(type: CHART_TYPE, viewContainerRef?: ViewContainerRef, createdChart?: any) {
Add comment 218 222 if (!this.chartTypesAvailability.get(type)) {
Add comment 219 223 return;
Add comment 220 224 }
Add comment 225 Plus   const chartType = this.dataCharts.get(type);
Add comment 226 Plus   const options: IChartComponentOptions = this.getChartOptions(type);
Add comment 227 Plus   const initializer: ChartInitializer = this.getInitializer(type, chartType);
Add comment 228 Plus   let chart;
Add comment 229 Plus   if (viewContainerRef) {
Add comment 221 230 let componentFactory: ComponentFactory<any>;
Add comment 222 231 let componentRef: ComponentRef<any>;
Add comment 223 232 this._sizeScale.maximumValue = 60;
Add comment 224 233 this._sizeScale.minimumValue = 10;
Add comment 225 Minus   const chartType = this.dataCharts.get(type);
Add comment 226 234
Add comment 227 235 if (type === CHART_TYPE.PIE) {
Add comment 228 236 componentFactory = this.factoryResolver.resolveComponentFactory(IgxPieChartComponent);
Add comment 231 239 componentFactory = this.factoryResolver.resolveComponentFactory(IgxDataChartComponent);
Add comment 232 240 componentRef = viewContainerRef.createComponent(componentFactory);
Add comment 233 241 }
Add comment 234 Minus   const options: IChartComponentOptions = this.getChartOptions(type);
Add comment 235 Minus   const initializer: ChartInitializer = this.getInitializer(type, chartType);
Add comment 242 Plus  
Add comment 236 243 if (this.useLegend) {
Add comment 237 244 const legendType = type === CHART_TYPE.PIE ? IgxItemLegendComponent : IgxLegendComponent;
Add comment 238 245 const legendFactory = this.factoryResolver.resolveComponentFactory(legendType as any);
Add comment 239 246 const legendComponentRef: ComponentRef<any> = viewContainerRef.createComponent(legendFactory);
Add comment 240 247 options.chartOptions['legend'] = legendComponentRef.instance;
Add comment 241 248 }
Add comment 242 Minus   const chart = initializer.initChart(componentRef.instance, options);
Add comment 249 Plus   chart = initializer.initChart(componentRef.instance, options);
Add comment 250 Plus   } else if (createdChart) {
Add comment 251 Plus   chart = initializer.initChart(createdChart, options);
Add comment 252 Plus   }
Add comment 243 253 this.onChartCreationDone.emit(chart);
Add comment 254 Plus   return chart;
Add comment 244 255 }
Add comment 245 256
Add comment 246 257 private getInitializer(chartType: CHART_TYPE, componentClassRef): ChartInitializer {
Add comment 339 350 this.customChartComponentOptions.get(chart)[optionsType][property] = options[property];
Add comment 340 351 });
Add comment 341 352 }
Add comment 342 Minus  
Add comment 343 353 }
Add comment 344 354
initializers.ts
/projects/igniteui-angular-extras/src/lib/directives/chart-integration/initializers.ts-1+13
/projects/igniteui-angular-extras/src/lib/directives/chart-integration/initializers.ts
Add comment 52 }
Add comment 53
Add comment 54 public initChart(chart: IgxPieChartComponent, options: IChartComponentOptions) {
Add comment 55 Minus  
Add comment 56 55 this.applyOptions(chart, options.chartOptions);
Add comment 57 56 return chart;
Add comment 58 57 }
Add comment 83 82 }
Add comment 84 83
Add comment 85 84 public initChart(chart: IgxDataChartComponent, options: IChartComponentOptions): IgxDataChartComponent {
Add comment 85 Plus   if (chart.series.count) {
Add comment 86 Plus   chart.series.clear();
Add comment 87 Plus   }
Add comment 88 Plus   if (chart.axes.count) {
Add comment 89 Plus   chart.axes.clear();
Add comment 90 Plus   }
Add comment 86 91 options.seriesOptions.forEach((option) => {
Add comment 87 92 const series = this.seriesFactory.create(this.seriesType);
Add comment 88 93 series.xAxis = this.xAxis;
Add comment 114 119 this.seriesType = seriesType;
Add comment 115 120 }
Add comment 116 121 public initChart(chart: IgxDataChartComponent, options?: IChartComponentOptions): IgxDataChartComponent {
Add comment 122 Plus   if (chart.series.count) {
Add comment 123 Plus   chart.series.clear();
Add comment 124 Plus   }
Add comment 125 Plus   if (chart.axes.count) {
Add comment 126 Plus   chart.axes.clear();
Add comment 127 Plus   }
Add comment 128 Plus  
Add comment 117 129 const series = this.seriesFactory.create(this.seriesType);
Add comment 118 130 series.xAxis = this.xAxis;
Add comment 119 131 series.yAxis = this.yAxis;
package-lock.json
/package-lock.json
/package-lock.json
package.json
/package.json
/package.json