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

Allow multi hover on metric graphs (v2) #1077

Merged
merged 8 commits into from
Mar 15, 2023
65 changes: 55 additions & 10 deletions packages/front-end/components/HomePage/NorthStar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ExperimentInterfaceStringDates } from "back-end/types/experiment";
import { useAuth } from "@/services/auth";
import { useUser } from "@/services/UserContext";
import useOrgSettings from "@/hooks/useOrgSettings";
import { useLocalStorage } from "@/hooks/useLocalStorage";
import Toggle from "@/components/Forms/Toggle";
import Modal from "../Modal";
import MetricsSelector from "../Experiment/MetricsSelector";
import Field from "../Forms/Field";
Expand All @@ -18,12 +20,17 @@ const NorthStar: FC<{
const { permissions, refreshOrganization } = useUser();
const settings = useOrgSettings();

const smoothByStorageKey = `northstar_metrics_smoothBy`;
const [smoothBy, setSmoothBy] = useLocalStorage<"day" | "week">(
smoothByStorageKey,
"week"
);

const form = useForm<{
title: string;
window: string | number;
metrics: string[];
resolution: string;
}>({ defaultValues: { resolution: "week" } });
}>();

useEffect(() => {
if (settings.northStar?.metricIds) {
Expand All @@ -38,6 +45,13 @@ const NorthStar: FC<{

const [openNorthStarModal, setOpenNorthStarModal] = useState(false);

const [northstarHoverDate, setNorthstarHoverDate] = useState<number | null>(
null
);
const onNorthstarHoverCallback = (ret: { d: number | null }) => {
setNorthstarHoverDate(ret.d);
};

const nameMap = new Map<string, string>();
experiments.forEach((e) => {
nameMap.set(e.id, e.name);
Expand Down Expand Up @@ -65,19 +79,50 @@ const NorthStar: FC<{
<BsGear />
</a>
)}
<h2>
{northStar?.title
? northStar.title
: `North Star Metric${
northStar?.metricIds.length > 1 ? "s" : ""
}`}
</h2>
<div className="row">
<div className="col">
<h2>
{northStar?.title
? northStar.title
: `North Star Metric${
northStar?.metricIds.length > 1 ? "s" : ""
}`}
</h2>
</div>
<div className="col" style={{ position: "relative" }}>
{northStar?.metricIds.length > 0 && (
<div
className="float-right mr-3"
style={{ position: "relative", top: 40 }}
>
<label
className="small my-0 mr-2 text-right align-middle"
htmlFor="toggle-group-smooth-by"
>
Smoothing
<br />
(7 day trailing)
</label>
<Toggle
value={smoothBy === "week"}
setValue={() =>
setSmoothBy(smoothBy === "week" ? "day" : "week")
}
id="toggle-group-smooth-by"
className="align-middle"
/>
</div>
)}
</div>
</div>
{northStar?.metricIds.map((mid) => (
<div key={mid}>
<NorthStarMetricDisplay
metricId={mid}
window={northStar?.window}
resolution={northStar?.resolution ?? "week"}
smoothBy={smoothBy}
hoverDate={northstarHoverDate}
onHoverCallback={onNorthstarHoverCallback}
/>
</div>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ const NorthStarMetricDisplay = ({
metricId,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
window,
resolution,
smoothBy,
hoverDate,
onHoverCallback,
}: {
metricId: string;
window?: number | string;
resolution?: string;
smoothBy?: string;
hoverDate?: number | null;
onHoverCallback?: (ret: { d: number | null }) => void;
}): React.ReactElement => {
const { project } = useDefinitions();
const permissions = usePermissions();
Expand Down Expand Up @@ -66,9 +70,11 @@ const NorthStarMetricDisplay = ({
dates={analysis.dates}
experiments={experiments}
showStdDev={false}
smoothBy={resolution === "week" ? "week" : "day"}
smoothBy={smoothBy === "week" ? "week" : "day"}
height={300}
method={metric.type !== "binomial" ? "avg" : "sum"}
onHover={onHoverCallback}
hoverDate={hoverDate}
/>
</div>
) : (
Expand Down