From 28a3d2291181d0264994a668d0d5e639b1207f10 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sat, 11 May 2024 11:19:25 -0500 Subject: [PATCH] Utilities for visualizing dictionaries. --- src/MiniDocs/OrderedDictionary.extension.st | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/MiniDocs/OrderedDictionary.extension.st b/src/MiniDocs/OrderedDictionary.extension.st index 4ab1a3f..4c763e4 100644 --- a/src/MiniDocs/OrderedDictionary.extension.st +++ b/src/MiniDocs/OrderedDictionary.extension.st @@ -33,3 +33,64 @@ OrderedDictionary >> redefineTimestampsBefore: dateAndTime [ self at: 'modified' put: dateAndTime asDateAndTime. self at: 'created' put: dateAndTime asDateAndTime - 1 second. ] + +{ #category : #'*MiniDocs' } +OrderedDictionary >> replaceNilsWith: aCharacter [ + self associationsDo: [:each | + each value ifNil: [self at: each key put: aCharacter]. + each value isDictionary ifTrue: [each value replaceNilsWith: aCharacter]. + each value isArray ifTrue: [ | newArray| + newArray := (each value asDataSeries replaceNilsWith: aCharacter) asArray. + self at: each key put: newArray + ] + ] +] + +{ #category : #'*MiniDocs' } +OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [ + | totalNils shortUID | + totalNils := self flattened asDataSeries countNils. + shortUID := [NanoID generate copyFrom: 1 to: 3]. + self associations doWithIndex: [:assoc :i | | subIndex | + subIndex := anInteger asString, '-', i asString. + assoc value + ifNil: [ self at: assoc key put: 'nil-', subIndex ]. + assoc value isBoolean + ifTrue: [ self at: assoc key put: assoc value asString, '-', subIndex ]. + assoc value isDictionary ifTrue: [assoc replaceWithUniqueNilsAndBooleansStartingAt: i]. + assoc value isArray ifTrue: [ | newArray| + newArray := (assoc value asDataSeries replaceNilsWith: 'nil-', shortUID value) asArray. + (newArray includesAny: #(true false)) + ifTrue: [ | response newItem | + response := OrderedCollection new. + self do: [ :item | + item isBoolean + ifTrue: [ newItem := item asString, '-', shortUID value] + ifFalse: [ newItem := item ]. + response add: newItem. + ]. + newArray := response asArray. + ]. + self at: assoc key put: newArray + ] + ] +] + +{ #category : #'*MiniDocs' } +OrderedDictionary >> treeView [ + | view | + view := GtMondrian new. + view nodes + stencil: [ :x | + BlElement new + border: (BlBorder paint: Color black); + geometry: BlEllipseGeometry new; + layout: (BlLinearLayout new alignCenter); + addChild: (BlTextElement text: (x asRopedText fontSize: 17)) ]; + with: (self flatCollectAsSet: #yourself) , self keys. + view edges + stencil: [ :x | BlLineElement new border: (BlBorder paint: (Color blue alpha: 0.5) width: 4) ]; + connect: self associations from: #key toAll: #value. + view layout tree. + ^ view +]