|
1 |
| -Class { |
2 |
| - #name : #GLHCommitDistributionVisualization, |
3 |
| - #superclass : #MiAbstractVisualization, |
4 |
| - #instVars : [ |
5 |
| - 'groupCommitBlock' |
6 |
| - ], |
7 |
| - #category : #'GitLabHealth-Model-Visualization' |
8 |
| -} |
9 |
| - |
10 |
| -{ #category : #'instance creation' } |
11 |
| -GLHCommitDistributionVisualization >> forCommits: commits [ |
12 |
| - |
13 |
| - | c lb oldestCommit horizontal commitGroups groupToCommitByDate alreadyAdded dates | |
14 |
| - c := RSCompositeChart new. |
15 |
| - commits ifEmpty: [ ^ c canvas]. |
16 |
| - oldestCommit := commits last. |
17 |
| - dates := (oldestCommit committed_date to: Date today) dates. |
18 |
| - |
19 |
| - commitGroups := commits groupedBy: self groupCommitBlock. |
20 |
| - |
21 |
| - groupToCommitByDate := commitGroups associations collect: [ :assoc | |
22 |
| - assoc key -> (dates collect: [ :date | |
23 |
| - date |
24 |
| - -> |
25 |
| - (assoc value select: [ :commit | |
26 |
| - commit committed_date asDate = date ]) ]) ]. |
27 |
| - |
28 |
| - alreadyAdded := dates collect: [ :d | 0 ]. |
29 |
| - groupToCommitByDate do: [ :assocGroupToCommitByDate | |
30 |
| - | chart | |
31 |
| - chart := (RSAbstractChart barHeights: |
32 |
| - (assocGroupToCommitByDate value collect: [ :dateToCommit | |
33 |
| - dateToCommit value size ])) bottom: alreadyAdded. |
34 |
| - c add: chart. |
35 |
| - alreadyAdded := chart yValues ]. |
36 |
| - |
37 |
| - horizontal := c horizontalTick fromNames: |
38 |
| - (dates collect: [ :date | date printString ]). |
39 |
| - horizontal configuration fontSize: 2. |
40 |
| - horizontal useDiagonalLabel. |
41 |
| - c verticalTick integer. |
42 |
| - c ylabel: 'Number of commits'. |
43 |
| - c title: 'Number of commits by date'. |
44 |
| - c build. |
45 |
| - lb := RSLegend new. |
46 |
| - lb layout vertical. |
47 |
| - commitGroups keys doWithIndex: [ :groupObject :index | |
48 |
| - lb |
49 |
| - text: groupObject fullDisplayString |
50 |
| - withBoxColor: (c plots at: index) computeColor ]. |
51 |
| - lb container: c canvas. |
52 |
| - lb location |
53 |
| - right; |
54 |
| - middle; |
55 |
| - offset: 10 @ 0. |
56 |
| - lb build. |
57 |
| - ^ c canvas |
58 |
| -] |
59 |
| - |
60 |
| -{ #category : #'as yet unclassified' } |
61 |
| -GLHCommitDistributionVisualization >> groupCommitBlock [ |
62 |
| - |
63 |
| - ^ groupCommitBlock |
64 |
| -] |
65 |
| - |
66 |
| -{ #category : #'as yet unclassified' } |
67 |
| -GLHCommitDistributionVisualization >> groupCommitBlock: anObject [ |
68 |
| - |
69 |
| - groupCommitBlock := anObject |
70 |
| -] |
71 |
| - |
72 |
| -{ #category : #initialization } |
73 |
| -GLHCommitDistributionVisualization >> initialize [ |
74 |
| - |
75 |
| - super initialize. |
76 |
| - groupCommitBlock := [ :commit | commit commitCreator ] |
77 |
| -] |
| 1 | +Class { |
| 2 | + #name : #GLHCommitDistributionVisualization, |
| 3 | + #superclass : #MiAbstractVisualization, |
| 4 | + #instVars : [ |
| 5 | + 'groupCommitBlock' |
| 6 | + ], |
| 7 | + #category : #'GitLabHealth-Model-Visualization' |
| 8 | +} |
| 9 | + |
| 10 | +{ #category : #'instance creation' } |
| 11 | +GLHCommitDistributionVisualization >> forCommits: aCommitsCollection [ |
| 12 | + |
| 13 | + | c lb horizontal commitGroups groupToCommitByDate alreadyAdded dates commits| |
| 14 | + c := RSCompositeChart new. |
| 15 | + aCommitsCollection ifEmpty: [ ^ c canvas]. |
| 16 | + commits := (aCommitsCollection sort: [ :c1 :c2 | c1 committed_date > c2 committed_date ]). |
| 17 | + "collect dates from oldest to youngest among commits" |
| 18 | + dates := (commits last committed_date to: commits first committed_date) dates. |
| 19 | + |
| 20 | + "default is group by commitCreator (initialize)" |
| 21 | + commitGroups := commits groupedBy: self groupCommitBlock. |
| 22 | + |
| 23 | + groupToCommitByDate := commitGroups associations collect: [ :assoc | |
| 24 | + assoc key -> (dates collect: [ :date | |
| 25 | + date |
| 26 | + -> |
| 27 | + (assoc value select: [ :commit | |
| 28 | + "weird, but only way I know to compare two dates with different timezone." |
| 29 | + commit committed_date asDate asString = date asString ]) ]) ]. |
| 30 | + |
| 31 | + alreadyAdded := dates collect: [ :d | 0 ]. |
| 32 | + groupToCommitByDate do: [ :assocGroupToCommitByDate | |
| 33 | + | chart | |
| 34 | + chart := (RSAbstractChart barHeights: |
| 35 | + (assocGroupToCommitByDate value collect: [ :dateToCommit | |
| 36 | + dateToCommit value size ])) bottom: alreadyAdded. |
| 37 | + c add: chart. |
| 38 | + alreadyAdded := alreadyAdded + chart yValues ]. |
| 39 | + |
| 40 | + horizontal := c horizontalTick fromNames: |
| 41 | + (dates collect: [ :date | date printString ]). |
| 42 | + horizontal configuration fontSize: 10. |
| 43 | + horizontal useDiagonalLabel. |
| 44 | + c verticalTick integer. |
| 45 | + c ylabel: 'Number of commits'. |
| 46 | + c title: 'Number of commits by date'. |
| 47 | + c build. |
| 48 | + lb := RSLegend new. |
| 49 | + lb layout vertical. |
| 50 | + commitGroups keys doWithIndex: [ :groupObject :index | |
| 51 | + lb |
| 52 | + text: groupObject fullDisplayString |
| 53 | + withBoxColor: (c plots at: index) computeColor ]. |
| 54 | + lb container: c canvas. |
| 55 | + lb location |
| 56 | + right; |
| 57 | + middle; |
| 58 | + offset: 10 @ 0. |
| 59 | + lb build. |
| 60 | + ^ c canvas |
| 61 | +] |
| 62 | + |
| 63 | +{ #category : #'as yet unclassified' } |
| 64 | +GLHCommitDistributionVisualization >> groupCommitBlock [ |
| 65 | + |
| 66 | + ^ groupCommitBlock |
| 67 | +] |
| 68 | + |
| 69 | +{ #category : #'as yet unclassified' } |
| 70 | +GLHCommitDistributionVisualization >> groupCommitBlock: anObject [ |
| 71 | + |
| 72 | + groupCommitBlock := anObject |
| 73 | +] |
| 74 | + |
| 75 | +{ #category : #initialization } |
| 76 | +GLHCommitDistributionVisualization >> initialize [ |
| 77 | + |
| 78 | + super initialize. |
| 79 | + groupCommitBlock := [ :commit | commit commitCreator ] |
| 80 | +] |
0 commit comments