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

Update focus order in sankey chart for vertical navigation #31469

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
krkshitij marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "Update focus order in sankey chart for vertical navigation",
"packageName": "@fluentui/react-charting",
"email": "kumarkshitij@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,41 @@ export class SankeyChartBase extends React.Component<ISankeyChartProps, ISankeyC
borderColorsForNodes,
);

const nodeLinkDomOrderArray: { layer: number; type: string; index: number }[] = [];
nodes.sort((a: SNode, b: SNode) => {
krkshitij marked this conversation as resolved.
Show resolved Hide resolved
if (a.x0 !== b.x0) {
return a.x0! - b.x0!;
}
return a.y0! - b.y0!;
});
nodes.forEach((item: SNode, index) => {
nodeLinkDomOrderArray.push({ layer: item.layer!, type: 'node', index: index });
});
links.sort((a: SLink, b: SLink) => {
const asx0 = (a.source as SNode).x0;
const bsx0 = (b.source as SNode).x0;
if (asx0 !== bsx0) {
return asx0! - bsx0!;
}
return a.y0! - b.y0!;
});
links.forEach((item: SLink, index) => {
nodeLinkDomOrderArray.push({ layer: (item.source as SNode).layer!, type: 'link', index: index });
});
nodeLinkDomOrderArray.sort((a, b) => {
if (a.layer !== b.layer) {
return a.layer - b.layer;
}

if (a.type > b.type) {
return -1;
}
if (a.type < b.type) {
return 1;
}
return 0;
});

// NOTE: I don't love this approach to caching the "select" result. Is it still valid from render-to-render?
// although local testing seems to indicate so, I do not trust that React will always support that instance.
// It might be better to perform this `fetch` within the `_showTooltip` and `_hideTooltip` methods.
Expand Down Expand Up @@ -792,12 +827,27 @@ export class SankeyChartBase extends React.Component<ISankeyChartProps, ISankeyC
ref={(rootElem: HTMLDivElement) => (this.chartContainer = rootElem)}
onMouseLeave={this._onCloseCallout}
>
<FocusZone direction={FocusZoneDirection.bidirectional}>
<FocusZone direction={FocusZoneDirection.vertical}>
<svg width={width} height={height} id={this._chartId}>
<g className={classNames.links} strokeOpacity={1}>
{linkData}
</g>
<g className={classNames.nodes}>{nodeData}</g>
{nodeLinkDomOrderArray.map(item => {
if (item.type === 'node') {
return (
<g key={nodes[item.index].nodeId} className={classNames.nodes}>
{nodeData![item.index]}
</g>
);
}

return (
<g
krkshitij marked this conversation as resolved.
Show resolved Hide resolved
key={`${(links[item.index].source as SNode).nodeId}-${(links[item.index].target as SNode).nodeId}`}
className={classNames.links}
strokeOpacity={1}
>
{linkData![item.index]}
</g>
);
krkshitij marked this conversation as resolved.
Show resolved Hide resolved
})}
{calloutProps.isCalloutVisible && (
<Callout {...calloutProps}>
<ChartHoverCard
Expand Down
Loading
Loading