Skip to content

Commit

Permalink
Self-review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Jan 27, 2019
1 parent 2e6da63 commit 21083a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- The LineChart now has an option to not anchor the Y axis at the zero value
for positive and negative series that don't contain zero value.
- The LineChart now has an option to change the behavior of the Y axis from
zero anchored to adaptive.
- Lint errors reported on the Go report card.

## [0.5.0] - 21-Jan-2019
Expand Down
6 changes: 4 additions & 2 deletions widgets/linechart/axes/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ func NewYScale(min, max float64, graphHeight, nonZeroDecimals int, mode YScaleMo
}

case YScaleModeAdaptive:
// Only make the scale zero based if all the data points are equal, so
// we can still draw something.
// Even in this mode, we still anchor the axis at the zero if all the
// data points are equal, so we can still draw something.
if min > 0 && min == max {
min = 0
}
if max < 0 && min == max {
max = 0
}
default:
return nil, fmt.Errorf("unsupported mode: %v(%d)", mode, mode)
}
diff := max - min
step := NewValue(diff/float64(usablePixels), nonZeroDecimals)
Expand Down
9 changes: 9 additions & 0 deletions widgets/linechart/axes/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ func TestYScale(t *testing.T) {
{4, nil, true},
},
},
{
desc: "fails on an unsupported Y scale mode",
min: 0,
max: 0,
graphHeight: 1,
nonZeroDecimals: 2,
mode: YScaleMode(-1),
wantErr: true,
},
{
desc: "works without data points",
min: 0,
Expand Down
11 changes: 4 additions & 7 deletions widgets/linechart/linechartdemo/linechartdemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"math"
"time"

"github.com/mum4k/termdash"
Expand All @@ -33,13 +34,9 @@ import (
func sineInputs() []float64 {
var res []float64

/*
for i := 0; i < 200; i++ {
v := math.Sin(float64(i) / 100 * math.Pi)
res = append(res, v)
}*/
for i := 1600; i < 1800; i++ {
res = append(res, float64(i))
for i := 0; i < 200; i++ {
v := math.Sin(float64(i) / 100 * math.Pi)
res = append(res, v)
}
return res
}
Expand Down

0 comments on commit 21083a9

Please sign in to comment.