@visactor/vchart 2.0.22-alpha.1 → 2.0.22-alpha.2

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.
package/build/index.es.js CHANGED
@@ -20505,13 +20505,14 @@ class DefaultBaseTextureRenderContribution {
20505
20505
  texture && this.drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding);
20506
20506
  }
20507
20507
  drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding) {
20508
- var _a, _b, _c, _d, _e;
20508
+ var _a, _b, _c, _d, _e, _f;
20509
20509
  const {
20510
20510
  textureRatio = graphicAttribute.textureRatio,
20511
20511
  textureOptions = null
20512
20512
  } = graphic.attribute;
20513
20513
  let pattern = null;
20514
- const patternKey = this.getPatternCacheKey(texture, textureSize, texturePadding, textureColor, context.dpr);
20514
+ const textureRadius = null !== (_a = null == textureOptions ? void 0 : textureOptions.radius) && void 0 !== _a ? _a : 0,
20515
+ patternKey = this.getPatternCacheKey(texture, textureSize, texturePadding, textureColor, context.dpr, textureRadius);
20515
20516
  if (null !== patternKey && (pattern = this.textureMap.get(patternKey)), !pattern) {
20516
20517
  if ("string" == typeof texture) switch (texture) {
20517
20518
  case "circle":
@@ -20538,7 +20539,7 @@ class DefaultBaseTextureRenderContribution {
20538
20539
  case "grid":
20539
20540
  pattern = this.createGridPattern(textureSize, texturePadding, textureColor, context);
20540
20541
  }
20541
- pattern || (pattern = this.createResourcePattern(texture, graphic, context)), pattern && null !== patternKey && this.textureMap.set(patternKey, pattern);
20542
+ pattern || (pattern = this.createResourcePattern(texture, graphic, context, texturePadding, textureRadius)), pattern && null !== patternKey && this.textureMap.set(patternKey, pattern);
20542
20543
  }
20543
20544
  if ("string" == typeof texture && textureOptions && textureOptions.dynamicTexture) {
20544
20545
  const {
@@ -20585,19 +20586,19 @@ class DefaultBaseTextureRenderContribution {
20585
20586
  for (let i = 0; i < gridRows; i++) for (let j = 0; j < gridColumns; j++) {
20586
20587
  const _x = x + cellSize / 2 + j * cellSize,
20587
20588
  _y = y + cellSize / 2 + i * cellSize;
20588
- null === (_a = textureOptions.beforeDynamicTexture) || void 0 === _a || _a.call(textureOptions, context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height()), context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height());
20589
+ null === (_b = textureOptions.beforeDynamicTexture) || void 0 === _b || _b.call(textureOptions, context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height()), context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height());
20589
20590
  }
20590
20591
  useNewCanvas && (originalContext.globalAlpha = 1, originalContext.drawImage(newCanvas.nativeCanvas, 0, 0, newCanvas.nativeCanvas.width, newCanvas.nativeCanvas.height, b.x1, b.y1, b.width() * originalContext.dpr, b.height() * originalContext.dpr)), originalContext.restore();
20591
20592
  } else if (pattern) {
20592
20593
  if (pattern.setTransform) {
20593
20594
  const alignToGraphic = !!(null == textureOptions ? void 0 : textureOptions.alignToGraphic),
20594
- alignOffsetX = null !== (_b = null == textureOptions ? void 0 : textureOptions.alignOffsetX) && void 0 !== _b ? _b : 0,
20595
- alignOffsetY = null !== (_c = null == textureOptions ? void 0 : textureOptions.alignOffsetY) && void 0 !== _c ? _c : 0;
20595
+ alignOffsetX = null !== (_c = null == textureOptions ? void 0 : textureOptions.alignOffsetX) && void 0 !== _c ? _c : 0,
20596
+ alignOffsetY = null !== (_d = null == textureOptions ? void 0 : textureOptions.alignOffsetY) && void 0 !== _d ? _d : 0;
20596
20597
  let translateX = 0,
20597
20598
  translateY = 0;
20598
20599
  if (alignToGraphic) {
20599
20600
  const m = context.currentMatrix;
20600
- translateX = (null !== (_d = null == m ? void 0 : m.e) && void 0 !== _d ? _d : 0) + x + alignOffsetX, translateY = (null !== (_e = null == m ? void 0 : m.f) && void 0 !== _e ? _e : 0) + y + alignOffsetY;
20601
+ translateX = (null !== (_e = null == m ? void 0 : m.e) && void 0 !== _e ? _e : 0) + x + alignOffsetX, translateY = (null !== (_f = null == m ? void 0 : m.f) && void 0 !== _f ? _f : 0) + y + alignOffsetY;
20601
20602
  } else (alignOffsetX || alignOffsetY) && (translateX = alignOffsetX, translateY = alignOffsetY);
20602
20603
  pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, translateX, translateY]));
20603
20604
  }
