406 _clip.quadraticCurveTo(transformCoords(coords, true)); |
406 _clip.quadraticCurveTo(transformCoords(coords, true)); |
407 break; |
407 break; |
408 } |
408 } |
409 }); |
409 }); |
410 |
410 |
411 var baseScale = Math.max(maxX - minX, maxY - minY) / 2; |
411 var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](maxX - minX, maxY - minY) / 2, |
412 this.image_delta = new paper.Point((maxX + minX) / (2 * baseScale), (maxY + minY) / (2 * baseScale)); |
412 centerPoint = new paper.Point((maxX + minX) / 2, (maxY + minY) / 2); |
413 if (!this.options.show_node_circles) { |
413 if (!this.options.show_node_circles) { |
414 this.h_ratio = (maxY - minY) / (2 * baseScale); |
414 this.h_ratio = (maxY - minY) / (2 * baseRadius); |
415 } |
415 } |
416 } else { |
416 } else { |
417 var baseScale = Math.max(width, height) / 2; |
417 var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](width, height) / 2, |
418 this.image_delta = new paper.Point(0,0); |
418 centerPoint = new paper.Point(0,0); |
419 if (!this.options.show_node_circles) { |
419 if (!this.options.show_node_circles) { |
420 this.h_ratio = height / (2 * baseScale); |
420 this.h_ratio = height / (2 * baseRadius); |
421 } |
421 } |
422 } |
422 } |
423 var _raster = new paper.Raster(_image); |
423 var _raster = new paper.Raster(_image); |
424 if (this.options.clip_node_images || hasClipPath) { |
424 if (hasClipPath) { |
425 if (!hasClipPath) { |
425 _raster = new paper.Group(_clip, _raster); |
426 var _clip = new paper.Path.Circle([0, 0], baseScale); |
426 _raster.opacity = .99; |
427 } |
|
428 this.node_image = new paper.Group(_clip, _raster); |
|
429 this.node_image.opacity = .99; |
|
430 /* This is a workaround to allow clipping at group level |
427 /* This is a workaround to allow clipping at group level |
431 * If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
428 * If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
432 */ |
429 */ |
433 this.node_image.clipped = true; |
430 _raster.clipped = true; |
434 _clip.__representation = this; |
431 _clip.__representation = this; |
435 } else { |
432 } |
436 this.node_image = _raster; |
433 if (this.options.clip_node_images) { |
437 } |
434 var _circleClip = new paper.Path.Circle(centerPoint, baseRadius); |
|
435 _raster = new paper.Group(_circleClip, _raster); |
|
436 _raster.opacity = .99; |
|
437 _raster.clipped = true; |
|
438 _circleClip.__representation = this; |
|
439 } |
|
440 this.image_delta = centerPoint.divide(baseRadius); |
|
441 this.node_image = _raster; |
438 this.node_image.__representation = _this; |
442 this.node_image.__representation = _this; |
439 this.node_image.scale(this.circle_radius / baseScale); |
443 this.node_image.scale(this.circle_radius / baseRadius); |
440 this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius)); |
444 this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius)); |
441 this.redraw(); |
445 this.redraw(); |
442 this.renderer.throttledPaperDraw(); |
446 this.renderer.throttledPaperDraw(); |
443 } else { |
447 } else { |
444 var _this = this; |
448 var _this = this; |