8000 Size metric selection by nimrossum · Pull Request #630 · git-truck/git-truck · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Size metric selection #630

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

Merged
merged 12 commits into from
May 28, 2023
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
2 changes: 1 addition & 1 deletion src/components/AuthorDistFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function AuthorDistFragment(props: AuthorDistFragProps) {
{metricType == "TOP_CONTRIBUTOR" ? (
<LegendDot className="ml-1" dotColor={authorColors.get(author) ?? "white"} />
) : null}
<span className="overflow-hidden overflow-ellipsis whitespace-pre font-bold opacity-70">{author}</span>
<span className="overflow-hidden overflow-ellipsis whitespace-pre font-bold opacity-80">{author}</span>
</div>
<p className="break-all text-right text-sm">{contribPercentage}%</p>
</Fragment>
Expand Down
58 changes: 34 additions & 24 deletions src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { useComponentSize } from "../hooks"
import { treemapBinary } from "d3-hierarchy"
import { getTextColorFromBackground, isBlob, isTree } from "~/util"
import clsx from "clsx"
import type { SizeMetricType } from "~/metrics/size-metric"
import { useSearch } from "~/contexts/SearchContext"

type CircleOrRectHiearchyNode = HierarchyCircularNode<HydratedGitObject> | HierarchyRectangularNode<HydratedGitObject>

Expand All @@ -44,16 +46,17 @@ export const Chart = memo(function Chart({
setHoveredObject: (obj: HydratedGitObject | null) => void
}) {
const [ref, rawSize] = useComponentSize()
const { searchResults } = useSearch()
const size = useDeferredValue(rawSize)
const { analyzerData } = useData()
const { chartType } = useOptions()
const { chartType, sizeMetric } = useOptions()
const { path } = usePath()
const { clickedObject, setClickedObject } = useClickedObject()
const { setPath } = usePath()
const nodes = useMemo(() => {
if (size.width === 0 || size.height === 0) return []
return createPartitionedHiearchy(analyzerData.commit, size, chartType, path).descendants()
}, [analyzerData.commit, size, chartType, path])
return createPartitionedHiearchy(analyzerData.commit, size, chartType, sizeMetric, path).descendants()
}, [size, analyzerData.commit, chartType, sizeMetric, path])

useEffect(() => {
setHoveredObject(null)
Expand Down Expand Up @@ -114,7 +117,7 @@ export const Chart = memo(function Chart({
key={`${chartType}${d.data.path}`}
{...createGroupHandlers(d, i === 0)}
>
<Node isRoot={i === 0} d={d} />
<Node isRoot={i === 0} d={d} isSearchMatch={Boolean(searchResults[d.data.path])} />
</g>
)
})}
Expand All @@ -123,7 +126,15 @@ export const Chart = memo(function Chart({
)
})

const Node = memo(function Node({ d, isRoot }: { d: CircleOrRectHiearchyNode; isRoot: boolean }) {
const Node = memo(function Node({
d,
isRoot,
isSearchMatch,
}: {
d: CircleOrRectHiearchyNode
isRoot: boolean
isSearchMatch: boolean
}) {
const { chartType, labelsVisible } = useOptions()
let showLabel = labelsVisible
const { path } = usePath()
Expand Down Expand Up @@ -174,21 +185,16 @@ const Node = memo(function Node({ d, isRoot }: { d: CircleOrRectHiearchyNode; is
"cursor-pointer": isBlob(d.data),
})}
d={d}
isSearchMatch={d.data.isSearchResult ?? false}
isSearchMatch={isSearchMatch}
/>
{showLabel ? (
chartType === "BUBBLE_CHART" ? (
<CircleText
d={d as HierarchyCircularNode<HydratedGitObject>}
displayText={displayText}
isSearchMatch={d.data.isSearchResult ?? false}
/>
<CircleText d={d as HierarchyCircularNode<HydratedGitObject>} displayText={displayText} />
) : (
<RectText
className="font-mono"
d={d as HierarchyRectangularNode<HydratedGitObject>}
displayText={displayText}
isSearchMatch={d.data.isSearchResult ?? false}
/>
)
) : null}
Expand Down Expand Up @@ -265,12 +271,10 @@ function Path({
function CircleText({
d,
displayText,
isSearchMatch,
className = "",
}: {
d: HierarchyCircularNode<HydratedGitObject>
displayText: string
isSearchMatch: boolean
className?: string
}) {
const [metricsData] = useMetrics()
Expand All @@ -282,9 +286,7 @@ function CircleText({
})

const textProps = useToggleableSpring({
fill: isSearchMatch
? searchMatchColor
: isBlob(d.data)
fill: isBlob(d.data)
? getTextColorFromBackground(metricsData[authorshipType].get(metricType)?.colormap.get(d.data.path) ?? "#333")
: "#333",
})
Expand Down Expand Up @@ -323,12 +325,10 @@ function CircleText({
function RectText({
d,
displayText,
isSearchMatch,
className = "",
}: {
d: HierarchyRectangularNode<HydratedGitObject>
displayText: string
isSearchMatch: boolean
className?: string
}) {
const [metricsData] = useMetrics()
Expand All @@ -340,9 +340,7 @@ function RectText({
const props = useToggleableSpring({
x: d.x0 + xOffset,
y: d.y0 + yOffset,
fill: isSearchMatch
? searchMatchColor
: isBlob(d.data)
fill: isBlob(d.data)
? getTextColorFromBackground(metricsData[authorshipType].get(metricType)?.colormap.get(d.data.path) ?? "#333")
: "#333",
})
Expand All @@ -363,6 +361,7 @@ function createPartitionedHiearchy(
data: HydratedGitCommitObject,
size: { height: number; width: number },
chartType: ChartType,
sizeMetricType: SizeMetricType,
path: string
) {
const root = data.tree as HydratedGitTreeObject
Expand All @@ -387,8 +386,19 @@ function createPartitionedHiearchy(

const hiearchy = hierarchy(castedTree)
.sum((d) => {
const lineCount = (d as HydratedGitBlobObject).sizeInBytes
return lineCount ? lineCount : 1
const hydratedBlob = d as HydratedGitBlobObject
switch (sizeMetricType) {
case "FILE_SIZE":
return hydratedBlob.sizeInBytes ?? 1
case "MOST_COMMITS":
return hydratedBlob.noCommits
case "EQUAL_SIZE":
return 1
case "LAST_CHANGED":
return (hydratedBlob.lastChangeEpoch ?? data.oldestLatestChangeEpoch) - data.oldestLatestChangeEpoch
case "TRUCK_FACTOR":
return Object.keys(hydratedBlob.authors ?? {}).length
}
})
.sort((a, b) => (b.value !== undefined && a.value !== undefined ? b.value - a.value : 0))

Expand Down
4 changes: 2 additions & 2 deletions src/components/ChevronButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Icon } from "@mdi/react"
import type { HTMLAttributes } from "react"

export function ChevronButton({
onClick,
onClick = () => void 0,
open,
className = "",
...props
}: { onClick: () => void; open: boolean } & HTMLAttributes<HTMLButtonElement>) {
}: { onClick?: () => void; open: boolean } & HTMLAttributes<HTMLButtonElement>) {
return (
<button className={`z-10 ${className}`} {...props}>
<Icon path={mdiChevronDown} size={1} className={`chevron transition-transform ${open ? "rotate-180" : ""}`} />
Expand Down
Loading
0