-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Presents watches in a simple grid per permutation (does not handle ov…
…erflow yet)
- Loading branch information
Showing
8 changed files
with
284 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
Class { | ||
#name : #SBCluster, | ||
#superclass : #Morph, | ||
#instVars : [ | ||
'morphResizer' | ||
], | ||
#category : #'Sandblocks-Babylonian' | ||
} | ||
|
||
{ #category : #'initialize-release' } | ||
SBCluster class >> newFromWatches: aCollectionOfSBExampleWatches havingSize: aSBMorphResizer [ | ||
|
||
^ self new | ||
morphResizer: aSBMorphResizer; | ||
buildFromWatches: aCollectionOfSBExampleWatches; | ||
yourself | ||
|
||
] | ||
|
||
{ #category : #visualisation } | ||
SBCluster >> buildFromWatches: aCollectionOfSBExampleWatches [ | ||
|
||
| matrix | | ||
matrix := self watchesAsMatrix: aCollectionOfSBExampleWatches. | ||
(matrix rowCount < 2 or: [matrix columnCount < 2]) ifTrue: [ ^ 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 : #initialization } | ||
SBCluster >> initialize [ | ||
|
||
super initialize. | ||
|
||
self | ||
color: Color white; | ||
changeTableLayout; | ||
listDirection: #topToBottom; | ||
vResizing: #shrinkWrap; | ||
hResizing: #shrinkWrap | ||
] | ||
|
||
{ #category : #accessing } | ||
SBCluster >> morphResizer [ | ||
|
||
^ morphResizer | ||
] | ||
|
||
{ #category : #accessing } | ||
SBCluster >> morphResizer: aSBMorphResizer [ | ||
|
||
morphResizer := aSBMorphResizer | ||
] | ||
|
||
{ #category : #helper } | ||
SBCluster >> newCellMorph [ | ||
|
||
^ self morphResizer applyOn: ( | ||
Morph new | ||
color: Color blue; | ||
changeTableLayout; | ||
listDirection: #topToBottom; | ||
listCentering: #center; | ||
wrapCentering: #center; | ||
hResizing: #rigid; | ||
vResizing: #rigid) | ||
] | ||
|
||
{ #category : #helper } | ||
SBCluster >> newContainerMorph [ | ||
|
||
^ Morph new | ||
color: Color banana; | ||
changeTableLayout; | ||
listDirection: #topToBottom; | ||
hResizing: #shrinkWrap; | ||
vResizing: #shrinkWrap; | ||
cellInset: SBGrid cellInsetValue | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBCluster >> newLeftColumnFrom: aCollectionOfMorphs [ | ||
|
||
"Height should be set, but width can vary" | ||
^ self newContainerMorph | ||
cellPositioning: #rightCenter; | ||
addAllMorphsBack: (aCollectionOfMorphs collect: [:aMorph | | ||
(self wrapInCell: aMorph flexVertically: false flexHorizontally: true) | ||
listDirection: #rightToLeft]) | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBCluster >> newTopLeftCornerPlaceholder [ | ||
|
||
^ self newCellMorph | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBCluster >> newTopRowFrom: aCollectionOfMorphs [ | ||
|
||
"Width should be set, but height can vary" | ||
^ self newContainerMorph | ||
listDirection: #leftToRight; | ||
listCentering: #bottomRight; | ||
cellPositioning: #bottomCenter; | ||
hResizing: #spaceFill; | ||
addAllMorphsBack: (aCollectionOfMorphs collect: [:aMorph | | ||
aMorph rotationDegrees: 90. | ||
self wrapInCell: aMorph owner flexVertically: true flexHorizontally: false]) | ||
] | ||
|
||
{ #category : #converting } | ||
SBCluster >> watchesAsMatrix: aCollectionOfSBExampleWatches [ | ||
|
||
"Determine how watches are dissected to create a grid. We assume inclusion of headings per default" | ||
^ self subclassResponsibility. | ||
] | ||
|
||
{ #category : #helper } | ||
SBCluster >> wrapInCell: aMorph [ | ||
|
||
^ self wrapInCell: aMorph flexVertically: false flexHorizontally: false | ||
|
||
] | ||
|
||
{ #category : #helper } | ||
SBCluster >> wrapInCell: aMorph flexVertically: aVBoolean flexHorizontally: aHBoolean [ | ||
|
||
| cell | | ||
cell := self newCellMorph. | ||
|
||
aVBoolean ifTrue: [cell vResizing: #shrinkWrap]. | ||
aHBoolean ifTrue: [cell hResizing: #shrinkWrap]. | ||
|
||
cell addMorph: aMorph. | ||
|
||
^ cell | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Class { | ||
#name : #SBExampleCluster, | ||
#superclass : #SBCluster, | ||
#category : #'Sandblocks-Babylonian' | ||
} | ||
|
||
{ #category : #'as yet unclassified' } | ||
SBExampleCluster >> watchesAsMatrix: aCollectionOfSBExampleWatches [ | ||
|
||
"Determine how watches are dissected to create a grid" | ||
^ self subclassResponsibility. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Class { | ||
#name : #SBGrid, | ||
#superclass : #Morph, | ||
#instVars : [ | ||
'columnCount' | ||
], | ||
#category : #'Sandblocks-Babylonian' | ||
} | ||
|
||
{ #category : #constants } | ||
SBGrid class >> cellInsetValue [ | ||
|
||
^ 5 | ||
] | ||
|
||
{ #category : #'initialize-release' } | ||
SBGrid class >> newDisplaying: aMatrixOfMorphs [ | ||
|
||
^ self new | ||
buildFromMatrix: aMatrixOfMorphs; | ||
yourself | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBGrid >> buildFromMatrix: aMatrixOfMorphs [ | ||
|
||
self submorphs copy do: #abandon. | ||
columnCount := aMatrixOfMorphs columnCount. | ||
|
||
aMatrixOfMorphs do: [:aMorph | self addMorphBack: aMorph]. | ||
self updateWidthToPersistColumns. | ||
] | ||
|
||
{ #category : #initialization } | ||
SBGrid >> initialize [ | ||
|
||
super initialize. | ||
columnCount := 5. | ||
|
||
self | ||
color: Color transparent; | ||
layoutPolicy: TableLayout new; | ||
listDirection: #leftToRight; | ||
wrapDirection: #topToBottom; | ||
wrapCentering: #topLeft; | ||
cellInset: self class cellInsetValue; | ||
width: 500; | ||
vResizing: #shrinkWrap. | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
SBGrid >> resizeContents: aSBMorphResizer [ | ||
|
||
self submorphsDo: [:aSubmorph | aSBMorphResizer applyOn: aSubmorph]. | ||
self updateWidthToPersistColumns. | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBGrid >> updateWidthToPersistColumns [ | ||
|
||
self width: (columnCount * (self submorphs first width + (2 * self class cellInsetValue))) | ||
] |
32 changes: 32 additions & 0 deletions
32
packages/Sandblocks-Babylonian/SBPermutationCluster.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Class { | ||
#name : #SBPermutationCluster, | ||
#superclass : #SBCluster, | ||
#category : #'Sandblocks-Babylonian' | ||
} | ||
|
||
{ #category : #visualisation } | ||
SBPermutationCluster >> extractedLeftHeadingsFrom: aCollectionOfSBExampleWatches [ | ||
|
||
^ (aCollectionOfSBExampleWatches collect: [:aWatch | aWatch expression]) | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBPermutationCluster >> extractedTopHeadingsFrom: aCollectionOfSBExampleWatches [ | ||
|
||
^ (aCollectionOfSBExampleWatches first exampleToDisplay values collect: [:aDisplay | aDisplay labelMorph]) | ||
] | ||
|
||
{ #category : #visualisation } | ||
SBPermutationCluster >> watchesAsMatrix: aCollectionOfSBExampleWatches [ | ||
|
||
| 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 | | ||
aWatch exampleToDisplay withIndexDo: [:exampleDisplayAssc :column | . | ||
matrix at: row+1 at: column+1 put: (exampleDisplayAssc display)]]. | ||
^ matrix | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters