Creating quotes histogram exporter.

This commit is contained in:
ruidajo 2022-04-20 16:44:34 -05:00
parent 66298fc248
commit 57adfca53a
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,34 @@
accessing
exportQuotesHistogram
| quotesOccurrences labels diagram x quotesHistogram |
quotesOccurrences := self quotesSortedByOccurrences.
x := 1 to: quotesOccurrences size.
labels := quotesOccurrences keys.
quotesHistogram := RSChart new.
quotesHistogram extent: 800@200.
diagram := RSBarPlot new x: x y: quotesOccurrences values.
diagram color: (Color r:(89/255) g:(217/255) b:(95/255)).
quotesHistogram addPlot: diagram.
quotesHistogram addDecoration: (RSHorizontalTick new
fromNames: labels;
labelRotation: 0;
fontSize: 80 /quotesOccurrences size;
yourself).
quotesHistogram addDecoration: (RSVerticalTick new
integer;
fontSize: 80 /quotesOccurrences size).
quotesHistogram build.
quotesHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.pdf')fullName;
export.
quotesHistogram canvas pngExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.png')fullName;
export.
^ self folder / 'quotes-histogram.png'

View File

@ -0,0 +1,39 @@
accessing
exportQuotesHistogramWithBars: aNumberOfBars
| keysToRemove quotes x labels quotesHistogram diagram |
quotes := self quotesSortedByOccurrences.
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
keysToRemove := OrderedCollection new.
1 to: quotes size - aNumberOfBars do:
[ :i | keysToRemove add: (quotes keys at: i + aNumberOfBars) ].
quotes removeKeys: keysToRemove.
x := 1 to: quotes size.
labels := quotes keys.
quotesHistogram := RSChart new.
quotesHistogram extent: 800@200.
diagram := RSBarPlot new x: x y: quotes values.
diagram color: (Color r:(89/255) g:(217/255) b:(95/255)).
quotesHistogram addPlot: diagram.
quotesHistogram addDecoration: (RSHorizontalTick new
fromNames: labels;
labelRotation: 0;
fontSize: 80 /quotes size;
yourself).
quotesHistogram addDecoration: (RSVerticalTick new
integer;
fontSize: 80 /quotes size).
quotesHistogram build.
quotesHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.pdf')fullName;
export.
quotesHistogram canvas pngExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.png')fullName;
export.
^ self folder / 'quotes-histogram.png'