Reply to this topic  Start new topic
> PieGraph
CSM
post Mar 24 2009, 08:32 AM
Post #1






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



This was written just for the hell of it. Enjoy.

IPB Image

Download PieGraph.js (right-click, save [link] as).

Sample usage:
CODE
var window = new Window();
var items = {"Widgets": 5, "More Widgets": 35, "Also Widgets": 20, "Bucket 'o Widgets": 10, "Desktop Widgets": 30}
var graph = new PieGraph(window, "3d", items, {});
graph.width = 100;
graph.height = 100;
graph.hOffset = 0;
graph.vOffset = 0;

// Extract and show the legend
var legend = graph.getLegend();
legend.hOffset = graph.width + 7;
legend.parent = window;

graph.suppressUpdates = true;
items["Widgets"] = 7;
items["More Widgets"] = 33;
graph.suppressUpdates = false;
graph.paintGraph();

For those that don't want the 3d perspective view, there's a "2d" mode as well, which draws the PieGraph as a flat circle. If you don't want a key, don't give the legend a parent frame/window.

Now includes properties for "borderColor", "style", and "labelType". The border color is for the lines between the slices and border around the legend squares. The style property should be a real Style object, so just create a dummy Text object set its properties and pass it in. The "labelType" property can be one of PieGraph.NONE, PieGraph.PERCENT, and PieGraph.VALUE. They show just the text, text + percentage of whole, and text + given value, respectively.

There are two convenience methods, setColor(key, colorValue) and setSlice(key, value). These update the stored values for each and repaints the graph.

If you don't like the colors generated by the PieGraph, you can optionally provide your own via the constructor:
CODE
var items = {"Widgets": 5, "More Widgets": 35, "Also Widgets": 20, "Bucket 'o Widgets": 10, "Desktop Widgets": 30}
var graph = new PieGraph(new Window(), "3d", items, {"Widgets": "blue"});

You are not required to specify a color for each slice, slices without an associated color will have one generated.




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
g6auc
post Mar 24 2009, 12:55 PM
Post #2






Posts: 4,244
Joined: 1-March 04
From: West Yorkshire, UK
Member No.: 2,322



QUOTE(CSM @ Mar 24 2009, 08:32 AM) *
This was written just for the hell of it. Enjoy.
Very nice!

There's some pre-Canvas and other work here, if you need something to do. laugh.gif






User is offlineProfile CardPM
Go to the top of the page
+Quote Post
VFRDaddy
post Mar 24 2009, 02:02 PM
Post #3






Posts: 226
Joined: 30-August 07
From: STL
Member No.: 25,156



This is really good and extremely useful.

I wrote something similar in Flash with some animations and other choices that I thought I would throw out there for possible inclusion
- The ability to choose the colors for each option/pie piece
- A MouseOver Animation that lifts the pie piece up in the chart when hovered (also displays a tooltip for when the legend is not visible)
- Ability to change the label types i.e. Total Votes vs. Percentages
- Ability to change Text Color and Styling
- Ability to change the piece borders
- Toggle a shadow on the 3d Chart ~ right now a shadow effects both the text and chart

Hope this helps.





Widget Realm, Inc
Way Beyond the Website
The leader in custom widget development.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image FaceBook(er) IPB Image FedEx Tracker IPB Image UPS Tracker IPB Image De Smet Jesuit HS IPB Image Filmcritic.com
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image File Uploader IPB Image Screen Ruler IPB Image Missouri Golf Assoc. IPB Image Server Monitor IPB Image The Cappies Inc.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 24 2009, 02:42 PM
Post #4






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



