Skip to content
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

Added Option for showing Diagrams based on selected Criteria #40

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/chart-js/src/bar-chart/bar-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class BarChartComponent extends ChartJsComponent{
text: resultRenderer.yAxisTitle
},
ticks: {
precision: 0
precision: 0,
autoSkip: false
}
},
x: {
Expand All @@ -52,7 +53,8 @@ export class BarChartComponent extends ChartJsComponent{
text: resultRenderer.xAxisTitle
},
ticks: {
precision: 0
precision: 0,
autoSkip: false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
::ng-deep lens-result-renderer-grid>.extra-high-diagram {
grid-row: auto / span 4;
}

::ng-deep lens-result-renderer-grid>.dontshow {
display: none;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {
CATALOGUE_FETCHER_TOKEN,
Category,
ChipTransformPipe,
LensConfig,
LENS_CONFIG_TOKEN,
QUERY_TRANSLATOR_TOKEN,
RESULT_TRANSFORMER_TOKEN,
STATIC_CATALOGUE_TOKEN,
TypescriptCatalogueFetcherService
} from '@samply/lens-core';

import { ResultRendererGridComponent } from './result-renderer-grid.component';
import { ResultRendererGridDirective } from './result-renderer-grid.directive';

const STATIC_CATALOGUE: Array<Category> = [];

describe('ResultRendererGridComponent', () => {
let component: ResultRendererGridComponent;
let fixture: ComponentFixture<ResultRendererGridComponent>;

beforeEach(async () => {
let queryTranslatorSpy = jasmine.createSpyObj(['transform']);
let resultTransformerSpy = jasmine.createSpyObj(['transform']);
await TestBed.configureTestingModule({
declarations: [ ResultRendererGridComponent, ResultRendererGridDirective ]
declarations: [ ResultRendererGridComponent, ResultRendererGridDirective ],
imports: [HttpClientTestingModule],
providers: [{
provide: QUERY_TRANSLATOR_TOKEN,
useValue: queryTranslatorSpy
},{
provide: RESULT_TRANSFORMER_TOKEN,
useValue: resultTransformerSpy
},{
provide: LENS_CONFIG_TOKEN,
useValue: new LensConfig()
},{
provide: ChipTransformPipe
},{
provide: CATALOGUE_FETCHER_TOKEN,
useClass: TypescriptCatalogueFetcherService
},{
provide: STATIC_CATALOGUE_TOKEN,
useValue: STATIC_CATALOGUE
}]
})
.compileComponents();

fixture = TestBed.createComponent(ResultRendererGridComponent);

component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from '@angular/core';
import {
ResultRenderer,
ResultRendererComponent
ResultRendererComponent,
QueryService
} from '@samply/lens-core';
import { ResultRendererGridDirective } from './result-renderer-grid.directive';

Expand All @@ -28,9 +29,18 @@ export class ResultRendererGridComponent implements OnInit {
@Input()
public resultRenderers: ResultRenderer[] = [];

private componentRefs: Array<any> = [];

constructor(
private renderer2: Renderer2
) { }
private renderer2: Renderer2,
private queryService: QueryService
) {
this.queryService.transformedResults$.subscribe(results => {
if(!this.queryService.isModified())
this.updateDiagramVisibility();
})
}

ngOnInit(): void {
this.loadResultRenderers()
}
Expand All @@ -39,13 +49,41 @@ export class ResultRendererGridComponent implements OnInit {
const viewContainerRef = this.resultRendererGrid.viewContainerRef;
viewContainerRef.clear();
this.resultRenderers.forEach((resultRenderer) => {
let resultRendererInjector = Injector.create(
const resultRendererInjector = Injector.create(
{name: "ResultRendererProvider", providers: [{provide: ResultRenderer, useValue: resultRenderer}]
});
let componentRef = viewContainerRef.createComponent<ResultRendererComponent>(resultRenderer.component, {injector: resultRendererInjector});
const componentRef = viewContainerRef.createComponent<ResultRendererComponent>(resultRenderer.component, {injector: resultRendererInjector});
if (resultRenderer.showOn != undefined
&& !this.showComponent(resultRenderer.showOn)) {
this.renderer2.addClass(componentRef.location.nativeElement, "dontshow");
} else {
this.renderer2.removeClass(componentRef.location.nativeElement, "dontshow");
}
if (resultRenderer.displayProperties.length > 0) {
resultRenderer.displayProperties.forEach(displayProperty => this.renderer2.addClass(componentRef.location.nativeElement, displayProperty))
}
this.componentRefs.push(componentRef)
})
}

updateDiagramVisibility() {
this.componentRefs.forEach((componentRef) => {
const resultRenderer = componentRef.instance.resultRenderer;
if (resultRenderer.showOn != undefined
&& !this.showComponent(resultRenderer.showOn)) {
this.renderer2.addClass(componentRef.location.nativeElement, "dontshow");
} else {
this.renderer2.removeClass(componentRef.location.nativeElement, "dontshow");
}
})
}

showComponent(showOn: Array<string>): boolean {
if (showOn.length === 0) return true;
return showOn.some(condition => {
if (condition === "empty-query" && this.queryService.isEmpty())
return true;
return this.queryService.read(condition) !== undefined;
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ResultRendererGridComponent } from './result-renderer-grid.component';
import {
CATALOGUE_FETCHER_TOKEN,
Category,
ChipTransformPipe,
LensConfig,
LENS_CONFIG_TOKEN,
QUERY_TRANSLATOR_TOKEN,
RESULT_TRANSFORMER_TOKEN,
STATIC_CATALOGUE_TOKEN,
TypescriptCatalogueFetcherService
} from '@samply/lens-core';

import { ResultRendererGridDirective } from './result-renderer-grid.directive';
import { HttpClientTestingModule } from '@angular/common/http/testing';

const STATIC_CATALOGUE: Array<Category> = [];

describe('ResultRendererGridDirective', () => {
let fixture: ComponentFixture<ResultRendererGridComponent>;
beforeEach(async () => {
let queryTranslatorSpy = jasmine.createSpyObj(['transform']);
let resultTransformerSpy = jasmine.createSpyObj(['transform']);
await TestBed.configureTestingModule({
declarations: [ResultRendererGridDirective, ResultRendererGridComponent],
imports: [HttpClientTestingModule],
providers: [{
provide: QUERY_TRANSLATOR_TOKEN,
useValue: queryTranslatorSpy
},{
provide: RESULT_TRANSFORMER_TOKEN,
useValue: resultTransformerSpy
},{
provide: LENS_CONFIG_TOKEN,
useValue: new LensConfig()
},{
provide: ChipTransformPipe
},{
provide: CATALOGUE_FETCHER_TOKEN,
useClass: TypescriptCatalogueFetcherService
},{
provide: STATIC_CATALOGUE_TOKEN,
useValue: STATIC_CATALOGUE
}]
}).compileComponents();
fixture = TestBed.createComponent(ResultRendererGridComponent);
})
Expand Down
1 change: 1 addition & 0 deletions core/src/lib/components/result-renderer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class ResultRendererComponent implements OnInit {
this.currentCondition = formerValue;
} else {
let criteria = this.catalogueService.getCriteria((this.resultRenderer.results[0].subset) ? this.resultRenderer.results[0].subset?.toLowerCase() : this.resultRenderer.results[0].key.toLowerCase())
if (criteria == undefined) return
this.currentCondition = new Condition(
criteria.key,
criteria.allowedConditionTypes[0],
Expand Down
4 changes: 4 additions & 0 deletions core/src/lib/model/result-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class ResultRenderer {
"#ff5600"
];
public readonly showNegotiationButton: boolean = false;
public readonly showOn: Array<string> = [];

constructor(
title: string,
Expand All @@ -82,6 +83,7 @@ export class ResultRenderer {
primaryColors?: string[]
hoverColors?: string[],
showNegotiationButton?: boolean
showOn?: Array<string>
} = { },
) {
this.title = title;
Expand Down Expand Up @@ -113,5 +115,7 @@ export class ResultRenderer {
this.hints = options.hints
if(options.showNegotiationButton != undefined)
this.showNegotiationButton = options.showNegotiationButton
if(options.showOn != undefined)
this.showOn = options.showOn
}
}
Loading