-
Notifications
You must be signed in to change notification settings - Fork 8
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
Feat/icicles d3 hover #1277
base: feat/refactor-icicles-d3
Are you sure you want to change the base?
Feat/icicles d3 hover #1277
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { ROOT_FF_ID } from "reducers/files-and-folders/files-and-folders-selectors"; | ||
import { FilesAndFolders } from "reducers/files-and-folders/files-and-folders-types"; | ||
import { fromFileName } from "./../../../util/color/color-util"; | ||
import { | ||
getRectangleHeight, | ||
isLabelVisible, | ||
format, | ||
VIEWBOX_WIDTH, | ||
VIEWBOX_HEIGHT, | ||
handleZoom, | ||
} from "./icicles-utils"; | ||
import { FOLDER_COLOR } from "util/color/color-util"; | ||
import * as d3 from "d3"; | ||
|
||
export const createPartition = (filesAndFolders) => { | ||
const root = d3 | ||
.hierarchy<FilesAndFolders>( | ||
filesAndFolders[ROOT_FF_ID], | ||
(element) => | ||
element?.children.map((childId) => filesAndFolders[childId]) ?? [] | ||
) | ||
.sum((d) => d?.file_size ?? 0); | ||
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. Remplacer |
||
return d3 | ||
.partition<FilesAndFolders>() | ||
.size([VIEWBOX_HEIGHT, ((root.height + 1) * VIEWBOX_WIDTH) / 10])(root); | ||
}; | ||
|
||
export const createSvg = (ref) => | ||
d3 | ||
.select(ref.current) | ||
.append("svg") | ||
.attr("viewBox", [0, 0, VIEWBOX_WIDTH, VIEWBOX_HEIGHT].join(" ")) | ||
.style("font", "10px Quicksand"); | ||
|
||
export const createCell = (svg, root) => { | ||
return svg | ||
.selectAll("g") | ||
.data(root.descendants()) | ||
.join("g") | ||
.attr("transform", ({ x0, y0 }) => `translate(${y0},${x0})`); | ||
}; | ||
|
||
export const createRect = (cell, elements) => { | ||
return cell | ||
.append("rect") | ||
.attr("width", ({ y0, y1 }) => y1 - y0 - 1) | ||
.attr("height", (d) => getRectangleHeight(d)) | ||
.attr("fill-opacity", 0.5) | ||
.attr("fill", (d: any) => { | ||
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. Renommer |
||
if (!d.depth) { | ||
return "#ccc"; | ||
} | ||
if (d.data.children.length > 0) { | ||
return FOLDER_COLOR; | ||
} | ||
return fromFileName(d.data.name); | ||
}) | ||
.style("cursor", "pointer") | ||
.on("dblclick", (_, currentRect) => handleZoom(_, currentRect, elements)); | ||
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. Si |
||
}; | ||
|
||
export const createTitle = (cellElement) => { | ||
const cell = cellElement | ||
.append("text") | ||
.style("user-select", "none") | ||
.attr("pointer-events", "none") | ||
.attr("x", 4) | ||
.attr("y", 13) | ||
.attr("fill-opacity", (d) => +isLabelVisible(d)) | ||
.append("tspan") | ||
.text((d: any) => d.data.name); | ||
|
||
cell.append("title").text( | ||
(d: any) => | ||
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. Idem, essayer de trouver un meilleur nom et pourquoi pas un type pour |
||
`${d | ||
.ancestors() | ||
.map((d: any) => d.data.name) | ||
.reverse() | ||
.join("/")}\n${format(d.value)}` | ||
); | ||
return cell; | ||
}; | ||
|
||
export const createSubtitle = (title) => { | ||
return title | ||
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. Peut se simplifier en retirant l'accolade et le |
||
.append("tspan") | ||
.attr("fill-opacity", (d: any) => (isLabelVisible(d) ? 0.7 : 0)) | ||
.text((d: any) => ` ${format(d.value)}`); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
import * as d3 from "d3"; | ||||||
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. Déplacer ce fichier dans le dossier |
||||||
export const VIEWBOX_WIDTH = 1000; | ||||||
export const VIEWBOX_HEIGHT = 300; | ||||||
export const TRANSITION_DURATION = 750; | ||||||
|
||||||
type Dimensions = { | ||||||
x0: number; | ||||||
y0: number; | ||||||
x1: number; | ||||||
y1: number; | ||||||
}; | ||||||
|
||||||
export const getRectangleHeight = ({ x0, x1 }): number => { | ||||||
return x1 - x0 - Math.min(1, (x1 - x0) / 2); | ||||||
}; | ||||||
|
||||||
export const getCurrentRect = (icicles, currentElementId) => { | ||||||
const rects = getAllRects(icicles); | ||||||
return rects.filter(({ data: { id } }) => id === currentElementId.data.id); | ||||||
}; | ||||||
|
||||||
export const getAllRects = (icicles) => | ||||||
d3.select(icicles.current).selectAll("rect"); | ||||||
|
||||||
export const getRectById = (icicles, rectId) => { | ||||||
const rects = getAllRects(icicles); | ||||||
return rects.filter(({ data: { id } }) => id === rectId); | ||||||
}; | ||||||
|
||||||
export const format = d3.format(",d"); | ||||||
|
||||||
export const isLabelVisible = ({ x0, x1, y0, y1 }): boolean => { | ||||||
return y1 <= VIEWBOX_WIDTH && y0 >= 0 && x1 - x0 > 16; | ||||||
}; | ||||||
|
||||||
export const dimensionsTarget: Record<string, Dimensions> = {}; | ||||||
|
||||||
export const getDimensions = (dimensions) => | ||||||
dimensionsTarget[dimensions.data.id]; | ||||||
|
||||||
export const handleZoom = (_, currentRect, elements) => { | ||||||
let { root, cell, rect, title, subtitle } = elements; | ||||||
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.
Suggested change
|
||||||
|
||||||
elements.focus = | ||||||
elements.focus === currentRect | ||||||
? (currentRect = currentRect.parent) | ||||||
: currentRect; | ||||||
|
||||||
root.each((dimensions) => { | ||||||
dimensionsTarget[dimensions.data.id] = { | ||||||
x0: | ||||||
((dimensions.x0 - currentRect.x0) / (currentRect.x1 - currentRect.x0)) * | ||||||
VIEWBOX_HEIGHT, | ||||||
x1: | ||||||
((dimensions.x1 - currentRect.x0) / (currentRect.x1 - currentRect.x0)) * | ||||||
VIEWBOX_HEIGHT, | ||||||
y0: dimensions.y0 - currentRect.y0, | ||||||
y1: dimensions.y1 - currentRect.y0, | ||||||
}; | ||||||
}); | ||||||
|
||||||
const transition = cell | ||||||
.transition() | ||||||
.duration(TRANSITION_DURATION) | ||||||
.attr( | ||||||
"transform", | ||||||
(d: any) => `translate(${getDimensions(d).y0},${getDimensions(d).x0})` | ||||||
); | ||||||
|
||||||
rect | ||||||
.transition(transition) | ||||||
.attr("height", (d: any) => getRectangleHeight(getDimensions(d))); | ||||||
title | ||||||
.transition(transition) | ||||||
.attr("fill-opacity", (d: any) => +isLabelVisible(getDimensions(d))); | ||||||
subtitle | ||||||
.transition(transition) | ||||||
.attr("fill-opacity", (d: any) => +isLabelVisible(getDimensions(d)) * 0.7); | ||||||
}; |
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.