From f284a5a4f3a7abbacf25eb1c9f0cd0a24d626c36 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Tue, 21 Nov 2023 22:13:32 +0100 Subject: [PATCH 1/2] Consistent sizing --- .../SBExampleValueDisplay.class.st | 12 ++++ .../SBExampleWatch.class.st | 13 +++-- packages/Sandblocks-Watch/SBBarChart.class.st | 9 +-- .../Sandblocks-Watch/SBLineChart.class.st | 11 ++-- .../SBRectangleChart.class.st | 40 ++++++-------- .../Sandblocks-Watch/SBVisualization.class.st | 55 ++++++++++++++----- .../Sandblocks-Watch/SBWatchView.class.st | 37 +++++++++++-- 7 files changed, 122 insertions(+), 55 deletions(-) diff --git a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st index 0a93f4f6..0b650aa5 100644 --- a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st @@ -21,6 +21,12 @@ SBExampleValueDisplay >> clear [ hadValue := false ] +{ #category : #'as yet unclassified' } +SBExampleValueDisplay >> display [ + + ^ display +] + { #category : #accessing } SBExampleValueDisplay >> displayedWatchValueBlocks [ @@ -127,6 +133,12 @@ SBExampleValueDisplay >> reportValues: aCollectionOfObjects name: aString sized: hadValue := true ] +{ #category : #actions } +SBExampleValueDisplay >> resizeThrough: aMorphResizer [ + + display resizeThrough: aMorphResizer +] + { #category : #actions } SBExampleValueDisplay >> updateDisplay [ diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index 3be95f48..e48cb2a7 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -116,8 +116,8 @@ SBExampleWatch >> applyModifyExpressionOnValues [ { #category : #'event handling' } SBExampleWatch >> applyResizerOnValues [ - "Clearing everything here as Morphs get distorted when resized multiple times." - self applyModifyExpressionOnValues. + exampleToDisplay associationsDo: [:anExampleDisplayPair | + anExampleDisplayPair value resizeThrough: self selectedMorphResizer] ] @@ -171,11 +171,12 @@ SBExampleWatch >> exampleStarting: anExample [ exampleToValues at: anExample put: OrderedCollection new. - (exampleToDisplay at: anExample ifAbsentPut: [ | display | - display := SBExampleValueDisplay new. - self addMorph: (exampleToDisplay at: anExample put: display) atIndex: 2. + (exampleToDisplay at: anExample ifAbsentPut: [ | valueDisplay | + valueDisplay := SBExampleValueDisplay new. + valueDisplay display fallbackResizer: self selectedMorphResizer. + self addMorph: (exampleToDisplay at: anExample put: valueDisplay) atIndex: 2. anExample when: #outOfWorld send: #exampleStopped: to: self with: anExample. - display]) + valueDisplay]) exampleStarting: anExample; name: anExample label ] diff --git a/packages/Sandblocks-Watch/SBBarChart.class.st b/packages/Sandblocks-Watch/SBBarChart.class.st index 0bc2eaa5..4b111277 100644 --- a/packages/Sandblocks-Watch/SBBarChart.class.st +++ b/packages/Sandblocks-Watch/SBBarChart.class.st @@ -5,17 +5,18 @@ Class { } { #category : #'initialize-release' } -SBBarChart class >> newWithValues: traceValues [ +SBBarChart class >> newWithValues: traceValues havingHeight: aNumber [ | valuesToVisualize | valuesToVisualize := traceValues ifEmpty: [#(0)] ifNotEmpty: [traceValues]. ^ self new + targetHeight: aNumber; traceValues: valuesToVisualize; scaleY: (SBScale newLinearScaleWithDomain: (({valuesToVisualize min. 0} min) to: valuesToVisualize max) - forRange: (0 to: self canvasHeight)); + forRange: (0 to: aNumber)); yourself ] @@ -30,7 +31,7 @@ SBBarChart >> newBarFor: aValue at: positionIndex [ "There is an extra Morph containing the datapoint itself so the tooltip is far easier to activate through more area" ^ Morph new - height: self class preferredHeight; + height: self targetHeight; left: ((positionIndex - 0.5) * self spaceBetweenPoints) rounded; width: self spaceBetweenPoints; color: Color transparent; @@ -39,7 +40,7 @@ SBBarChart >> newBarFor: aValue at: positionIndex [ color: self datapointDefaultColor; width: self barWidth; height: {(self scaleY scaledValueOf: aValue). 1} max; - bottom: self class canvasHeight + self class heightMargin; + bottom: self canvasHeight + self class heightMargin; left: positionIndex * self spaceBetweenPoints; setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue); yourself); diff --git a/packages/Sandblocks-Watch/SBLineChart.class.st b/packages/Sandblocks-Watch/SBLineChart.class.st index c3429539..f89ac2b3 100644 --- a/packages/Sandblocks-Watch/SBLineChart.class.st +++ b/packages/Sandblocks-Watch/SBLineChart.class.st @@ -5,17 +5,18 @@ Class { } { #category : #'initialize-release' } -SBLineChart class >> newWithValues: traceValues [ +SBLineChart class >> newWithValues: traceValues havingHeight: aNumber [ | valuesToVisualize | valuesToVisualize := traceValues ifEmpty: [#(0)] ifNotEmpty: [traceValues]. ^ self new + targetHeight: aNumber; traceValues: valuesToVisualize; scaleY: (SBScale newLinearScaleWithDomain: (valuesToVisualize min to: valuesToVisualize max) - forRange: (0 to: self canvasHeight)); + forRange: (0 to: aNumber)); yourself ] @@ -71,7 +72,7 @@ SBLineChart >> newDatapointFor: aValue at: positionIndex [ "There is an extra Morph containing the datapoint itself so the tooltip is far easier to activate through more area" ^ Morph new - height: self class preferredHeight; + height: self targetHeight; left: ((positionIndex - 0.5) * self spaceBetweenPoints) rounded; width: self spaceBetweenPoints; color: Color transparent; @@ -81,7 +82,7 @@ SBLineChart >> newDatapointFor: aValue at: positionIndex [ color: self datapointDefaultColor; borderWidth: 0; left: positionIndex * self spaceBetweenPoints; - top: self class canvasHeight - (self scaleY scaledValueOf: aValue); + top: self canvasHeight - (self scaleY scaledValueOf: aValue); setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue); yourself); yourself @@ -135,7 +136,7 @@ SBLineChart >> newScaleLineHeight: height length: length [ SBLineChart >> newScaleLinesOn: aMorph [ | section | - section := self class canvasHeight / (self numberScaleLines - 1). + section := self canvasHeight / (self numberScaleLines - 1). ^ (0 to: (self numberScaleLines - 1)) collect: [:i | self newScaleLineHeight: (section * i) + self scaleYOffset length: aMorph width] diff --git a/packages/Sandblocks-Watch/SBRectangleChart.class.st b/packages/Sandblocks-Watch/SBRectangleChart.class.st index 8534b6a8..65d4248b 100644 --- a/packages/Sandblocks-Watch/SBRectangleChart.class.st +++ b/packages/Sandblocks-Watch/SBRectangleChart.class.st @@ -7,35 +7,25 @@ Class { #category : #'Sandblocks-Watch' } -{ #category : #constants } -SBRectangleChart class >> coordinateSystemSize [ - - ^ self canvasHeight @ self canvasHeight -] - { #category : #'initialize-release' } -SBRectangleChart class >> newWithValues: traceValues [ +SBRectangleChart class >> newWithValues: traceValues havingHeight: aNumber [ - | biggestCoordinate absolutePoints | + | biggestCoordinate absolutePoints coordinateSystemSize | absolutePoints := traceValues collect: [:aPoint | aPoint abs]. biggestCoordinate := {absolutePoints max x. absolutePoints max y} max. + coordinateSystemSize := aNumber - self heightMargin. ^ self new + targetHeight: aNumber; traceValues: traceValues; scaleY: (SBScale newLinearScaleWithDomain: (biggestCoordinate negated to: biggestCoordinate) - forRange: (self coordinateSystemSize y / 2 negated to: self coordinateSystemSize y / 2)) + forRange: (coordinateSystemSize / 2 negated to: coordinateSystemSize / 2)) scaleX: (SBScale newLinearScaleWithDomain: (biggestCoordinate negated to: biggestCoordinate) - forRange: (self coordinateSystemSize x / 2 negated to: self coordinateSystemSize x / 2)); + forRange: (coordinateSystemSize / 2 negated to: coordinateSystemSize / 2)); yourself ] -{ #category : #constants } -SBRectangleChart class >> preferredHeight [ - - ^ 40 -] - { #category : #conversion } SBRectangleChart class >> supportedInterface [ @@ -62,6 +52,12 @@ SBRectangleChart >> borderStyleFor: scaledValues [ ^ BorderStyle width: borderWidth color: color ] +{ #category : #'visualization - constants' } +SBRectangleChart >> coordinateSystemSize [ + + ^ self canvasHeight @ self canvasHeight +] + { #category : #visualization } SBRectangleChart >> newCoordinateSystemFor: aValue at: positionIndex [ @@ -70,7 +66,7 @@ SBRectangleChart >> newCoordinateSystemFor: aValue at: positionIndex [ left := ((positionIndex - 1) * self spaceBetweenPoints) rounded. center := ((positionIndex - 0.5) * self spaceBetweenPoints) rounded. ^ Morph new - extent: self class coordinateSystemSize; + extent: self coordinateSystemSize; left: left; width: self spaceBetweenPoints; color: Color transparent; @@ -78,11 +74,11 @@ SBRectangleChart >> newCoordinateSystemFor: aValue at: positionIndex [ addAllMorphs: {LineMorph from: center@0 - to: center@(self class coordinateSystemSize y) + to: center@(self coordinateSystemSize y) color: self lineColor width: self scaleLineWidth. LineMorph - from: left@(self class coordinateSystemSize y / 2) - to: (left + self spaceBetweenPoints)@(self class coordinateSystemSize y / 2) + from: left@(self coordinateSystemSize y / 2) + to: (left + self spaceBetweenPoints)@(self coordinateSystemSize y / 2) color: self lineColor width: self scaleLineWidth.}; yourself ] @@ -107,7 +103,7 @@ SBRectangleChart >> newRectangleFor: aValue at: positionIndex [ color: (self rectangleColorForValue: aValue); borderStyle: (self borderStyleFor: (scaledWidth @ scaledHeight)); left: (scaledWidth / 2) + left; - top: (self class coordinateSystemSize y / 2) - (scaledHeight abs / 2) - (scaledHeight/2) ; + top: (self coordinateSystemSize y / 2) - (scaledHeight abs / 2) - (scaledHeight/2) ; yourself ] @@ -178,7 +174,7 @@ SBRectangleChart >> scaleY: aYSBScale scaleX: aXSBScale [ { #category : #'visualization - constants' } SBRectangleChart >> spaceBetweenPoints [ - ^ self class coordinateSystemSize x + ^ self coordinateSystemSize x ] { #category : #'visualization - constants' } diff --git a/packages/Sandblocks-Watch/SBVisualization.class.st b/packages/Sandblocks-Watch/SBVisualization.class.st index 5d2e8296..f79b318e 100644 --- a/packages/Sandblocks-Watch/SBVisualization.class.st +++ b/packages/Sandblocks-Watch/SBVisualization.class.st @@ -20,21 +20,22 @@ Class { #superclass : #SBBlock, #instVars : [ 'scaleY', - 'traceValues' + 'traceValues', + 'targetHeight' ], #category : #'Sandblocks-Watch' } { #category : #constants } -SBVisualization class >> canvasHeight [ +SBVisualization class >> defaultHeight [ - ^ self preferredHeight - self heightMargin + ^ 100 sbScaled ] { #category : #constants } -SBVisualization class >> heightMargin [ - - ^ 5 sbScaled +SBVisualization class >> heightMargin [ + + ^ 5 sbScaled ] { #category : #constants } @@ -46,13 +47,13 @@ SBVisualization class >> highlightedDataPercentage [ { #category : #'initialize-release' } SBVisualization class >> newWithValues: traceValues [ - ^ self subclassResponsibility + ^ self newWithValues: traceValues havingHeight: self defaultHeight ] -{ #category : #constants } -SBVisualization class >> preferredHeight [ +{ #category : #'initialize-release' } +SBVisualization class >> newWithValues: traceValues havingHeight: aNumber [ - ^ 100 sbScaled + ^ self subclassResponsibility ] { #category : #conversion } @@ -93,6 +94,21 @@ 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 [ @@ -118,17 +134,16 @@ SBVisualization >> isTopLevel [ { #category : #'visualization - constants' } SBVisualization >> lineColor [ - ^ self drawnColor + ^ self foregroundColor ] { #category : #visualization } SBVisualization >> newBackground [ - - + ^ Morph new color: self drawnColor; width: (self traceValues size + 2 "to have some margin") * self spaceBetweenPoints; - height: self class preferredHeight; + height: self targetHeight; borderWidth: 0; yourself ] @@ -165,6 +180,18 @@ SBVisualization >> spaceBetweenPoints [ ^ 10 sbScaled ] +{ #category : #accessing } +SBVisualization >> targetHeight [ + + ^ targetHeight ifNil: [targetHeight:= self class defaultHeight] +] + +{ #category : #accessing } +SBVisualization >> targetHeight: aNumber [ + + targetHeight := aNumber +] + { #category : #accessing } SBVisualization >> traceValues [ diff --git a/packages/Sandblocks-Watch/SBWatchView.class.st b/packages/Sandblocks-Watch/SBWatchView.class.st index f7fb96ea..c4ed4b2c 100644 --- a/packages/Sandblocks-Watch/SBWatchView.class.st +++ b/packages/Sandblocks-Watch/SBWatchView.class.st @@ -10,8 +10,8 @@ Class { 'dark', 'count', 'clear', - 'updateScheduled', - 'env' + 'fallbackResizer', + 'updateScheduled' ], #category : #'Sandblocks-Watch' } @@ -52,6 +52,7 @@ 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)}}. index := UIManager default chooseFrom: (options collect: #first). index = 0 ifTrue: [^ self]. @@ -164,6 +165,18 @@ SBWatchView >> exploreValues [ self object explore ] +{ #category : #accessing } +SBWatchView >> fallbackResizer [ + + ^ fallbackResizer +] + +{ #category : #accessing } +SBWatchView >> fallbackResizer: aSBMorphResizer [ + + fallbackResizer := aSBMorphResizer +] + { #category : #accessing } SBWatchView >> incrementCount [ @@ -179,6 +192,7 @@ SBWatchView >> initialize [ updateScheduled := false. numSavedValues := 1. watchValues := LinkedList new. + fallbackResizer := SBMorphResizer newSmall. self layoutPolicy: SBAlgebraLayout new; @@ -247,15 +261,16 @@ SBWatchView >> printOn: aStream [ self object printOn: aStream ] -{ #category : #accessing } +{ #category : #actions } SBWatchView >> reportValue: anObject [ self reportValue: {anObject} sized: SBMorphResizer newIdentity ] -{ #category : #accessing } +{ #category : #actions } SBWatchView >> reportValues: aCollectionOfObjects sized: aMorphResizer [ + self fallbackResizer: aMorphResizer. aCollectionOfObjects do: [:anObject | self addValue: anObject sized: aMorphResizer]. self count: self count contents + aCollectionOfObjects size. @@ -264,6 +279,20 @@ SBWatchView >> reportValues: aCollectionOfObjects sized: aMorphResizer [ Project current addDeferredUIMessage: [self updateDisplay]] ] +{ #category : #actions } +SBWatchView >> resizeThrough: aMorphResizer [ + + "Clearing everything here as Morphs get distorted when resized multiple times." + | valuesMorph | + valuesMorph := self watchValuesContainer. + valuesMorph addAllMorphsBack: (self displayedMorphs + collect: #sbSnapshot + thenDo: [:aMorph | aMorphResizer applyOn: aMorph]). + + self displayOnScrollPane: valuesMorph. + self fallbackResizer: aMorphResizer. +] + { #category : #layout } SBWatchView >> scrollBarHeight [ From 3108d303f19333ace280aa5c7ad98f0db60ec74c Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Tue, 21 Nov 2023 22:14:39 +0100 Subject: [PATCH 2/2] categorisation --- packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st index 0b650aa5..93312cee 100644 --- a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st @@ -21,7 +21,7 @@ SBExampleValueDisplay >> clear [ hadValue := false ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } SBExampleValueDisplay >> display [ ^ display