Skip to content

Commit

Permalink
Refactors clusters and views
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Nov 21, 2023
1 parent 5b2daa1 commit dadb435
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 112 deletions.
49 changes: 20 additions & 29 deletions packages/Sandblocks-Babylonian/SBCluster.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,10 @@ Class {
#category : #'Sandblocks-Babylonian'
}

{ #category : #'initialize-release' }
SBCluster class >> newFromWatches: aCollectionOfSBExampleWatches havingSize: aSBMorphResizer [

^ self new
morphResizer: aSBMorphResizer;
buildFromWatches: aCollectionOfSBExampleWatches;
yourself

]

{ #category : #visualisation }
SBCluster >> buildFromWatches: aCollectionOfSBExampleWatches [
SBCluster >> buildDisplayMatrix [

| matrix |
matrix := self watchesAsMatrix: aCollectionOfSBExampleWatches.
matrix ifEmpty: [ ^ self].

self addAllMorphsBack: {
self newTopRowFrom: (matrix atRow: 1) allButFirst. "ignore placeholder morph"
self newContainerMorph
listDirection: #leftToRight;
cellInset: 0;
addAllMorphsBack: {
self newLeftColumnFrom: (matrix atColumn: 1) allButFirst. "ignore placeholder morph"
SBGrid newDisplaying:
((matrix atRows: 2 to: matrix rowCount columns: 2 to: matrix columnCount)
collect: [:aMorph | self wrapInCell: aMorph])}}
self subclassResponsibility
]

{ #category : #initialization }
Expand Down Expand Up @@ -121,11 +98,25 @@ SBCluster >> newTopRowFrom: aCollectionOfMorphs [
(self wrapInCell: aMorph owner flexVertically: true flexHorizontally: false) borderWidth: 0])
]

{ #category : #converting }
SBCluster >> watchesAsMatrix: aCollectionOfSBExampleWatches [
{ #category : #visualisation }
SBCluster >> visualize [

"Determine how watches are dissected to create a grid. We assume inclusion of headings per default"
^ self subclassResponsibility.
| matrix |
self submorphs copy do: #delete.

matrix := self buildDisplayMatrix.
matrix ifEmpty: [ ^ self].

self addAllMorphsBack: {
self newTopRowFrom: (matrix atRow: 1) allButFirst. "ignore placeholder morph"
self newContainerMorph
listDirection: #leftToRight;
cellInset: 0;
addAllMorphsBack: {
self newLeftColumnFrom: (matrix atColumn: 1) allButFirst. "ignore placeholder morph"
SBGrid newDisplaying:
((matrix atRows: 2 to: matrix rowCount columns: 2 to: matrix columnCount)
collect: [:aMorph | self wrapInCell: aMorph])}}
]

{ #category : #helper }
Expand Down
99 changes: 99 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleCluster.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Class {
#name : #SBExampleCluster,
#superclass : #SBCluster,
#instVars : [
'displayedIndex',
'multiverse'
],
#category : #'Sandblocks-Babylonian'
}

{ #category : #'initialize-release' }
SBExampleCluster class >> newForSize: aSBMorphResizer multiverse: aSBMultiverse displaying: aNumber [

^ self new
morphResizer: aSBMorphResizer;
multiverse: aSBMultiverse;
displayedIndex: aNumber;
visualize;
yourself

]

{ #category : #visualisation }
SBExampleCluster >> buildDisplayMatrix [

| matrix |
matrix := Matrix
rows: (self multiverse universes first watches size) + 1
columns: self multiverse universes size + 1.

matrix atRow: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedTopHeadingsFrom: self multiverse)).
matrix atColumn: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedLeftHeadingsFrom: self multiverse)).

self multiverse universes withIndexDo: [:aUniverse :column |
(self extractRowsFrom: aUniverse) withIndexDo: [:aCellMorph :row|
matrix at: row+1 at: column+1 put: aCellMorph]].

^ matrix
]

{ #category : #accessing }
SBExampleCluster >> displayedIndex [

^ displayedIndex
]

{ #category : #accessing }
SBExampleCluster >> displayedIndex: aNumber [

displayedIndex := aNumber
]

{ #category : #visualisation }
SBExampleCluster >> extractRowsFrom: aUniverse [

^ aUniverse watches collect: [:anExample | | display displayedMorphs |
display := (anExample exampleToDisplay associations at: self displayedIndex) value display.
displayedMorphs := display displayedMorphs collect: [:aMorph |
aMorph watchValue morphResizer: self morphResizer.
aMorph watchValue asValueMorph].
(displayedMorphs size = 1)
ifTrue: [displayedMorphs first]
ifFalse: [self newCellMorph
borderWidth: 0;
when: #clicked send: #exploreValues to: display;
listDirection: #leftToRight;
wrapDirection: #topToBottom;
addAllMorphsBack: displayedMorphs]]
]

{ #category : #visualisation }
SBExampleCluster >> extractedLeftHeadingsFrom: aSBMultiverse [

^ (aSBMultiverse universes first watches collect: [:aWatch | aWatch expression copy])
]

{ #category : #visualisation }
SBExampleCluster >> extractedTopHeadingsFrom: aSBMultiverse [

^ (aSBMultiverse universes collect: [:aUniverse |
self newContainerMorph
addAllMorphsBack: {
SBStringMorph new contents: aUniverse activePermutation asString.
SBButton newApplyPermutationFor: aUniverse activePermutation}])
]

{ #category : #accessing }
SBExampleCluster >> multiverse [

^ multiverse
]

{ #category : #accessing }
SBExampleCluster >> multiverse: aSBMultiverse [

multiverse := aSBMultiverse
]
47 changes: 47 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleGridsView.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Class {
#name : #SBExampleGridsView,
#superclass : #SBGridResultsView,
#category : #'Sandblocks-Babylonian'
}

{ #category : #building }
SBExampleGridsView >> buildAllPossibleResults [

self multiverse activeExamples withIndexDo: [:anExample :anIndex | self buildExampleFor: anIndex]
]

{ #category : #building }
SBExampleGridsView >> buildExampleFor: aNumber [

gridContainer addMorphBack: (self containerRow cellPositioning: #center;
addAllMorphsBack: {
self containerRow listDirection: #topToBottom;
addAllMorphsBack: {
SBOwnTextMorph new contents: 'example: ', (self multiverse activeExamples at: aNumber) label.
SBExampleCluster
newForSize: SBMorphResizer newMedium
multiverse: self multiverse
displaying: aNumber}.
LineMorph from: 0@0 to: 0@50 color: Color black width: 2}).

self updateContainerWidth.
]

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

super initialize.

self name: 'Example Grid View'.
]

{ #category : #updating }
SBExampleGridsView >> updateContainerWidth [

gridContainer width:
(self multiverse activeExamples size safeSquareRoot ceiling)
* (gridContainer lastSubmorph fullBounds width
+ (2 * gridContainer cellInset)
+ (2 * gridContainer cellGap)
+ 10)
]
2 changes: 1 addition & 1 deletion packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ SBExploriants >> visualize [

| tabs |
self width: 0.
"tabs will visualize as soon as multiverse is finished"
tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse newInEditor: self sandblockEditor).
tabs do: #visualize.

self namedBlocks: tabs activeIndex: 1.

Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SBExploriantsView class >> block: aSBBlock named: aString [
{ #category : #'instance creation' }
SBExploriantsView class >> getTabsInMultiverse: aSBMultiverse [

^ {SBPermutationGridsView. SBPlainResultsView. SBVariantsView}
^ {SBPermutationGridsView. SBExampleGridsView. SBPlainResultsView. SBVariantsView}
collect: [:mySubclass | mySubclass newMultiverse: aSBMultiverse]
]

Expand Down
11 changes: 11 additions & 0 deletions packages/Sandblocks-Babylonian/SBGridResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ SBGridResultsView >> newGridContainer [
vResizing: #shrinkWrap;
yourself
]

{ #category : #updating }
SBGridResultsView >> updateContainerWidth [

gridContainer width:
(self multiverse universes size safeSquareRoot ceiling)
* (gridContainer lastSubmorph fullBounds width
+ (2 * gridContainer cellInset)
+ (2 * gridContainer cellGap)
+ 10)
]
25 changes: 19 additions & 6 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [
]

{ #category : #'initialize-release' }
SBMultiverse >> initialize [
SBMultiverse >> initialize [

| permutations |
super initialize.

"We are looking for already opened methods so that we can assign the
variant there as the original in SBVariantProxy. That way, we immediately
have consistency between changes."
Expand All @@ -130,14 +131,26 @@ SBMultiverse >> initialize [
variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
activeExamples := self allActiveExamples.

universes := (SBPermutation allPermutationsOf: variants) collect: [:aPermutation |
self createUniverseFomPermutation: aPermutation].

self triggerEvent: #initialized.
permutations := SBPermutation allPermutationsOf: variants.
universes := OrderedCollection new.
"sicher dass wir das so machen wollen?"
[permutations do: [:aPermutation |
SBActiveVariantPermutation value: aPermutation.
activeExamples do: #runSynchronouslyIgnoreReturn.
universes add: (self createUniverseFomPermutation: aPermutation)].
self resetWatchesToOriginalPermutationRunning: activeExamples.
self triggerEvent: #initialized] forkAt: Processor userSchedulingPriority.


]

{ #category : #state }
SBMultiverse >> resetWatchesToOriginalPermutationRunning: activeExamples [

SBActiveVariantPermutation value: nil.
activeExamples do: #runSynchronouslyIgnoreReturn
]

{ #category : #accessing }
SBMultiverse >> sandblockEditor [

Expand Down
63 changes: 45 additions & 18 deletions packages/Sandblocks-Babylonian/SBPermutationCluster.class.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
Class {
#name : #SBPermutationCluster,
#superclass : #SBCluster,
#instVars : [
'watches'
],
#category : #'Sandblocks-Babylonian'
}

{ #category : #'initialize-release' }
SBPermutationCluster class >> newForSize: aSBMorphResizer havingWatches: aCollectionOfSBExampleWatches [

^ self new
morphResizer: aSBMorphResizer;
watches: aCollectionOfSBExampleWatches;
visualize;
yourself

]

{ #category : #converting }
SBPermutationCluster >> buildDisplayMatrix [

| matrix |
self watches ifEmpty: [^ Matrix new].
matrix := Matrix
rows: self watches size + 1
columns: (self watches first examples size) + 1.

matrix atRow: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedTopHeadingsFrom: self watches)).
matrix atColumn: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedLeftHeadingsFrom: self watches)).

self watches withIndexDo: [:aWatch :row |
(self extractColumnsFrom: aWatch) withIndexDo: [:aCellMorph :column|
matrix at: row+1 at: column+1 put: aCellMorph]].

^ matrix
]

{ #category : #visualisation }
SBPermutationCluster >> extractColumnsFrom: anExampleWatch [
SBPermutationCluster >> extractColumnsFrom: aCollectionOfSBExampleWatches [

^ anExampleWatch exampleToDisplay collect: [:anExampleValueDisplay | | displayedMorphs |
^ aCollectionOfSBExampleWatches exampleToDisplay collect: [:anExampleValueDisplay | | displayedMorphs |
displayedMorphs := anExampleValueDisplay display displayedMorphs
collect: [:aMorph | aMorph watchValue morphResizer: self morphResizer. aMorph watchValue asValueMorph].
(displayedMorphs size = 1)
Expand All @@ -32,22 +67,14 @@ SBPermutationCluster >> extractedTopHeadingsFrom: aCollectionOfSBExampleWatches
^ (aCollectionOfSBExampleWatches first exampleToDisplay values collect: [:aDisplay | aDisplay labelMorph copy])
]

{ #category : #converting }
SBPermutationCluster >> watchesAsMatrix: aCollectionOfSBExampleWatches [
{ #category : #accessing }
SBPermutationCluster >> watches [

| matrix |
matrix := Matrix
rows: aCollectionOfSBExampleWatches size + 1
columns: (aCollectionOfSBExampleWatches first examples size) + 1.

matrix atRow: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedTopHeadingsFrom: aCollectionOfSBExampleWatches)).
matrix atColumn: 1 put: ({self newTopLeftCornerPlaceholder},
(self extractedLeftHeadingsFrom: aCollectionOfSBExampleWatches)).

aCollectionOfSBExampleWatches withIndexDo: [:aWatch :row |
(self extractColumnsFrom: aWatch) withIndexDo: [:aCellMorph :column|
matrix at: row+1 at: column+1 put: aCellMorph]].
^ watches
]

^ matrix
{ #category : #accessing }
SBPermutationCluster >> watches: aCollectionOfSBExampleWatches [

watches := aCollectionOfSBExampleWatches
]
Loading

0 comments on commit dadb435

Please sign in to comment.