add methods to change values without raising
authorca
Fri, 13 Feb 1998 14:51:54 +0100
changeset 755 96aada921c11
parent 754 c55a5727bf04
child 756 204971de9150
add methods to change values without raising a change notification
GraphColumn.st
--- a/GraphColumn.st	Fri Feb 13 14:51:18 1998 +0100
+++ b/GraphColumn.st	Fri Feb 13 14:51:54 1998 +0100
@@ -35,6 +35,17 @@
     ^ super basicNew initialize
 ! !
 
+!GraphColumn class methodsFor:'constants'!
+
+lineStyleFor:aStyle
+    "returns the valid style for a style; supported styles
+     are:
+        #dashed and #solid
+    "
+    ^ aStyle == #dashed ifFalse:[#solid] ifTrue:[#dashed]
+
+! !
+
 !GraphColumn class methodsFor:'menu definitions'!
 
 colorMenuSelector:aSelector
@@ -208,49 +219,35 @@
 
 !
 
-relativeXaxis:aNumberOrNil
+relativeXaxis:aValue
     "sets the relative X-axis (y == 0) into the graph view; staring at top (0.0) to
      bottom (1.0). Thus a relative X axis of 0.5 means the graph is centered in the view.
      In case that the value is not a valid number, the relative X axis is set to 0.5.
     "
     |x|
 
-    aNumberOrNil notNil ifTrue:[
-        x := aNumberOrNil isInteger ifTrue:[aNumberOrNil]
-                                   ifFalse:[aNumberOrNil asFloat]       "/ no fractions
-    ] ifFalse:[
-        x := 0.5
-    ].
+    self aspectAt:#relativeXaxis put:(self numberFrom:aValue onError:[0.5])
 
-    self aspectAt:#relativeXaxis put:x
 !
 
 scaleY
     "returns the current y-scale of the column (~~ 0); this value should be set once
-     dependant on the maximum and minimum Y value. To zoom the graph vertical use
+     dependent on the maximum and minimum Y value. To zoom the graph vertical use
      insteat #zoomY:.
     "
     ^ aspects at:#scaleY ifAbsent:1
 !
 
-scaleY:aNumberOrNil
+scaleY:aFactor
     "set the current y-scale of the column (~~ 0); this value should be set once
-     dependant on the maximum and minimum Y value. To zoom the graph vertical use
+     dependent on the maximum and minimum Y value. To zoom the graph vertical use
      insteat #zoomY:.
      In case that the value is not a valid number or less equal zero, the scale Y
      factor is set to its default value (1).
     "
     |y|
 
-    aNumberOrNil notNil ifTrue:[
-        y := aNumberOrNil isInteger ifTrue:[aNumberOrNil]
-                                   ifFalse:[aNumberOrNil asFloat].      "/ no fractions
-
-        y > 0 ifFalse:[y := 1]
-    ] ifFalse:[
-        y := 1
-    ].
-
+    (y := self numberFrom:aFactor onError:[1]) > 0 ifFalse:[ y := 1 ].
     self aspectAt:#scaleY put:y
 !
 
@@ -272,19 +269,10 @@
     ^ aspects at:#transY ifAbsent:0
 !
 
-transY:anIntegerOrNil
+transY:aValue
     "set the current y-transition of the column to an integer or nil (== 0).
     "
-    |y|
-
-    anIntegerOrNil notNil ifTrue:[
-        y := anIntegerOrNil isInteger ifTrue:[anIntegerOrNil]
-                                     ifFalse:[anIntegerOrNil asFloat rounded]   "/ catch fractions
-    ] ifFalse:[
-        y := 0
-    ].
-        
-    self aspectAt:#transY put:y
+    self aspectAt:#transY put:(self integerFrom:aValue onError:[0])
 !
 
 zoomY
@@ -302,16 +290,8 @@
     "
     |y|
 
-    aFactor notNil ifTrue:[
-        y := aFactor isInteger ifTrue:[aFactor]
-                              ifFalse:[aFactor asFloat].        "/ no fractions
-
-        y > 0 ifFalse:[y := 1]
-    ] ifFalse:[
-        y := 1
-    ].
+    (y := self numberFrom:aFactor onError:[1]) > 0 ifFalse:[ y := 1 ].
     self aspectAt:#zoomY put:y
-
 ! !
 
 !GraphColumn methodsFor:'accessing Y function'!
