Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
measures: { setMeasureVisibility },
},
validSpecStore,
dashboardStore,
} = getStateManagers();

const timeControlsStore = useTimeControlStore(getStateManagers());
Expand Down Expand Up @@ -275,7 +274,6 @@
exploreName,
measureName: measure.name!,
selectedTimeRange,
selectedTimezone: $dashboardStore.selectedTimezone,
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Annotation } from "@rilldata/web-common/components/data-graphic/ma
import { useExploreValidSpec } from "@rilldata/web-common/features/explores/selectors.ts";
import { TIME_GRAIN } from "@rilldata/web-common/lib/time/config.ts";
import { prettyFormatTimeRange } from "@rilldata/web-common/lib/time/ranges/formatter.ts";
import { getLocalIANA } from "@rilldata/web-common/lib/time/timezone";
import {
getOffset,
getStartOfPeriod,
Expand All @@ -25,13 +26,11 @@ export function getAnnotationsForMeasure({
exploreName,
measureName,
selectedTimeRange,
selectedTimezone,
}: {
instanceId: string;
exploreName: string;
measureName: string;
selectedTimeRange: DashboardTimeControls | undefined;
selectedTimezone: string;
}): Readable<Annotation[]> {
const exploreValidSpec = useExploreValidSpec(instanceId, exploreName);
const selectedPeriod = TIME_GRAIN[selectedTimeRange?.interval ?? ""]
Expand Down Expand Up @@ -76,7 +75,7 @@ export function getAnnotationsForMeasure({
a,
selectedPeriod,
selectedTimeRange?.interval ?? V1TimeGrain.TIME_GRAIN_UNSPECIFIED,
selectedTimezone,
getLocalIANA(), // Use system timezone for annotations similar to chart labels
),
) ?? [];
annotations.sort((a, b) => a.startTime.getTime() - b.startTime.getTime());
Expand All @@ -88,29 +87,24 @@ function convertV1AnnotationsResponseItemToAnnotation(
annotation: V1MetricsViewAnnotationsResponseAnnotation,
period: Period | undefined,
selectedTimeGrain: V1TimeGrain,
selectedTimezone: string,
timezone: string,
) {
let startTime = new Date(annotation.time as string);
let endTime = annotation.timeEnd ? new Date(annotation.timeEnd) : undefined;

// Only truncate start and ceil end when there is a grain column in the annotation.
if (period && annotation.duration) {
startTime = getStartOfPeriod(startTime, period, selectedTimezone);
startTime = getStartOfPeriod(startTime, period, timezone);
if (endTime) {
endTime = getOffset(
endTime,
period,
TimeOffsetType.ADD,
selectedTimezone,
);
endTime = getStartOfPeriod(endTime, period, selectedTimezone);
endTime = getOffset(endTime, period, TimeOffsetType.ADD, timezone);
endTime = getStartOfPeriod(endTime, period, timezone);
}
}

const formattedTimeOrRange = prettyFormatTimeRange(
Interval.fromDateTimes(
DateTime.fromJSDate(startTime).setZone(selectedTimezone),
DateTime.fromJSDate(endTime ?? startTime).setZone(selectedTimezone),
DateTime.fromJSDate(startTime).setZone(timezone),
DateTime.fromJSDate(endTime ?? startTime).setZone(timezone),
),
selectedTimeGrain,
);
Expand Down
Loading