Skip to content

Commit

Permalink
Merge pull request #131 from hpi-swa/feature/consistent-display-sizing
Browse files Browse the repository at this point in the history
Consistent Resizing in Watches
  • Loading branch information
tom95 authored Nov 24, 2023
2 parents d651e36 + 7851299 commit 13d88b8
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 55 deletions.
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ SBExampleValueDisplay >> reportValues: aCollectionOfObjects name: aString sized:
hadValue := true
]

{ #category : #actions }
SBExampleValueDisplay >> resizeThrough: aMorphResizer [

display resizeThrough: aMorphResizer
]

{ #category : #actions }
SBExampleValueDisplay >> updateDisplay [

Expand Down
13 changes: 7 additions & 6 deletions packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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]

]

Expand Down Expand Up @@ -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
]
Expand Down
9 changes: 5 additions & 4 deletions packages/Sandblocks-Watch/SBBarChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand All @@ -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;
Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions packages/Sandblocks-Watch/SBLineChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
40 changes: 18 additions & 22 deletions packages/Sandblocks-Watch/SBRectangleChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand All @@ -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 [

Expand All @@ -70,19 +66,19 @@ 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;
balloonText: aValue printString;
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
]
Expand All @@ -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

]
Expand Down Expand Up @@ -178,7 +174,7 @@ SBRectangleChart >> scaleY: aYSBScale scaleX: aXSBScale [
{ #category : #'visualization - constants' }
SBRectangleChart >> spaceBetweenPoints [

^ self class coordinateSystemSize x
^ self coordinateSystemSize x
]

{ #category : #'visualization - constants' }
Expand Down
55 changes: 41 additions & 14 deletions packages/Sandblocks-Watch/SBVisualization.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down Expand Up @@ -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 [

Expand All @@ -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
]
Expand Down Expand Up @@ -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 [

Expand Down
Loading

0 comments on commit 13d88b8

Please sign in to comment.