CompoundPath.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var Path = require("./Path");
  2. // CompoundPath to improve performance
  3. var _default = Path.extend({
  4. type: 'compound',
  5. shape: {
  6. paths: null
  7. },
  8. _updatePathDirty: function () {
  9. var dirtyPath = this.__dirtyPath;
  10. var paths = this.shape.paths;
  11. for (var i = 0; i < paths.length; i++) {
  12. // Mark as dirty if any subpath is dirty
  13. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14. }
  15. this.__dirtyPath = dirtyPath;
  16. this.__dirty = this.__dirty || dirtyPath;
  17. },
  18. beforeBrush: function () {
  19. this._updatePathDirty();
  20. var paths = this.shape.paths || [];
  21. var scale = this.getGlobalScale(); // Update path scale
  22. for (var i = 0; i < paths.length; i++) {
  23. if (!paths[i].path) {
  24. paths[i].createPathProxy();
  25. }
  26. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  27. }
  28. },
  29. buildPath: function (ctx, shape) {
  30. var paths = shape.paths || [];
  31. for (var i = 0; i < paths.length; i++) {
  32. paths[i].buildPath(ctx, paths[i].shape, true);
  33. }
  34. },
  35. afterBrush: function () {
  36. var paths = this.shape.paths || [];
  37. for (var i = 0; i < paths.length; i++) {
  38. paths[i].__dirtyPath = false;
  39. }
  40. },
  41. getBoundingRect: function () {
  42. this._updatePathDirty();
  43. return Path.prototype.getBoundingRect.call(this);
  44. }
  45. });
  46. module.exports = _default;