-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from hpi-swa/feature/display-graph
Graphs for Example Watches
- Loading branch information
Showing
9 changed files
with
890 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
" | ||
A numerical legend for a scale | ||
" | ||
Class { | ||
#name : #SBAxisNotation, | ||
#superclass : #Morph, | ||
#instVars : [ | ||
'scale', | ||
'numberTicks' | ||
], | ||
#category : #'Sandblocks-Watch' | ||
} | ||
|
||
{ #category : #'initialize-release' } | ||
SBAxisNotation class >> newFromScale: aSBScale ticking: aNumber [ | ||
|
||
^ self new | ||
scale: aSBScale | ||
numberTicks: aNumber | ||
] | ||
|
||
{ #category : #initialization } | ||
SBAxisNotation >> initialize [ | ||
|
||
super initialize. | ||
|
||
numberTicks := 3. | ||
scale := SBScale newLinearScaleWithDomain: (0 to: 100) forRange: (0 to: 100). | ||
|
||
self color: Color transparent; | ||
layoutPolicy: ProportionalLayout new; | ||
hResizing: #shrinkWrap; | ||
vResizing: #spaceFill | ||
] | ||
|
||
{ #category : #accessing } | ||
SBAxisNotation >> numberTicks [ | ||
|
||
^ numberTicks | ||
] | ||
|
||
{ #category : #accessing } | ||
SBAxisNotation >> numberTicks: aNumber [ | ||
|
||
numberTicks := aNumber. | ||
|
||
self visualize | ||
] | ||
|
||
{ #category : #visualization } | ||
SBAxisNotation >> relativeTickHeights [ | ||
|
||
| section adjustedTicks | | ||
(self numberTicks < 2) ifTrue: [^#()]. | ||
|
||
"Starting count from 0 here instead of 1" | ||
adjustedTicks := self numberTicks - 1. | ||
section := 1 / adjustedTicks. | ||
^ (0 to: adjustedTicks) collect: [:i | (section * i)] | ||
] | ||
|
||
{ #category : #accessing } | ||
SBAxisNotation >> scale [ | ||
|
||
^ scale | ||
] | ||
|
||
{ #category : #accessing } | ||
SBAxisNotation >> scale: aSBScale [ | ||
|
||
scale := aSBScale. | ||
|
||
self visualize | ||
] | ||
|
||
{ #category : #accessing } | ||
SBAxisNotation >> scale: aSBScale numberTicks: aNumber [ | ||
|
||
scale := aSBScale. | ||
numberTicks := aNumber. | ||
|
||
self visualize | ||
] | ||
|
||
{ #category : #visualization } | ||
SBAxisNotation >> visualize [ | ||
|
||
self submorphs copy do: #abandon. | ||
|
||
self addAllMorphsBack: ( | ||
self relativeTickHeights collect: [:aFraction | | annotation | | ||
annotation := SBOwnTextMorph new | ||
contents: ((self scale domainValueOfRelative: aFraction) asFloat asString); | ||
verySmall; | ||
layoutFrame: (LayoutFrame new topFraction: (1 - aFraction)). | ||
|
||
"Move text center to be fraction. 0 and 1 will be adjusted to align at the borders." | ||
annotation layoutFrame topOffset: (-0.5*(annotation minExtent y)). | ||
(aFraction = 1) ifTrue: [annotation layoutFrame topOffset: 0]. | ||
(aFraction = 0) ifTrue: [annotation layoutFrame topOffset: (-1*(annotation minExtent y))]. | ||
|
||
annotation]) | ||
|
||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Class { | ||
#name : #SBBarChart, | ||
#superclass : #SBLineChart, | ||
#category : #'Sandblocks-Watch' | ||
} | ||
|
||
{ #category : #'initialize-release' } | ||
SBBarChart class >> newWithValues: traceValues [ | ||
|
||
| valuesToVisualize | | ||
valuesToVisualize := traceValues | ||
ifEmpty: [#(0)] | ||
ifNotEmpty: [traceValues]. | ||
^ self new | ||
traceValues: valuesToVisualize; | ||
scaleY: (SBScale | ||
newLinearScaleWithDomain: (({valuesToVisualize min. 0} min) to: valuesToVisualize max) | ||
forRange: (0 to: self canvasHeight)); | ||
yourself | ||
] | ||
|
||
{ #category : #'visualization - constants' } | ||
SBBarChart >> barWidth [ | ||
|
||
^ self spaceBetweenPoints / 2 | ||
] | ||
|
||
{ #category : #visualization } | ||
SBBarChart >> newBarFor: aValue at: positionIndex [ | ||
|
||
"There is an extra Morph containing the datapoint itself so the tooltip is far easier to activate through more area" | ||
^ Morph new | ||
height: self class preferredHeight; | ||
left: ((positionIndex - 0.5) * self spaceBetweenPoints) rounded; | ||
width: self spaceBetweenPoints; | ||
color: Color transparent; | ||
balloonText: aValue printString; | ||
addMorph: (Morph new | ||
color: self datapointDefaultColor; | ||
width: self barWidth; | ||
height: {(self scaleY scaledValueOf: aValue). 1} max; | ||
bottom: self class canvasHeight + self class heightMargin; | ||
left: positionIndex * self spaceBetweenPoints; | ||
setProperty: #chartValue toValue: (self scaleY scaledValueOf: aValue); | ||
yourself); | ||
yourself | ||
|
||
|
||
|
||
] | ||
|
||
{ #category : #visualization } | ||
SBBarChart >> newDataPoints [ | ||
|
||
^ self traceValues collectWithIndex: [:aTraceValue :index | self newBarFor: aTraceValue at: index] | ||
] | ||
|
||
{ #category : #visualization } | ||
SBBarChart >> newLineFrom: aDataPointMorph1 to: aDataPointMorph2 [ | ||
|
||
^ LineMorph | ||
from: aDataPointMorph1 topCenter | ||
to: aDataPointMorph2 topCenter | ||
color: ((self lineColorFrom: aDataPointMorph1 to: aDataPointMorph2) alpha: 0.2) | ||
width: self lineWidth | ||
|
||
|
||
] |
Oops, something went wrong.