-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanford Rosenthal
authored and
Stanford Rosenthal
committed
Oct 26, 2015
1 parent
1e472bd
commit 624c2d7
Showing
3 changed files
with
119 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Enter a percentage 1-25 | ||
// var percent = 20; | ||
|
||
var alert = [NSAlert alertWithMessageText: "Insert Pie Chart" | ||
defaultButton:"Insert" | ||
alternateButton:"Cancel" | ||
otherButton:nil | ||
informativeTextWithFormat:"What percent? (1-25 for now)"]; | ||
|
||
var input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)]; | ||
[input setStringValue:"25"]; | ||
[input autorelease]; | ||
[alert setAccessoryView:input]; | ||
var button = [alert runModal]; | ||
[input validateEditing]; | ||
var percent = [input stringValue]; | ||
|
||
var offset = (100 - percent * 4) * 2; | ||
var doc = context.document; | ||
var unit = 100; | ||
|
||
// create the pie | ||
var color = "#0000FF"; | ||
var ovalShape = MSOvalShape.alloc().init(); | ||
ovalShape.frame = MSRect.rectWithRect(NSMakeRect(0,0,unit*2,unit*2)); | ||
var pie=MSShapeGroup.shapeWithPath(ovalShape); | ||
var fill = pie.style().fills().addNewStylePart(); | ||
fill.color = MSColor.colorWithSVGString(color); | ||
pie.frame().constrainProportions = true; | ||
doc.currentPage().addLayers([pie]); | ||
|
||
// create the mask | ||
var color = "#FF0000"; | ||
var ovalShape = MSOvalShape.alloc().init(); | ||
ovalShape.frame = MSRect.rectWithRect(NSMakeRect(0,0,unit*2,unit*2)); | ||
var mask=MSShapeGroup.shapeWithPath(ovalShape); | ||
var fill = mask.style().fills().addNewStylePart(); | ||
fill.color = MSColor.colorWithSVGString(color); | ||
mask.frame().constrainProportions = true; | ||
|
||
// create the slice | ||
var path = NSBezierPath.bezierPath(); | ||
path.moveToPoint(NSMakePoint(unit,unit)); | ||
path.lineToPoint(NSMakePoint(unit,-unit)); | ||
path.lineToPoint(NSMakePoint(-unit + offset,unit - offset)); | ||
// path.lineToPoint(NSMakePoint(-unit,unit)); | ||
path.lineToPoint(NSMakePoint(unit,unit)); | ||
path.frame = MSRect.rectWithRect(NSMakeRect(0,0,unit*2,unit*2)); | ||
|
||
var slice = MSShapeGroup.shapeWithBezierPath(path); | ||
|
||
doc.currentPage().addLayers([mask, slice]); | ||
|
||
// make the cut | ||
[mask select:true byExpandingSelection:false] | ||
[slice select:true byExpandingSelection:true] | ||
var intersectAction = doc.actionsController().actionWithName("MSIntersectAction"); | ||
if (intersectAction.validate()) { | ||
intersectAction.booleanIntersect(nil); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters