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