Compare commits

..

2 Commits

Author SHA1 Message Date
Willem Dantuma
b17bce1cd2 Add default unitScale
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
2021-01-25 20:18:04 +01:00
Willem Dantuma
bb555eec74 Remove fill colors for selected items 2021-01-25 18:28:26 +01:00
3 changed files with 84 additions and 86 deletions

View File

@ -116,8 +116,6 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
if (!this.stylesCache[key]) { if (!this.stylesCache[key]) {
if (this.itemTypeService.itemTypes[key]) { if (this.itemTypeService.itemTypes[key]) {
let itemType = this.itemTypeService.itemTypes[key]; let itemType = this.itemTypeService.itemTypes[key];
let fillColor = color.asArray(itemType.iconColor);
fillColor[3] = this.selectedItem?0:0.5;
this.stylesCache[key] = new style.Style({ this.stylesCache[key] = new style.Style({
image: itemType.icon ? new style.Icon({ image: itemType.icon ? new style.Icon({
anchor: [0.5, 1], anchor: [0.5, 1],
@ -128,9 +126,6 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
color: 'red', color: 'red',
width: 1 width: 1
}), }),
fill: new style.Fill({
color: fillColor
}),
geometry:(feature) => this.geometry(feature) geometry:(feature) => this.geometry(feature)
}); });
} else { } else {

View File

@ -64,9 +64,6 @@ export class MapEffects {
stroke: new style.Stroke({ stroke: new style.Stroke({
color: 'red', color: 'red',
width: 1 width: 1
}),
fill: new style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
}) })
}))); })));
actions.push(new mapActions.SetStyle('selected',new style.Style({ actions.push(new mapActions.SetStyle('selected',new style.Style({
@ -78,9 +75,6 @@ export class MapEffects {
stroke: new style.Stroke({ stroke: new style.Stroke({
color: 'red', color: 'red',
width: 3 width: 3
}),
fill: new style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
}) })
}))); })));

View File