QUOTE( @ Mar 24 2009, 09:02 AM) *
- The ability to choose the colors for each option/pie piece
Not in there for now, until I can add it in nicely.

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
- A MouseOver Animation that lifts the pie piece up in the chart when hovered (also displays a tooltip for when the legend is not visible)
That's hard. It's all one Canvas, so I'd have to determine where you are on the Canvas, and since I do a scale ...

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
- Ability to change the label types i.e. Total Votes vs. Percentages
1/2 done. You can disable the percentages in the legend now. Since the values given to the PieGraph have to be out of 100 already, I don't think your "totalVotes" is possible, unless you mean just display without the % sign.

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
- Ability to change Text Color and Styling
Done. Just set the "style" property to a style prepared on a dummy Text object.

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
- Ability to change the piece borders
Done. Just set "borderColor" property.

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
- Toggle a shadow on the 3d Chart ~ right now a shadow effects both the text and chart
That's because a Window puts the shadow on the whole internal Frame's contents. I can't control Y!WE's shadow any more than you can (and I have terrible luck at making my own "realistic" ones).

QUOTE(VFRDaddy @ Mar 24 2009, 09:02 AM) *
Hope this helps.
Definitely.

I also fixed a bug Harry notified me about, I used the variable "i" in a sub-loop of a loop using "i" already. It didn't cause issues because the outer loop was a for-each loop, which is unaffected by changes to its "counter" variable.

I also had to host the script on my website now because the forum was bitching about mismatched bbcode tags (probably the [i] I use everywhere).

QUOTE(g6auc @ Mar 24 2009, 07:55 AM) *
There's some pre-Canvas and other work here, if you need something to do. laugh.gif
Well, I don't know ... he could have done it with Canvas. How much time do you think I have? tongue.gif Most of those don't look hard, but there's probably more than meets the eye.




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 24 2009, 03:01 PM
Post #5






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



I updated PieGraph again ... it now calculates the percentages based on the total, not an assumed 100. As a result, I removed showPercentages and changed it to labelType. "labelType" can be one of NONE, PERCENT, VALUE. These are obtained from either PieGraph (PieGraph.NONE) or off of an instance of PieGraph. Default is NONE.




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 24 2009, 04:02 PM
Post #6






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



Updated for hopefully the last time. Now the last parameter of the constructor takes a map that maps the slice names to their color. If a color is not given for a slice, it is generated (like before). Beware, no checking is done to ensure that the hues of the generated values are far enough away from any user-defined colors.

I also added two convenience functions: setSlice and setColor. Both take the slice name and a value. I added them in case you pass the values directly to the constructor (like the example) and don't want to keep more than one reference around (the graph).




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
VFRDaddy
post Mar 24 2009, 07:50 PM
Post #7






Posts: 226
Joined: 30-August 07
From: STL
Member No.: 25,156



My comment on the shadow for the pie chart shadow was more looking at splitting the pie chart and the legend into two separate canvases.

That way the legend could be easily toggled, the shadow would be specific to the pie chart, the legend could be scaled independently, and the legend could be placed at different points in the window.

Really like the new changes.

To do the animated pie pieces, each piece would need to be split into separate canvas pieces, then it would be possible to detect the MouseOver/Out and place the tooltip ~ smile.gif

Like I said, had to do this already in Flash so I tackled most of the issues... I know it sucks. dry.gif




Widget Realm, Inc
Way Beyond the Website
The leader in custom widget development.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image FaceBook(er) IPB Image FedEx Tracker IPB Image UPS Tracker IPB Image De Smet Jesuit HS IPB Image Filmcritic.com
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image File Uploader IPB Image Screen Ruler IPB Image Missouri Golf Assoc. IPB Image Server Monitor IPB Image The Cappies Inc.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 24 2009, 08:43 PM
Post #8






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



QUOTE(VFRDaddy @ Mar 24 2009, 02:50 PM) *
My comment on the shadow for the pie chart shadow was more looking at splitting the pie chart and the legend into two separate canvases.

That way the legend could be easily toggled, the shadow would be specific to the pie chart, the legend could be scaled independently, and the legend could be placed at different points in the window.
Done. See first post.

QUOTE(VFRDaddy @ Mar 24 2009, 02:50 PM) *
Really like the new changes.
Thanks

QUOTE(VFRDaddy @ Mar 24 2009, 02:50 PM) *
To do the animated pie pieces, each piece would need to be split into separate canvas pieces, then it would be possible to detect the MouseOver/Out and place the tooltip ~ smile.gif
*shudder* 1 Canvas per piece. ew.

