From acfd17c9db0cc28fd766f60736bb5f04cabd610e Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Tue, 20 Feb 2024 00:24:45 +0100 Subject: [PATCH] Display other displays in exploriants --- .../Sandblocks-Babylonian/SBCluster.class.st | 20 ++++-- .../SBExampleCluster.class.st | 4 +- .../SBExampleWatch.class.st | 40 +++++++++--- .../SBMultiverse.class.st | 28 +++++++-- .../Sandblocks-Watch/SBLineChart.class.st | 11 ++-- .../Sandblocks-Watch/SBWatchView.class.st | 61 ++++++++++++++----- 6 files changed, 122 insertions(+), 42 deletions(-) diff --git a/packages/Sandblocks-Babylonian/SBCluster.class.st b/packages/Sandblocks-Babylonian/SBCluster.class.st index 292f2d3b..da341094 100644 --- a/packages/Sandblocks-Babylonian/SBCluster.class.st +++ b/packages/Sandblocks-Babylonian/SBCluster.class.st @@ -11,9 +11,13 @@ Class { SBCluster >> compressedMorphsForDisplay: aSBWatchView [ | displayedMorphs | - displayedMorphs := aSBWatchView watchValues collect: [:aWatchValue | - aWatchValue morphResizer: self morphResizer. - aWatchValue asValueMorph]. + aSBWatchView isDisplayingWatchValues + ifTrue: [displayedMorphs := self gatherAndCopyWatchValuesFrom: aSBWatchView] + ifFalse: [ | display | + display := aSBWatchView selectedDisplay submorphs + ifEmpty: [aSBWatchView selectedDisplay] + ifNotEmpty: [:submorphs | submorphs last]. + displayedMorphs := {self morphResizer applyOn: display}]. ^ (displayedMorphs size = 1) ifTrue: [displayedMorphs first] ifFalse: [self newCellMorph @@ -24,6 +28,14 @@ SBCluster >> compressedMorphsForDisplay: aSBWatchView [ addAllMorphsBack: displayedMorphs] ] +{ #category : #visualisation } +SBCluster >> gatherAndCopyWatchValuesFrom: aSBWatchView [ + + ^ aSBWatchView watchValues collect: [:aWatchValue | + aWatchValue morphResizer: self morphResizer. + aWatchValue asValueMorph] +] + { #category : #initialization } SBCluster >> initialize [ @@ -177,7 +189,7 @@ SBCluster >> wrapInCell: aMorph flexVertically: aVBoolean flexHorizontally: aHBo self flag: #todo. "Another way besides turning into an image to keep interactions.-jb" cell addMorph: (ImageMorph new - newForm: (aMorph iconOrThumbnailOfSize: targetExtent); + newForm: (aMorph imageForm scaledIntoFormOfSize: targetExtent); when: #clicked send: #triggerEvent: to: aMorph with: #clicked). cell on: #click send: #value to: [cell submorphs first triggerEvent: #clicked]. ^ cell diff --git a/packages/Sandblocks-Babylonian/SBExampleCluster.class.st b/packages/Sandblocks-Babylonian/SBExampleCluster.class.st index bee77678..00635bc3 100644 --- a/packages/Sandblocks-Babylonian/SBExampleCluster.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleCluster.class.st @@ -55,8 +55,8 @@ SBExampleCluster >> displayedIndex: aNumber [ { #category : #visualisation } SBExampleCluster >> extractRowsFrom: aUniverse [ - ^ aUniverse watches collect: [:anExample | | display | - display := (anExample exampleToDisplay associations at: self displayedIndex) value display. + ^ aUniverse watches collect: [:aWatch | | display | + display := (aWatch exampleToDisplay associations at: self displayedIndex) value display. self compressedMorphsForDisplay: display] ] diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index 6e3c7680..8dcdcfb3 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -131,15 +131,34 @@ SBExampleWatch >> asInactiveCopy [ modifyExpression: self modifyExpression veryDeepCopy; dimensionOptions: self dimensionOptions veryDeepCopy. - exampleToValues keys do: [:anExample | copy exampleStarting: anExample; - reportValues: (self valuesForExample: anExample) for: anExample; - exampleFinished: anExample ]. + exampleToValues keys do: [:anExample | + copy exampleStarting: anExample; + reportValues: (self valuesForExample: anExample) for: anExample]. + + "Keep switched views consistent" + exampleToDisplay keys do: [:anExample | + (copy exampleToDisplay at: anExample) display + selectedDisplayIndex: (exampleToDisplay at: anExample) display selectedDisplayIndex]. + + exampleToValues keys do: [:anExample | copy exampleFinished: anExample]. + ^ copy saveObjectsActivePermutations; yourself ] +{ #category : #initialization } +SBExampleWatch >> buildDefaultDisplayFor: anExample [ + + | 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. + ^ valueDisplay +] + { #category : #accessing } SBExampleWatch >> cleanedExpression [ @@ -169,6 +188,14 @@ SBExampleWatch >> color [ ^ self parentSandblock color ] +{ #category : #copying } +SBExampleWatch >> copySelectedDisplayIndicesFrom: other [ + + other exampleToDisplay associationsDo: [:exampleToDisplayAss | + (exampleToDisplay at: exampleToDisplayAss key ifAbsentPut: [self buildDefaultDisplayFor: exampleToDisplayAss key]) + display selectedDisplayIndex: exampleToDisplayAss value display selectedDisplayIndex] +] + { #category : #'insert/delete' } SBExampleWatch >> deleteCommandFor: aBlock [ @@ -220,12 +247,7 @@ SBExampleWatch >> exampleStarting: anExample [ exampleToValues at: anExample put: OrderedCollection new. - (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. - valueDisplay]) + (exampleToDisplay at: anExample ifAbsentPut: [self buildDefaultDisplayFor: anExample]) exampleStarting: anExample; name: anExample label ] diff --git a/packages/Sandblocks-Babylonian/SBMultiverse.class.st b/packages/Sandblocks-Babylonian/SBMultiverse.class.st index 539a3c8f..827df561 100644 --- a/packages/Sandblocks-Babylonian/SBMultiverse.class.st +++ b/packages/Sandblocks-Babylonian/SBMultiverse.class.st @@ -110,7 +110,8 @@ SBMultiverse >> asyncKaboom [ SBMultiverse >> cleanUp [ watches do: #resumeGraphicalUpdates. - (watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete + (watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete. + watches select: #isInEditor thenDo: [:aWatch | aWatch exampleToDisplay values do: #updateDisplay]. ] { #category : #collecting } @@ -123,6 +124,20 @@ SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [ ifClosed: [aCompiledMethod asSandblock]] ] +{ #category : #collecting } +SBMultiverse >> findExistingOrConvertToBlocksMaintainingWatches: aCollectionOfCompiledMethods [ + + ^ aCollectionOfCompiledMethods + collect: [:aCompiledMethod | | sandBlock | + sandBlock := aCompiledMethod asSandblock. + sandBlock setProperty: #originals toValue: WeakOrderedCollection new. + self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod) + ifOpen: [:existingMethodBlock | + (sandBlock valueOfProperty: #originals) addAll: existingMethodBlock containedExampleWatches. + sandBlock] + ifClosed: [sandBlock]] +] + { #category : #'initialize-release' } SBMultiverse >> gatherElements [ @@ -131,7 +146,7 @@ SBMultiverse >> gatherElements [ have consistency between changes." allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants. - allMethodBlocksContainingWatches := self allCompiledMethodsContainingExampleWatches collect: #asSandblock. + allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches. universes := OrderedCollection new. activeExamples := self allActiveExamples. @@ -139,9 +154,12 @@ SBMultiverse >> gatherElements [ variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten. variants := variants select: #isActive. - watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten. - watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample]. - aWatch hide. aWatch extent: 1@1]. + watches := (allMethodBlocksContainingWatches collect: [:aMethodBlock | | copies | + copies := aMethodBlock containedExampleWatches. + (aMethodBlock valueOfProperty: #originals) withIndexDo: [:original :i | (copies at: i) copySelectedDisplayIndicesFrom: original]. + copies ]) flatten. + watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample]]. + watches reject: #isInEditor thenDo: [:aWatch | aWatch hide. aWatch extent: 1@1] ] diff --git a/packages/Sandblocks-Watch/SBLineChart.class.st b/packages/Sandblocks-Watch/SBLineChart.class.st index 2435a8a3..cb68eb91 100644 --- a/packages/Sandblocks-Watch/SBLineChart.class.st +++ b/packages/Sandblocks-Watch/SBLineChart.class.st @@ -42,7 +42,7 @@ SBLineChart >> datapointExtent [ SBLineChart >> extent: aPoint [ super extent: aPoint. - self targetHeight: aPoint y. + self targetHeight: aPoint y- 6. self scaleY range: (self scaleY range start to: aPoint y). self visualize ] @@ -91,13 +91,12 @@ SBLineChart >> newDatapointFor: aValue at: positionIndex [ color: self datapointDefaultColor; borderWidth: 0; left: positionIndex * self spaceBetweenPoints; - top: self targetHeight - (self scaleY scaledValueOf: aValue) - (self datapointExtent y / 2); + top: ((self targetHeight - (self scaleY scaledValueOf: aValue)) + clampLow: 0 + high: (targetHeight - (self datapointExtent y / 2))); setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue); yourself); - yourself - - - + yourself ] { #category : #visualization } diff --git a/packages/Sandblocks-Watch/SBWatchView.class.st b/packages/Sandblocks-Watch/SBWatchView.class.st index e61d78da..b53b11d0 100644 --- a/packages/Sandblocks-Watch/SBWatchView.class.st +++ b/packages/Sandblocks-Watch/SBWatchView.class.st @@ -9,6 +9,7 @@ Class { 'count', 'shouldUpdateDisplay', 'selectedDisplayIndex', + 'displayOptionsCache', 'fallbackResizer', 'clear', 'updateScheduled' @@ -24,20 +25,16 @@ SBWatchView >> addValue: aWatchValue sized: aSBMorphResizer [ ] { #category : #display } -SBWatchView >> buildCustomDisplayWith: aCollectionOfWatchValues [ +SBWatchView >> buildCustomDisplay [ - | 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)) + addMorphBack: (self displayOptionsCache at: selectedDisplayIndex) second ] { #category : #display } -SBWatchView >> buildDefaultDisplayWith: aCollectionOfWatchValues [ +SBWatchView >> buildDefaultDisplay [ - ^ self watchValuesContainer addAllMorphsBack: (aCollectionOfWatchValues collect: #asValueMorph) + ^ self watchValuesContainer addAllMorphsBack: (watchValues collect: #asValueMorph) ] { #category : #display } @@ -47,7 +44,7 @@ SBWatchView >> buildDisplayOptions [ 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 := options, {{'default'. self buildDefaultDisplay}}. ^ options ] @@ -67,16 +64,15 @@ SBWatchView >> canDeleteChild: aBlock [ SBWatchView >> changeDisplay [ - | index options | - options := self buildDisplayOptions. - index := UIManager default chooseFrom: (options collect: #first). + | index | + index := UIManager default chooseFrom: (self displayOptionsCache collect: #first). index = 0 ifTrue: [^ self]. - (options at: index) first = 'default' + (displayOptionsCache at: index) first = 'default' ifTrue: [selectedDisplayIndex := 0] ifFalse: [selectedDisplayIndex := index]. - self displayOnScrollPane: (options at: index) second. + self displayOnScrollPane: (displayOptionsCache at: index) second. ] { #category : #actions } @@ -148,13 +144,19 @@ SBWatchView >> displayOnScrollPane: aMorph [ ifFalse: [self maxWidth]) ] +{ #category : #accessing } +SBWatchView >> displayOptionsCache [ + + ^ displayOptionsCache ifNil: [displayOptionsCache := self buildDisplayOptions] +] + { #category : #display } SBWatchView >> displayWatchValues [ | valuesMorph | valuesMorph := self isDisplayingWatchValues - ifTrue: [self buildDefaultDisplayWith: watchValues] - ifFalse: [self buildCustomDisplayWith: watchValues]. + ifTrue: [self buildDefaultDisplay] + ifFalse: [self buildCustomDisplay]. "Will sometimes not update size otherwise when rushing through runs" valuesMorph doLayoutSafely. self displayOnScrollPane: valuesMorph. @@ -352,6 +354,25 @@ SBWatchView >> scroller [ ^ self scrollPane scroller ] +{ #category : #display } +SBWatchView >> selectedDisplay [ + + ^ (self displayOptionsCache atWrap: selectedDisplayIndex) second +] + +{ #category : #accessing } +SBWatchView >> selectedDisplayIndex [ + + ^ selectedDisplayIndex +] + +{ #category : #accessing } +SBWatchView >> selectedDisplayIndex: aNumber [ + + "Private, no side effects! Call updateDisplay if an update is desired" + selectedDisplayIndex := aNumber +] + { #category : #accessing } SBWatchView >> shouldUpdateDisplay [ @@ -375,6 +396,13 @@ SBWatchView >> storeAsExample [ self sandblockEditor open: class >> name asSymbol ] +{ #category : #accessing } +SBWatchView >> updateCache [ + + self isDisplayingWatchValues ifTrue: [^ self]. + displayOptionsCache := self buildDisplayOptions +] + { #category : #display } SBWatchView >> updateDisplay [ @@ -388,6 +416,7 @@ SBWatchView >> updateDisplay [ disableLayout: false; visible: true]. + self updateCache. self displayWatchValues ]