@@ -20610,14 +20611,42 @@ class DefaultBaseTextureRenderContribution {
20610
20611
  }), x + b.x1 - x, y + b.y1 - y), context.restore();
20611
20612
  }
20612
20613
  }
20613
- getPatternCacheKey(texture, textureSize, texturePadding, textureColor, dpr) {
20614
- return "string" != typeof texture ? texture : "wave" === texture ? null : `${texture}-${textureSize}-${texturePadding}-${textureColor}-${dpr}`;
20614
+ getPatternCacheKey(texture, textureSize, texturePadding, textureColor, dpr, textureRadius) {
20615
+ return "string" != typeof texture ? texturePadding > 0 || textureRadius > 0 ? null : texture : "wave" === texture ? null : `${texture}-${textureSize}-${texturePadding}-${textureColor}-${dpr}`;
20615
20616
  }
20616
- createResourcePattern(texture, graphic, context) {
20617
+ createResourcePattern(texture, graphic, context, texturePadding, textureRadius) {
20617
20618
  var _a;
20618
20619
  const resource = null === (_a = graphic.resources) || void 0 === _a ? void 0 : _a.get(texture),
20619
20620
  data = "success" === (null == resource ? void 0 : resource.state) ? resource.data : "object" == typeof texture ? texture : null;
20620
20621
  if (!data) return null;
20622
+ if (texturePadding > 0 || textureRadius > 0) {
20623
+ const w = data.naturalWidth || data.width,
20624
+ h = data.naturalHeight || data.height;
20625
+ if (w > 0 && h > 0) {
20626
+ const tileW = w + 2 * texturePadding,
20627
+ tileH = h + 2 * texturePadding,
20628
+ canvas = canvasAllocate.allocate({
20629
+ width: tileW,
20630
+ height: tileH,
20631
+ dpr: context.dpr
20632
+ }),
20633
+ ctx = canvas.getContext("2d");
20634
+ if (ctx) {
20635
+ if (ctx.inuse = !0, ctx.clearMatrix(), ctx.setTransformForCurrent(!0), ctx.clearRect(0, 0, tileW, tileH), textureRadius > 0) {
20636
+ const r = Math.max(0, Math.min(textureRadius, Math.min(w, h) / 2)),
20637
+ x0 = texturePadding,
20638
+ y0 = texturePadding,
20639
+ x1 = x0 + w,
20640
+ y1 = y0 + h;
20641
+ ctx.beginPath(), ctx.moveTo(x0 + r, y0), ctx.lineTo(x1 - r, y0), ctx.quadraticCurveTo(x1, y0, x1, y0 + r), ctx.lineTo(x1, y1 - r), ctx.quadraticCurveTo(x1, y1, x1 - r, y1), ctx.lineTo(x0 + r, y1), ctx.quadraticCurveTo(x0, y1, x0, y1 - r), ctx.lineTo(x0, y0 + r), ctx.quadraticCurveTo(x0, y0, x0 + r, y0), ctx.closePath(), ctx.clip();
20642
+ }
20643
+ ctx.drawImage(data, texturePadding, texturePadding, w, h);
20644
+ const pattern = context.createPattern(canvas.nativeCanvas, "repeat");
20645
+ return (null == pattern ? void 0 : pattern.setTransform) && pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, 0, 0])), canvasAllocate.free(canvas), pattern;
20646
+ }
20647
+ canvasAllocate.free(canvas);
20648
+ }
20649
+ }
20621
20650
  const pattern = context.createPattern(data, "repeat");
