Skip to content

Commit

Permalink
render: Calculate height automatically to fit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnor committed Jan 3, 2018
1 parent d139930 commit 0ecbeff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions render.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ function renderGraph(graph, options) {
if (!options.library) { options.library = libraryFromGraph(graph); }
if (!options.theme) { options.theme = 'the-graph-dark' };
if (!options.width) { options.width = 1200; }
if (!options.height) { options.height = options.width * 0.7; }

// TODO support doing autolayout. Default to on if graph is missing x/y positions
// FIXME: Set zoom-level, width,height so that whole graph shows with all info
// TODO: default height based on fitted aspect ratio

// fit based on width constrained (height near infinite)
var fit = TheGraph.findFit(graph, options.width, options.width*100, TheGraph.config.nodeSize);
var aspectRatio = fit.graphWidth / fit.graphHeight;
if (!options.height) {
// calculate needed aspect ratio
options.height = options.width / aspectRatio;
}
console.log('f', aspectRatio, options.height, JSON.stringify(fit));

var props = {
readonly: true,
Expand Down
4 changes: 3 additions & 1 deletion the-graph/geometryutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ var findFit = function (graph, width, height, sizeLimit) {
return {
x: x,
y: y,
scale: scale
scale: scale,
graphWidth: gWidth,
graphHeight: gHeight,
};
};

Expand Down

0 comments on commit 0ecbeff

Please sign in to comment.