QUOTE(VFRDaddy @ Mar 24 2009, 02:50 PM) *
Like I said, had to do this already in Flash so I tackled most of the issues... I know it sucks. dry.gif
Canvas > Flash smile.gif




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
VFRDaddy
post Mar 24 2009, 09:30 PM
Post #9






Posts: 226
Joined: 30-August 07
From: STL
Member No.: 25,156



Awesome!




Widget Realm, Inc
Way Beyond the Website
The leader in custom widget development.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image FaceBook(er) IPB Image FedEx Tracker IPB Image UPS Tracker IPB Image De Smet Jesuit HS IPB Image Filmcritic.com
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPB Image File Uploader IPB Image Screen Ruler IPB Image Missouri Golf Assoc. IPB Image Server Monitor IPB Image The Cappies Inc.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Indiana
post Mar 25 2009, 12:36 PM
Post #10






Posts: 679
Joined: 16-November 05
From: Munich, Germany
Member No.: 11,213



Thanks, I currently work on a PieChart in Objective-C .. that helps much.




User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 25 2009, 07:15 PM
Post #11






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



Some hints for you then (or explanations, depending on how you see it) from when I was making this ...

The 2d pie-graph was easy, I use Canvas to keep track of rotation, so I draw each slice as if it was at the start location, but because I rotated the context, it actually draws at the location I want.

The 3d pie-graph actually draws two pies, but one is quite interesting looking. The top one is the same as the 2d pie-graph, but the bottom one (which is drawn first) has to draw the vertical lines for the sections. As a result, it needs be able to draw an absolutely vertical line. If I had used the context-rotation approach, this would be near impossible (I tried loads of combinations, none worked right). However, if you keep track of the rotation yourself (the current arc is from totalArcSoFar to totalArcSoFar + myArcLength) you don't need to rotate the context, and going from (x,y) to (x,y-a) really is "up" on the screen, and not "up" relative to the rotation.

