Projects STRLCPY termdash Commits fc1de116
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    CHANGELOG.md
    skipped 6 lines
    7 7   
    8 8  ## [Unreleased]
    9 9   
     10 +## [0.6.1] - 12-Feb-2019
     11 + 
     12 +### Fixes
     13 + 
     14 +- The LineChart widget now correctly places custom labels.
     15 + 
    10 16  ## [0.6.0] - 07-Feb-2019
    11 17   
    12 18  ### Added
    skipped 70 lines
    83 89  - The Gauge widget.
    84 90  - The Text widget.
    85 91   
    86  -[Unreleased]: https://github.com/mum4k/termdash/compare/v0.6.0...devel
     92 +[Unreleased]: https://github.com/mum4k/termdash/compare/v0.6.1...devel
     93 +[0.6.1]: https://github.com/mum4k/termdash/compare/v0.6.0...v0.6.1
    87 94  [0.6.0]: https://github.com/mum4k/termdash/compare/v0.5.0...v0.6.0
    88 95  [0.5.0]: https://github.com/mum4k/termdash/compare/v0.4.0...v0.5.0
    89 96  [0.4.0]: https://github.com/mum4k/termdash/compare/v0.3.0...v0.4.0
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    widgets/linechart/axes/label.go
    skipped 168 lines
    169 169   
    170 170   next := 0
    171 171   for haveLabels := 0; haveLabels <= int(scale.Max.Value); haveLabels = len(res) {
    172  - label, err := colLabel(scale, space, next, customLabels)
     172 + label, err := colLabel(scale, space, customLabels)
    173 173   if err != nil {
    174 174   return nil, err
    175 175   }
    skipped 26 lines
    202 202   return res, nil
    203 203  }
    204 204   
    205  -// colLabel returns a label placed either at the beginning of the space.
     205 +// colLabel returns a label placed at the beginning of the space.
    206 206  // The space is adjusted according to how much space was taken by the label.
    207 207  // Returns nil, nil if the label doesn't fit in the space.
    208  -func colLabel(scale *XScale, space *xSpace, labelNum int, customLabels map[int]string) (*Label, error) {
    209  - var val *Value
    210  - if custom, ok := customLabels[labelNum]; ok {
    211  - val = NewTextValue(custom)
    212  - } else {
    213  - pos := space.Relative()
    214  - v, err := scale.CellLabel(pos.X)
    215  - if err != nil {
    216  - return nil, fmt.Errorf("unable to determine label value for column %d: %v", pos.X, err)
    217  - }
    218  - val = v
     208 +func colLabel(scale *XScale, space *xSpace, customLabels map[int]string) (*Label, error) {
     209 + pos := space.Relative()
     210 + label, err := scale.CellLabel(pos.X)
     211 + if err != nil {
     212 + return nil, fmt.Errorf("unable to determine label value for column %d: %v", pos.X, err)
    219 213   }
    220 214   
    221  - labelLen := len(val.Text())
     215 + if custom, ok := customLabels[int(label.Value)]; ok {
     216 + label = NewTextValue(custom)
     217 + }
     218 + 
     219 + labelLen := len(label.Text())
    222 220   if labelLen > space.Remaining() {
    223 221   return nil, nil
    224 222   }
    skipped 4 lines
    229 227   }
    230 228   
    231 229   return &Label{
    232  - Value: val,
     230 + Value: label,
    233 231   Pos: abs,
    234 232   }, nil
    235 233  }
    skipped 1 lines
  • ■ ■ ■ ■ ■ ■
    widgets/linechart/axes/label_test.go
    skipped 265 lines
    266 266   },
    267 267   },
    268 268   {
     269 + desc: "custom labels provided, but only some fit, regression for #117",
     270 + numPoints: 8,
     271 + graphWidth: 5,
     272 + graphZero: image.Point{0, 1},
     273 + customLabels: map[int]string{
     274 + 0: "a",
     275 + 1: "b",
     276 + 2: "c",
     277 + 3: "d",
     278 + 4: "e",
     279 + 5: "f",
     280 + 6: "g",
     281 + 7: "h",
     282 + },
     283 + want: []*Label{
     284 + {NewTextValue("a"), image.Point{0, 3}},
     285 + {NewTextValue("g"), image.Point{4, 3}},
     286 + },
     287 + },
     288 + {
    269 289   desc: "only some custom labels provided",
    270 290   numPoints: 4,
    271 291   graphWidth: 100,
    skipped 55 lines
Please wait...
Page is in error, reload to recover