Skip to content

Commit

Permalink
works around unsized div bug by forcing explicit div size
Browse files Browse the repository at this point in the history
  • Loading branch information
embeepea committed May 3, 2013
1 parent b97d217 commit db078ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/core/multigraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ window.multigraph.util.namespace("window.multigraph.core", function (ns) {
div = $("#" + div)[0];
}

// Force the div to have the specific width or height given in the options, if any.
// I'm adding this code to resolve a problem with the div size sometimes not being
// available when src/graphics/canvas/multigraph.js:createCanvasGraphFromString()
// is used; see the notes in that file.
if (options.width !== undefined && options.width > 0) {
$(div).width(options.width);
}
if (options.height !== undefined && options.height > 0) {
$(div).height(options.height);
}

//
// NOTE: each of the Multigraph.create{DRIVER}Graph functions below takes an
// "options" object argument just like Multigraph.createGraph does. In general this
Expand Down
10 changes: 9 additions & 1 deletion src/graphics/canvas/multigraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ window.multigraph.util.namespace("window.multigraph.graphics.canvas", function (
window.multigraph.core.Multigraph.createCanvasGraph = function (options) {
var muglPromise,
deferred;

try {
applyMixins(options);
muglPromise = $.ajax({
Expand All @@ -110,6 +110,7 @@ window.multigraph.util.namespace("window.multigraph.graphics.canvas", function (

muglPromise.done(function (data) {
try {
// TODO: div size IS available here; see below. What's going on???!!!
var multigraph = generateInitialGraph(data, options);
deferred.resolve(multigraph);
} catch (e) {
Expand All @@ -126,6 +127,13 @@ window.multigraph.util.namespace("window.multigraph.graphics.canvas", function (
try {
applyMixins(options);
deferred = $.Deferred();
// TODO: figure this out! div size is not available here? Apparently, at this point in
// code execution, the browser hasn't laid things out enough for the div to have been
// assigned a size, at least sometimes??? But it IS available at the corresponding place in
// createCanvasGraph above? This is worked around by the code in
// src/core/multigraph.js:createGraph() that forces the div to have the size specified in
// the options --- so we can work around the problem by passing an explicit size in the
// options. But we need to really figure out what's going on and resolve it.
var multigraph = generateInitialGraph(options.muglString, options);
deferred.resolve(multigraph);
} catch (e) {
Expand Down

0 comments on commit db078ba

Please sign in to comment.