[FIX] Bug in GraphMorph::drawOn/drawDataOn:
Robert M. Fuhrer
rfuhrer at watson.ibm.com
Thu Sep 9 17:36:57 UTC 1999
I posted this earlier, but in HTML (finger slipped). I'm assuming that I got
no replies because of the formatting, so I'm trying again...
I think I've found a small bug with the arrangement of drawing methods in
GraphMorph, which I stumbled upon when subclassing GraphMorph.
I needed to override the way in which the shape of the underlying function is
defined. That was easy. The problem cropped up in the display portion.
Looking at the code, it seemed most appropriate to me to override drawDataOn:
in my derived class. Now, GraphMorph::drawOn: calls "super drawOn:". If my
overriding method implementation calls "super drawOn:" (necessary in order to
get the border drawn), an infinite recursion ensues.
Pictorially (excuse the ASCII line art):
---------------------------
| RectangleMorph::drawOn: | <-----------------------------------------
--------------------------- |
|
----------------------- --------------------------- |
| GraphMorph::drawOn: | isGraphMorph? | GraphMorph::drawDataOn: | |
| self drawDataOn: |- - - - - - - -> | super drawOn: |---
----------------------- \ ---------------------------
^ \ no
| \
|----------------------------------------------------
\ ------------------------- |
\ | MyMorph::drawDataOn: | |
----> | super drawOn: |----
-------------------------
It seems the fix is to move the call to "super drawOn:" from
GraphMorph::drawDataOn: to GraphMorph::drawOn:, as in the fileIn below.
Comments?
============================================================
!GraphMorph methodsFor: 'drawing' stamp: 'RMF 8/25/1999 18:02'!
drawOn: aCanvas
| c |
super drawOn: aCanvas.
cachedForm = nil
ifTrue:
[c _ FormCanvas extent: bounds extent.
c translateBy: bounds origin negated during:
[:tempCanvas | self drawDataOn: tempCanvas].
cachedForm _ c form].
aCanvas
cache: bounds
using: cachedForm
during: [:cachingCanvas | self drawDataOn: cachingCanvas].
self drawCursorOn: aCanvas! !
!GraphMorph methodsFor: 'private' stamp: 'RMF 8/25/1999 18:02'!
drawDataOn: aCanvas
| yScale baseLine x start end value left top bottom right |
data isEmpty ifTrue: [^ self].
maxVal = minVal
ifTrue: [yScale _ 1]
ifFalse: [yScale _ (bounds height - (2 * borderWidth))
asFloat /
(maxVal - minVal)].
baseLine _ bounds bottom - borderWidth + (minVal * yScale) truncated.
left _ top _ 0.
right _ 10.
bottom _ 0.
x _ bounds left + borderWidth.
start _ (startIndex asInteger max: 1)
min: data size.
end _ start + bounds width min: data size.
start to: end do:
[:i |
left _ x truncated.
right _ x + 1.
right > (bounds right - borderWidth) ifTrue: [^ self].
value _ (data at: i) asFloat.
value >= 0.0
ifTrue:
[top _ baseLine - (yScale * value) truncated.
bottom _ baseLine]
ifFalse:
[top _ baseLine.
bottom _ baseLine - (yScale * value)
truncated].
aCanvas fillRectangle: (left @ top corner: right @ bottom)
color: dataColor.
x _ x + 1]! !
--------------------------------
Robert M. Fuhrer 34-231 (914) 945-3830
IBM T. J. Watson Research Center rfuhrer at watson.ibm.com
Yorktown Heights, NY 10598 PGP Public Key available on request
More information about the Squeak-dev
mailing list
|