remove moment from angular build

This commit is contained in:
2023-09-30 20:26:06 +02:00
parent 9a41f132f8
commit 96955e0515
3 changed files with 50 additions and 32 deletions

View File

@@ -1,10 +1,12 @@
import { Component, Output, EventEmitter } from '@angular/core';
import { DataType, AxesTypes, PlotResponseStats, PlotConfig, PlotService, PlotResponse, PlotRequest, RenderOptions, DataSeriesStats, DashTypeAndColor } from '../plot.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import * as moment from 'moment';
//import * as moment from 'moment';
import { WidgetDimensions } from '../dashboard.service';
import { Overlay } from "@angular/cdk/overlay";
import { DateTime, Duration } from "luxon";
@Component({
selector: 'pdb-plot-view',
templateUrl: './plot-view.component.html',
@@ -12,7 +14,7 @@ import { Overlay } from "@angular/cdk/overlay";
})
export class PlotViewComponent {
readonly DATE_PATTERN = "YYYY-MM-DD HH:mm:ss"; // for moment-JS
readonly DATE_PATTERN = "yyyy-MM-dd HH:mm:ss"; // for moment-JS
readonly gnuplotLMargin = 110; // The left margin configured for gnuplot
readonly gnuplotRMargin = 110; // The right margin configured for gnuplot
@@ -178,8 +180,8 @@ export class PlotViewComponent {
}
setDateRange(startDate: any, endDate: any) {
const formattedStartDate = startDate.format(this.DATE_PATTERN);
const formattedEndDate = endDate.format(this.DATE_PATTERN);
const formattedStartDate = startDate.toFormat(this.DATE_PATTERN);
const formattedEndDate = endDate.toFormat(this.DATE_PATTERN);
const newDateRange = formattedStartDate+" - "+formattedEndDate;
@@ -295,13 +297,13 @@ export class PlotViewComponent {
shiftDateByAnchor(dateRange:string, anchorInPercentOfDateRange:number, zoomFactor:number)
{
const dateRangeParsed = this.parseDateRange(dateRange);
const dateRangeInSeconds = dateRangeParsed.duration.asSeconds();
const dateRangeInSeconds = Math.floor(dateRangeParsed.duration.toMillis()/1000);
const anchorTimestampInSeconds = dateRangeParsed.startDate.clone().add(Math.floor(dateRangeInSeconds*anchorInPercentOfDateRange), "seconds");
const anchorTimestampInSeconds = dateRangeParsed.startDate.plus(Math.floor(dateRangeInSeconds*anchorInPercentOfDateRange)*1000);
const newDateRangeInSeconds = dateRangeInSeconds * zoomFactor;
const newStartDate = anchorTimestampInSeconds.clone().subtract(newDateRangeInSeconds*anchorInPercentOfDateRange, "seconds");
const newEndDate = newStartDate.clone().add({seconds: newDateRangeInSeconds});;
const newStartDate = anchorTimestampInSeconds.minus(newDateRangeInSeconds*anchorInPercentOfDateRange*1000);
const newEndDate = newStartDate.plus({seconds: newDateRangeInSeconds});;
this.setDateRange(newStartDate, newEndDate);
}
@@ -318,22 +320,23 @@ export class PlotViewComponent {
shiftDate(dateRange: string, factorStartDate: number, factorEndDate: number)
{
const dateRangeParsed = this.parseDateRange(dateRange);
const dateRangeInSeconds = dateRangeParsed.duration.asSeconds();
const dateRangeInSeconds = Math.floor(dateRangeParsed.duration.toMillis()/1000);
const newStartDate = dateRangeParsed.startDate.add({seconds: dateRangeInSeconds*factorStartDate});
const newEndDate = dateRangeParsed.endDate.add({seconds: dateRangeInSeconds*factorEndDate});
const newStartDate = dateRangeParsed.startDate.plus({seconds: dateRangeInSeconds*factorStartDate});
const newEndDate = dateRangeParsed.endDate.plus({seconds: dateRangeInSeconds*factorEndDate});
this.setDateRange(newStartDate, newEndDate);
}
parseDateRange(dateRangeAsString : string) : DateRange {
const startDate = moment(dateRangeAsString.slice(0, 19));
const endDate = moment(dateRangeAsString.slice(22, 41));
const startDate = DateTime.fromFormat(dateRangeAsString.slice(0, 19), this.DATE_PATTERN );
const endDate = DateTime.fromFormat(dateRangeAsString.slice(22, 41), this.DATE_PATTERN );
return {
startDate: startDate,
endDate: endDate,
duration: moment.duration(endDate.diff(startDate))
duration: endDate.diff(startDate),
};
}
@@ -375,7 +378,8 @@ export class LoadingEvent {
}
export class DateRange {
startDate: any;
endDate: any;
duration: any;
constructor(
public startDate: DateTime,
public endDate: DateTime,
public duration: Duration){}
}