Skip to content

Commit 85e8094

Browse files
committed
select circo based on graph density
1 parent 650b95f commit 85e8094

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/components/GraphViewport.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default class GraphViewport extends Component<
144144
rawError instanceof Error
145145
? rawError
146146
: new Error('Unknown error: ' + String(rawError));
147+
console.error(error);
147148
this.setState(() => {
148149
throw error;
149150
});

src/graph/dot.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,14 @@ export function getDot(typeGraph: TypeGraph): Graph {
128128
});
129129
}
130130

131+
const graphDensity = edges.length / (nodes.length * (nodes.length - 1));
131132
return {
132133
directed: true,
133134
graphAttributes: {
134135
rankdir: 'LR',
135136
ranksep: 2.0,
137+
layout:
138+
typeGraph.rootType == null && graphDensity > 0.4 ? 'circo' : 'dot',
136139
},
137140
nodeAttributes: {
138141
fontsize: '16',

src/graph/svg-renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export async function renderSvg(typeGraph: TypeGraph) {
1414
const rawSVG = await vizWorker.render({
1515
input: dot,
1616
options: {
17-
engine: typeGraph.rootType == null ? 'circo' : 'dot',
17+
// @ts-expect-error FIXME should be fixed in dotviz
18+
engine: dot.graphAttributes.layout,
1819
format: 'svg',
1920
},
2021
});

0 commit comments

Comments
 (0)