20622
20651
  return (null == pattern ? void 0 : pattern.setTransform) && pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, 0, 0])), pattern;
20623
20652
  }
package/build/index.js CHANGED
@@ -20511,13 +20511,14 @@
20511
20511
  texture && this.drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding);
20512
20512
  }
20513
20513
  drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding) {
20514
- var _a, _b, _c, _d, _e;
20514
+ var _a, _b, _c, _d, _e, _f;
20515
20515
  const {
20516
20516
  textureRatio = graphicAttribute.textureRatio,
20517
20517
  textureOptions = null
20518
20518
  } = graphic.attribute;
20519
20519
  let pattern = null;
20520
- const patternKey = this.getPatternCacheKey(texture, textureSize, texturePadding, textureColor, context.dpr);
20520
+ const textureRadius = null !== (_a = null == textureOptions ? void 0 : textureOptions.radius) && void 0 !== _a ? _a : 0,
20521
+ patternKey = this.getPatternCacheKey(texture, textureSize, texturePadding, textureColor, context.dpr, textureRadius);
20521
20522
  if (null !== patternKey && (pattern = this.textureMap.get(patternKey)), !pattern) {
20522
20523
  if ("string" == typeof texture) switch (texture) {
20523
20524
  case "circle":
@@ -20544,7 +20545,7 @@
20544
20545
  case "grid":
20545
20546
  pattern = this.createGridPattern(textureSize, texturePadding, textureColor, context);
20546
20547
  }
20547
- pattern || (pattern = this.createResourcePattern(texture, graphic, context)), pattern && null !== patternKey && this.textureMap.set(patternKey, pattern);
20548
+ pattern || (pattern = this.createResourcePattern(texture, graphic, context, texturePadding, textureRadius)), pattern && null !== patternKey && this.textureMap.set(patternKey, pattern);
20548
20549
  }
20549
20550
  if ("string" == typeof texture && textureOptions && textureOptions.dynamicTexture) {
20550
20551
  const {
@@ -20591,19 +20592,19 @@
20591
20592
  for (let i = 0; i < gridRows; i++) for (let j = 0; j < gridColumns; j++) {
20592
20593
  const _x = x + cellSize / 2 + j * cellSize,
20593
20594
  _y = y + cellSize / 2 + i * cellSize;
20594
- null === (_a = textureOptions.beforeDynamicTexture) || void 0 === _a || _a.call(textureOptions, context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height()), context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height());
20595
+ null === (_b = textureOptions.beforeDynamicTexture) || void 0 === _b || _b.call(textureOptions, context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height()), context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height());
20595
20596
  }
20596
20597
  useNewCanvas && (originalContext.globalAlpha = 1, originalContext.drawImage(newCanvas.nativeCanvas, 0, 0, newCanvas.nativeCanvas.width, newCanvas.nativeCanvas.height, b.x1, b.y1, b.width() * originalContext.dpr, b.height() * originalContext.dpr)), originalContext.restore();
20597
20598
  } else if (pattern) {
20598
20599
  if (pattern.setTransform) {
20599
20600
  const alignToGraphic = !!(null == textureOptions ? void 0 : textureOptions.alignToGraphic),
20600
- alignOffsetX = null !== (_b = null == textureOptions ? void 0 : textureOptions.alignOffsetX) && void 0 !== _b ? _b : 0,
20601
- alignOffsetY = null !== (_c = null == textureOptions ? void 0 : textureOptions.alignOffsetY) && void 0 !== _c ? _c : 0;
20601
+ alignOffsetX = null !== (_c = null == textureOptions ? void 0 : textureOptions.alignOffsetX) && void 0 !== _c ? _c : 0,
20602
+ alignOffsetY = null !== (_d = null == textureOptions ? void 0 : textureOptions.alignOffsetY) && void 0 !== _d ? _d : 0;
20602
20603
  let translateX = 0,
20603
20604
  translateY = 0;
20604
20605
  if (alignToGraphic) {
20605
20606
  const m = context.currentMatrix;
20606
- translateX = (null !== (_d = null == m ? void 0 : m.e) && void 0 !== _d ? _d : 0) + x + alignOffsetX, translateY = (null !== (_e = null == m ? void 0 : m.f) && void 0 !== _e ? _e : 0) + y + alignOffsetY;
20607
+ translateX = (null !== (_e = null == m ? void 0 : m.e) && void 0 !== _e ? _e : 0) + x + alignOffsetX, translateY = (null !== (_f = null == m ? void 0 : m.f) && void 0 !== _f ? _f : 0) + y + alignOffsetY;
20607
20608
  } else (alignOffsetX || alignOffsetY) && (translateX = alignOffsetX, translateY = alignOffsetY);
20608
20609
  pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, translateX, translateY]));
