Skip to content

Commit

Permalink
Wardley Map: JSON exporter supports notes [feenkcom/gtoolkit#3781]
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed May 20, 2024
1 parent c65d6da commit 0f8d41e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/GToolkit-WardleyMap/GtWardleyMapAsDictionaryExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ GtWardleyMapAsDictionaryExporter >> visitWardleyId: aUUID [

{ #category : #visiting }
GtWardleyMapAsDictionaryExporter >> visitWardleyMap: aWardleyMap [
^ OrderedDictionary new
| aDictionary |
aDictionary := OrderedDictionary new.

aWardleyMap notes
ifNotEmpty: [ :allNotes |
aDictionary
at: #notes
put: (allNotes collect: [ :eachNote | eachNote accept: self ] as: Array) ].

^ aDictionary
at: #nodes put: (aWardleyMap nodes collect: [ :eachNode | eachNode accept: self ] as: Array);
at: #edges put: (aWardleyMap edges collect: [ :eachEdge | eachEdge accept: self ] as: Array);
yourself
Expand Down Expand Up @@ -76,9 +85,9 @@ GtWardleyMapAsDictionaryExporter >> visitWardleyMapNodeLabel: aWardleyMapNodeLab
GtWardleyMapAsDictionaryExporter >> visitWardleyMapNote: aWardleyMapNote [
^ OrderedDictionary new
at: #id put: (self visitWardleyId: aWardleyMapNote id);
at: #label put: (aWardleyMapNote label);
at: #color put: (self visitColor: aWardleyMapNote color);
at: #x put: aWardleyMapNote x;
at: #y put: aWardleyMapNote y;
at: #label put: (aWardleyMapNote labelModel accept: self);
yourself
]
7 changes: 7 additions & 0 deletions src/GToolkit-WardleyMap/GtWardleyMapConstants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ GtWardleyMapConstants class >> nodeSize [
^ 12 @ 12
]

{ #category : #'api - constants' }
GtWardleyMapConstants class >> noteColor [
"I represent a default note model color"

^ Color black
]

{ #category : #'api - constants' }
GtWardleyMapConstants class >> pipelineHeight [
"I represent a pipeline height in pixels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,30 @@ GtWardleyMapJsonExporterImporterExamples >> exportWardleyMapAsDictionary [
{ #category : #export }
GtWardleyMapJsonExporterImporterExamples >> exportWardleyMapWithPipelineInnerNodesAsDictionary [
<gtExample>
| aWardleyMap anExportedDictionary aFirstNodeDictionary aFirstNodeLabelDictionary aSecondNodeDictionary anEdgeDictionary aFirstNodePipelineDictionary aFirstNodePipelineInnerNodesArray aFourthNodeDictionary aFifthNodeDictionary aSecondNodePipelineDictionary |
| aWardleyMap anExportedDictionary aFirstNodeDictionary aFirstNodeLabelDictionary aSecondNodeDictionary anEdgeDictionary aFirstNodePipelineDictionary aFirstNodePipelineInnerNodesArray aFourthNodeDictionary aFifthNodeDictionary aSecondNodePipelineDictionary aNoteADictionary |

aWardleyMap := GtWardleyMapModelExamples new newMapWithPipelineInnerNodes.
anExportedDictionary := aWardleyMap accept: GtWardleyMapAsDictionaryExporter new.

self assert: anExportedDictionary size equals: 2.
self assert: anExportedDictionary size equals: 3.
self assert: (anExportedDictionary includesKey: #notes).
self assert: (anExportedDictionary includesKey: #nodes).
self assert: (anExportedDictionary includesKey: #edges).

self assert: (anExportedDictionary at: #notes) size equals: 1.
self assert: (anExportedDictionary at: #nodes) size equals: 7.

aNoteADictionary := (anExportedDictionary at: #notes) at: 1.
self assert: aNoteADictionary size equals: 5.
self assert: (aNoteADictionary at: #x) equals: 0.47.
self assert: (aNoteADictionary at: #y) equals: 0.4.
self assert: (aNoteADictionary at: #label) equals: 'Note A'.
self assert: (aNoteADictionary at: #color) size equals: 4.
self assert: ((aNoteADictionary at: #color) at: #green) equals: Color lightOrange green.
self assert: ((aNoteADictionary at: #color) at: #blue) equals: Color lightOrange blue.
self assert: ((aNoteADictionary at: #color) at: #red) equals: Color lightOrange red.
self assert: ((aNoteADictionary at: #color) at: #alpha) equals: Color lightOrange alpha.

aFirstNodeDictionary := (anExportedDictionary at: #nodes) at: 1.
self assert: aFirstNodeDictionary size equals: 8.
self assert: (aFirstNodeDictionary at: #x) equals: 0.25.
Expand Down
12 changes: 11 additions & 1 deletion src/GToolkit-WardleyMap/GtWardleyMapModelExamples.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ GtWardleyMapModelExamples >> newMapWithNodes_nodeAtRight_displayPipeline [
{ #category : #'examples - model' }
GtWardleyMapModelExamples >> newMapWithPipelineInnerNodes [
<gtExample>
| aWardleyMap aNodeA aNodeD aNodeE aNodeF aNodeG |
| aWardleyMap aNodeA aNodeD aNodeE aNodeF aNodeG aNoteA |
aWardleyMap := self newMapWithPipelines.

aNodeA := aWardleyMap nodes first.
Expand All @@ -464,11 +464,17 @@ GtWardleyMapModelExamples >> newMapWithPipelineInnerNodes [
aNodeG coordinate: 0.38 @ 0.78.
aNodeG color: Color yellow darker.
aNodeG label: 'Node G'.

aNoteA := GtWardleyMapNoteModelExamples new newNote.
aNoteA label: 'Note A'.
aNoteA color: Color lightOrange.
aNoteA coordinate: 0.47 @ 0.40.

aWardleyMap addNode: aNodeD.
aWardleyMap addNode: aNodeE.
aWardleyMap addNode: aNodeF.
aWardleyMap addNode: aNodeG.
aWardleyMap addNote: aNoteA.

self assert: aNodeD coordinate equals: 0.2 @ 0.761.
self assert: aNodeE coordinate equals: 0.3 @ 0.762.
Expand All @@ -495,6 +501,10 @@ GtWardleyMapModelExamples >> newMapWithPipelineInnerNodes [
self assert: aNodeF coordinate equals: 0.41 @ 0.76.
self assert: aNodeG coordinate equals: 0.38 @ 0.78.

self assert: aNoteA label equals: 'Note A'.
self assert: aNoteA color equals: Color lightOrange.
"self assert: aNoteA coordinate equals: 0.04 @ 0.80."

^ aWardleyMap
]

Expand Down
3 changes: 2 additions & 1 deletion src/GToolkit-WardleyMap/GtWardleyMapNoteElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ GtWardleyMapNoteElement >> labelElementDo: aBlock [

{ #category : #'event handling' }
GtWardleyMapNoteElement >> onNoteLabelTextChanged [
labelElement text: self wardleyMapNoteViewModel label
labelElement text: self wardleyMapNoteViewModel label.
labelElement aptitude foreground: self wardleyMapNoteViewModel color.
]
6 changes: 4 additions & 2 deletions src/GToolkit-WardleyMap/GtWardleyMapNoteModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ GtWardleyMapNoteModel >> id: anObject [
GtWardleyMapNoteModel >> initialize [
super initialize.

label := 'note'.
id := nil
label := 'Note'.
id := nil.
coordinate := 0.5@0.5.
color := GtWardleyMapConstants noteColor.
]

{ #category : #accessing }
Expand Down
18 changes: 18 additions & 0 deletions src/GToolkit-WardleyMap/GtWardleyMapNoteModelExamples.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : #GtWardleyMapNoteModelExamples,
#superclass : #Object,
#category : #'GToolkit-WardleyMap-Examples'
}

{ #category : #'instance creation' }
GtWardleyMapNoteModelExamples >> newNote [
<gtExample>
| aWardleyNote |

aWardleyNote := GtWardleyMapNoteModel new.
self assert: aWardleyNote label equals: 'Note'.
self assert: aWardleyNote coordinate equals: 0.5 @ 0.5.
self assert: aWardleyNote color equals: GtWardleyMapConstants nodeColor.

^ aWardleyNote
]
10 changes: 10 additions & 0 deletions src/GToolkit-WardleyMap/GtWardleyMapNoteViewModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ GtWardleyMapNoteViewModel >> announcer [
^ announcer ifNil: [ announcer := Announcer new ]
]

{ #category : #'api - accessing' }
GtWardleyMapNoteViewModel >> color [
^ self wardleyMapNoteModel color
]

{ #category : #'api - accessing' }
GtWardleyMapNoteViewModel >> color: aColor [
^ self wardleyMapNoteModel color: aColor
]

{ #category : #'api - accessing' }
GtWardleyMapNoteViewModel >> coordinate [
^ self wardleyMapNoteModel coordinate
Expand Down

0 comments on commit 0f8d41e

Please sign in to comment.