Skip to content

Commit

Permalink
Make watch displays consistent, fix graph vizs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Feb 19, 2024
1 parent dc43e9c commit 4a804e7
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SBExampleValueDisplay >> display [
{ #category : #accessing }
SBExampleValueDisplay >> displayedWatchValueBlocks [

display isDisplayingWatchValues ifFalse: [^ {}].
^ display displayedMorphs
]

Expand Down Expand Up @@ -82,7 +83,7 @@ SBExampleValueDisplay >> initialize [
statusLabel := SBStringMorph new contents: ''.
self newChangeVizButton};
yourself);
addMorphBack: (display := SBExampleWatch watchViewClass saving: -1)
addMorphBack: (display := SBExampleWatch watchViewClass new)
]

{ #category : #accessing }
Expand Down
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ SBExampleWatch >> exampleToDisplay: anExampleToDisplayDict [
exampleToDisplay := anExampleToDisplayDict
]

{ #category : #accessing }
SBExampleWatch >> exampleToValues [

^ exampleToValues
]

{ #category : #accessing }
SBExampleWatch >> exampleToValues: anExampleToCollectionOfWatchValuesDict [

Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBTrace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ SBTrace >> sortedWatchValuesFor: anExample givenWatches: aCollectionOfWatches [
| allValues |
allValues := SortedCollection sortBlock: [:a :b | a tracePosition <= b tracePosition].
aCollectionOfWatches do: [:aWatch |
aWatch exampleToDisplay at: anExample
ifPresent: [:aSBWatchView | allValues addAll: aSBWatchView display watchValues ]
aWatch exampleToValues at: anExample
ifPresent: [:aCollectionOfWatchValues | allValues addAll: aCollectionOfWatchValues ]
ifAbsent: [{}]].
^ allValues
]
Expand Down
8 changes: 7 additions & 1 deletion packages/Sandblocks-Watch/SBBarChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SBBarChart >> newBarFor: aValue at: positionIndex [
color: self datapointDefaultColor;
width: self barWidth;
height: {(self scaleY scaledValueOf: aValue). 1} max;
bottom: self canvasHeight + self class heightMargin;
bottom: self targetHeight;
left: positionIndex * self spaceBetweenPoints;
setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue);
yourself);
Expand All @@ -67,3 +67,9 @@ SBBarChart >> newLineFrom: aDataPointMorph1 to: aDataPointMorph2 [


]

{ #category : #'visualization - constants' }
SBBarChart >> scaleYOffset [

^ 0
]
8 changes: 8 additions & 0 deletions packages/Sandblocks-Watch/SBExampleWatchView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ SBExampleWatchView >> reportValues: aCollectionOfWatchValues sized: aMorphResize
updateScheduled := true
]

{ #category : #accessing }
SBExampleWatchView >> savingCount [

"Any value < 1 will result in saving all reported values"
"Save all values"
^ -1
]

{ #category : #display }
SBExampleWatchView >> updateDisplay [

Expand Down
22 changes: 12 additions & 10 deletions packages/Sandblocks-Watch/SBLineChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ SBLineChart >> datapointExtent [
^ 4@4
]

{ #category : #geometry }
SBLineChart >> extent: aPoint [

super extent: aPoint.
self targetHeight: aPoint y.
self scaleY range: (self scaleY range start to: aPoint y).
self visualize
]

{ #category : #visualization }
SBLineChart >> lineColorFrom: aDataPoint1 to: aDataPoint2 [

Expand Down Expand Up @@ -82,7 +91,7 @@ SBLineChart >> newDatapointFor: aValue at: positionIndex [
color: self datapointDefaultColor;
borderWidth: 0;
left: positionIndex * self spaceBetweenPoints;
top: self canvasHeight - (self scaleY scaledValueOf: aValue);
top: self targetHeight - (self scaleY scaledValueOf: aValue) - (self datapointExtent y / 2);
setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue);
yourself);
yourself
Expand Down Expand Up @@ -136,10 +145,9 @@ SBLineChart >> newScaleLineHeight: height length: length [
SBLineChart >> newScaleLinesOn: aMorph [

| section |
section := self canvasHeight / (self numberScaleLines - 1).

section := self targetHeight / (self numberScaleLines - 1).
^ (0 to: (self numberScaleLines - 1)) collect: [:i |
self newScaleLineHeight: (section * i) + self scaleYOffset length: aMorph width]
self newScaleLineHeight: (section * i) length: aMorph width]


]
Expand All @@ -156,12 +164,6 @@ SBLineChart >> positiveGradientColor [
^ Color green
]

{ #category : #'visualization - constants' }
SBLineChart >> scaleYOffset [

^ self datapointExtent y / 2
]

{ #category : #'visualization - constants' }
SBLineChart >> spaceBetweenPoints [

Expand Down
21 changes: 15 additions & 6 deletions packages/Sandblocks-Watch/SBRectangleChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SBRectangleChart class >> newWithValues: traceValues havingHeight: aNumber [
| biggestCoordinate absolutePoints coordinateSystemSize |
absolutePoints := traceValues collect: [:aPoint | aPoint abs].
biggestCoordinate := {absolutePoints max x. absolutePoints max y} max.
coordinateSystemSize := aNumber - self heightMargin.
coordinateSystemSize := aNumber.
^ self new
targetHeight: aNumber;
traceValues: traceValues;
Expand Down Expand Up @@ -55,7 +55,17 @@ SBRectangleChart >> borderStyleFor: scaledValues [
{ #category : #'visualization - constants' }
SBRectangleChart >> coordinateSystemSize [

^ self canvasHeight @ self canvasHeight
^ self targetHeight @ self targetHeight
]

{ #category : #geometry }
SBRectangleChart >> extent: aPoint [

super extent: aPoint.
self targetHeight: aPoint y.
self scaleY range: (aPoint y / 2 negated to: aPoint y / 2).
self scaleX range: (aPoint y / 2 negated to: aPoint y / 2).
self visualize
]

{ #category : #visualization }
Expand Down Expand Up @@ -97,13 +107,12 @@ SBRectangleChart >> newRectangleFor: aValue at: positionIndex [
scaledWidth := self scaleX scaledValueOf: aValue x.
scaledHeight := self scaleY scaledValueOf: aValue y.
left := ((positionIndex - 0.5) * self spaceBetweenPoints) rounded.

^ Morph new
extent: scaledWidth abs@scaledHeight abs;
extent: {scaledWidth abs. 1} max@{scaledHeight abs. 1} max;
color: (self rectangleColorForValue: aValue);
borderStyle: (self borderStyleFor: (scaledWidth @ scaledHeight));
left: (scaledWidth / 2) + left;
top: (self coordinateSystemSize y / 2) - (scaledHeight abs / 2) - (scaledHeight/2) ;
left: ({scaledWidth. 0} min )+ left;
top: (self coordinateSystemSize y / 2) - {scaledHeight. 0} max;
yourself

]
Expand Down
25 changes: 2 additions & 23 deletions packages/Sandblocks-Watch/SBVisualization.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ Class {
{ #category : #constants }
SBVisualization class >> defaultHeight [

^ 100 sbScaled
]

{ #category : #constants }
SBVisualization class >> heightMargin [

^ 5 sbScaled
^ 100
]

{ #category : #constants }
Expand Down Expand Up @@ -94,21 +88,6 @@ SBVisualization >> axisYNotation [
^ SBAxisNotation newFromScale: self scaleY ticking: 5
]

{ #category : #'visualization - constants' }
SBVisualization >> canvasHeight [

^ self targetHeight - self class heightMargin
]

{ #category : #geometry }
SBVisualization >> extent: aPoint [

super extent: aPoint.
self targetHeight: aPoint y.
self scaleY range: (0 to: aPoint y).
self visualize
]

{ #category : #initialization }
SBVisualization >> initialize [

Expand Down Expand Up @@ -142,7 +121,7 @@ SBVisualization >> newBackground [

^ Morph new
color: self drawnColor;
width: (self traceValues size + 2 "to have some margin") * self spaceBetweenPoints;
width: self traceValues size * self spaceBetweenPoints;
height: self targetHeight;
borderWidth: 0;
yourself
Expand Down
87 changes: 57 additions & 30 deletions packages/Sandblocks-Watch/SBWatchView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,51 @@ Class {
#superclass : #SBBlock,
#instVars : [
'watchValues',
'numSavedValues',
'dark',
'count',
'clear',
'shouldUpdateDisplay',
'selectedDisplayIndex',
'fallbackResizer',
'updateScheduled',
'shouldUpdateDisplay'
'clear',
'updateScheduled'
],
#category : #'Sandblocks-Watch'
}

{ #category : #'as yet unclassified' }
SBWatchView class >> saving: anInteger [
"Any value < 1 will result in saving all reported values"

^ self new numSavedValues: anInteger
]

{ #category : #accessing }
SBWatchView >> addValue: aWatchValue sized: aSBMorphResizer [

(watchValues size >= numSavedValues and: [numSavedValues > 0]) ifTrue: [watchValues removeFirst].
(watchValues size >= self savingCount and: [self savingCount > 0]) ifTrue: [watchValues removeFirst].
^ watchValues addLast: (aWatchValue morphResizer: aSBMorphResizer)
]

{ #category : #display }
SBWatchView >> buildCustomDisplayWith: aCollectionOfWatchValues [

| options |
options := Array streamContents: [:stream |
(aCollectionOfWatchValues collect: #watchedValue)
allConversionsFor: SBInterfaces topLevel do: [:pair | stream nextPut: pair]].
^ self watchValuesContainer
addMorphBack: (self fallbackResizer applyOn: ((options atWrap: selectedDisplayIndex) second))
]

{ #category : #display }
SBWatchView >> buildDefaultDisplayWith: aCollectionOfWatchValues [

^ self watchValuesContainer addAllMorphsBack: (aCollectionOfWatchValues collect: #asValueMorph)
]

{ #category : #display }
SBWatchView >> buildDisplayOptions [

| options |
options := Array streamContents: [:stream |
self values allConversionsFor: SBInterfaces topLevel do: [:pair | stream nextPut: pair]].
options := options do: [:aPair | aPair at: 2 put: (self watchValuesContainer addMorphBack: (self fallbackResizer applyOn: aPair second))].
options := options, {{'default'. self buildDefaultDisplayWith: watchValues}}.
^ options
]

{ #category : #'insert/delete' }
SBWatchView >> canDelete [

Expand All @@ -43,18 +63,19 @@ SBWatchView >> canDeleteChild: aBlock [
^ false
]

{ #category : #display }
{ #category : #actions }
SBWatchView >> changeDisplay [
<action>

| index options |
options := Array streamContents: [:stream |
self values allConversionsFor: SBInterfaces topLevel do: [:pair | stream nextPut: pair]].
options := options do: [:aPair | aPair at: 2 put: (self watchValuesContainer addMorphBack: (self fallbackResizer applyOn: aPair second))].
options := options, {{'default'. self watchValuesContainer addAllMorphsBack: (watchValues collect: #asValueMorph)}}.
options := self buildDisplayOptions.
index := UIManager default chooseFrom: (options collect: #first).
index = 0 ifTrue: [^ self].

(options at: index) first = 'default'
ifTrue: [selectedDisplayIndex := 0]
ifFalse: [selectedDisplayIndex := index].

self displayOnScrollPane: (options at: index) second.
]

Expand Down Expand Up @@ -131,8 +152,9 @@ SBWatchView >> displayOnScrollPane: aMorph [
SBWatchView >> displayWatchValues [

| valuesMorph |
valuesMorph := self watchValuesContainer.
valuesMorph addAllMorphsBack: (watchValues collect: #asValueMorph).
valuesMorph := self isDisplayingWatchValues
ifTrue: [self buildDefaultDisplayWith: watchValues]
ifFalse: [self buildCustomDisplayWith: watchValues].
"Will sometimes not update size otherwise when rushing through runs"
valuesMorph doLayoutSafely.
self displayOnScrollPane: valuesMorph.
Expand Down Expand Up @@ -191,9 +213,8 @@ SBWatchView >> initialize [

super initialize.

dark := true.
selectedDisplayIndex := 0.
updateScheduled := false.
numSavedValues := 1.
watchValues := LinkedList new.
fallbackResizer := SBMorphResizer newSmall.
shouldUpdateDisplay := true.
Expand All @@ -217,6 +238,12 @@ SBWatchView >> initialize [
visible: false)
]

{ #category : #accessing }
SBWatchView >> isDisplayingWatchValues [

^ selectedDisplayIndex = 0
]

{ #category : #accessing }
SBWatchView >> lastValue [

Expand All @@ -237,13 +264,6 @@ SBWatchView >> maxWidth [
^ 350
]

{ #category : #accessing }
SBWatchView >> numSavedValues: anInteger [
"Private"

numSavedValues := anInteger
]

{ #category : #'object interface' }
SBWatchView >> object [

Expand Down Expand Up @@ -306,6 +326,14 @@ SBWatchView >> resizeThrough: aMorphResizer [
self fallbackResizer: aMorphResizer.
]

{ #category : #accessing }
SBWatchView >> savingCount [

"Any value < 1 will result in saving all reported values"
"Only save the last recent one"
^ 1
]

{ #category : #layout }
SBWatchView >> scrollBarHeight [

Expand Down Expand Up @@ -366,7 +394,6 @@ SBWatchView >> updateDisplay [
{ #category : #accessing }
SBWatchView >> values [

watchValues ifEmpty: [^{}].
^ watchValues collect: [:value | value watchedValue]
]

Expand Down

0 comments on commit 4a804e7

Please sign in to comment.