/
Decision.sketchplugin
51 lines (41 loc) · 1.79 KB
/
Decision.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Sketch Plugin: AEFlowchart - Decision (ctrl shift d)
// Source: github.com/tadija/AEFlowchart
// Version: 1.0
@import 'AEFlowchart.js'
var stepName = "Decision";
/* call AEFlowchart main function with custom name and shape function */
createStep(stepName, decisionShape);
/* draw decision diamond shape for given label */
function decisionShape(label)
{
// get label size
var labelFrame = [label frame];
var labelWidth = [labelFrame width];
var labelHeight = [labelFrame height];
// set shape padding
var minPadding = 32.0;
var maxPadding = 64.0;
// horizontal
var shapeHorizontalPadding = labelWidth * 0.3;
if(shapeHorizontalPadding < minPadding) shapeHorizontalPadding = minPadding;
if(shapeHorizontalPadding > maxPadding) shapeHorizontalPadding = maxPadding;
// vertical
var shapeVerticalPadding = labelHeight * 1.3;
if(shapeVerticalPadding < minPadding) shapeVerticalPadding = minPadding;
if(shapeVerticalPadding > maxPadding) shapeVerticalPadding = maxPadding;
// create shape path
var shapePath = [NSBezierPath bezierPath];
[shapePath moveToPoint:CGPointMake([labelFrame midX], [labelFrame minY] - shapeVerticalPadding)];
[shapePath lineToPoint:CGPointMake([labelFrame maxX] + shapeHorizontalPadding, [labelFrame midY])];
[shapePath lineToPoint:CGPointMake([labelFrame midX], [labelFrame maxY] + shapeVerticalPadding)];
[shapePath lineToPoint:CGPointMake([labelFrame minX] - shapeHorizontalPadding, [labelFrame midY])];
[shapePath closePath];
// create shape
var shape = [MSShapeGroup shapeWithBezierPath: shapePath];
styleType = "layerStyles";
if(doesStyleExist(stepName, shape, styleType) == false) {
// log(stepName + " style doesn't exist so create it");
createLayerStyle(stepName, shape, decisionColor, decisionInnerShadows)
}
return shape;
}