@@ -372,7 +352,8 @@
     "returns the style in which the graph is drawn; if no style is defined, the
      default style is used (#solid).
 
-     Supported styles are #solid or #dashed
+     Supported styles are:
+         #solid or #dashed
     "
     ^ aspects at:#lineStyle ifAbsent:#solid
 !
@@ -381,12 +362,10 @@
     "set the style in which the graph is drawn; if no style is defined or
      in case of a non valid style, the default style is used (#solid).
 
-     Supported styles are #solid or #dashed
+     Supported styles are:
+        #solid or #dashed
     "
-    |style|
-
-    style := aStyle == #dashed ifFalse:[#solid] ifTrue:[#dashed].
-    self aspectAt:#lineStyle put:style
+    self aspectAt:#lineStyle put:(self class lineStyleFor:aStyle)
 !
 
 lineWidth
@@ -429,7 +408,8 @@
     "
     |col|
 
-    col := (aCollection size ~~ 0) ifTrue:[aCollection] ifFalse:[nil].
+    col := (aCollection size ~~ 0) ifTrue:[aCollection]
+                                  ifFalse:[nil].
 
     self aspectAt:#hLineList put:col
 !
@@ -438,7 +418,8 @@
     "returns the style in which the horizontal lines are drawn; if no style is
      defined, the default style is used (#solid).
 
-     Supported styles are #solid or #dashed
+     Supported styles are:
+        #solid or #dashed
     "
     ^ aspects at:#hLineStyle ifAbsent:#solid
 !
@@ -447,12 +428,11 @@
     "set the style in which the horizontal lines are drawn; if no style is defined
      or in case of a non valid style, the default style is used (#solid).
 
-     Supported styles are #solid or #dashed.
+     Supported styles are:
+         #solid or #dashed.
     "
-    |style|
+    self aspectAt:#hLineStyle put:(self class lineStyleFor:aStyle)
 
-    style := aStyle == #dashed ifFalse:[#solid] ifTrue:[#dashed].
-    self aspectAt:#hLineStyle put:style
 !
 
 hLineWidth
@@ -485,6 +465,139 @@
 
 ! !
 
+!GraphColumn methodsFor:'accessing without notify'!
+
+setForegroundColor:aColor
+    "set the color of the graph; if the color is nil the default foreground color
+     of the graph is used which derives from the style sheet.
+     No change notification is raised
+    "
+    self withoutNotificationAspectAt:#foregroundColor put:aColor
+
+!
+
+setHLineFgColor:aColor
+    "set the color of the horizontal lines; if the color is nil the default foreground
+     color of the graph is used which derives from the style sheet.
+     No change notification is raised
+    "
+    self withoutNotificationAspectAt:#hLineFgColor put:aColor
+!
+
+setHLineList:aCollection
+    "set the list of horizontal lines to be drawn; no
+     change notification is raised
+    "
+    |col|
+
+    col := (aCollection size ~~ 0) ifTrue:[aCollection]
+                                  ifFalse:[nil].
+
+    self withoutNotificationAspectAt:#hLineList put:col
+!
+
+setHLineStyle:aStyle
+    "set the style in which the horizontal lines are drawn; if no style is defined
+     or in case of a non valid style, the default style is used (#solid).
+     No change notification is raised.
+
+     Supported styles are:
+         #solid or #dashed.
+    "
+    self withoutNotificationAspectAt:#hLineStyle put:(self class lineStyleFor:aStyle)
+
+!
+
+setHLineWidth:anInteger
+    "set the width of the horizontal lines; if the width is not defined or
+     not a valid number, the default value is set (1).
+     No change notification is raised.
+    "
+    self withoutNotificationAspectAt:#hLineWidth put:(anInteger ? 1)
+
+
+!
+
+setLineStyle:aStyle
+    "set the style in which the graph is drawn; if no style is defined or
+     in case of a non valid style, the default style is used (#solid).
+     No change notification is raised.
+
+     Supported styles are:
+        #solid or #dashed
+    "
+    self withoutNotificationAspectAt:#lineStyle put:(self class lineStyleFor:aStyle)
+
+!
+
+setLineWidth:anInteger
+    "set the width of the graph line; if the width is not defined or
+     not a valid number, the default value is set (1).
+     No change notification is raised
+    "
+    self withoutNotificationAspectAt:#lineWidth put:(anInteger ? 1)
+!
+
+setName:aName
+    "set the name of the column; no change notification is raised
+    "
+    self withoutNotificationAspectAt:#name put:aName
+!
+
+setRelativeXaxis:aValue
+    "sets the relative X-axis (y == 0) into the graph view; staring at top (0.0) to
+     bottom (1.0). Thus a relative X axis of 0.5 means the graph is centered in the view.
+     In case that the value is not a valid number, the relative X axis is set to 0.5.
+     No change notification is raised.
+    "
+    self withoutNotificationAspectAt:#relativeXaxis
+                                 put:(self numberFrom:aValue onError:[0.5])
+
+!
+
+setScaleY:aFactor
+    "set the current y-scale of the column (~~ 0); this value should be set once
+     dependent on the maximum and minimum Y value. To zoom the graph vertical use
+     insteat #zoomY:.
+     In case that the value is not a valid number or less equal zero, the scale Y
+     factor is set to its default value (1).
+     No change notification is raised.
+    "
+    |y|
+
+    (y := self numberFrom:aFactor onError:[1]) > 0 ifFalse:[ y := 1 ].
+    self withoutNotificationAspectAt:#scaleY put:y
+!
+
+setShown:aState
+    "set the visibility state of the column; 
+     no notification is raised
+    "
+    self withoutNotificationAspectAt:#shown put:aState
+!
+
+setTransY:aValue
+    "set the current y-transition of the column to an integer or nil (== 0).
+     no notification is raised
+    "
+    self withoutNotificationAspectAt:#transY
+                                 put:(self integerFrom:aValue onError:[0])
+!
+
+setZoomY:aFactor
+    "set the current y-zoom factor of the column. The graph and its
+     horizontal lines are vertical zoomed relative to its center defined
+     by the relativeXaxis.
+     In case that the value is not a valid number or less equal zero, the zoom Y
+     factor is set to its default value (1).
+     No change notification is raised.
+    "
+    |y|
+
+    (y := self numberFrom:aFactor onError:[1]) > 0 ifFalse:[ y := 1 ].
+    self withoutNotificationAspectAt:#zoomY put:y
+! !
+
 !GraphColumn methodsFor:'aspects'!
 
 aspect
@@ -539,6 +652,40 @@
     ] ifFalse:[
         aspects := aDictionaryOrNil
     ]
+!
+
+withoutNotificationAspectAt:aKey put:aValue
+    "set an aspect without a change notification
+    "
+    aValue notNil ifTrue:[ aspects at:aKey put:aValue ]
+                 ifFalse:[ aspects removeKey:aKey ifAbsent:nil ]
+! !
+
+!GraphColumn methodsFor:'conversion'!
+
+integerFrom:aValue onError:aBlock
+    "converts something to an integer, on error the result of the block is returned
+    "
+    |v|
+
+    aValue isNumber ifTrue:[
+        ^ aValue isInteger ifTrue:[aValue]
+                          ifFalse:[(aValue asFloat) rounded]    "/ no fractions
+    ].
+    ^ aBlock value
+
+
+!
+
+numberFrom:aValue onError:aBlock
+    "converts something to a number (no fractions); on error
+     the result of the block is returned
+    "
+    aValue isNumber ifTrue:[
+        ^ aValue isInteger ifTrue:[aValue]
+                          ifFalse:[aValue asFloat]      "/ no fractions
+    ].
+    ^ aBlock value
 ! !
 
 !GraphColumn methodsFor:'initialization'!
@@ -563,14 +710,14 @@
 !GraphColumn methodsFor:'queries'!
 
 centerGraphMaxY:maxY minY:minY
-    "set the transition Y for the graph dependant on the current scaleY, the maximum
+    "set the transition Y for the graph dependent on the current scaleY, the maximum
      and minimum Y value; the graph is centered to its relative X-Axis.
     "
     self transY:(((maxY + minY) / 2) * self scaleY)
 !
 
 scaleToHeight:aHeight maxY:maxY minY:minY
-    "set the scale Y value dependant on the maximum and minimum Y value to fit into
+    "set the scale Y value dependent on the maximum and minimum Y value to fit into
      a height >= 1
     "
     |dltY|
@@ -582,5 +729,5 @@
 !GraphColumn class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumn.st,v 1.2 1998-02-09 09:49:55 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumn.st,v 1.3 1998-02-13 13:51:54 ca Exp $'
 ! !