This repository has been archived by the owner on Feb 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Rendering and markup for statistic tab #3
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
acce5fa
added rendering and markup for statistic tab
ViktoriiaNakoryk da567e4
updated package-lock
ViktoriiaNakoryk 77d334d
fixed indents
ViktoriiaNakoryk 2289736
add scroll to statistic component
ViktoriiaNakoryk 8456d04
created components for table, changed type in locale to be default as…
ViktoriiaNakoryk caf6893
moved defining data from components to parent component
ViktoriiaNakoryk 979f547
fixed types
ViktoriiaNakoryk aab39d1
added storybooks for table and plots
ViktoriiaNakoryk d986685
moved defining useEventBus hook to a parent component
ViktoriiaNakoryk 9cd68ac
mocked useEventBusForChat in test
ViktoriiaNakoryk 7ca23f1
moved stub table data to separate files. replaced imported ReactEchar…
ViktoriiaNakoryk f799b42
created eventBus for statistic
ViktoriiaNakoryk d16a2fe
saved the the parsed json for table data, moved Statistic to features…
ViktoriiaNakoryk ca14457
changed name of test-file
ViktoriiaNakoryk f4809ef
created feature-flag for statistic
ViktoriiaNakoryk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For readability, can you save the parsed json and use const json = {...}
export const TABLE = {
data: JSON.stringify(json)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}}', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([ | ||
MarcMcIntosh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍🏻