@inweb/viewer-visualize 26.5.2 → 26.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17794,7 +17794,10 @@
17794
17794
  };
17795
17795
  }
17796
17796
  }
17797
- const ARC_RADIUS = 16;
17797
+ const ARC_RADIUS = 8;
17798
+ const ARC_LENGTH = 15;
17799
+ const MIN_CLOUD_WIDTH = 50;
17800
+ const MIN_CLOUD_HEIGHT = 50;
17798
17801
  this._ref = new Konva.Shape({
17799
17802
  x: params.position.x,
17800
17803
  y: params.position.y,
@@ -17806,63 +17809,76 @@
17806
17809
  strokeScaleEnabled: false,
17807
17810
  globalCompositeOperation: "source-over",
17808
17811
  sceneFunc: (context, shape) => {
17809
- function calculateMidpoint(position, width, height) {
17810
- const midX = position.x + width / 2;
17811
- const midY = position.y + height / 2;
17812
- return {
17813
- x: midX,
17814
- y: midY
17815
- };
17816
- }
17812
+ const width = this._ref.width();
17813
+ const height = this._ref.height();
17817
17814
  const points = [ {
17818
17815
  x: 0,
17819
17816
  y: 0
17820
17817
  }, {
17821
- x: 0 + this._ref.width(),
17818
+ x: 0 + width,
17822
17819
  y: 0
17823
17820
  }, {
17824
- x: 0 + this._ref.width(),
17825
- y: 0 + this._ref.height()
17821
+ x: 0 + width,
17822
+ y: 0 + height
17826
17823
  }, {
17827
17824
  x: 0,
17828
- y: 0 + this._ref.height()
17825
+ y: 0 + height
17829
17826
  }, {
17830
17827
  x: 0,
17831
17828
  y: 0
17832
17829
  } ];
17833
- const midPoint = calculateMidpoint({
17834
- x: 0,
17835
- y: 0
17836
- }, this._ref.width(), this._ref.height());
17837
- const baseArcLength = 30;
17838
- context.beginPath();
17839
- for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
17840
- let approxArcLength = baseArcLength;
17841
- const dx = points[iPoint + 1].x - points[iPoint].x;
17842
- const dy = points[iPoint + 1].y - points[iPoint].y;
17843
- const length = Math.sqrt(dx * dx + dy * dy);
17844
- const arcCount = Math.floor(length / approxArcLength);
17845
- const lengthMod = length % approxArcLength;
17846
- approxArcLength = baseArcLength + arcCount / lengthMod;
17847
- let pX = points[iPoint].x + dx / arcCount / 2;
17848
- let pY = points[iPoint].y + dy / arcCount / 2;
17849
- const pEndX = points[iPoint + 1].x;
17850
- const pEndY = points[iPoint + 1].y;
17851
- const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
17852
- const startAngle = endAngle + Math.PI;
17853
- const counterClockwise = pX > midPoint.x && pY > midPoint.y;
17854
- for (let iArc = 0; iArc < arcCount; iArc++) {
17855
- if (counterClockwise) {
17856
- context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
17857
- } else {
17858
- context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
17830
+ if (width >= MIN_CLOUD_WIDTH - 1 || height >= MIN_CLOUD_HEIGHT - 1) drawCloud(ARC_RADIUS, ARC_LENGTH); else if (width >= MIN_CLOUD_WIDTH / 2 || height >= MIN_CLOUD_HEIGHT / 2) drawCloud(ARC_RADIUS / 2, ARC_LENGTH / 2); else drawRectangle();
17831
+ function calculateMidpoint(position) {
17832
+ const midX = position.x + width / 2;
17833
+ const midY = position.y + height / 2;
17834
+ return {
17835
+ x: midX,
17836
+ y: midY
17837
+ };
17838
+ }
17839
+ function drawCloud(arcRadius, arcLength) {
17840
+ const midPoint = calculateMidpoint({
17841
+ x: 0,
17842
+ y: 0
17843
+ });
17844
+ context.beginPath();
17845
+ for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
17846
+ let approxArcLength = arcLength;
17847
+ const dx = points[iPoint + 1].x - points[iPoint].x;
17848
+ const dy = points[iPoint + 1].y - points[iPoint].y;
17849
+ const length = Math.sqrt(dx * dx + dy * dy);
17850
+ const arcCount = Math.floor(length / approxArcLength);
17851
+ const lengthMod = length % approxArcLength;
17852
+ approxArcLength = arcLength + arcCount / lengthMod;
17853
+ let pX = points[iPoint].x + dx / arcCount / 2;
17854
+ let pY = points[iPoint].y + dy / arcCount / 2;
17855
+ const pEndX = points[iPoint + 1].x;
17856
+ const pEndY = points[iPoint + 1].y;
17857
+ const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
17858
+ const startAngle = endAngle + Math.PI;
17859
+ const counterClockwise = pX > midPoint.x && pY > midPoint.y;
17860
+ for (let iArc = 0; iArc < arcCount; iArc++) {
17861
+ if (counterClockwise) {
17862
+ context.arc(pX, pY, arcRadius, endAngle, startAngle);
17863
+ } else {
17864
+ context.arc(pX, pY, arcRadius, startAngle, endAngle);
17865
+ }
17866
+ pX += dx / arcCount;
17867
+ pY += dy / arcCount;
17859
17868
  }
17860
- pX += dx / arcCount;
17861
- pY += dy / arcCount;
17862
17869
  }
17870
+ context.closePath();
17871
+ context.fillStrokeShape(shape);
17872
+ }
17873
+ function drawRectangle() {
17874
+ context.beginPath();
17875
+ context.lineTo(points[1].x, points[1].y);
17876
+ context.lineTo(points[2].x, points[2].y);
17877
+ context.lineTo(points[3].x, points[3].y);
17878
+ context.lineTo(points[4].x, points[4].y);
17879
+ context.closePath();
17880
+ context.fillStrokeShape(shape);
17863
17881
  }
17864
- context.closePath();
17865
- context.fillStrokeShape(shape);
17866
17882
  }
17867
17883
  });
17868
17884
  this._ref.className = "Cloud";
@@ -17882,10 +17898,8 @@
17882
17898
  if (scaleByX) newWidth *= attrs.scaleX;
17883
17899
  let newHeight = this._ref.height();
17884
17900
  if (scaleByY) newHeight *= attrs.scaleY;
17885
- const minWidth = 100;
17886
- const minHeight = 100;
17887
- if (newWidth < minWidth) newWidth = minWidth;
17888
- if (newHeight < minHeight) newHeight = minHeight;
17901
+ if (newWidth < MIN_CLOUD_WIDTH) newWidth = MIN_CLOUD_WIDTH;
17902
+ if (newHeight < MIN_CLOUD_HEIGHT) newHeight = MIN_CLOUD_HEIGHT;
17889
17903
  if (scaleByX) {
17890
17904
  this._ref.width(newWidth);
17891
17905
  }