Skip to content

Commit

Permalink
Remove max override and apply facet filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
wwtamu committed Aug 7, 2024
1 parent 640d1f0 commit ea74a7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="card shadow bg-white rounded m-1">
<div class="card-body">
<div class="h5">{{ 'DATA_AND_ANALYTICS.ACADEMIC_AGE_GROUP.PUBLICATIONS' | translate }}</div>
<scholars-barplot id="academicAgeBarplot" scale="1" [input]="academicAge" lineColor="{{primaryThemeColor | async}}" maxOverride="{{maxOverride | async}}"></scholars-barplot>
<scholars-barplot id="academicAgeBarplot" scale="1" [input]="academicAge" lineColor="{{primaryThemeColor | async}}"></scholars-barplot> <!-- [maxOverride]="maxOverride" -->
</div>
</div>
</div>
Expand All @@ -29,7 +29,7 @@
<div class="card shadow bg-white rounded m-1">
<div class="card-body">
<div class="h5">{{ 'DATA_AND_ANALYTICS.ACADEMIC_AGE_GROUP.AVERAGE_PUBLICATIONS' | translate }}</div>
<scholars-barplot id="averagePubRateAcademicAgeBarplot" scale="1" [input]="averagePubRateAcademicAge" lineColor="{{primaryThemeColor | async}}" maxOverride="{{maxOverride | async}}"></scholars-barplot>
<scholars-barplot id="averagePubRateAcademicAgeBarplot" scale="1" [input]="averagePubRateAcademicAge" lineColor="{{primaryThemeColor | async}}"></scholars-barplot><!-- [maxOverride]="maxOverride" -->
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -65,7 +66,8 @@ export class AcademicAgeGroupComponent implements OnInit, OnChanges {
@ViewChildren(BarplotComponent)
private barplots: QueryList<BarplotComponent>;

public maxOverride: Subject<number>;
// TODO: get from dataAndAnalyticsView
// public maxOverride: Subject<number>;

public mean: Subject<number>;

Expand All @@ -85,7 +87,7 @@ export class AcademicAgeGroupComponent implements OnInit, OnChanges {
private dialog: DialogService,
) {
this.labelEvent = new EventEmitter<string>();
this.maxOverride = new Subject<number>();
// this.maxOverride = new Subject<number>();
this.mean = new Subject<number>();
this.median = new Subject<number>();
this.sidebarMenuSections = {};
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 {

Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit ea74a7f

Please sign in to comment.