Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Urgen bug fixes... for current version. (refs #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsayer2 committed Nov 18, 2018
1 parent fb577d3 commit bcd174e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
15 changes: 10 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { DataStorageService } from './shared/data-storage.service';
import { Router, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
import { ColorGeneratorService } from './shared/color-generator.service';
import { Aurum } from './shared/aurum.model';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -46,17 +47,21 @@ export class AppComponent {
onInputData(event: any) {
const data = event.target.value;
const idOfData = event.target.id;
// console.log('READ from ', idOfData, ' input field with data: ', data);
const dataParsed: Aurum = JSON.parse(data);

this.dataStorage.changeData(JSON.parse(data), idOfData);
if (idOfData === 'data2') {
this.dataStorage.isComparison = true;
if (idOfData === 'data1') {
this.dataStorage.changeData(JSON.parse(data), idOfData);
}

// Cheap trick to not use the color generator twice as the attributes are the same for both
if (this.isNotGenerated) {
this.colorGenerator.generateStyleRules();
this.colorGenerator.generateStyleRules(dataParsed.searchTerms);
this.isNotGenerated = false;
}

if (idOfData === 'data2') {
this.dataStorage.changeIsComparison(true);
this.dataStorage.changeData(JSON.parse(data), idOfData);
}
}
}
9 changes: 7 additions & 2 deletions src/app/shared/color-generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export class ColorGeneratorService {
private criteriasArray: Array<String>;
private nColors: number;

generateStyleRules() {
generateStyleRules(searchTerms?: Array<string>) {
// Cretae the empty stylesheet
this.createStylesheet();
// Get the criterias now
this.criteriasArray = this.dataStorage.searchTermsInput;
if (searchTerms) {
this.criteriasArray = searchTerms;
} else {
this.criteriasArray = this.dataStorage.searchTermsInput;
}

this.nColors = this.criteriasArray.length;

// Generate the random colors next and the styles for each
Expand Down
31 changes: 18 additions & 13 deletions src/app/shared/data-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export class DataStorageService {
};

private defaultColor = new Map([['sample', 'rgb(200, 74, 12)'], ['test', 'rgb(220, 82, 110)']]);
private defaultComparison = false;

// Global variable that is used to see if we are in comparsion mode or not
private _isComparsion: boolean;
private _isComparsion = new BehaviorSubject<boolean>(this.defaultComparison);
public readonly isComparison = this._isComparsion.asObservable();

// The search terms of both
private _searchTermsInput: Array<String>;
// The set colors and position of rule in stylesheet
Expand All @@ -36,7 +39,6 @@ export class DataStorageService {
* Just initialize some stuff.
*/
constructor() {
this._isComparsion = false;
}

/**
Expand Down Expand Up @@ -69,19 +71,22 @@ export class DataStorageService {
this._currentColors.next(color);
}

/**
* Getter method for the check if we are in comparsion mode or not.
*/
get isComparsion(): boolean {
return this._isComparsion;
changeIsComparison(state: boolean) {
this._isComparsion.next(state);
}
// /**
// * Getter method for the check if we are in comparsion mode or not.
// */
// get isComparsion(): boolean {
// return this._isComparsion;
// }

/**
* Setter method for the check if we are in comparsion mode or not.
*/
set isComparison(value: boolean) {
this._isComparsion = value;
}
// /**
// * Setter method for the check if we are in comparsion mode or not.
// */
// set isComparison(value: boolean) {
// this._isComparsion = value;
// }

/**
* Getter method in order to retrieve all the search terms;
Expand Down
1 change: 1 addition & 0 deletions src/app/subsites/viz/viz.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
overflow: hidden;
}

.textOverview {
Expand Down
4 changes: 3 additions & 1 deletion src/app/subsites/viz/viz.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class VizComponent implements OnInit {
*/
ngOnInit() {
// Check if we are in comparison mode or not
this.isComparison = this.dataStorage.isComparsion;
this.dataStorage.isComparison.subscribe((val) => {
this.isComparison = val;
});

// TODO: Add maybe take(1) as we only need the values once anc can unsubscribe later
this.dataStorage.currentData.subscribe((data) => {
Expand Down

0 comments on commit bcd174e

Please sign in to comment.