Skip to content

Commit

Permalink
Implemented reative x axis labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Mar 5, 2024
1 parent 5beb296 commit e041672
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/Roassal-Chart/RSHistogramPlot.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Class {
'x',
'bins',
'bars',
'binningStrategy'
'binningStrategy',
'isRelativeVerticalTicks'
],
#category : 'Roassal-Chart-Core',
#package : 'Roassal-Chart',
Expand All @@ -52,6 +53,13 @@ RSHistogramPlot class >> of: aCollection on: aBloc [
^ self new collectDataOf: aCollection on: aBloc
]

{ #category : 'accessing' }
RSHistogramPlot >> absoluteVerticalTicks [

isRelativeVerticalTicks := false.
self verticalTick labelConversion: [ :labelValue | labelValue ]
]

{ #category : 'accessing' }
RSHistogramPlot >> bars [
^ bars
Expand Down Expand Up @@ -139,8 +147,10 @@ RSHistogramPlot >> definedValuesY [

{ #category : 'initialization' }
RSHistogramPlot >> initialize [

super initialize.
self binningStrategy: RSDefaultBinning new
self binningStrategy: RSDefaultBinning new.
isRelativeVerticalTicks := false
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -179,6 +189,16 @@ RSHistogramPlot >> numberOfBins: aNumber [
self computeXYValues
]

{ #category : 'accessing' }
RSHistogramPlot >> relativeVerticalTicks [

"Adjust the vertical ticks label to show the relative labels. E.g. instead of showing that a bin appeared 17 times it will show 50%"

isRelativeVerticalTicks := true.
self verticalTick
labelConversion: [ :labelValue | (labelValue / x size) * 100 asInteger ]
]

{ #category : 'rendering' }
RSHistogramPlot >> renderIn: canvas [

Expand Down Expand Up @@ -209,3 +229,15 @@ RSHistogramPlot >> x: aCollection [
x := aCollection sorted.
self computeXYValues
]

{ #category : 'accessing' }
RSHistogramPlot >> yTicksRangeMax: max numberOfTicks: numberOfTicks [

| relativeMax |
relativeMax := isRelativeVerticalTicks
ifFalse: [ max ]
ifTrue: [ x size * (max / 100) ].

self verticalTick ticksData:
((0 to: relativeMax count: numberOfTicks) collect: #asInteger)
]

0 comments on commit e041672

Please sign in to comment.