20609
20610
  }
@@ -20616,14 +20617,42 @@
20616
20617
  }), x + b.x1 - x, y + b.y1 - y), context.restore();
20617
20618
  }
20618
20619
  }
20619
- getPatternCacheKey(texture, textureSize, texturePadding, textureColor, dpr) {
20620
- return "string" != typeof texture ? texture : "wave" === texture ? null : `${texture}-${textureSize}-${texturePadding}-${textureColor}-${dpr}`;
20620
+ getPatternCacheKey(texture, textureSize, texturePadding, textureColor, dpr, textureRadius) {
20621
+ return "string" != typeof texture ? texturePadding > 0 || textureRadius > 0 ? null : texture : "wave" === texture ? null : `${texture}-${textureSize}-${texturePadding}-${textureColor}-${dpr}`;
20621
20622
  }
20622
- createResourcePattern(texture, graphic, context) {
20623
+ createResourcePattern(texture, graphic, context, texturePadding, textureRadius) {
20623
20624
  var _a;
20624
20625
  const resource = null === (_a = graphic.resources) || void 0 === _a ? void 0 : _a.get(texture),
20625
20626
  data = "success" === (null == resource ? void 0 : resource.state) ? resource.data : "object" == typeof texture ? texture : null;
20626
20627
  if (!data) return null;
20628
+ if (texturePadding > 0 || textureRadius > 0) {
20629
+ const w = data.naturalWidth || data.width,
20630
+ h = data.naturalHeight || data.height;
20631
+ if (w > 0 && h > 0) {
20632
+ const tileW = w + 2 * texturePadding,
20633
+ tileH = h + 2 * texturePadding,
20634
+ canvas = canvasAllocate.allocate({
20635
+ width: tileW,
20636
+ height: tileH,
20637
+ dpr: context.dpr
20638
+ }),
20639
+ ctx = canvas.getContext("2d");
20640
+ if (ctx) {
20641
+ if (ctx.inuse = !0, ctx.clearMatrix(), ctx.setTransformForCurrent(!0), ctx.clearRect(0, 0, tileW, tileH), textureRadius > 0) {
20642
+ const r = Math.max(0, Math.min(textureRadius, Math.min(w, h) / 2)),
20643
+ x0 = texturePadding,
20644
+ y0 = texturePadding,
20645
+ x1 = x0 + w,
20646
+ y1 = y0 + h;
20647
+ ctx.beginPath(), ctx.moveTo(x0 + r, y0), ctx.lineTo(x1 - r, y0), ctx.quadraticCurveTo(x1, y0, x1, y0 + r), ctx.lineTo(x1, y1 - r), ctx.quadraticCurveTo(x1, y1, x1 - r, y1), ctx.lineTo(x0 + r, y1), ctx.quadraticCurveTo(x0, y1, x0, y1 - r), ctx.lineTo(x0, y0 + r), ctx.quadraticCurveTo(x0, y0, x0 + r, y0), ctx.closePath(), ctx.clip();
20648
+ }
20649
+ ctx.drawImage(data, texturePadding, texturePadding, w, h);
20650
+ const pattern = context.createPattern(canvas.nativeCanvas, "repeat");
20651
+ return (null == pattern ? void 0 : pattern.setTransform) && pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, 0, 0])), canvasAllocate.free(canvas), pattern;
20652
+ }
20653
+ canvasAllocate.free(canvas);
20654
+ }
20655
+ }
20627
20656
  const pattern = context.createPattern(data, "repeat");
20628
20657
  return (null == pattern ? void 0 : pattern.setTransform) && pattern.setTransform(new DOMMatrix([1 / context.dpr, 0, 0, 1 / context.dpr, 0, 0])), pattern;
20629
20658
  }