@antv/g-plugin-canvas-path-generator
Advanced tools
Comparing version 1.1.51 to 1.2.0-alpha.1
@@ -8,2 +8,1 @@ import { AbstractRendererPlugin } from '@antv/g-lite'; | ||
export * from './interfaces'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,348 +1,298 @@ | ||
import { __read, __extends } from 'tslib'; | ||
import { isDisplayObject, Shape, AbstractRendererPlugin } from '@antv/g-lite'; | ||
import { clamp } from '@antv/util'; | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
function generatePath$6(context, parsedStyle) { | ||
var r = parsedStyle.r; | ||
context.arc(r, r, r, 0, Math.PI * 2, false); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function generatePath(context, parsedStyle) { | ||
var r = parsedStyle.r; | ||
context.arc(r, r, r, 0, Math.PI * 2, false); | ||
function generatePath$5(context, parsedStyle) { | ||
var rxInPixels = parsedStyle.rx, ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
} | ||
else { | ||
// 如果不支持,则使用圆来绘制,进行变形 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.save(); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, 0, Math.PI * 2); | ||
} | ||
} | ||
function generatePath$1(context, parsedStyle) { | ||
var rxInPixels = parsedStyle.rx, | ||
ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
} else { | ||
// 如果不支持,则使用圆来绘制,进行变形 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.save(); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, 0, Math.PI * 2); | ||
} | ||
function generatePath$4(context, parsedStyle) { | ||
var x1 = parsedStyle.x1, y1 = parsedStyle.y1, x2 = parsedStyle.x2, y2 = parsedStyle.y2, _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = x2 - x1; | ||
y = y2 - y1; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = x1 - x2; | ||
y = y1 - y2; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
} | ||
function generatePath$2(context, parsedStyle) { | ||
var x1 = parsedStyle.x1, | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = x2 - x1; | ||
y = y2 - y1; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = x1 - x2; | ||
y = y1 - y2; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
} | ||
function generatePath$3(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var _parsedStyle$path = parsedStyle.path, | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(), | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(), | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
x = _p[0] - _p2[0]; | ||
y = _p[1] - _p2[1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
var params = absolutePath[i]; | ||
var command = params[0]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0; | ||
switch (command) { | ||
case 'M': | ||
// Use start marker offset | ||
if (useStartOffset) { | ||
context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY); | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} else { | ||
context.moveTo(params[1] - defX, params[2] - defY); | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var _c = parsedStyle.path, absolutePath = _c.absolutePath, segments = _c.segments; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
var _d = __read(markerStart.parentNode.getStartTangent(), 2), p1 = _d[0], p2 = _d[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
var _e = __read(markerEnd.parentNode.getEndTangent(), 2), p1 = _e[0], p2 = _e[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
var params = absolutePath[i]; | ||
var command = params[0]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || | ||
(nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z'))) && | ||
endOffsetX !== 0 && | ||
endOffsetY !== 0; | ||
switch (command) { | ||
case 'M': | ||
// Use start marker offset | ||
if (useStartOffset) { | ||
context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY); | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
else { | ||
context.moveTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'L': | ||
if (useEndOffset) { | ||
context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY); | ||
} | ||
else { | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': { | ||
var arcParams = segments[i].arcParams; | ||
var cx = arcParams.cx, cy = arcParams.cy, rx = arcParams.rx, ry = arcParams.ry, startAngle = arcParams.startAngle, endAngle = arcParams.endAngle, xRotation = arcParams.xRotation, sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} | ||
else { | ||
// @see https://stackoverflow.com/a/47494351 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.translate(cx - defX, cy - defY); | ||
context.rotate(xRotation); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag)); | ||
context.scale(1 / scaleX, 1 / scaleY); | ||
context.rotate(-xRotation); | ||
context.translate(-(cx - defX), -(cy - defY)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
context.closePath(); | ||
break; | ||
} | ||
break; | ||
case 'L': | ||
if (useEndOffset) { | ||
context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY); | ||
} else { | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': | ||
{ | ||
var arcParams = segments[i].arcParams; | ||
var cx = arcParams.cx, | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} else { | ||
// @see https://stackoverflow.com/a/47494351 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.translate(cx - defX, cy - defY); | ||
context.rotate(xRotation); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag)); | ||
context.scale(1 / scaleX, 1 / scaleY); | ||
context.rotate(-xRotation); | ||
context.translate(-(cx - defX), -(cy - defY)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
context.closePath(); | ||
break; | ||
} | ||
} | ||
} | ||
function generatePath$4(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 1][0] - points[0][0]; | ||
y = points[length - 1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2, y2); | ||
function generatePath$2(context, parsedStyle) { | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 1][0] - points[0][0]; | ||
y = points[length - 1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2, y2); | ||
} | ||
function generatePath$5(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 2][0] - points[length - 1][0]; | ||
y = points[length - 2][1] - points[length - 1][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
function generatePath$1(context, parsedStyle) { | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 2][0] - points[length - 1][0]; | ||
y = points[length - 2][1] - points[length - 1][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
} | ||
function generatePath$6(context, parsedStyle) { | ||
var radius = parsedStyle.radius, | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
var w = width; | ||
var h = height; | ||
var hasRadius = radius && radius.some(function (r) { | ||
return r !== 0; | ||
}); | ||
if (!hasRadius) { | ||
// Canvas support negative width/height of rect | ||
context.rect(0, 0, w, h); | ||
} else { | ||
var signX = width > 0 ? 1 : -1; | ||
var signY = height > 0 ? 1 : -1; | ||
var sweepFlag = signX + signY === 0; | ||
var _radius$map = radius.map(function (r) { | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
function generatePath(context, parsedStyle) { | ||
var radius = parsedStyle.radius, width = parsedStyle.width, height = parsedStyle.height; | ||
var w = width; | ||
var h = height; | ||
var hasRadius = radius && radius.some(function (r) { return r !== 0; }); | ||
if (!hasRadius) { | ||
// Canvas support negative width/height of rect | ||
context.rect(0, 0, w, h); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
else { | ||
var signX = width > 0 ? 1 : -1; | ||
var signY = height > 0 ? 1 : -1; | ||
var sweepFlag = signX + signY === 0; | ||
var _a = __read(radius.map(function (r) { | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), 4), tlr = _a[0], trr = _a[1], brr = _a[2], blr = _a[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, (-signY * Math.PI) / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
} | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
} | ||
} | ||
} | ||
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) { | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var Plugin = /** @class */ (function (_super) { | ||
__extends(Plugin, _super); | ||
function Plugin() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.name = 'canvas-path-generator'; | ||
return _this; | ||
} | ||
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this; | ||
_this.name = 'canvas-path-generator'; | ||
return _this; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
var _pathGeneratorFactory; | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[Shape.CIRCLE] = generatePath, _pathGeneratorFactory[Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[Shape.RECT] = generatePath$6, _pathGeneratorFactory[Shape.LINE] = generatePath$2, _pathGeneratorFactory[Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[Shape.PATH] = generatePath$3, _pathGeneratorFactory[Shape.TEXT] = undefined, _pathGeneratorFactory[Shape.GROUP] = undefined, _pathGeneratorFactory[Shape.IMAGE] = undefined, _pathGeneratorFactory[Shape.HTML] = undefined, _pathGeneratorFactory[Shape.MESH] = undefined, _pathGeneratorFactory); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
_proto.destroy = function destroy() { | ||
// @ts-ignore | ||
delete this.context.pathGeneratorFactory; | ||
}; | ||
return Plugin; | ||
}(AbstractRendererPlugin); | ||
Plugin.prototype.init = function () { | ||
var _a; | ||
var pathGeneratorFactory = (_a = {}, | ||
_a[Shape.CIRCLE] = generatePath$6, | ||
_a[Shape.ELLIPSE] = generatePath$5, | ||
_a[Shape.RECT] = generatePath, | ||
_a[Shape.LINE] = generatePath$4, | ||
_a[Shape.POLYLINE] = generatePath$1, | ||
_a[Shape.POLYGON] = generatePath$2, | ||
_a[Shape.PATH] = generatePath$3, | ||
_a[Shape.TEXT] = undefined, | ||
_a[Shape.GROUP] = undefined, | ||
_a[Shape.IMAGE] = undefined, | ||
_a[Shape.HTML] = undefined, | ||
_a[Shape.MESH] = undefined, | ||
_a); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
Plugin.prototype.destroy = function () { | ||
// @ts-ignore | ||
delete this.context.pathGeneratorFactory; | ||
}; | ||
return Plugin; | ||
}(AbstractRendererPlugin)); | ||
export { Plugin }; | ||
//# sourceMappingURL=index.esm.js.map |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var tslib = require('tslib'); | ||
var gLite = require('@antv/g-lite'); | ||
var util = require('@antv/util'); | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
function generatePath$6(context, parsedStyle) { | ||
var r = parsedStyle.r; | ||
context.arc(r, r, r, 0, Math.PI * 2, false); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function generatePath(context, parsedStyle) { | ||
var r = parsedStyle.r; | ||
context.arc(r, r, r, 0, Math.PI * 2, false); | ||
function generatePath$5(context, parsedStyle) { | ||
var rxInPixels = parsedStyle.rx, ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
} | ||
else { | ||
// 如果不支持,则使用圆来绘制,进行变形 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.save(); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, 0, Math.PI * 2); | ||
} | ||
} | ||
function generatePath$1(context, parsedStyle) { | ||
var rxInPixels = parsedStyle.rx, | ||
ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
} else { | ||
// 如果不支持,则使用圆来绘制,进行变形 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.save(); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, 0, Math.PI * 2); | ||
} | ||
function generatePath$4(context, parsedStyle) { | ||
var x1 = parsedStyle.x1, y1 = parsedStyle.y1, x2 = parsedStyle.x2, y2 = parsedStyle.y2, _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = x2 - x1; | ||
y = y2 - y1; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = x1 - x2; | ||
y = y1 - y2; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
} | ||
function generatePath$2(context, parsedStyle) { | ||
var x1 = parsedStyle.x1, | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = x2 - x1; | ||
y = y2 - y1; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = x1 - x2; | ||
y = y1 - y2; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
} | ||
function generatePath$3(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var _parsedStyle$path = parsedStyle.path, | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(), | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(), | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
x = _p[0] - _p2[0]; | ||
y = _p[1] - _p2[1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
var params = absolutePath[i]; | ||
var command = params[0]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0; | ||
switch (command) { | ||
case 'M': | ||
// Use start marker offset | ||
if (useStartOffset) { | ||
context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY); | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} else { | ||
context.moveTo(params[1] - defX, params[2] - defY); | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var _c = parsedStyle.path, absolutePath = _c.absolutePath, segments = _c.segments; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
var _d = tslib.__read(markerStart.parentNode.getStartTangent(), 2), p1 = _d[0], p2 = _d[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
var _e = tslib.__read(markerEnd.parentNode.getEndTangent(), 2), p1 = _e[0], p2 = _e[1]; | ||
x = p1[0] - p2[0]; | ||
y = p1[1] - p2[1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
var params = absolutePath[i]; | ||
var command = params[0]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || | ||
(nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z'))) && | ||
endOffsetX !== 0 && | ||
endOffsetY !== 0; | ||
switch (command) { | ||
case 'M': | ||
// Use start marker offset | ||
if (useStartOffset) { | ||
context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY); | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
else { | ||
context.moveTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'L': | ||
if (useEndOffset) { | ||
context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY); | ||
} | ||
else { | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': { | ||
var arcParams = segments[i].arcParams; | ||
var cx = arcParams.cx, cy = arcParams.cy, rx = arcParams.rx, ry = arcParams.ry, startAngle = arcParams.startAngle, endAngle = arcParams.endAngle, xRotation = arcParams.xRotation, sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} | ||
else { | ||
// @see https://stackoverflow.com/a/47494351 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.translate(cx - defX, cy - defY); | ||
context.rotate(xRotation); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag)); | ||
context.scale(1 / scaleX, 1 / scaleY); | ||
context.rotate(-xRotation); | ||
context.translate(-(cx - defX), -(cy - defY)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
context.closePath(); | ||
break; | ||
} | ||
break; | ||
case 'L': | ||
if (useEndOffset) { | ||
context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY); | ||
} else { | ||
context.lineTo(params[1] - defX, params[2] - defY); | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': | ||
{ | ||
var arcParams = segments[i].arcParams; | ||
var cx = arcParams.cx, | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} else { | ||
// @see https://stackoverflow.com/a/47494351 | ||
var r = rx > ry ? rx : ry; | ||
var scaleX = rx > ry ? 1 : rx / ry; | ||
var scaleY = rx > ry ? ry / rx : 1; | ||
context.translate(cx - defX, cy - defY); | ||
context.rotate(xRotation); | ||
context.scale(scaleX, scaleY); | ||
context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag)); | ||
context.scale(1 / scaleX, 1 / scaleY); | ||
context.rotate(-xRotation); | ||
context.translate(-(cx - defX), -(cy - defY)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
context.closePath(); | ||
break; | ||
} | ||
} | ||
} | ||
function generatePath$4(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 1][0] - points[0][0]; | ||
y = points[length - 1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2, y2); | ||
function generatePath$2(context, parsedStyle) { | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 1][0] - points[0][0]; | ||
y = points[length - 1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2, y2); | ||
} | ||
function generatePath$5(context, parsedStyle) { | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 2][0] - points[length - 1][0]; | ||
y = points[length - 2][1] - points[length - 1][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
function generatePath$1(context, parsedStyle) { | ||
var _a = parsedStyle.defX, defX = _a === void 0 ? 0 : _a, _b = parsedStyle.defY, defY = _b === void 0 ? 0 : _b, markerStart = parsedStyle.markerStart, markerEnd = parsedStyle.markerEnd, markerStartOffset = parsedStyle.markerStartOffset, markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
var length = points.length; | ||
var x1 = points[0][0] - defX; | ||
var y1 = points[0][1] - defY; | ||
var x2 = points[length - 1][0] - defX; | ||
var y2 = points[length - 1][1] - defY; | ||
var startOffsetX = 0; | ||
var startOffsetY = 0; | ||
var endOffsetX = 0; | ||
var endOffsetY = 0; | ||
var rad = 0; | ||
var x; | ||
var y; | ||
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) { | ||
x = points[1][0] - points[0][0]; | ||
y = points[1][1] - points[0][1]; | ||
rad = Math.atan2(y, x); | ||
startOffsetX = Math.cos(rad) * (markerStartOffset || 0); | ||
startOffsetY = Math.sin(rad) * (markerStartOffset || 0); | ||
} | ||
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) { | ||
x = points[length - 2][0] - points[length - 1][0]; | ||
y = points[length - 2][1] - points[length - 1][1]; | ||
rad = Math.atan2(y, x); | ||
endOffsetX = Math.cos(rad) * (markerEndOffset || 0); | ||
endOffsetY = Math.sin(rad) * (markerEndOffset || 0); | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
var point = points[i]; | ||
context.lineTo(point[0] - defX, point[1] - defY); | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
} | ||
function generatePath$6(context, parsedStyle) { | ||
var radius = parsedStyle.radius, | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
var w = width; | ||
var h = height; | ||
var hasRadius = radius && radius.some(function (r) { | ||
return r !== 0; | ||
}); | ||
if (!hasRadius) { | ||
// Canvas support negative width/height of rect | ||
context.rect(0, 0, w, h); | ||
} else { | ||
var signX = width > 0 ? 1 : -1; | ||
var signY = height > 0 ? 1 : -1; | ||
var sweepFlag = signX + signY === 0; | ||
var _radius$map = radius.map(function (r) { | ||
return util.clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
function generatePath(context, parsedStyle) { | ||
var radius = parsedStyle.radius, width = parsedStyle.width, height = parsedStyle.height; | ||
var w = width; | ||
var h = height; | ||
var hasRadius = radius && radius.some(function (r) { return r !== 0; }); | ||
if (!hasRadius) { | ||
// Canvas support negative width/height of rect | ||
context.rect(0, 0, w, h); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
else { | ||
var signX = width > 0 ? 1 : -1; | ||
var signY = height > 0 ? 1 : -1; | ||
var sweepFlag = signX + signY === 0; | ||
var _a = tslib.__read(radius.map(function (r) { | ||
return util.clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), 4), tlr = _a[0], trr = _a[1], brr = _a[2], blr = _a[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, (-signY * Math.PI) / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
} | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
} | ||
} | ||
} | ||
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) { | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var Plugin = /** @class */ (function (_super) { | ||
tslib.__extends(Plugin, _super); | ||
function Plugin() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.name = 'canvas-path-generator'; | ||
return _this; | ||
} | ||
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this; | ||
_this.name = 'canvas-path-generator'; | ||
return _this; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
var _pathGeneratorFactory; | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
_proto.destroy = function destroy() { | ||
// @ts-ignore | ||
delete this.context.pathGeneratorFactory; | ||
}; | ||
return Plugin; | ||
}(gLite.AbstractRendererPlugin); | ||
Plugin.prototype.init = function () { | ||
var _a; | ||
var pathGeneratorFactory = (_a = {}, | ||
_a[gLite.Shape.CIRCLE] = generatePath$6, | ||
_a[gLite.Shape.ELLIPSE] = generatePath$5, | ||
_a[gLite.Shape.RECT] = generatePath, | ||
_a[gLite.Shape.LINE] = generatePath$4, | ||
_a[gLite.Shape.POLYLINE] = generatePath$1, | ||
_a[gLite.Shape.POLYGON] = generatePath$2, | ||
_a[gLite.Shape.PATH] = generatePath$3, | ||
_a[gLite.Shape.TEXT] = undefined, | ||
_a[gLite.Shape.GROUP] = undefined, | ||
_a[gLite.Shape.IMAGE] = undefined, | ||
_a[gLite.Shape.HTML] = undefined, | ||
_a[gLite.Shape.MESH] = undefined, | ||
_a); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
Plugin.prototype.destroy = function () { | ||
// @ts-ignore | ||
delete this.context.pathGeneratorFactory; | ||
}; | ||
return Plugin; | ||
}(gLite.AbstractRendererPlugin)); | ||
exports.Plugin = Plugin; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasPathGenerator={}),t.window.G)}(this,(function(t,e){"use strict";function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function r(t,e){var a=e.r;t.arc(a,a,a,0,2*Math.PI,!1)}function n(t,e){var a=e.rx,r=e.ry;if(t.ellipse)t.ellipse(a,r,a,r,0,0,2*Math.PI,!1);else{var n=a>r?a:r,o=a>r?1:a/r,i=a>r?r/a:1;t.save(),t.scale(o,i),t.arc(0,0,n,0,2*Math.PI)}}function o(t,a){var r=a.x1,n=a.y1,o=a.x2,i=a.y2,s=a.defX,h=void 0===s?0:s,c=a.defY,l=void 0===c?0:c,f=a.markerStart,p=a.markerEnd,d=a.markerStartOffset,v=a.markerEndOffset,M=0,u=0,T=0,m=0,y=0;f&&e.isDisplayObject(f)&&d&&(M=Math.cos(y=Math.atan2(i-n,o-r))*(d||0),u=Math.sin(y)*(d||0)),p&&e.isDisplayObject(p)&&v&&(T=Math.cos(y=Math.atan2(n-i,r-o))*(v||0),m=Math.sin(y)*(v||0)),t.moveTo(r-h+M,n-l+u),t.lineTo(o-h+T,i-l+m)}function i(t,a){var r=a.defX,n=void 0===r?0:r,o=a.defY,i=void 0===o?0:o,s=a.markerStart,h=a.markerEnd,c=a.markerStartOffset,l=a.markerEndOffset,f=a.path,p=f.absolutePath,d=f.segments,v=0,M=0,u=0,T=0,m=0;if(s&&e.isDisplayObject(s)&&c){var y=s.parentNode.getStartTangent(),P=y[0],b=y[1];v=Math.cos(m=Math.atan2(P[1]-b[1],P[0]-b[0]))*(c||0),M=Math.sin(m)*(c||0)}if(h&&e.isDisplayObject(h)&&l){var O=h.parentNode.getEndTangent(),S=O[0],g=O[1];u=Math.cos(m=Math.atan2(S[1]-g[1],S[0]-g[0]))*(l||0),T=Math.sin(m)*(l||0)}for(var k=0;p.length>k;k++){var I=p[k],E=p[k+1],j=0===k&&(0!==v||0!==M),x=(k===p.length-1||E&&("M"===E[0]||"Z"===E[0]))&&0!==u&&0!==T;switch(I[0]){case"M":j?(t.moveTo(I[1]-n+v,I[2]-i+M),t.lineTo(I[1]-n,I[2]-i)):t.moveTo(I[1]-n,I[2]-i);break;case"L":x?t.lineTo(I[1]-n+u,I[2]-i+T):t.lineTo(I[1]-n,I[2]-i);break;case"Q":t.quadraticCurveTo(I[1]-n,I[2]-i,I[3]-n,I[4]-i),x&&t.lineTo(I[3]-n+u,I[4]-i+T);break;case"C":t.bezierCurveTo(I[1]-n,I[2]-i,I[3]-n,I[4]-i,I[5]-n,I[6]-i),x&&t.lineTo(I[5]-n+u,I[6]-i+T);break;case"A":var G=d[k].arcParams,L=G.cx,D=G.cy,A=G.rx,C=G.ry,Y=G.startAngle,_=G.endAngle,w=G.xRotation,N=G.sweepFlag;if(t.ellipse)t.ellipse(L-n,D-i,A,C,w,Y,_,!!(1-N));else{var R=A>C?A:C,X=A>C?1:A/C,F=A>C?C/A:1;t.translate(L-n,D-i),t.rotate(w),t.scale(X,F),t.arc(0,0,R,Y,_,!!(1-N)),t.scale(1/X,1/F),t.rotate(-w),t.translate(-(L-n),-(D-i))}x&&t.lineTo(I[6]-n+u,I[7]-i+T);break;case"Z":t.closePath()}}}function s(t,a){var r=a.defX,n=void 0===r?0:r,o=a.defY,i=void 0===o?0:o,s=a.markerStart,h=a.markerEnd,c=a.markerStartOffset,l=a.markerEndOffset,f=a.points.points,p=f.length,d=f[0][0]-n,v=f[0][1]-i,M=f[p-1][0]-n,u=f[p-1][1]-i,T=0,m=0,y=0,P=0,b=0;s&&e.isDisplayObject(s)&&c&&(T=Math.cos(b=Math.atan2(f[1][1]-f[0][1],f[1][0]-f[0][0]))*(c||0),m=Math.sin(b)*(c||0)),h&&e.isDisplayObject(h)&&l&&(y=Math.cos(b=Math.atan2(f[p-1][1]-f[0][1],f[p-1][0]-f[0][0]))*(l||0),P=Math.sin(b)*(l||0)),t.moveTo(d+(T||y),v+(m||P));for(var O=1;p-1>O;O++){var S=f[O];t.lineTo(S[0]-n,S[1]-i)}t.lineTo(M,u)}function h(t,a){var r=a.defX,n=void 0===r?0:r,o=a.defY,i=void 0===o?0:o,s=a.markerStart,h=a.markerEnd,c=a.markerStartOffset,l=a.markerEndOffset,f=a.points.points,p=f.length,d=f[0][0]-n,v=f[0][1]-i,M=f[p-1][0]-n,u=f[p-1][1]-i,T=0,m=0,y=0,P=0,b=0;s&&e.isDisplayObject(s)&&c&&(T=Math.cos(b=Math.atan2(f[1][1]-f[0][1],f[1][0]-f[0][0]))*(c||0),m=Math.sin(b)*(c||0)),h&&e.isDisplayObject(h)&&l&&(y=Math.cos(b=Math.atan2(f[p-2][1]-f[p-1][1],f[p-2][0]-f[p-1][0]))*(l||0),P=Math.sin(b)*(l||0)),t.moveTo(d+T,v+m);for(var O=1;p-1>O;O++){var S=f[O];t.lineTo(S[0]-n,S[1]-i)}t.lineTo(M+y,u+P)}function c(t,e){var a=e.radius,r=e.width,n=e.height,o=r,i=n;if(a&&a.some((function(t){return 0!==t}))){var s=r>0?1:-1,h=n>0?1:-1,c=s+h===0,l=a.map((function(t){return e=t,a=0,r=Math.min(Math.abs(o)/2,Math.abs(i)/2),a>e?a:e>r?r:e;var e,a,r})),f=l[0],p=l[1],d=l[2],v=l[3];t.moveTo(s*f,0),t.lineTo(o-s*p,0),0!==p&&t.arc(o-s*p,h*p,p,-h*Math.PI/2,s>0?0:Math.PI,c),t.lineTo(o,i-h*d),0!==d&&t.arc(o-s*d,i-h*d,d,s>0?0:Math.PI,h>0?Math.PI/2:1.5*Math.PI,c),t.lineTo(s*v,i),0!==v&&t.arc(s*v,i-h*v,v,h>0?Math.PI/2:-Math.PI/2,s>0?Math.PI:0,c),t.lineTo(0,h*f),0!==f&&t.arc(s*f,h*f,f,s>0?Math.PI:0,h>0?1.5*Math.PI:Math.PI/2,c)}else t.rect(0,0,o,i)}var l=function(t){var l,f;function p(){for(var e,a=arguments.length,r=Array(a),n=0;a>n;n++)r[n]=arguments[n];return(e=t.call.apply(t,[this].concat(r))||this).name="canvas-path-generator",e}(l=p).prototype=Object.create((f=t).prototype),l.prototype.constructor=l,a(l,f);var d=p.prototype;return d.init=function(){var t,a=((t={})[e.Shape.CIRCLE]=r,t[e.Shape.ELLIPSE]=n,t[e.Shape.RECT]=c,t[e.Shape.LINE]=o,t[e.Shape.POLYLINE]=h,t[e.Shape.POLYGON]=s,t[e.Shape.PATH]=i,t[e.Shape.TEXT]=void 0,t[e.Shape.GROUP]=void 0,t[e.Shape.IMAGE]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.pathGeneratorFactory=a},d.destroy=function(){delete this.context.pathGeneratorFactory},p}(e.AbstractRendererPlugin);t.Plugin=l,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasPathGenerator={}),t.window.G)}(this,(function(t,e){"use strict";var a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])},a(t,e)};function r(t,e){var a="function"==typeof Symbol&&t[Symbol.iterator];if(!a)return t;var r,n,o=a.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(t){n={error:t}}finally{try{r&&!r.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}function n(t,e){var a=e.r;t.arc(a,a,a,0,2*Math.PI,!1)}function o(t,e){var a=e.rx,r=e.ry;if(t.ellipse)t.ellipse(a,r,a,r,0,0,2*Math.PI,!1);else{var n=a>r?a:r,o=a>r?1:a/r,i=a>r?r/a:1;t.save(),t.scale(o,i),t.arc(0,0,n,0,2*Math.PI)}}function i(t,a){var r=a.x1,n=a.y1,o=a.x2,i=a.y2,s=a.defX,c=void 0===s?0:s,l=a.defY,h=void 0===l?0:l,f=a.markerStart,p=a.markerEnd,v=a.markerStartOffset,u=a.markerEndOffset,d=0,M=0,y=0,T=0,m=0;f&&e.isDisplayObject(f)&&v&&(d=Math.cos(m=Math.atan2(i-n,o-r))*(v||0),M=Math.sin(m)*(v||0)),p&&e.isDisplayObject(p)&&u&&(y=Math.cos(m=Math.atan2(n-i,r-o))*(u||0),T=Math.sin(m)*(u||0)),t.moveTo(r-c+d,n-h+M),t.lineTo(o-c+y,i-h+T)}function s(t,a){var n=a.defX,o=void 0===n?0:n,i=a.defY,s=void 0===i?0:i,c=a.markerStart,l=a.markerEnd,h=a.markerStartOffset,f=a.markerEndOffset,p=a.path,v=p.absolutePath,u=p.segments,d=0,M=0,y=0,T=0,m=0;if(c&&e.isDisplayObject(c)&&h){var P=r(c.parentNode.getStartTangent(),2);d=Math.cos(m=Math.atan2((b=P[0])[1]-(O=P[1])[1],b[0]-O[0]))*(h||0),M=Math.sin(m)*(h||0)}if(l&&e.isDisplayObject(l)&&f){var b,O,S=r(l.parentNode.getEndTangent(),2);y=Math.cos(m=Math.atan2((b=S[0])[1]-(O=S[1])[1],b[0]-O[0]))*(f||0),T=Math.sin(m)*(f||0)}for(var k=0;v.length>k;k++){var g=v[k],E=v[k+1],I=0===k&&(0!==d||0!==M),x=(k===v.length-1||E&&("M"===E[0]||"Z"===E[0]))&&0!==y&&0!==T;switch(g[0]){case"M":I?(t.moveTo(g[1]-o+d,g[2]-s+M),t.lineTo(g[1]-o,g[2]-s)):t.moveTo(g[1]-o,g[2]-s);break;case"L":x?t.lineTo(g[1]-o+y,g[2]-s+T):t.lineTo(g[1]-o,g[2]-s);break;case"Q":t.quadraticCurveTo(g[1]-o,g[2]-s,g[3]-o,g[4]-s),x&&t.lineTo(g[3]-o+y,g[4]-s+T);break;case"C":t.bezierCurveTo(g[1]-o,g[2]-s,g[3]-o,g[4]-s,g[5]-o,g[6]-s),x&&t.lineTo(g[5]-o+y,g[6]-s+T);break;case"A":var j=u[k].arcParams,w=j.cx,G=j.cy,L=j.rx,C=j.ry,D=j.startAngle,_=j.endAngle,A=j.xRotation,Y=j.sweepFlag;if(t.ellipse)t.ellipse(w-o,G-s,L,C,A,D,_,!!(1-Y));else{var N=L>C?L:C,R=L>C?1:L/C,X=L>C?C/L:1;t.translate(w-o,G-s),t.rotate(A),t.scale(R,X),t.arc(0,0,N,D,_,!!(1-Y)),t.scale(1/R,1/X),t.rotate(-A),t.translate(-(w-o),-(G-s))}x&&t.lineTo(g[6]-o+y,g[7]-s+T);break;case"Z":t.closePath()}}}function c(t,a){var r=a.defX,n=void 0===r?0:r,o=a.defY,i=void 0===o?0:o,s=a.markerStart,c=a.markerEnd,l=a.markerStartOffset,h=a.markerEndOffset,f=a.points.points,p=f.length,v=f[0][0]-n,u=f[0][1]-i,d=f[p-1][0]-n,M=f[p-1][1]-i,y=0,T=0,m=0,P=0,b=0;s&&e.isDisplayObject(s)&&l&&(y=Math.cos(b=Math.atan2(f[1][1]-f[0][1],f[1][0]-f[0][0]))*(l||0),T=Math.sin(b)*(l||0)),c&&e.isDisplayObject(c)&&h&&(m=Math.cos(b=Math.atan2(f[p-1][1]-f[0][1],f[p-1][0]-f[0][0]))*(h||0),P=Math.sin(b)*(h||0)),t.moveTo(v+(y||m),u+(T||P));for(var O=1;p-1>O;O++){var S=f[O];t.lineTo(S[0]-n,S[1]-i)}t.lineTo(d,M)}function l(t,a){var r=a.defX,n=void 0===r?0:r,o=a.defY,i=void 0===o?0:o,s=a.markerStart,c=a.markerEnd,l=a.markerStartOffset,h=a.markerEndOffset,f=a.points.points,p=f.length,v=f[0][0]-n,u=f[0][1]-i,d=f[p-1][0]-n,M=f[p-1][1]-i,y=0,T=0,m=0,P=0,b=0;s&&e.isDisplayObject(s)&&l&&(y=Math.cos(b=Math.atan2(f[1][1]-f[0][1],f[1][0]-f[0][0]))*(l||0),T=Math.sin(b)*(l||0)),c&&e.isDisplayObject(c)&&h&&(m=Math.cos(b=Math.atan2(f[p-2][1]-f[p-1][1],f[p-2][0]-f[p-1][0]))*(h||0),P=Math.sin(b)*(h||0)),t.moveTo(v+y,u+T);for(var O=1;p-1>O;O++){var S=f[O];t.lineTo(S[0]-n,S[1]-i)}t.lineTo(d+m,M+P)}var h=function(t,e,a){return e>t?e:t>a?a:t};function f(t,e){var a=e.radius,n=e.width,o=e.height,i=n,s=o;if(a&&a.some((function(t){return 0!==t}))){var c=n>0?1:-1,l=o>0?1:-1,f=c+l===0,p=r(a.map((function(t){return h(t,0,Math.min(Math.abs(i)/2,Math.abs(s)/2))})),4),v=p[0],u=p[1],d=p[2],M=p[3];t.moveTo(c*v,0),t.lineTo(i-c*u,0),0!==u&&t.arc(i-c*u,l*u,u,-l*Math.PI/2,c>0?0:Math.PI,f),t.lineTo(i,s-l*d),0!==d&&t.arc(i-c*d,s-l*d,d,c>0?0:Math.PI,l>0?Math.PI/2:1.5*Math.PI,f),t.lineTo(c*M,s),0!==M&&t.arc(c*M,s-l*M,M,l>0?Math.PI/2:-Math.PI/2,c>0?Math.PI:0,f),t.lineTo(0,l*v),0!==v&&t.arc(c*v,l*v,v,c>0?Math.PI:0,l>0?1.5*Math.PI:Math.PI/2,f)}else t.rect(0,0,i,s)}var p=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="canvas-path-generator",e}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+e+" is not a constructor or null");function r(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(r,t),r.prototype.init=function(){var t,a=((t={})[e.Shape.CIRCLE]=n,t[e.Shape.ELLIPSE]=o,t[e.Shape.RECT]=f,t[e.Shape.LINE]=i,t[e.Shape.POLYLINE]=l,t[e.Shape.POLYGON]=c,t[e.Shape.PATH]=s,t[e.Shape.TEXT]=void 0,t[e.Shape.GROUP]=void 0,t[e.Shape.IMAGE]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.pathGeneratorFactory=a},r.prototype.destroy=function(){delete this.context.pathGeneratorFactory},r}(e.AbstractRendererPlugin);t.Plugin=p})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -6,2 +6,1 @@ import type { ParsedBaseStyleProps } from '@antv/g-lite'; | ||
export type PathGenerator<T extends ParsedBaseStyleProps> = (context: CanvasRenderingContext2D, attributes: T) => void; | ||
//# sourceMappingURL=interfaces.d.ts.map |
import type { ParsedCircleStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedCircleStyleProps): void; | ||
//# sourceMappingURL=Circle.d.ts.map |
import type { ParsedEllipseStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedEllipseStyleProps): void; | ||
//# sourceMappingURL=Ellipse.d.ts.map |
@@ -8,2 +8,1 @@ export { generatePath as CirclePath } from './Circle'; | ||
export { generatePath as RectPath } from './Rect'; | ||
//# sourceMappingURL=index.d.ts.map |
import type { ParsedLineStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedLineStyleProps): void; | ||
//# sourceMappingURL=Line.d.ts.map |
import type { ParsedPathStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedPathStyleProps): void; | ||
//# sourceMappingURL=Path.d.ts.map |
import type { ParsedPolygonStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedPolygonStyleProps): void; | ||
//# sourceMappingURL=Polygon.d.ts.map |
import type { ParsedPolylineStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedPolylineStyleProps): void; | ||
//# sourceMappingURL=Polyline.d.ts.map |
import type { ParsedRectStyleProps } from '@antv/g-lite'; | ||
export declare function generatePath(context: CanvasRenderingContext2D, parsedStyle: ParsedRectStyleProps): void; | ||
//# sourceMappingURL=Rect.d.ts.map |
{ | ||
"name": "@antv/g-plugin-canvas-path-generator", | ||
"version": "1.1.51", | ||
"version": "1.2.0-alpha.1", | ||
"description": "A G plugin of path generator with Canvas2D API", | ||
@@ -19,2 +19,7 @@ "keywords": [ | ||
"author": "https://github.com/orgs/antvis/people", | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.esm.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"main": "dist/index.js", | ||
@@ -31,19 +36,16 @@ "unpkg": "dist/index.umd.min.js", | ||
"scripts": { | ||
"sync": "tnpm sync" | ||
"build": "npm run clean && rollup -c", | ||
"clean": "rimraf dist", | ||
"sync": "tnpm sync", | ||
"watch": "rollup -c -w" | ||
}, | ||
"dependencies": { | ||
"@antv/g-math": "^1.7.49", | ||
"@antv/g-lite": "workspace:*", | ||
"@antv/g-math": "workspace:*", | ||
"@antv/util": "^3.3.1", | ||
"tslib": "^2.3.1" | ||
"tslib": "^2.5.3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^25.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@antv/g-lite": "^1.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "53932c66ed9f2cbc28993e1e359c8df27703fc52" | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
98031
0
19
637
2
+ Added@antv/g-lite@workspace:*
- Removed@antv/g-lite@1.2.24(transitive)
- Removed@antv/g-math@1.8.12.0.2(transitive)
- Removedd3-color@1.4.1(transitive)
- Removedeventemitter3@5.0.1(transitive)
- Removedquickselect@2.0.0(transitive)
- Removedrbush@3.0.1(transitive)
Updated@antv/g-math@workspace:*
Updatedtslib@^2.5.3