The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Taking Stock In Cairo

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Taking Stock In Cairo Posted: Jul 6, 2007 5:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Taking Stock In Cairo
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

Arden Thomas was talking to me about some stock visualization stuff he was playing with the other day using Cairo. I thought it would be fun to sit down and make one of his charts look really snazzy.

Over the years, I've written a number of charting views for different domains. I've come to the basic conclusion that the best you can hope for is a gray box set of things that can be used as examples or plugged in at a low level. But when it comes to a reusable "graph" widget, I've come to the conclusion that you're better to just go the custom view route (possibly reusing a couple of low level scaling things).

One of the fun things about using Cairo to do the graphics, is that the alpha channel allows us (to attempt) to integrate the different elements of a chart in a way we probably wouldn't as easily with the traditional graphics engine. We can integrate controls right into the view itself. As well as use background tricks to show axis information.

Here's another audioless wink showing me playing with the chart for a minute. It took a little more than half a day to code it from scratch and tweak it to pleasing.

There are two particular cool tricks in the above if you look close. One is the "electric" glow of the red line. This is accomplished with a loop that looks like:

	31 to: 1
		by: -3
		do: 
			[:width | 
			cr
				source: (ColorBlend red alpha: width reciprocal);
				strokeWidth: width;
				strokePreserve].
	cr newPath
Basically we define the path once, and then we repeatedly stroke it with a smaller and smaller width, but a rapidly increasing alpha value.

The other is the selection rectangle. It uses the "electric line" around it too. But the neat thing about it is how it grays out everything outside of the rectangle. We do this by defining a path composed of two rectangles. The first is the outside rectangle with rounded corners. The second rectangle is the selection rectangle, but its winding direction is backwards from the first. What is meant here is that one of the dimensions of the rectangle (not both) is negative. So the rectangle is defined with its origin at its topRight, and its corner at the bottomLeft. Then it's just a clip, set the source to a color with medium alpha and tell it to paint.

This one is in Arden's sandbox so you'll have to bug him if you want the code in the wild.

Read: Taking Stock In Cairo

Topic: Small, but useful Previous Topic   Next Topic Topic: Channeling Smalltalkers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use