Browse Source

Merge pull request #278 from sfairgrieve/develop

[Network] Added support for a broken image fallback when node image fails to load
v3_develop
Alex 10 years ago
parent
commit
a45bf08c83
4 changed files with 19 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +6
    -0
      docs/network.html
  3. +10
    -1
      lib/network/Images.js
  4. +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
npm-debug.log
examples/graph/24_hierarchical_layout_userdefined2.html
.DS_Store

+ 6
- 0
docs/network.html View File

@ -964,6 +964,12 @@ All options defined per-node override these global settings.
<td>undefined</td>
<td>Default image url for the nodes. only applicable to shape <code>image</code>.</td>
</tr>
<tr>
<td class="greenField">brokenImage</td>
<td>String</td>
<td>undefined</td>
<td>Image url to use in the event that the url specified in the <code>image</code> property fails to load. only applicable to shape <code>image</code>.</td>
</tr>
<tr>
<td class="greenField">mass</td>
<td>number</td>

+ 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 an image to use if the url image is not found
* @return {Image} img The image object
*/
Images.prototype.load = function(url) {
Images.prototype.load = function(url, brokenUrl) {
var img = this.images[url];
if (img == undefined) {
// create the image
@ -34,6 +35,14 @@ Images.prototype.load = function(url) {
images.callback(this);
}
};
img.onerror = function () {
this.src = brokenUrl;
if (images.callback) {
images.callback(this);
}
};
img.src = url;
}

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

@ -135,7 +135,7 @@ Node.prototype.setProperties = function(properties, constants) {
return;
}
var fields = ['borderWidth','borderWidthSelected','shape','image','radius','fontColor',
var fields = ['borderWidth','borderWidthSelected','shape','image','brokenImage','radius','fontColor',
'fontSize','fontFace','fontFill','group','mass'
];
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.imagelist) {
this.imageObj = this.imagelist.load(this.options.image);
this.imageObj = this.imagelist.load(this.options.image, this.options.brokenImage);
}
else {
throw "No imagelist provided";

Loading…
Cancel
Save