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] View histogram comfortably #468

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: 1 addition & 3 deletions js/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Box,
Flex,
Link,
Text,
Spacer,
Icon,
LinkProps,
Expand Down Expand Up @@ -53,7 +52,6 @@ import { RunResultPane } from "@/components/run/RunResultPane";
import { VscGitPullRequest } from "react-icons/vsc";
import { RunList } from "@/components/run/RunList";


function getCookie(key: string) {
var b = document.cookie.match("(^|;)\\s*" + key + "\\s*=\\s*([^;]+)");
return b ? b.pop() : "";
Expand Down Expand Up @@ -320,7 +318,7 @@ function Main() {
>
<Box style={{ contain: "size" }}>{_isHistoryOpen && <RunList />}</Box>
<VSplit
sizes={_isRunResultOpen ? [60, 40] : [100, 0]}
sizes={_isRunResultOpen ? [50, 50] : [100, 0]}
minSize={_isRunResultOpen ? 100 : 0}
gutterSize={_isRunResultOpen ? 5 : 0}
style={{
Expand Down
40 changes: 19 additions & 21 deletions js/src/components/charts/HistogramChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import {
LinearScale,
AnimationOptions,
ScaleOptions,
Title,
Legend,
} from "chart.js";
import { Chart } from "react-chartjs-2";
import {
formatAsAbbreviatedNumber,
formatIntervalMinMax,
} from "@/utils/formatters";
import { Flex, Spacer, Text } from "@chakra-ui/react";
import {
BASE_BAR_COLOR_WITH_ALPHA,
CURRENT_BAR_COLOR_WITH_ALPHA,
SquareIcon,
} from "./SquareIcon";

export const INFO_VAL_COLOR = "#63B3ED";
Expand All @@ -37,6 +37,7 @@ export const VALUE_RANGE = "Value Range";

type HistogramChartProps = {
data: {
title: string;
type: string;
samples?: number;
min?: string | number;
Expand All @@ -58,6 +59,8 @@ export function HistogramChart({
TimeSeriesScale,
LinearScale,
CategoryScale,
Title,
Legend,
Tooltip
);

Expand All @@ -69,24 +72,12 @@ export function HistogramChart({

//infer `any` to allow for union data configurations & options
return (
<>
<Flex alignItems={"center"} direction={"row"}>
<Spacer />
<Text as="h3" size="sm" p="2" color="gray">
<SquareIcon color={BASE_BAR_COLOR_WITH_ALPHA} /> Base
</Text>
<Text as="h3" size="sm" p="2" color="gray">
<SquareIcon color={CURRENT_BAR_COLOR_WITH_ALPHA} /> Current
</Text>
<Spacer />
</Flex>
<Chart
type="bar"
options={chartOptions}
data={chartData as any}
plugins={[]}
/>
</>
<Chart
type="bar"
options={chartOptions}
data={chartData as any}
plugins={[]}
/>
);
}

Expand Down Expand Up @@ -150,13 +141,20 @@ export function getHistogramChartOptions(
hideAxis = false,
{ ...configOverrides }: ChartOptions<"bar"> = {}
): ChartOptions<"bar"> {
const { datasets, type, samples = 0, binEdges } = data;
const { title, datasets, type, samples = 0, binEdges } = data;
const [base, current] = datasets;
const isDatetime = type === "datetime";
return {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: title,
font: {
size: 20,
},
},
tooltip: {
mode: "index",
// position: 'nearest',
Expand Down
20 changes: 5 additions & 15 deletions js/src/components/histogram/HistogramDiffResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { HistogramDiffParams, HistogramDiffResult } from "@/lib/api/profile";
import { RunResultViewProps } from "../run/types";
import {
HStack,
Box,
Flex,
Spacer,
Heading,
forwardRef,
} from "@chakra-ui/react";
import { HStack, Box, Flex, Spacer, forwardRef } from "@chakra-ui/react";
import { HistogramChart } from "../charts/HistogramChart";
import { ScreenshotBox } from "../screenshot/ScreenshotBox";

Expand All @@ -30,17 +23,14 @@ function _HistogramDiffResultView(
}

return (
<Flex direction="column" height="500px">
<Flex direction="column" height="100%">
<ScreenshotBox ref={ref} height="100%">
<Heading as="h1" size="md" paddingTop="4" textAlign="center">
Model {params.model}.{params.column_name}
</Heading>
<HStack>
<Spacer />
<Box w="80%" h="300px" m="4">
{/* <Heading as='h3' size="sm" m="2" color='gray'>Base</Heading> */}
<Box w="80%" h="35vh" m="4">
<HistogramChart
data={{
title: `Model ${params.model}.${params.column_name}`,
type: run.params?.column_type || "",
datasets: [current, base],
min: min,
Expand All @@ -57,4 +47,4 @@ function _HistogramDiffResultView(
);
}

export const HistogramDiffResultView = forwardRef(_HistogramDiffResultView);
export const HistogramDiffResultView = forwardRef(_HistogramDiffResultView);
19 changes: 9 additions & 10 deletions js/src/components/top-k/TopKDiffResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { TopKDiffParams, TopKDiffResult } from "@/lib/api/profile";
import { RunResultViewProps } from "../run/types";
import {
Box,
Flex,
HStack,
Heading,
Spacer,
Text,
VStack,
Divider,
Link,
forwardRef,
} from "@chakra-ui/react";
import {
TopKSummaryBarChart,
TopKSummaryList,
} from "../charts/TopKSummaryList";
import { TopKSummaryBarChart } from "../charts/TopKSummaryList";
import { useState } from "react";
import { ScreenshotBox } from "../screenshot/ScreenshotBox";

Expand All @@ -34,7 +27,13 @@ const _TopKDiffResultView = ({ run }: TopKDiffResultViewProp, ref: any) => {
return (
<Flex direction="column" height={"100%"}>
<ScreenshotBox ref={ref} blockSize={"auto"}>
<Heading as="h1" size="md" paddingTop={4} textAlign="center">
<Heading
as="h1"
size="md"
paddingTop={4}
textAlign="center"
color="gray.600"
>
Model {params.model}.{params.column_name}
</Heading>
<HStack>
Expand Down Expand Up @@ -62,4 +61,4 @@ const _TopKDiffResultView = ({ run }: TopKDiffResultViewProp, ref: any) => {
);
};

export const TopKDiffResultView = forwardRef(_TopKDiffResultView);
export const TopKDiffResultView = forwardRef(_TopKDiffResultView);
Loading