@ -1,75 +1,84 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { Observable , Observer } from 'rxjs'; import { Observable , Observer } from 'rxjs';
import { ITypeaheadItem } from '../models/typeahead.item'; import { ITypeaheadItem } from '../models/typeahead.item';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class TimespanService { export class TimespanService {
constructor(private datePipe: DatePipe) { constructor(private datePipe: DatePipe) {
} }
unitScales: number[] = [1, 1000, 1000 * 60, 1000 * 60 * 60, 1000 * 60 * 60 * 24, 1000 * 60 * 60 * 24 * 7, 1000 * 60 * 60 * 24 * 31, 1000 * 60 * 60 * 24 * 31 * 3, 1000 * 60 * 60 * 24 * 365.25]; unitScales: number[] = [1, 1000, 1000 * 60, 1000 * 60 * 60, 1000 * 60 * 60 * 24, 1000 * 60 * 60 * 24 * 7, 1000 * 60 * 60 * 24 * 31, 1000 * 60 * 60 * 24 * 31 * 3, 1000 * 60 * 60 * 24 * 365.25];
units: string[] = ['millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year']; units: string[] = ['millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
quarters: string[] = ['KW1', 'KW2', 'KW3', 'KW4']; quarters: string[] = ['KW1', 'KW2', 'KW3', 'KW4'];
getStartEndCaption(date: Date, otherDate: Date, unitScale: number, suffix: boolean = false, extended: boolean = true): string { getStartEndCaption(date: Date, otherDate: Date, unitScale: number, suffix: boolean = false, extended: boolean = true): string {
let showSuffix = false; let showSuffix = false;
otherDate = new Date(otherDate.getTime() - 1); // fix year edge case otherDate = new Date(otherDate.getTime() - 1); // fix year edge case
if (unitScale == 3) { if (unitScale == 3) {
let format = "HH:00"; let format = "HH:00";
if (extended) { if (extended) {
if (suffix || date.getFullYear() != otherDate.getFullYear()) if (suffix || date.getFullYear() != otherDate.getFullYear())
format = "d MMM yyyy:HH:00"; format = "d MMM yyyy:HH:00";
else if (date.getMonth() !== otherDate.getMonth()) else if (date.getMonth() !== otherDate.getMonth())
format = "d MMM HH:00"; format = "d MMM HH:00";
} }
return this.datePipe.transform(date, format); return this.datePipe.transform(date, format);
} }
if (unitScale == 4) { if (unitScale == 4) {
let format = "d"; let format = "d";
if (extended) { if (extended) {
if (suffix || date.getFullYear() != otherDate.getFullYear()) if (suffix || date.getFullYear() != otherDate.getFullYear())
format = "d MMM yyyy"; format = "d MMM yyyy";
else if (date.getMonth() !== otherDate.getMonth()) else if (date.getMonth() !== otherDate.getMonth())
format = "d MMM" format = "d MMM"
} }
return this.datePipe.transform(date, format); return this.datePipe.transform(date, format);
} }
if (unitScale == 6) { if (unitScale == 6) {
let format = "MMM"; let format = "MMM";
if (extended) { if (extended) {
if (suffix || date.getFullYear() != otherDate.getFullYear()) if (suffix || date.getFullYear() != otherDate.getFullYear())
format = "MMM yyyy"; format = "MMM yyyy";
} }
return this.datePipe.transform(date, format); return this.datePipe.transform(date, format);
} }
if (unitScale == 7) { if (unitScale == 7) {
let q = Math.trunc(date.getMonth() / 3); let q = Math.trunc(date.getMonth() / 3);
return this.quarters[q]; return this.quarters[q];
} }
if (unitScale == 8) { if (unitScale == 8) {
return this.datePipe.transform(date, "yyyy"); return this.datePipe.transform(date, "yyyy");
} }
return ""; return "";
} }
getStartCaption(startDate: Date, endDate: Date, unitScale: number, suffix: boolean = false, extended: boolean = true): string { getStartCaption(startDate: Date, endDate: Date, unitScale: number, suffix: boolean = false, extended: boolean = true): string {
return this.getStartEndCaption(new Date(startDate.getTime() + (this.unitScales[unitScale] / 2)), endDate, unitScale, suffix, extended); return this.getStartEndCaption(new Date(startDate.getTime() + (this.unitScales[unitScale] / 2)), endDate, unitScale, suffix, extended);
} }
getEndCaption(startDate: Date,endDate: Date, unitScale: number, suffix: boolean = true): string { getEndCaption(startDate: Date,endDate: Date, unitScale: number, suffix: boolean = true): string {
return this.getStartEndCaption(new Date(endDate.getTime() - (this.unitScales[unitScale] / 2)), startDate, unitScale, suffix); return this.getStartEndCaption(new Date(endDate.getTime() - (this.unitScales[unitScale] / 2)), startDate, unitScale, suffix);
} }
getCaption(startDate: Date, endDate: Date, unitScale: number): string { getCaption(startDate: Date, endDate: Date, unitScale?: number): string {
let startCaption = this.getStartCaption(startDate, endDate, unitScale); let scale = unitScale;
let endCaption = this.getEndCaption(startDate,endDate, unitScale); if(unitScale==null) {
if ((endDate.getTime() - startDate.getTime()) < (1.5 * this.unitScales[unitScale])) scale=4;
return endCaption; if(startDate.getUTCMonth() == 0 && startDate.getUTCDate() == 1 && startDate.getUTCHours() == 0 && startDate.getUTCMinutes() ==0 && startDate.getUTCSeconds() ==0 &&
return `${startCaption}-${endCaption}`; endDate.getUTCMonth() == 0 && endDate.getUTCDate() == 1 && endDate.getUTCHours() == 0 && endDate.getUTCMinutes() ==0 && endDate.getUTCSeconds() ==0) {
} scale=8;
} else if (startDate.getUTCHours() > 0 && startDate.getUTCMinutes() >0) {
} scale =3
}
}
let startCaption = this.getStartCaption(startDate, endDate, scale);
let endCaption = this.getEndCaption(startDate,endDate, scale);
if ((endDate.getTime() - startDate.getTime()) < (1.5 * this.unitScales[scale]))
return endCaption;
return `${startCaption}-${endCaption}`;
}
}