kieler / klayjs

(deprecated) KIELER's layout algorithms for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

doesn't work as npm module (with browserify)

freder opened this issue · comments

hi,

I'm using browserify, and I just tried this:

var klay = require('klayjs');
console.log(klay);
console.log(klay.layout);

node js output:

{ layout: [Function] }
[Function]

however, in the browser I get:

Object {}
undefined

any idea why that might be?

Could be related to the assumptions we made when registering the script.

if (typeof document !== "undefined") {
  // DEFAULT BROWSER 
  $wnd.$klay = klay;
} else if (typeof module === "object" && module.exports) { 
  // NODE JS
  module.exports = klay;
}

I assume since you are in a browser nothing is registered for nodejs (the else branch). Could you try to replace the following piece of code in line 1296 of the klay.js file. If that helps, I'll fix it properly. Sorry about the code, I hope you find the spot ... it's generated code :).

typeof document!==mkb?($wnd.$klay=b):typeof module===Jjb&&module.exports&&(module.exports=b);
if(typeof document!==mkb) $wnd.$klay=b; if(typeof module===Jjb&&module.exports) module.exports=b;

yep, that seems to work:

Object {layout: function}
function (a){njb(cM(a))}

Should be fixed.