Skip to content
This repository has been archived by the owner on Feb 28, 2025. It is now read-only.

Rendering and markup for statistic tab #3

Merged
merged 15 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"@vitest/coverage-v8": "^1.1.0",
"@vitest/ui": "^1.1.0",
"classnames": "^2.3.2",
"echarts": "^5.4.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting :)... I've not seen this library before, I'll need to check the bundle size but I'd imagine it's tree shakable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run npx vite-bundle-visualizer if you want check the bundle size 👍🏻

"echarts-for-react": "^3.0.2",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.33.2",
Expand Down
1 change: 1 addition & 0 deletions src/__fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { STUB_CAPS_RESPONSE } from "./caps";
export { MARS_ROVER_CHAT } from "./chat";
export { TABLE } from "./table";
3 changes: 3 additions & 0 deletions src/__fixtures__/table.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, can you save the parsed json and use JSON.stringify when it's being exported?

const json = {...}
export const TABLE = {
  data: JSON.stringify(json)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TABLE = {
data: '{"refact_impact_dates":{"data":{"daily":{"2023-12-15":{"completions":14,"human":52,"langs":[".rs",".py"],"refact":203,"refact_impact":0.7960784435272217,"total":255},"2023-12-18":{"completions":16,"human":83,"langs":[".py"],"refact":245,"refact_impact":0.7469512224197388,"total":328},"2023-12-19":{"completions":6,"human":4,"langs":[".cpp"],"refact":103,"refact_impact":0.9626168012619019,"total":107},"2023-12-20":{"completions":46,"human":857,"langs":[".py"],"refact":693,"refact_impact":0.4470967650413513,"total":1550},"2023-12-21":{"completions":92,"human":1157,"langs":[".py"],"refact":3103,"refact_impact":0.7284037470817566,"total":4260},"2023-12-22":{"completions":59,"human":-38,"langs":[".py"],"refact":2005,"refact_impact":1.0193188190460205,"total":1967},"2023-12-27":{"completions":13,"human":28,"langs":[".py"],"refact":409,"refact_impact":0.9359267950057983,"total":437},"2023-12-29":{"completions":2,"human":2,"langs":[".py"],"refact":71,"refact_impact":0.9726027250289917,"total":73},"2024-01-04":{"completions":12,"human":1772,"langs":[".rs"],"refact":303,"refact_impact":0.14602409303188324,"total":2075},"2024-01-09":{"completions":4,"human":33,"langs":[".py"],"refact":166,"refact_impact":0.8341708779335022,"total":199},"2024-01-24":{"completions":10,"human":808,"langs":[".rs"],"refact":410,"refact_impact":0.3366174101829529,"total":1218},"2024-01-25":{"completions":76,"human":7993,"langs":[".rs"],"refact":2772,"refact_impact":0.25750115513801575,"total":10765},"2024-01-26":{"completions":21,"human":1931,"langs":[".rs"],"refact":557,"refact_impact":0.22387459874153137,"total":2488},"2024-01-29":{"completions":21,"human":2574,"langs":[".rs"],"refact":655,"refact_impact":0.20284917950630188,"total":3229},"2024-01-30":{"completions":29,"human":1849,"langs":[".rs"],"refact":1310,"refact_impact":0.41468819975852966,"total":3159},"2024-01-31":{"completions":31,"human":3452,"langs":[".rs",".txt"],"refact":1114,"refact_impact":0.24397721886634827,"total":4566},"2024-02-01":{"completions":57,"human":8806,"langs":[".rs",".txt"],"refact":2465,"refact_impact":0.21870286762714386,"total":11271},"2024-02-02":{"completions":11,"human":5869,"langs":[".rs",".txt",".py"],"refact":307,"refact_impact":0.04970854893326759,"total":6176},"2024-02-05":{"completions":5,"human":1976,"langs":[".rs",".txt"],"refact":233,"refact_impact":0.10547759383916855,"total":2209}},"weekly":{"2023-12-15":{"completions":14,"human":52,"langs":[".py",".rs"],"refact":203,"refact_impact":0.7960784435272217,"total":255},"2023-12-22":{"completions":219,"human":2063,"langs":[".py",".cpp"],"refact":6149,"refact_impact":0.7487822771072388,"total":8212},"2023-12-27":{"completions":15,"human":30,"langs":[".py"],"refact":480,"refact_impact":0.9411764740943909,"total":510},"2024-01-04":{"completions":12,"human":1772,"langs":[".rs"],"refact":303,"refact_impact":0.14602409303188324,"total":2075},"2024-01-09":{"completions":4,"human":33,"langs":[".py"],"refact":166,"refact_impact":0.8341708779335022,"total":199},"2024-01-24":{"completions":107,"human":10732,"langs":[".rs"],"refact":3739,"refact_impact":0.2583788335323334,"total":14471},"2024-02-02":{"completions":149,"human":22550,"langs":[".rs",".py",".txt"],"refact":5851,"refact_impact":0.20601387321949005,"total":28401},"2024-02-05":{"completions":5,"human":1976,"langs":[".rs",".txt"],"refact":233,"refact_impact":0.10547759383916855,"total":2209}}}},"table_refact_impact":{"columns":["Language","Refact","Human","Total (characters)","Refact Impact","Completions"],"data":[{"completions":276,"human":31996,"lang":".rs","refact":10092,"refact_impact":0.23978331685066223,"total":42088},{"completions":243,"human":7110,"lang":".py","refact":6929,"refact_impact":0.49355366826057434,"total":14039},{"completions":6,"human":4,"lang":".cpp","refact":103,"refact_impact":0.9626168012619019,"total":107},{"completions":0,"human":98,"lang":".txt","refact":0,"refact_impact":0.0,"total":98}],"title":"Refact\'s impact by language"}}',
};
92 changes: 92 additions & 0 deletions src/components/Chart/Chart.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { Meta } from "@storybook/react";
import { Chart } from "./Chart";
import { Box } from "@radix-ui/themes";

const meta = {
title: "Chart",
component: Chart,
} satisfies Meta<typeof Chart>;

export default meta;

export const Primary = () => {
return (
<Box
p="2"
style={{
width: "260px",
backgroundColor: "color(display-p3 0.004 0.004 0.204 / 0.059)",
height: "100%",
}}
>
<Chart
refactImpactDatesWeekly={{
"2023-12-15": {
completions: 14,
human: 52,
langs: [".py", ".rs"],
refact: 203,
refact_impact: 0.7960784435272217,
total: 255,
},
"2023-12-22": {
completions: 219,
human: 2063,
langs: [".py", ".cpp"],
refact: 6149,
refact_impact: 0.7487822771072388,
total: 8212,
},
"2023-12-27": {
completions: 15,
human: 30,
langs: [".py"],
refact: 480,
refact_impact: 0.9411764740943909,
total: 510,
},
"2024-01-04": {
completions: 12,
human: 1772,
langs: [".rs"],
refact: 303,
refact_impact: 0.14602409303188324,
total: 2075,
},
"2024-01-09": {
completions: 4,
human: 33,
langs: [".py"],
refact: 166,
refact_impact: 0.8341708779335022,
total: 199,
},
"2024-01-24": {
completions: 107,
human: 10732,
langs: [".rs"],
refact: 3739,
refact_impact: 0.2583788335323334,
total: 14471,
},
"2024-02-02": {
completions: 149,
human: 22550,
langs: [".rs", ".py", ".txt"],
refact: 5851,
refact_impact: 0.20601387321949005,
total: 28401,
},
"2024-02-05": {
completions: 5,
human: 1976,
langs: [".rs", ".txt"],
refact: 233,
refact_impact: 0.10547759383916855,
total: 2209,
},
}}
/>
</Box>
);
};
119 changes: 119 additions & 0 deletions src/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React from "react";
import { Box, Text } from "@radix-ui/themes";
import { RefactTableImpactDateObj } from "../../services/refact";
import ReactEChartsCore from "echarts-for-react/lib/core";
import * as echarts from "echarts/core";
import { BarChart } from "echarts/charts";
import {
GridComponent,
TooltipComponent,
AxisPointerComponent,
TitleComponent,
} from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";

import { Spinner } from "../Spinner";
echarts.use([
TitleComponent,
TooltipComponent,
GridComponent,
BarChart,
CanvasRenderer,
AxisPointerComponent,
]);

export const Chart: React.FC<{
refactImpactDatesWeekly: Record<string, RefactTableImpactDateObj> | null;
}> = ({ refactImpactDatesWeekly }) => {
if (refactImpactDatesWeekly === null) {
return <Spinner />;
}

const dates: string[] = Object.keys(refactImpactDatesWeekly).map((date) => {
return new Date(date).toLocaleString(undefined, {
month: "short",
day: "numeric",
});
});
const humanData: number[] = Object.values(refactImpactDatesWeekly).map(
(entry) => entry.human,
);
const refactData: number[] = Object.values(refactImpactDatesWeekly).map(
(entry) => entry.refact,
);

const option = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
legend: {},
height: "200px",
grid: {
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true,
},
xAxis: [
{
type: "category",
data: dates,
axisLabel: {
fontSize: 8,
},
},
],
yAxis: [
{
type: "value",
},
],
series: [
{
name: "Human",
type: "bar",
stack: "Ad",
data: humanData,
barWidth: "80%",
},
{
name: "Refact",
type: "bar",
stack: "Ad",
data: refactData,
barWidth: "80%",
},
],
};

return (
<Box mt="3" width="100%">
<Text as="p" size="2">
Refact vs Human
</Text>
<ReactEChartsCore
echarts={echarts}
option={option}
style={{ width: "100%", height: "300px" }}
/>
<Box>
{dates.map((date: string, index: number) => (
<Box key={index}>
<Text size="1" as="p">
Date: {date}
</Text>
<Text size="1" as="p">
Human: {humanData[index]} ch.
</Text>
<Text size="1" mb="2" as="p">
Refact: {refactData[index]} ch.
</Text>
</Box>
))}
</Box>
</Box>
);
};
2 changes: 1 addition & 1 deletion src/components/Sidebar/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Settings: React.FC = () => {
};

return (
<Flex p="4">
<Flex>
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Trigger>
<IconButton variant="outline" title="Settings">
Expand Down
Loading
Loading