diff --git a/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.html b/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.html index f18e5f4ac..529a2644b 100644 --- a/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.html +++ b/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.html @@ -13,7 +13,7 @@
{{ 'DATA_AND_ANALYTICS.ACADEMIC_AGE_GROUP.PUBLICATIONS' | translate }}
- +
@@ -29,7 +29,7 @@
{{ 'DATA_AND_ANALYTICS.ACADEMIC_AGE_GROUP.AVERAGE_PUBLICATIONS' | translate }}
- +
diff --git a/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.ts b/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.ts index a10a99f12..9311c54ed 100644 --- a/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.ts +++ b/src/app/+data-and-analytics/academic-age-group/academic-age-group.component.ts @@ -1,5 +1,5 @@ import { isPlatformServer } from '@angular/common'; -import { Component, EventEmitter, Inject, Input, OnChanges, OnInit, Output, PLATFORM_ID, QueryList, SimpleChanges, ViewChildren } from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, OnChanges, OnInit, Output, PLATFORM_ID, QueryList, SimpleChanges, ViewChildren } from '@angular/core'; import { Store, select } from '@ngrx/store'; import { Observable, Subject, filter, map, tap } from 'rxjs'; @@ -35,6 +35,7 @@ const apk = 'Average publications'; templateUrl: './academic-age-group.component.html', styleUrls: ['./academic-age-group.component.scss'], animations: [fadeIn], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class AcademicAgeGroupComponent implements OnInit, OnChanges { @@ -65,7 +66,8 @@ export class AcademicAgeGroupComponent implements OnInit, OnChanges { @ViewChildren(BarplotComponent) private barplots: QueryList; - public maxOverride: Subject; + // TODO: get from dataAndAnalyticsView + // public maxOverride: Subject; public mean: Subject; @@ -85,7 +87,7 @@ export class AcademicAgeGroupComponent implements OnInit, OnChanges { private dialog: DialogService, ) { this.labelEvent = new EventEmitter(); - this.maxOverride = new Subject(); + // this.maxOverride = new Subject(); this.mean = new Subject(); this.median = new Subject(); this.sidebarMenuSections = {}; @@ -144,59 +146,61 @@ export class AcademicAgeGroupComponent implements OnInit, OnChanges { setTimeout(() => { const additionalFilters = []; - if (!!filters) { - if (!!filters.previousValue) { - filters.previousValue.forEach((entry: any) => { - if (filters.currentValue.indexOf(entry) === -1) { - const section = this.sidebarMenuSections[entry.field]; - if (!!section) { + if (filters) { + if (filters.previousValue) { + filters.previousValue.forEach((previousValue: any) => { + if (filters.currentValue.indexOf(previousValue) === -1) { + const section = this.sidebarMenuSections[previousValue.field]; + if (section) { this.store.dispatch(new fromSidebar.RemoveSectionAction({ sectionIndex: section.index, - itemLabel: entry.value, - itemField: entry.field, + itemLabel: previousValue.value, + itemField: previousValue.field, })); } } }); } - filters.currentValue.forEach((entry: any) => { - if (filters.previousValue === undefined || filters.previousValue.indexOf(entry) === -1) { - const section = this.sidebarMenuSections[entry.field]; - if (!!section) { - const remove = {}; - remove[entry.field] + filters.currentValue.forEach((currentFilter: any) => { + if (filters.previousValue === undefined || filters.previousValue.indexOf(currentFilter) === -1) { + const section = this.sidebarMenuSections[currentFilter.field]; + if (section) { this.store.dispatch(new fromSidebar.AddSectionItemAction({ sectionIndex: section.index, sectionItem: { type: SidebarItemType.ACTION, - label: entry.value, + label: currentFilter.value, selected: true, - action: new fromRouter.RemoveFilter({ filter: entry }), + action: new fromRouter.RemoveFilter({ filter: currentFilter }), } })); } } + additionalFilters.push(currentFilter); }); - additionalFilters.push(filters.currentValue); - additionalFilters.shift(); } - if (this.organization.id === this.defaultId) { - this.maxOverride.next(3000); - } else { - this.maxOverride.next(undefined); - } + // if (this.organization.id === this.defaultId) { + // this.maxOverride.next(3000); + // } else { + // this.maxOverride.next(undefined); + // } this.barplots.forEach(barplot => barplot.draw()); if (this.organization.id !== this.defaultId && !!this.organization.name) { - additionalFilters.push({ + + const actualFilter = { field: 'organizations', value: this.organization.name, opKey: OpKey.EQUALS - }); + }; + + if (additionalFilters.indexOf(actualFilter) === -1) { + additionalFilters.push(actualFilter); + } } this.store.dispatch( diff --git a/src/app/+data-and-analytics/academic-age-group/barplot/barplot.component.ts b/src/app/+data-and-analytics/academic-age-group/barplot/barplot.component.ts index 5bf87b637..45c4ab369 100644 --- a/src/app/+data-and-analytics/academic-age-group/barplot/barplot.component.ts +++ b/src/app/+data-and-analytics/academic-age-group/barplot/barplot.component.ts @@ -1,5 +1,5 @@ import { isPlatformServer } from '@angular/common'; -import { Component, Inject, Input, PLATFORM_ID } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, Input, PLATFORM_ID } from '@angular/core'; import * as d3 from 'd3'; @@ -15,7 +15,8 @@ export interface BarplotInput { @Component({ selector: 'scholars-barplot', templateUrl: './barplot.component.html', - styleUrls: ['./barplot.component.scss'] + styleUrls: ['./barplot.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class BarplotComponent { @@ -67,7 +68,7 @@ export class BarplotComponent { const data = [...input.data].reverse(); if (index === 0) { - const max = !!this.maxOverride ? this.maxOverride : d3.max(data.map((d: any) => d.value)); + const max = this.maxOverride ? this.maxOverride : d3.max(data.map((d: any) => d.value)); // append the svg object to the body of the page svg = d3.select(`#${this.id}`)