--- a/GraphColumnView.st Mon Feb 09 10:49:55 1998 +0100
+++ b/GraphColumnView.st Mon Feb 09 11:31:27 1998 +0100
@@ -1,12 +1,34 @@
View subclass:#GraphColumnView
- instanceVariableNames:'listHolder zoomYHolder columns oldMenuMessage windowSizeHolder
- windowSize gridColor showGrid fgColor bgColor vLinesColor zoomY'
+ instanceVariableNames:'columns vLines listHolder vLinesHolder zoomYHolder oldMenuMessage
+ windowSizeHolder windowSize gridColor showGrid fgColor bgColor
+ vLinesColor zoomY scrollUpdatesOriginX graphOriginX
+ graphOriginXHolder'
classVariableNames:'DefaultBackgroundColor DefaultGridColor DefaultForegroundColor
DefaultVLinesColor'
poolDictionaries:''
category:'Views-Graphs'
!
+!GraphColumnView class methodsFor:'documentation'!
+
+documentation
+"
+ The class describes the common interface supported by the 2D or 3D GraphColumnView.
+ This Viewclasses provide a lot of functionality for showing and manipulating graphs
+ described through to a GraphColumn description. Each change in a graph description
+ immediately take affect in the garph view.
+
+
+ [See also:]
+ GraphColumn
+ GraphColumnView2D
+ GraphColumnView3D
+
+ [Author:]
+ Claus Atzkern
+"
+
+! !
!GraphColumnView class methodsFor:'defaults'!
@@ -33,7 +55,7 @@
!GraphColumnView methodsFor:'accessing'!
columns
- "returns list of column descriptions
+ "returns the list of column descriptions
"
^ columns
@@ -41,7 +63,7 @@
!
columns:aList
- "set list of columns
+ "set the list of columns descriptions
"
columns notNil ifTrue:[
columns do:[:aCol| aCol removeDependent:self ]
@@ -60,14 +82,62 @@
self recomputeWholeGraph
!
+graphOriginX
+ "returns the logical index X of the first visible row; this number is used for
+ accessing Y values from the GraphColumn description. On default, the value
+ is set to 1.
+ "
+ ^ graphOriginX
+
+
+!
+
+graphOriginX:aNumber
+ "set the logical index X of the first visible row; this number is used for
+ accessing Y values from the GraphColumn description. On default, the value
+ is set to 1.
+ Changing the number, a scroll left or right is triggered.
+ "
+ |newX state|
+
+ aNumber isNumber ifTrue:[
+ newX := aNumber isInteger ifTrue:[aNumber]
+ ifFalse:[(aNumber asFloat) rounded]. "/ no fractions
+
+ newX ~~ graphOriginX ifTrue:[
+ state := scrollUpdatesOriginX.
+ scrollUpdatesOriginX := true.
+ self scroll:(graphOriginX - newX).
+ scrollUpdatesOriginX := state.
+ ]
+ ]
+!
+
+scrollUpdatesOriginX
+ "returns true, if the graphOriginX automatically is updated by
+ any scroll action. The default is set to false.
+ "
+ ^ scrollUpdatesOriginX
+!
+
+scrollUpdatesOriginX:aBool
+ "set to true if the graphOriginX automatically should be updated by any
+ scroll action. Otherwise a scroll has no influnce to the current
+ graphOriginX.
+ The default is set to false.
+ "
+ scrollUpdatesOriginX := aBool
+!
+
showDefaultMenu
- "enable or disable my default menu
+ "returns true, if the middleButton menu is set to the default menu
+ provided by the graph.
"
^ self menuMessage == #defaultMenu
!
showDefaultMenu:aBool
- "enable or disable my default menu
+ "enable or disable the default menu provided by the graph
"
|currMsg|
@@ -88,7 +158,7 @@
!GraphColumnView methodsFor:'accessing dimensions'!
windowSize
- "get number of horizontal steps ( X )
+ "get the number of horizontal steps ( X )
"
^ windowSize
@@ -96,7 +166,7 @@
!
windowSize:aValue
- "set number of horizontal steps ( X )
+ "set the number of horizontal steps ( X )
"
|sz|
@@ -118,8 +188,8 @@
!
zoomY:aValue
- "set current y-zoom factor; if the argument is nil,
- the y-zoom is set to 1 ( no zoom ).
+ "set the current y-zoom factor; if the argument is nil,
+ the y-zoom is set to 1.
"
|zY|
@@ -138,7 +208,7 @@
!GraphColumnView methodsFor:'accessing look'!
backgroundColor
- "get the background color
+ "returns the current background color of the graph
"
^ bgColor
@@ -146,7 +216,7 @@
!
backgroundColor:aColor
- "set the background color
+ "set the background color of the graph
"
(aColor isColor and:[bgColor ~= aColor]) ifTrue:[
shown ifTrue:[
@@ -159,16 +229,16 @@
!
foregroundColor
- "get the default foreground color; used in case that no color for
- a column is specified
+ "returns the default foreground color used to draw graphs which
+ has no foreground color specified.
"
^ fgColor
!
foregroundColor:aColor
- "set the default foreground color; used in case that no color for
- a column is specified
+ "set the default foreground color used to draw graphs which
+ has no foreground color specified.
"
(aColor isColor and:[fgColor ~= aColor]) ifTrue:[
shown ifTrue:[
@@ -182,7 +252,7 @@
!
gridColor
- "get the foreground color of the grid
+ "returns the foreground color of the grid
"
^ gridColor
@@ -206,11 +276,15 @@
!
showGrid
+ "returns true if the grid is enabled
+ "
^ showGrid
!
showGrid:aBool
+ "set the visibility state of the grid
+ "
|hasGrid|
showGrid ~~ aBool ifTrue:[
@@ -224,7 +298,7 @@
!
vLinesColor
- "get the foreground color of the vertical lines
+ "returns the foreground color used to draw vertical lines
"
^ vLinesColor
@@ -232,7 +306,7 @@
!
vLinesColor:aColor
- "set the foreground color of the vertical lines
+ "set the foreground color used to draw vertical lines
"
(aColor isColor and:[vLinesColor ~= aColor]) ifTrue:[
shown ifTrue:[
@@ -247,8 +321,29 @@
!GraphColumnView methodsFor:'accessing mvc'!
+graphOriginXHolder
+ "returns the valueHolder, which keeps the current graphOriginX (see: #graphOriginX:)
+ "
+ ^ graphOriginXHolder
+!
+
+graphOriginXHolder:aHolder
+ "set the valueHolder, which keeps the current graphOriginX (see: #graphOriginX:)
+ "
+ graphOriginXHolder == aHolder ifFalse:[
+ graphOriginXHolder notNil ifTrue:[
+ graphOriginXHolder removeDependent:self
+ ].
+ (graphOriginXHolder := aHolder) notNil ifTrue:[
+ graphOriginXHolder addDependent:self
+ ].
+ ].
+ self graphOriginX:(graphOriginXHolder value)
+
+!
+
listHolder
- "get the valueHolder which holds the list of column descriptons
+ "returns the valueHolder, which keeps the list of column descriptions (see: #column:)
"
^ listHolder
@@ -256,7 +351,7 @@
!
listHolder:aHolder
- "set the valueHolder which holds the list of column descriptons
+ "set the valueHolder, which keeps the list of column descriptions (see: #column:)
"
listHolder == aHolder ifFalse:[
listHolder notNil ifTrue:[
@@ -288,15 +383,38 @@
!
+vLinesHolder
+ "returns the valueHolder, which keeps the list of vLines (see: #vLines:)
+ "
+ ^ vLinesHolder
+
+
+!
+
+vLinesHolder:aHolder
+ "set the valueHolder, which keeps the list of vLines (see: #vLines:)
+ "
+ vLinesHolder == aHolder ifFalse:[
+ vLinesHolder notNil ifTrue:[
+ vLinesHolder removeDependent:self
+ ].
+ (vLinesHolder := aHolder) notNil ifTrue:[
+ vLinesHolder addDependent:self
+ ].
+ ].
+ self vLines:(vLinesHolder value)
+
+!
+
windowSizeHolder
- "get the valueHolder which holds the size of the window; X
+ "returns the valueHolder, which keeps the windowSize (see: #windowSize:)
"
^ windowSizeHolder
!
windowSizeHolder:aHolder
- "set the valueHolder which holds the size of the window; X
+ "set the valueHolder, which keeps the windowSize (see: #windowSize:)
"
windowSizeHolder == aHolder ifFalse:[
windowSizeHolder notNil ifTrue:[
@@ -311,14 +429,14 @@
!
zoomYHolder
- "get the valueHolder which holds the y zoom factor
+ "returns the valueHolder, which keeps the zoom Y factor (see: #zoomY:)
"
^ zoomYHolder
!
zoomYHolder:aHolder
- "set the valueHolder which holds the y zoom factor
+ "set the valueHolder, which keeps the zoom Y factor (see: #zoomY:)
"
zoomYHolder == aHolder ifFalse:[
zoomYHolder notNil ifTrue:[
@@ -332,6 +450,97 @@
! !
+!GraphColumnView methodsFor:'accessing vLines'!
+
+vLineAdd:aLineIndex
+ "add vertical line index to end of list
+ "
+ ^ self vLineAdd:aLineIndex beforeIndex:(vLines size + 1)
+!
+
+vLineAdd:aLineIndex beforeIndex:anIndex
+ "add a vertical line index before an index
+ "
+ |x|
+
+ vLines add:aLineIndex beforeIndex:anIndex.
+
+ (shown and:[aLineIndex > graphOriginX]) ifTrue:[
+ (x := ((aLineIndex - 1) * self stepX) rounded) < width ifTrue:[
+ self vLinesSizeChanged:#insert: atX:x.
+ ]
+ ].
+ ^ aLineIndex
+!
+
+vLineAddAll:aCollection beforeIndex:anIndex
+ "add a collection of vertical line indices before an index
+ "
+ aCollection size ~~ 0 ifTrue:[
+ vLines size == 0 ifTrue:[
+ self vLines:aCollection
+ ] ifFalse:[
+ vLines addAll:aCollection beforeIndex:anIndex.
+ self recomputeWholeGraph.
+ ]
+ ]
+
+!
+
+vLineRemove:aLineIndex
+ "remove a vertical line index
+ "
+ ^ self vLineRemoveIndex:(vLines identityIndexOf:aLineIndex)
+
+!
+
+vLineRemoveAll
+ "remove all vertical line indices
+ "
+ self vLines:nil
+!
+
+vLineRemoveIndex:anIndex
+ "remove the vertical line index at an index
+ "
+ |lineIndex x|
+
+ lineIndex := vLines removeAtIndex:anIndex.
+
+ (shown and:[lineIndex > graphOriginX]) ifTrue:[
+ (x := ((lineIndex - 1) * self stepX) rounded) < width ifTrue:[
+ self vLinesSizeChanged:#remove: atX:x.
+ ]
+ ].
+ ^ lineIndex
+
+
+!
+
+vLines
+ "returns list of vertical lines
+ "
+ ^ vLines
+
+
+!
+
+vLines:aListOfIndices
+ "set list of vertical lines
+ "
+ aListOfIndices size == 0 ifTrue:[
+ vLines isEmpty ifTrue:[
+ ^ self
+ ]
+ ] ifFalse:[
+ vLines := OrderedCollection new.
+ aListOfIndices do:[:i| vLines add:i ]
+ ].
+ shown ifTrue:[
+ self recomputeWholeGraph
+ ]
+! !
+
!GraphColumnView methodsFor:'adding & removing'!
add:aColumn
@@ -443,6 +652,39 @@
^ self zoomY:(zoomYHolder value)
].
+ chgObj == graphOriginXHolder ifTrue:[
+ ^ self graphOriginX:(graphOriginXHolder value)
+ ].
+
+ chgObj == vLinesHolder ifTrue:[
+ (what == #insert:) ifTrue:[
+ self vLineAdd:(list at:aPara) beforeIndex:aPara
+ ] ifFalse:[
+ (what == #remove:) ifTrue:[
+ self vLineRemoveIndex:aPara
+ ] ifFalse:[
+ (what == #insertCollection:) ifTrue:[
+ start := aPara first.
+ size := aPara last.
+
+ size ~~ 0 ifTrue:[
+ size == 1 ifTrue:[
+ self vLineAdd:(list at:start) beforeIndex:start
+ ] ifFalse:[
+ stop := start + size - 1.
+ self vLineAddAll:(list copyFrom:start to:stop) beforeIndex:start
+ ]
+ ]
+ ] ifFalse:[
+ self vLinesHolder:chgObj
+ ]
+ ]
+ ].
+ ^ self
+ ].
+
+
+
chgObj == model ifTrue:[
(what == #selectionIndex or:[what == #selection]) ifTrue:[
^ self
@@ -497,15 +739,13 @@
!GraphColumnView methodsFor:'conversion'!
floatFrom:aValue onError:aBlock
- "converts something to a float, on error the result of the
- block is returned
+ "converts something to a float, on error the result of the block is returned
"
^ aValue isNumber ifTrue:[aValue asFloat] ifFalse:[aBlock value]
!
unsignedIntegerFrom:aValue onError:aBlock
- "converts something to an unsigned integer, on error the result of the
- block is returned
+ "converts something to an unsigned integer, on error the result of the block is returned
"
|v|
@@ -536,14 +776,11 @@
"
super destroy.
- listHolder removeDependent:self.
- listHolder := nil.
-
- windowSizeHolder removeDependent:self.
- windowSizeHolder := nil.
-
- zoomYHolder removeDependent:self.
- zoomYHolder := nil.
+ listHolder removeDependent:self.
+ vLinesHolder removeDependent:self.
+ windowSizeHolder removeDependent:self.
+ zoomYHolder removeDependent:self.
+ graphOriginXHolder removeDependent:self.
columns notNil ifTrue:[
columns do:[:aCol| aCol removeDependent:self ]
@@ -560,20 +797,23 @@
self class updateStyleCache
].
- windowSize := 101.
- showGrid := false.
- zoomY := 1.
-
+ vLines := OrderedCollection new.
+ windowSize := 101.
+ showGrid := false.
+ zoomY := 1.
+ graphOriginX := 1.
+ scrollUpdatesOriginX := false.
! !
!GraphColumnView methodsFor:'menu & submenus'!
defaultMenu
- "returns the default middle button menu
+ "returns the default middle button menu provided by the graph
"
|menu|
menu := self class defaultMenu decodeAsLiteralArray.
+
menu notNil ifTrue:[
menu receiver:self
].
@@ -583,6 +823,9 @@
!
doZoomY:aValue
+ "triggered by the default menu to change the current zoom Y factor;
+ on change, the corresponding model (zoomYHolder) is updated.
+ "
|old|
old := self zoomY.
@@ -594,7 +837,7 @@
!
subMenuZoomY
- "returns a submenu to configure the y-zoom value
+ "returns the submenu to configure the zoom Y factor
"
^ GraphColumn zoomMenuSelector:#doZoomY:
@@ -604,19 +847,33 @@
!GraphColumnView methodsFor:'protocol'!
colorChanged:what
- "called if a color changed, #foreground, #background, #grid or #vLines
+ "called if any color changed; the argument to the change notification
+ specifies the color which has changed:
+
+ #foreground the foreground color
+ #background the background color
+ #grid the color of the grid
+ #vLines the color of the vertical lines
"
self recomputeWholeGraph
!
columnChanged:what with:aPara from:aColumn
- "a column changed
+ "a column has changed one of its attributes; the arguments to the
+ notification are passed by the column.
"
self recomputeWholeGraph
!
+graphOriginXChanged:deltaX
+ "scroll left or right n x-steps. A positive value scrolls to the right
+ a negative value to the left.
+ "
+ self recomputeWholeGraph
+!
+
invalidateGraph
"called to redraw the graph
"
@@ -624,7 +881,8 @@
!
listSizeChanged:what from:aColumn
- "called if a column is inserted (#insert:) or removed from list
+ "called if a column description is inserted (#insert:) or removed (#remove:)
+ from the list of columns.
"
self recomputeWholeGraph
!
@@ -633,12 +891,19 @@
"called if the whole graph should be recomputed
"
self subclassResponsibility
+!
+
+vLinesSizeChanged:what atX:aPhysX
+ "called if the list of vertical lines changed; a new lineIndex is inserted (#insert:)
+ or removed (#remove:) from the list
+ "
+ self recomputeWholeGraph
! !
!GraphColumnView methodsFor:'queries'!
numberOfVisibleColumns
- "returns number of visible Columns
+ "returns the number of visible Columns (shown is true)
"
|no|
@@ -650,8 +915,75 @@
^ no
! !
+!GraphColumnView methodsFor:'scrolling'!
+
+halfWindowSizeLeft
+ "scroll left half window size
+ "
+ self scrollLeft:(windowSize // 2)
+
+!
+
+halfWindowSizeRight
+ "scroll right half window size
+ "
+ self scrollRight:(windowSize // 2)
+
+!
+
+scroll:nIndices
+ "scroll left or right n x-steps. a positive value scrolls to the right
+ a negative value to the left.
+ "
+ |max|
+
+ nIndices ~~ 0 ifTrue:[
+ scrollUpdatesOriginX ifTrue:[
+ graphOriginX := graphOriginX - nIndices
+ ].
+
+ shown ifTrue:[
+ max := 2 * (windowSize // 3).
+
+ (nIndices abs) > max ifTrue:[
+ self recomputeWholeGraph "/ full redraw
+ ] ifFalse:[
+ self graphOriginXChanged:nIndices "/ scroll
+ ]
+ ]
+ ].
+!
+
+scrollLeft:nIndices
+ "scroll n indices left
+ "
+ self scroll:(nIndices negated)
+
+!
+
+scrollRight:nIndices
+ "scroll n indices right
+ "
+ self scroll:nIndices
+
+!
+
+windowSizeLeft
+ "scroll left window size
+ "
+ self scrollLeft:windowSize
+
+!
+
+windowSizeRight
+ "scroll right window size
+ "
+ self scrollRight:windowSize
+
+! !
+
!GraphColumnView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView.st,v 1.1 1998-02-07 15:15:50 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView.st,v 1.2 1998-02-09 10:31:27 ca Exp $'
! !