SetScaleY sets the Y scale number of lines and color
(lines int, color *math32.Color)
| 204 | |
| 205 | // SetScaleY sets the Y scale number of lines and color |
| 206 | func (ch *Chart) SetScaleY(lines int, color *math32.Color) { |
| 207 | |
| 208 | if ch.scaleY != nil { |
| 209 | ch.ClearScaleY() |
| 210 | } |
| 211 | |
| 212 | if lines < 2 { |
| 213 | lines = 2 |
| 214 | } |
| 215 | |
| 216 | // Add scale lines |
| 217 | ch.scaleY = newChartScaleY(ch, lines, color) |
| 218 | ch.Add(ch.scaleY) |
| 219 | |
| 220 | // Add scale labels |
| 221 | // The position of the labels will be set by 'recalc()' |
| 222 | value := ch.minY |
| 223 | step := (ch.maxY - ch.minY) / float32(lines-1) |
| 224 | for i := 0; i < lines; i++ { |
| 225 | l := NewLabel(fmt.Sprintf(ch.formatY, value)) |
| 226 | l.SetColor4(math32.NewColor4("black")) |
| 227 | l.SetFontSize(ch.fontSizeY) |
| 228 | ch.Add(l) |
| 229 | ch.labelsY = append(ch.labelsY, l) |
| 230 | value += step |
| 231 | } |
| 232 | ch.recalc() |
| 233 | } |
| 234 | |
| 235 | // ClearScaleY removes the Y scale if it was previously set |
| 236 | func (ch *Chart) ClearScaleY() { |
no test coverage detected