Also, because my PieGraph in 3d is really an illusion (it's not a true 3d object), it has a minimum value for which the illusion stops working (when you can tell I cheated). Fortunately for me, you have to have a graph size of about 50px before it starts to be really noticeable. Decreasing my internal "pieHeight" variable will make the graph look better at those tiny sizes.

Some improvements that could be made to your pie-graph (or mine) is to have a random/set rotational offset for the slices, as depending on your data, it might look better without the first slice starting a 0.




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Indiana
post Mar 26 2009, 12:49 PM
Post #12






Posts: 679
Joined: 16-November 05
From: Munich, Germany
Member No.: 11,213



The hint came to late, I already (I direct draw the arc without rotation) had all except the 3d-effect.
And that was easy to find in your code which looks like I had it in mind (some play with lines and calculate the point with sin + cos).
Only the line (you draw a box) on the left side at 180° was new for me.
But If you make the chart bigger you see that there is something wrong on that point :-(
Also I don't have a border, so I have to determine the color on the left side :-(

CODE
CGContextScaleCTM(ctx, 1, 0.3);

float x = rect.size.width / 2;
float y = rect.size.height / 2;
float chartHeight = 0.0; // planned for 3D
float radius = rect.size.width / 2 - chartHeight - 1;

float lastStart = radians( 270 ); // Start at 12 o'clock
float currentEnd = 0;
for(int i = 0; i < [self.data count]; i++) {
    currentEnd = radians([[self.data objectAtIndex:i] floatValue] * 360 / 100 ); // Data contain 100% values, convet to 360°

    // Here was some code to get the color ... just a big switch structure.

    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, x, y); // Got to the center
    CGContextAddArc(ctx, x, y, radius, lastStart, lastStart - currentEnd, 1); // The line to the arc is generated automaticly
    CGContextClosePath(ctx); // The line back to the start(center) us generated automaticly
    CGContextFillPath(ctx); // I use no border!
    
    lastStart -= currentEnd;
}


IPB Image




User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 26 2009, 05:18 PM
Post #13






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



Whoa. That looks very nice.


To figure out the left most item, just remember the index/name of the slice that causes your total arc so far to be greater than 180 (plus the starting arc location). Then after you're done painting the lower pie, just gob some extra paint at the left. Since my line worked well enough for me, I didn't bother doing/thinking of this when I wrote mine.




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Indiana
post Mar 27 2009, 04:27 PM
Post #14






Posts: 679
Joined: 16-November 05
From: Munich, Germany
Member No.: 11,213



Thx.

I got enlightenment ... blink.gif

On the left, it was easy: Just a line at (x - radius) and a filled box (to be save i draw it with radius as width)

But on the right it looks really ugly if you scale it grater than 200 pixel .. but it was easy, what else ohmy.gif
If arc end is < 0° only draw it until 0° and stop drawing and other arc's :-P

IPB Image

And now with the second pie chart on top ... tadaaa

IPB Image




User is offlineProfile CardPM
Go to the top of the page
+Quote Post
CSM
post Mar 28 2009, 09:06 AM
Post #15






Posts: 2,376
Joined: 1-September 06
From: Ohio
Member No.: 16,587



Nice job.

I find it interesting how even though the Canvas context is 2d, what I ended up drawing for the under-layer of the pie-graph was a pretty convincing 3d anyway (imo).


// Edit:
I noticed before you used a different scale (my .5 versus your .3). Any particular reason or just that it looked better for your graphs (it does)? For mine, (I just tried it) it's a toss-up as to which works best. I could have made it a property, but if you know enough to think about it, you stand to do a little code hacking smile.gif




A result of starting my server over, links from my posts may not work (especially those in the "temp" subdomain). If there is a link to something of which anyone would like to have a copy, personal message me with what you're looking for along with a way to provide this to you, and I'll see if I can find a copy. Thanks for your patience and understanding.


IPB Image - "Not just another open source project. Lend your talent and make a difference!" (Dead)

IPB Image - "The future is now." (No longer community site)

Published: AtomicComicBlast, Barra de Lenguas, ComicWizard-4.0, MicroColors, PassGen, ScrabbleChecker, SoundBank, Uni, VisualWidget, WarpedReality
Unavailable: Paradigm [clock], Puzzled, SecurityLogger, Wayback Widget
Ready to be published: Cαlcυlατοr, CursorTails, Blackout, Block Puzzler, BombSquad, Palette, SnipIt
ActiveDev:
InactiveDev/Dead: BeatMod, Bubble Pop, Canvas Clock, Canvas Gauges, Canvas Pro, Clipboard, Crayon, Hermes, InTune, Konverter, Magic Deck, OverRuled, Outside, Slither, SystemBeat, Tetresque, Tetrad, Widget, WinSysRemote
Dropped: BlankScreen, Document "Fixer", Intuitive [ -> Blackout], Motion Widget: HHGTTG
CoDevelopment: Atmosphere, Block Puzzler,
BombSquad
Miniature Scripts: BinarySearchTree, Calendar, Canvas Gears, Checkbox, File-Browser, LinkedList/Stack, MDI Setup, MiniMax AI, PieGraph, ProgressBar, Slider widget, TabbedPane, Table, Tokenizer, TreeMenu
Java+: Java Music Daemon, ScreenCapture JAR, Widget-Java/Server Bridge Example
"Published" Texts: DynamicWidgetGuide
Konfabulator Libraries: Color-space Library, Javable Widget Project
Widget Tutorials: "Spawning" Widgets, JavaScript Classes
Contests: Widget 4k - "Expanded" [not happening; canceled]
Non-Widget Work: Hazlenut, Konspirators Online, PHP BB-Code Parser, ShortClient, Zap
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Indiana
post Mar 28 2009, 03:34 PM
Post #16






Posts: 679
Joined: 16-November 05
From: Munich, Germany
Member No.: 11,213



I use .3 to save space because I only have 320x460 Pixel on my iPhone :-P




User is offlineProfile CardPM
Go to the top of the page
+Quote Post
  Reply to this topic    Start new topic  
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: