From 4a804e78c862ab2cf10ef7116715427ce09cc20d Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Mon, 19 Feb 2024 21:12:23 +0100 Subject: [PATCH] Make watch displays consistent, fix graph vizs --- .../SBExampleValueDisplay.class.st | 3 +- .../SBExampleWatch.class.st | 6 ++ .../Sandblocks-Babylonian/SBTrace.class.st | 4 +- packages/Sandblocks-Watch/SBBarChart.class.st | 8 +- .../SBExampleWatchView.class.st | 8 ++ .../Sandblocks-Watch/SBLineChart.class.st | 22 ++--- .../SBRectangleChart.class.st | 21 +++-- .../Sandblocks-Watch/SBVisualization.class.st | 25 +----- .../Sandblocks-Watch/SBWatchView.class.st | 87 ++++++++++++------- 9 files changed, 111 insertions(+), 73 deletions(-) diff --git a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st index e3508187..3d82a123 100644 --- a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st @@ -30,6 +30,7 @@ SBExampleValueDisplay >> display [ { #category : #accessing } SBExampleValueDisplay >> displayedWatchValueBlocks [ + display isDisplayingWatchValues ifFalse: [^ {}]. ^ display displayedMorphs ] @@ -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 } diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index 3b364996..6e3c7680 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -250,6 +250,12 @@ SBExampleWatch >> exampleToDisplay: anExampleToDisplayDict [ exampleToDisplay := anExampleToDisplayDict ] +{ #category : #accessing } +SBExampleWatch >> exampleToValues [ + + ^ exampleToValues +] + { #category : #accessing } SBExampleWatch >> exampleToValues: anExampleToCollectionOfWatchValuesDict [ diff --git a/packages/Sandblocks-Babylonian/SBTrace.class.st b/packages/Sandblocks-Babylonian/SBTrace.class.st index a835d348..84f0f4d5 100644 --- a/packages/Sandblocks-Babylonian/SBTrace.class.st +++ b/packages/Sandblocks-Babylonian/SBTrace.class.st @@ -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 ] diff --git a/packages/Sandblocks-Watch/SBBarChart.class.st b/packages/Sandblocks-Watch/SBBarChart.class.st index 4b111277..40c16830 100644 --- a/packages/Sandblocks-Watch/SBBarChart.class.st +++ b/packages/Sandblocks-Watch/SBBarChart.class.st @@ -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); @@ -67,3 +67,9 @@ SBBarChart >> newLineFrom: aDataPointMorph1 to: aDataPointMorph2 [ ] + +{ #category : #'visualization - constants' } +SBBarChart >> scaleYOffset [ + + ^ 0 +] diff --git a/packages/Sandblocks-Watch/SBExampleWatchView.class.st b/packages/Sandblocks-Watch/SBExampleWatchView.class.st index c0f2279c..2209499b 100644 --- a/packages/Sandblocks-Watch/SBExampleWatchView.class.st +++ b/packages/Sandblocks-Watch/SBExampleWatchView.class.st @@ -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 [ diff --git a/packages/Sandblocks-Watch/SBLineChart.class.st b/packages/Sandblocks-Watch/SBLineChart.class.st index 6a20b490..2435a8a3 100644 --- a/packages/Sandblocks-Watch/SBLineChart.class.st +++ b/packages/Sandblocks-Watch/SBLineChart.class.st @@ -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 [ @@ -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 @@ -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] ] @@ -156,12 +164,6 @@ SBLineChart >> positiveGradientColor [ ^ Color green ] -{ #category : #'visualization - constants' } -SBLineChart >> scaleYOffset [ - - ^ self datapointExtent y / 2 -] - { #category : #'visualization - constants' } SBLineChart >> spaceBetweenPoints [ diff --git a/packages/Sandblocks-Watch/SBRectangleChart.class.st b/packages/Sandblocks-Watch/SBRectangleChart.class.st index 65d4248b..6714d5d5 100644 --- a/packages/Sandblocks-Watch/SBRectangleChart.class.st +++ b/packages/Sandblocks-Watch/SBRectangleChart.class.st @@ -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; @@ -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 } @@ -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 ] diff --git a/packages/Sandblocks-Watch/SBVisualization.class.st b/packages/Sandblocks-Watch/SBVisualization.class.st index f79b318e..dd72c9d2 100644 --- a/packages/Sandblocks-Watch/SBVisualization.class.st +++ b/packages/Sandblocks-Watch/SBVisualization.class.st @@ -29,13 +29,7 @@ Class { { #category : #constants } SBVisualization class >> defaultHeight [ - ^ 100 sbScaled -] - -{ #category : #constants } -SBVisualization class >> heightMargin [ - - ^ 5 sbScaled + ^ 100 ] { #category : #constants } @@ -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 [ @@ -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 diff --git a/packages/Sandblocks-Watch/SBWatchView.class.st b/packages/Sandblocks-Watch/SBWatchView.class.st index 4d302c50..e61d78da 100644 --- a/packages/Sandblocks-Watch/SBWatchView.class.st +++ b/packages/Sandblocks-Watch/SBWatchView.class.st @@ -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 [ @@ -43,18 +63,19 @@ SBWatchView >> canDeleteChild: aBlock [ ^ false ] -{ #category : #display } +{ #category : #actions } SBWatchView >> changeDisplay [ | 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. ] @@ -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. @@ -191,9 +213,8 @@ SBWatchView >> initialize [ super initialize. - dark := true. + selectedDisplayIndex := 0. updateScheduled := false. - numSavedValues := 1. watchValues := LinkedList new. fallbackResizer := SBMorphResizer newSmall. shouldUpdateDisplay := true. @@ -217,6 +238,12 @@ SBWatchView >> initialize [ visible: false) ] +{ #category : #accessing } +SBWatchView >> isDisplayingWatchValues [ + + ^ selectedDisplayIndex = 0 +] + { #category : #accessing } SBWatchView >> lastValue [ @@ -237,13 +264,6 @@ SBWatchView >> maxWidth [ ^ 350 ] -{ #category : #accessing } -SBWatchView >> numSavedValues: anInteger [ - "Private" - - numSavedValues := anInteger -] - { #category : #'object interface' } SBWatchView >> object [ @@ -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 [ @@ -366,7 +394,6 @@ SBWatchView >> updateDisplay [ { #category : #accessing } SBWatchView >> values [ - watchValues ifEmpty: [^{}]. ^ watchValues collect: [:value | value watchedValue] ]