Refactoring quotes and retweets histograms.
This commit is contained in:
parent
ff38d34dc4
commit
485572a81e
@ -1,30 +1,49 @@
|
||||
accessing
|
||||
exportHistogramFor: aDictionary By: aTypeString
|
||||
"TODO: quotes and retweets"
|
||||
| messagesByTimeSpan histogram diagram tempMessages |
|
||||
| messagesDict histogram diagram tempMessages labels subtotals |
|
||||
tempMessages := self perform: (aDictionary at: 'messagesType') asSymbol.
|
||||
|
||||
tempMessages ifEmpty: [ self exportEmptyHistogramNamed:
|
||||
(aDictionary at: 'messagesType'), '-histogram' ].
|
||||
aTypeString isNumber ifTrue: [ messagesByTimeSpan := tempMessages splitBytimeSpansOf: aTypeString ].
|
||||
|
||||
((((aDictionary at: 'messagesType') = 'tweets') or: [(aDictionary at: 'messagesType') = 'replies'])
|
||||
and: aTypeString isNumber)
|
||||
ifTrue: [ messagesDict := tempMessages splitBytimeSpansOf: aTypeString ].
|
||||
(aTypeString = 'day' or: [ aTypeString = 'days' ])
|
||||
ifTrue: [ messagesByTimeSpan := tempMessages splitByDays ].
|
||||
ifTrue: [ messagesDict := tempMessages splitByDays ].
|
||||
(aTypeString = 'week' or: [ aTypeString = 'weeks' ])
|
||||
ifTrue: [ messagesByTimeSpan := tempMessages splitByWeeks ].
|
||||
ifTrue: [ messagesDict := tempMessages splitByWeeks ].
|
||||
|
||||
(((aDictionary at: 'messagesType') = 'retweets') or: [ (aDictionary at: 'messagesType') = 'quotes' ])
|
||||
ifTrue: [
|
||||
messagesDict := tempMessages asMessagesUserNamesSortedByOccurrences.
|
||||
((aTypeString > messagesDict size) or: [ aTypeString = 1 ])
|
||||
ifFalse: [ | keysToRemove |
|
||||
keysToRemove := OrderedCollection new.
|
||||
1 to: messagesDict size - aTypeString do:
|
||||
[ :i | keysToRemove add: (messagesDict keys at: i + aTypeString) ].
|
||||
messagesDict removeKeys: keysToRemove. ].
|
||||
labels := messagesDict keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
subtotals := messagesDict values
|
||||
]
|
||||
ifFalse: [ labels := messagesDict keys.
|
||||
subtotals := (messagesDict values collect: [ :collection | collection size ])].
|
||||
|
||||
histogram := RSChart new.
|
||||
histogram extent: (aDictionary at: 'extent').
|
||||
diagram := RSBarPlot new
|
||||
y: (messagesByTimeSpan values collect: [ :collection | collection size ]).
|
||||
"diagram color: (Color r:(91/255) g:(131/255) b:(222/255))."
|
||||
y: subtotals.
|
||||
diagram color: (aDictionary at: 'color').
|
||||
histogram addPlot: diagram.
|
||||
histogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: messagesByTimeSpan keys;
|
||||
fromNames: labels;
|
||||
labelRotation: 0;
|
||||
fontSize: 68 /messagesByTimeSpan size;
|
||||
fontSize: 68 /messagesDict size;
|
||||
yourself).
|
||||
histogram addDecoration: (RSVerticalTick new
|
||||
integer;
|
||||
fontSize: 68 /messagesByTimeSpan size).
|
||||
fontSize: 68 /messagesDict size).
|
||||
histogram build.
|
||||
^ histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder
|
@ -1,46 +0,0 @@
|
||||
accessing
|
||||
exportQuotesHistogram
|
||||
|
||||
| quotesOccurrences labels diagram quotesHistogram |
|
||||
|
||||
self quotes ifEmpty: [
|
||||
quotesHistogram := RSChart new.
|
||||
quotesHistogram extent: 800@200.
|
||||
quotesHistogram build.
|
||||
quotesHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'quotes-histogram.pdf')fullName;
|
||||
export.
|
||||
^ self
|
||||
].
|
||||
quotesOccurrences := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||
labels := quotesOccurrences keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
quotesHistogram := RSChart new.
|
||||
quotesHistogram extent: 800@200.
|
||||
diagram := RSBarPlot new
|
||||
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: 72 /quotesOccurrences size;
|
||||
yourself).
|
||||
quotesHistogram addDecoration: (RSVerticalTick new
|
||||
asFloat: 2;
|
||||
fontSize: 72 /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'
|
@ -1,7 +1,16 @@
|
||||
accessing
|
||||
exportQuotesHistogramWithBars: aNumberOfBars
|
||||
|
||||
| keysToRemove quotes labels quotesHistogram diagram |
|
||||
| quotesDict |
|
||||
quotesDict := {
|
||||
'messagesType' -> 'quotes'.
|
||||
'extent' -> (800@200).
|
||||
'color' -> (Color r:(89/255) g:(217/255) b:(95/255))
|
||||
} asDictionary.
|
||||
^ self exportHistogramFor: quotesDict By: aNumberOfBars
|
||||
|
||||
|
||||
"| keysToRemove quotes labels quotesHistogram diagram |
|
||||
quotes := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
|
||||
keysToRemove := OrderedCollection new.
|
||||
@ -37,4 +46,4 @@ exportQuotesHistogramWithBars: aNumberOfBars
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'quotes-histogram.png')fullName;
|
||||
export.
|
||||
^ self folder / 'quotes-histogram.png'
|
||||
^ self folder / 'quotes-histogram.png'"
|
@ -1,37 +0,0 @@
|
||||
accessing
|
||||
exportRetweetsHistogram
|
||||
|
||||
| retweetsOccurrences labels retweetColor diagram retweetsHistogram |
|
||||
|
||||
retweetsOccurrences := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||
retweetColor := (Color r:(217/255) g:(56/255) b: (124/255)).
|
||||
labels := retweetsOccurrences keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
retweetsHistogram := RSChart new.
|
||||
retweetsHistogram extent: 800@200.
|
||||
diagram := RSBarPlot new
|
||||
x: (1 to: retweetsOccurrences size)
|
||||
y: retweetsOccurrences values.
|
||||
diagram color: retweetColor.
|
||||
retweetsHistogram addPlot: diagram.
|
||||
retweetsHistogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: labels;
|
||||
labelRotation: 0;
|
||||
fontSize: 72 /retweetsOccurrences size;
|
||||
yourself).
|
||||
retweetsHistogram addDecoration: (RSVerticalTick new
|
||||
integer;
|
||||
fontSize: 72 /retweetsOccurrences size).
|
||||
retweetsHistogram build.
|
||||
|
||||
retweetsHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'retweets-histogram.pdf')fullName;
|
||||
export.
|
||||
retweetsHistogram canvas pngExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'retweets-histogram.png')fullName;
|
||||
export.
|
||||
^ self folder / 'retweets-histogram.png'
|
@ -1,41 +1,10 @@
|
||||
accessing
|
||||
exportRetweetsHistogramWithBars: aNumberOfBars
|
||||
|
||||
| keysToRemove retweets labels retweetsHistogram diagram |
|
||||
retweets := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||
(aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ].
|
||||
keysToRemove := OrderedCollection new.
|
||||
1 to: retweets size - aNumberOfBars do:
|
||||
[ :i | keysToRemove add: (retweets keys at: i + aNumberOfBars) ].
|
||||
retweets removeKeys: keysToRemove.
|
||||
|
||||
labels := retweets keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
retweetsHistogram := RSChart new.
|
||||
retweetsHistogram extent: 800@200.
|
||||
diagram := RSBarPlot new
|
||||
x: (1 to: retweets size)
|
||||
y: retweets values.
|
||||
diagram color: (Color r:(217/255) g:(56/255) b: (124/255)).
|
||||
retweetsHistogram addPlot: diagram.
|
||||
retweetsHistogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: labels;
|
||||
labelRotation: 0;
|
||||
fontSize: 72 /retweets size;
|
||||
yourself).
|
||||
retweetsHistogram addDecoration: (RSVerticalTick new
|
||||
integer;
|
||||
fontSize: 72 /retweets size).
|
||||
retweetsHistogram build.
|
||||
|
||||
retweetsHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'retweets-histogram.pdf')fullName;
|
||||
export.
|
||||
retweetsHistogram canvas pngExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'retweets-histogram.png')fullName;
|
||||
export.
|
||||
^ self folder / 'retweets-histogram.png'
|
||||
| retweetsDict |
|
||||
retweetsDict := {
|
||||
'messagesType' -> 'retweets'.
|
||||
'extent' -> (800@200).
|
||||
'color' -> (Color r:(217/255) g:(56/255) b: (124/255))
|
||||
} asDictionary.
|
||||
^ self exportHistogramFor: retweetsDict By: aNumberOfBars
|
Loading…
Reference in New Issue
Block a user