Skip to content

Commit a7b3bb2

Browse files
committed
Add function to help validate number of defining shape vertices
1 parent c8be45f commit a7b3bb2

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/components/shapes/helpers.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
5353
return extractedCoordinates;
5454
};
5555

56+
exports.countDefiningCoords = function(path, isNotPath) {
57+
// non-path shapes always have 2 defining coordinates
58+
if(isNotPath) return 2;
59+
if(!path) return 0;
60+
61+
var segments = path.match(constants.segmentRE);
62+
if(!segments) return 0;
63+
64+
var coordCount = 0;
65+
segments.forEach(function(segment) {
66+
// for each path command, check if there is a drawn coordinate
67+
var segmentType = segment.charAt(0);
68+
var hasDrawnX = constants.paramIsX[segmentType].drawn !== undefined;
69+
var hasDrawnY = constants.paramIsY[segmentType].drawn !== undefined;
70+
if(hasDrawnX || hasDrawnY) coordCount++;
71+
});
72+
return coordCount;
73+
};
74+
5675
exports.getDataToPixel = function(gd, axis, shift, isVertical, refType) {
5776
var gs = gd._fullLayout._size;
5877
var dataToPixel;

0 commit comments

Comments
 (0)