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

Feature/dpg fixes and improvements #46

Merged
merged 19 commits into from
Nov 8, 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
47 changes: 19 additions & 28 deletions src/app/datapoints-graph/charts/chart-realtime.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import {
} from '@c8y/ngx-components';
import type { ECharts, SeriesOption } from 'echarts';
import { EchartsOptionsService } from './echarts-options.service';
import {
customSeriesMarkLineData,
customSeriesMarkPointData,
CustomSeriesOptions,
} from './chart.model';
import { CustomSeriesOptions } from './chart.model';

type Milliseconds = number;

Expand Down Expand Up @@ -224,7 +220,7 @@ export class ChartRealtimeService {
seriesDataToUpdate.get(datapoint)?.push(measurement);
});

const allDataSeries = this.echartsInstance?.getOption()[
let allDataSeries = this.echartsInstance?.getOption()[
'series'
] as CustomSeriesOptions[];

Expand Down Expand Up @@ -301,29 +297,24 @@ export class ChartRealtimeService {
);
}
);
// update the last value of the markline to the new value
const markLine = alarmSeries.find((series) => series['markLine']);
const alarmSeriesMarkLine = markLine![
'markLine'
] as customSeriesMarkLineData;
alarmSeriesMarkLine.data[1].xAxis = (alarmOrEvent as IAlarm)[
'lastUpdated'
];
// update the last value of the markpoint to the new value
const markPoint = alarmSeries.find((series) => series['markPoint']);
const alarmSeriesMarkPoint = markPoint![
'markPoint'
] as customSeriesMarkPointData;
// remove all matching alarm series which are in the array
alarmSeries.forEach((series) => {
allDataSeries = allDataSeries.filter(
(s) => s['id'] !== series['id']
);
});

// the if block is needed in case an alarm has occured, of that type, but for a different target device.
if (alarmSeriesMarkPoint.data?.length > 2) {
alarmSeriesMarkPoint.data[2].coord[0] = (alarmOrEvent as IAlarm)[
'lastUpdated'
];
alarmSeriesMarkPoint.data[3].coord[0] = (alarmOrEvent as IAlarm)[
'lastUpdated'
];
}
const newAlarmSeries =
this.echartsOptionsService.getAlarmOrEventSeries(
dp,
renderType,
false,
[alarmOrEvent],
'alarm',
displayOptions,
(alarmOrEvent as IAlarm).creationTime
);
allDataSeries.push(...newAlarmSeries);
} else {
const newAlarmSeries =
this.echartsOptionsService.getAlarmOrEventSeries(
Expand Down
2 changes: 2 additions & 0 deletions src/app/datapoints-graph/charts/charts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ export class ChartsComponent implements OnChanges, OnInit, OnDestroy {
{
displayMarkedLine: this.config.displayMarkedLine || false,
displayMarkedPoint: this.config.displayMarkedPoint || false,
mergeMatchingDatapoints: this.config.mergeMatchingDatapoints || false,
showLabelAndUnit: this.config.showLabelAndUnit || false,
}
);
}
Expand Down
105 changes: 90 additions & 15 deletions src/app/datapoints-graph/charts/echarts-options.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
);
// then
expect(JSON.stringify(options)).toBe(
Expand Down Expand Up @@ -192,7 +197,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
);
// then
expect(options.grid).toEqual({
Expand All @@ -219,7 +229,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
);
// then
expect(options.grid).toEqual({
Expand Down Expand Up @@ -252,7 +267,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
);
// then
expect(options.grid).toEqual({
Expand All @@ -277,7 +297,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).dataZoom as DataZoomComponentOption;
// then
expect(dataZoomOptions.filterMode).toBe('filter');
Expand All @@ -294,7 +319,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).dataZoom as DataZoomComponentOption;
// then
expect(dataZoomOptions.filterMode).toBe('none');
Expand All @@ -311,7 +341,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).xAxis as XAXisOption;
// then
expect(xAxisOptions.axisLine?.onZeroAxisIndex).toBe(-1);
Expand All @@ -328,7 +363,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).xAxis as XAXisOption;
// then
expect(xAxisOptions.axisLine?.onZeroAxisIndex).toBe(1);
Expand Down Expand Up @@ -361,7 +401,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).tooltip as TooltipOption
).formatter as TooltipFormatterCallback<TopLevelFormatterParams>;
// when
Expand Down Expand Up @@ -408,7 +453,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).tooltip as TooltipOption
).formatter as TooltipFormatterCallback<TopLevelFormatterParams>;
// when
Expand Down Expand Up @@ -469,7 +519,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).tooltip as TooltipOption
).formatter as TooltipFormatterCallback<TopLevelFormatterParams>;
// when
Expand Down Expand Up @@ -513,7 +568,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).tooltip as TooltipOption
).formatter as TooltipFormatterCallback<TopLevelFormatterParams>;
// when
Expand Down Expand Up @@ -543,7 +603,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).series as SeriesOption[];
// then
expect(series).toHaveLength(1);
Expand Down Expand Up @@ -574,7 +639,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).series as SeriesOption[];
// then
expect(series).toHaveLength(2);
Expand Down Expand Up @@ -613,7 +683,12 @@ describe('EchartsOptionsService', () => {
},
[],
[],
{ displayMarkedLine: true, displayMarkedPoint: true }
{
displayMarkedLine: true,
displayMarkedPoint: true,
mergeMatchingDatapoints: true,
showLabelAndUnit: true,
}
).series as SeriesOption[];
// then
expect(series).toHaveLength(2);
Expand Down
Loading
Loading