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

feat: Enforce X limits of axis based on selected timerange #65

Merged
merged 3 commits into from
Jul 13, 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
4 changes: 4 additions & 0 deletions services/frontend/src/components/charts/chart-analog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:height="props.height"
:show-x-ticks="props.showXTicks"
:x-tick-unit="props.xTickUnit"
:x-limits="props.dateRange"
/>
</template>

Expand Down Expand Up @@ -40,6 +41,7 @@ import {
DeepPartial,
} from '@/utils/types.ts';
import {
IDatetimeRange,
ITimeseries, toChartJsData,
} from '@/components/charts/timeseries.ts';

Expand All @@ -52,6 +54,7 @@ interface IChartAnalogProps {
tickStepSize?: number;
showXTicks?: boolean;
xTickUnit?: TimeUnit;
dateRange?: IDatetimeRange;
}

const props = withDefaults(defineProps<IChartAnalogProps>(), {
Expand All @@ -64,6 +67,7 @@ const props = withDefaults(defineProps<IChartAnalogProps>(), {
tickStepSize: 5,
showXTicks: true,
xTickUnit: 'day',
dateRange: undefined,
});

const lineGradient = ref<GradientCache>({
Expand Down
7 changes: 7 additions & 0 deletions services/frontend/src/components/charts/chart-base-line.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ import {
xTicksGradient,
} from '@/components/charts/gradients.ts';
import crosshair from '@/components/charts/crosshair.ts';
import {
IDatetimeRange,
} from '@/components/charts/timeseries.ts';

interface IChartBaseLineProps {
chartData: DeepPartial<TLineChartData>;
yAxes: TLineAxisProps;
height?: string;
showXTicks?: boolean;
xTickUnit?: TimeUnit;
xLimits?: IDatetimeRange;
}

const props = withDefaults(
Expand All @@ -55,6 +59,7 @@ const props = withDefaults(
height: '10rem',
showXTicks: true,
xTickUnit: 'day',
xLimits: undefined,
},
);

Expand Down Expand Up @@ -101,6 +106,8 @@ const chartOptions = computed<DeepPartial<ChartOptions>>(() => {
color: tickColor,
tickColor,
},
min: props.xLimits?.startAt.toISOString(),
max: props.xLimits?.endAt.toISOString(),
},
};
// explicitly set the color of the ticks and grid lines if not set in the props
Expand Down
4 changes: 4 additions & 0 deletions services/frontend/src/components/charts/chart-digital.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:y-axes="yAxes"
:height="props.height"
:show-x-ticks="props.showXTicks"
:x-limits="props.dateRange"
/>
</template>

Expand Down Expand Up @@ -34,6 +35,7 @@ import {
DeepPartial,
} from '@/utils/types.ts';
import {
IDatetimeRange,
ITimeseries, toChartJsData,
} from '@/components/charts/timeseries.ts';
import i18n from '@/plugins/i18n';
Expand All @@ -43,12 +45,14 @@ interface IChartAnalogProps {
color: string | GradientDefinition | DiscreteGradientDefinition;
height?: string;
showXTicks?: boolean;
dateRange?: IDatetimeRange;
}

const props = withDefaults(defineProps<IChartAnalogProps>(), {
height: '10rem',
tickStepSize: 5,
showXTicks: true,
dateRange: undefined,
});

const limits: [number, number] = [
Expand Down
4 changes: 4 additions & 0 deletions services/frontend/src/components/charts/chart-temp-humi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:y-axes="yAxes"
height="20rem"
:x-tick-unit="xTickUnit"
:x-limits="props.dateRange"
/>
</template>

Expand Down Expand Up @@ -40,15 +41,18 @@ import {
DeepPartial,
} from '@/utils/types.ts';
import {
IDatetimeRange,
ITimeseries, toChartJsData,
} from '@/components/charts/timeseries.ts';

const props = withDefaults(defineProps<{
temperature: ITimeseries,
humidity: ITimeseries,
xTickUnit?: TimeUnit;
dateRange?: IDatetimeRange;
}>(), {
xTickUnit: 'day',
dateRange: undefined,
});

const tempGradient = ref<GradientCache>({
Expand Down
15 changes: 14 additions & 1 deletion services/frontend/src/components/charts/timeseries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import dayjs from 'dayjs';
import dayjs, {
Dayjs,
} from 'dayjs';

/**
* Determines the type of values of the timeseries.
Expand All @@ -13,6 +15,17 @@ export enum ETimeseriesValueType {
BOOLEAN = 'boolean',
}

/**
* Defines a timerange
*
* @property startAt - The first timestamp to be included in the range
* @property endAt - The last timestamp to be included in the range
*/
export interface IDatetimeRange {
startAt: Dayjs,
endAt: Dayjs,
}

/**
* Defines a timeseries with all information required to render it.
*
Expand Down
18 changes: 13 additions & 5 deletions services/frontend/src/components/driver/driver-timeseries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:temperature="signalTimeseries.find((ts) => ts.displayName === 'temperature')!"
:humidity="signalTimeseries.find((ts) => ts.displayName === 'humidity')!"
:x-tick-unit="xTickUnit"
:date-range="dataRange"
/>
<div
v-for="ts in signalTimeseries"
Expand All @@ -43,6 +44,7 @@
:timeseries="ts"
:color="nextColor()"
:x-tick-unit="xTickUnit"
:date-range="dataRange"
/>
</div>
</template>
Expand All @@ -69,7 +71,7 @@ import {
TGetTimeseriesResponse,
} from '@/api/timeseries.ts';
import {
getLastTimestamp,
getLastTimestamp, IDatetimeRange,
ITimeseries,
} from '@/components/charts/timeseries.ts';
import {
Expand All @@ -94,6 +96,14 @@ const props = withDefaults(defineProps<{
});

const rawData = ref<TGetTimeseriesResponse | undefined>();
const dataRange = computed<IDatetimeRange>(() => {
const now = dayjs();

return {
startAt: now.subtract(props.duration),
endAt: now,
};
});

type LocalTs = (ITimeseries & {isVisibleOnDashboard: boolean})[];

Expand Down Expand Up @@ -129,12 +139,10 @@ const xTickUnit = computed<TimeUnit>(() => {
});

function updateData() {
const now = dayjs();

const params: TGetTimeseriesQueryParams = {
timeseriesId: props.signalList.map((signal) => signal.timeseriesId),
endAtUtc: now.toISOString(),
startAtUtc: now.subtract(props.duration).toISOString(),
startAtUtc: dataRange.value.startAt.toISOString(),
endAtUtc: dataRange.value.endAt.toISOString(),
};
getTimeseries(params).then((response) => {
rawData.value = response.data;
Expand Down