1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-27 13:48:49 +08:00

Merge branch 'hotfix-0.6.1' into devel

This commit is contained in:
Jakub Sobon 2019-02-12 23:41:16 -05:00
commit 29a2010b28
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
4 changed files with 43 additions and 17 deletions

View File

@ -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
@ -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

View File

@ -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 (

View File

@ -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
}
@ -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)
}
labelLen := len(val.Text())
if custom, ok := customLabels[int(label.Value)]; ok {
label = NewTextValue(custom)
}
labelLen := len(label.Text())
if labelLen > space.Remaining() {
return nil, nil
}
@ -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
}

View File

@ -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,