Skip to content

Commit

Permalink
Merge branch 'hotfix-0.6.1' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Feb 13, 2019
2 parents 6473cab + 9df48f9 commit 29a2010
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Generalised mouse button FSM for use in widgets that need to track mouse
button clicks.

=======
## [0.6.1] - 12-Feb-2019

### Fixes

- The LineChart widget now correctly places custom labels.

## [0.6.0] - 07-Feb-2019

### Changed
Expand Down Expand Up @@ -92,7 +99,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The Gauge widget.
- The Text widget.

[Unreleased]: https://github.com/mum4k/termdash/compare/v0.6.0...devel
[Unreleased]: https://github.com/mum4k/termdash/compare/v0.6.1...devel
[0.6.1]: https://github.com/mum4k/termdash/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/mum4k/termdash/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/mum4k/termdash/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/mum4k/termdash/compare/v0.3.0...v0.4.0
Expand Down
2 changes: 1 addition & 1 deletion attrrange/attrrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Package attrrange simplifies tracking of attributes that apply to a range of
// items.
// Refer to the examples if the test file for details on usage.
// Refer to the examples in the test file for details on usage.
package attrrange

import (
Expand Down
28 changes: 13 additions & 15 deletions widgets/linechart/axes/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func xLabels(scale *XScale, graphZero image.Point, customLabels map[int]string)

next := 0
for haveLabels := 0; haveLabels <= int(scale.Max.Value); haveLabels = len(res) {
label, err := colLabel(scale, space, next, customLabels)
label, err := colLabel(scale, space, customLabels)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,23 +202,21 @@ func xLabels(scale *XScale, graphZero image.Point, customLabels map[int]string)
return res, nil
}

// colLabel returns a label placed either at the beginning of the space.
// colLabel returns a label placed at the beginning of the space.
// The space is adjusted according to how much space was taken by the label.
// Returns nil, nil if the label doesn't fit in the space.
func colLabel(scale *XScale, space *xSpace, labelNum int, customLabels map[int]string) (*Label, error) {
var val *Value
if custom, ok := customLabels[labelNum]; ok {
val = NewTextValue(custom)
} else {
pos := space.Relative()
v, err := scale.CellLabel(pos.X)
if err != nil {
return nil, fmt.Errorf("unable to determine label value for column %d: %v", pos.X, err)
}
val = v
func colLabel(scale *XScale, space *xSpace, customLabels map[int]string) (*Label, error) {
pos := space.Relative()
label, err := scale.CellLabel(pos.X)
if err != nil {
return nil, fmt.Errorf("unable to determine label value for column %d: %v", pos.X, err)
}

if custom, ok := customLabels[int(label.Value)]; ok {
label = NewTextValue(custom)
}

labelLen := len(val.Text())
labelLen := len(label.Text())
if labelLen > space.Remaining() {
return nil, nil
}
Expand All @@ -229,7 +227,7 @@ func colLabel(scale *XScale, space *xSpace, labelNum int, customLabels map[int]s
}

return &Label{
Value: val,
Value: label,
Pos: abs,
}, nil
}
20 changes: 20 additions & 0 deletions widgets/linechart/axes/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,26 @@ func TestXLabels(t *testing.T) {
{NewTextValue("d"), image.Point{94, 3}},
},
},
{
desc: "custom labels provided, but only some fit, regression for #117",
numPoints: 8,
graphWidth: 5,
graphZero: image.Point{0, 1},
customLabels: map[int]string{
0: "a",
1: "b",
2: "c",
3: "d",
4: "e",
5: "f",
6: "g",
7: "h",
},
want: []*Label{
{NewTextValue("a"), image.Point{0, 3}},
{NewTextValue("g"), image.Point{4, 3}},
},
},
{
desc: "only some custom labels provided",
numPoints: 4,
Expand Down

0 comments on commit 29a2010

Please sign in to comment.