Browse Source

Update network/node image code to allow for specifying a broken image url to use when a node image fails to load

v3_develop
Scott Fairgrieve 10 years ago
parent
commit
2ca1972f01
3 changed files with 13 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +10
    -1
      lib/network/Images.js
  3. +2
    -2
      lib/network/Node.js

+ 1
- 0
.gitignore View File

@ -7,3 +7,4 @@ node_modules
.settings/org.eclipse.wst.jsdt.ui.superType.name .settings/org.eclipse.wst.jsdt.ui.superType.name
npm-debug.log npm-debug.log
examples/graph/24_hierarchical_layout_userdefined2.html examples/graph/24_hierarchical_layout_userdefined2.html
.DS_Store

+ 10
- 1
lib/network/Images.js View File

@ -20,9 +20,10 @@ Images.prototype.setOnloadCallback = function(callback) {
/** /**
* *
* @param {string} url Url of the image * @param {string} url Url of the image
* @param {string} url Url of an image to use if the url image is not found
* @return {Image} img The image object * @return {Image} img The image object
*/ */
Images.prototype.load = function(url) {
Images.prototype.load = function(url, brokenUrl) {
var img = this.images[url]; var img = this.images[url];
if (img == undefined) { if (img == undefined) {
// create the image // create the image
@ -34,6 +35,14 @@ Images.prototype.load = function(url) {
images.callback(this); images.callback(this);
} }
}; };
img.onerror = function () {
this.src = brokenUrl;
if (images.callback) {
images.callback(this);
}
};
img.src = url; img.src = url;
} }

+ 2
- 2
lib/network/Node.js View File

@ -135,7 +135,7 @@ Node.prototype.setProperties = function(properties, constants) {
return; return;
} }
var fields = ['borderWidth','borderWidthSelected','shape','image','radius','fontColor',
var fields = ['borderWidth','borderWidthSelected','shape','image','brokenImage','radius','fontColor',
'fontSize','fontFace','fontFill','group','mass' 'fontSize','fontFace','fontFill','group','mass'
]; ];
util.selectiveDeepExtend(fields, this.options, properties); util.selectiveDeepExtend(fields, this.options, properties);
@ -176,7 +176,7 @@ Node.prototype.setProperties = function(properties, constants) {
if (this.options.image!== undefined && this.options.image!= "") { if (this.options.image!== undefined && this.options.image!= "") {
if (this.imagelist) { if (this.imagelist) {
this.imageObj = this.imagelist.load(this.options.image);
this.imageObj = this.imagelist.load(this.options.image, this.options.brokenImage);
} }
else { else {
throw "No imagelist provided"; throw "No imagelist provided";

Loading…
Cancel
Save