Graphics Reference
In-Depth Information
Classes for Selecting Observations
In order to select observations on graphics, we need to select objects that represent
observations such as points in a scatterplot, rectangular bins in a histogram or line
segments in a parallel coordinate plot.
Adraggableselectorisonetoolforselectingsuchobjects.Wefirstspecifyaselector
such as a rectangular box, then select objects inside the selector. We may wish to
move the selector by mouse dragging and to change selected objects dynamically.
Such a selector is realized by the RectangleSelector class in Jasplot. It may be
preferable to specify the shape of selector region freely by a mouse cursor, but this is
not yet realized in Jasplot.
We wish to select one bin of a histogram by pointing at it with the mouse cursor
andclickingamousebutton.hisisrealizedbythe PointSelector class. his
class can also select objects that are located inside a rectangular area specified by
pressinga mousebutton, dragging the mousecursorandreleasing the mousebutton.
he rectangle area disappears ater we release the mouse button.
To select line segments, for example in a parallel coordinate plot, we can use the
LineSelector class, which is a vertical line segment that selects line segments
representing observations that intersect the selector.
Wesometimeswishtoreplacetheseselectorsaccordingtothepurposeofouranal-
ysis. Such replacement is easily realized by following the “Strategy” design pattern.
heStrategypatterndefinesafamilyofalgorithms,encapsulateseachone,and
makes them interchangeable. Strategy lets the algorithm vary independently
from the clients that use it (Gamma et al., ).
he strategy pattern consists of decoupling an algorithm from its host, and encap-
sulating the algorithm into a separate class. When we have several objects that are
basically the same, anddifferonly in their behavior,the strategy pattern is useful.We
can reduce these several objects to one class that uses several strategies.
We first implement a strategy interface for strategy objects. We then implement
concrete strategy classes that implement the strategy interface. In the context class,
we maintain a private reference to a strategy object. hen context class implements
public “setter” and “getter” methods for the strategy object. Wecan see that the strat-
egy pattern satisfies the open-closed principle. he context class can be extended by
adding new strategy objects without changing any code inside the context class.
hestrategyandstatepatterns canbeconfused.hestrategypatternisbetterifthe
context will contain only one of several possible state/strategy objects. On the other
hand,thestatepatternisbetterifthecontextmaycontainmanydifferentstate/strategy
objects. An object is usually put into a state by an external client, while it will choose
a strategy on its own.
In Jasplot, we use the Selector interface to define common methods for all
selectors such as create , getRegion ,and mouseReleased . Rectangle-
Selector , PointSelector and LineSelector implement Selector .Fig-
ure . shows a class diagram for these classes.
For example, HistogramPlotModel uses PointSelector as default. his
isrealized bya setSelector(new PointSelector) methodcall inthe con-
Search WWH ::




Custom Search