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

WIP: explore d3 library #605

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

WIP: explore d3 library #605

wants to merge 10 commits into from

Conversation

balzdur
Copy link
Contributor

@balzdur balzdur commented Nov 25, 2024

This is a PoC of D3 to handle the testrun charts display.

In this PR :

  • fake http://localhost:3000/d3 page with hardcoded data
  • creation of a D3 chart, rendered with React (not the D3 primitives), that should look like the first graph on Figma.

@balzdur balzdur marked this pull request as draft November 25, 2024 14:34
@balzdur balzdur requested a review from carere November 25, 2024 14:34
Comment on lines +164 to +167
.range([
height - (numberOfOutcomes - 1) * gap - margin.bottom,
margin.top,
]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This weird computation is required to handle the "gaps" between each part of the stack. This depends on each stack so we need to compute an yScale per stack.
image

Comment on lines +192 to +198
<use
href={`${iconsSVGSpriteHref}#arrow-right`}
height={40}
width={40}
x={(width + margin.left - margin.right - 40) / 2}
y={(height + margin.top - margin.bottom - 40) / 2}
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reuse of an existing svg icon (it's the abstracted SVG code hidden inside Icon component)

Comment on lines +123 to +137
const foo = d3.index(
data,
(d) => d.version,
(d) => d.outcome,
);

// Determine the series that need to be stacked.
const series = d3
.stack<[string, d3.InternMap<Outcome, Data['nodes'][number]>], Outcome>()
.offset(d3.stackOffsetExpand)
.keys(orderredOutcomes)
.order(d3.stackOrderNone)
.value(([, D], key) => {
return D.get(key)?.count ?? 0;
})(foo);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the strength of D3 (but also the reason it's difficult to understand).

d3.stack() is exactly what we need here, but to make use of it, it's better to use the D3 internal data manipulation fonctions, (like d3.index) and the data structure is not something usual (take some time to reason about).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants