newChartScaleX creates and returns a pointer to a new chartScaleX for the specified chart, number of lines and color
(chart *Chart, lines int, color *math32.Color)
| 455 | // newChartScaleX creates and returns a pointer to a new chartScaleX for the specified |
| 456 | // chart, number of lines and color |
| 457 | func newChartScaleX(chart *Chart, lines int, color *math32.Color) *chartScaleX { |
| 458 | |
| 459 | sx := new(chartScaleX) |
| 460 | sx.chart = chart |
| 461 | sx.lines = lines |
| 462 | sx.uniBounds.Init("Bounds") |
| 463 | |
| 464 | // Appends bottom horizontal line |
| 465 | positions := math32.NewArrayF32(0, 0) |
| 466 | positions.Append(0, -1+deltaLine, 0, 1, -1+deltaLine, 0) |
| 467 | |
| 468 | // Appends vertical lines |
| 469 | step := 1 / float32(lines) |
| 470 | for i := 0; i < lines; i++ { |
| 471 | nx := float32(i) * step |
| 472 | if i == 0 { |
| 473 | nx += deltaLine |
| 474 | } |
| 475 | positions.Append(nx, 0, 0, nx, -1, 0) |
| 476 | } |
| 477 | |
| 478 | // Creates geometry and adds VBO |
| 479 | geom := geometry.NewGeometry() |
| 480 | geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition)) |
| 481 | |
| 482 | // Initializes the panel graphic |
| 483 | gr := graphic.NewGraphic(sx, geom, gls.LINES) |
| 484 | sx.mat.Init(color) |
| 485 | gr.AddMaterial(sx, &sx.mat, 0, 0) |
| 486 | sx.Panel.InitializeGraphic(chart.ContentWidth(), chart.ContentHeight(), gr) |
| 487 | |
| 488 | sx.recalc() |
| 489 | return sx |
| 490 | } |
| 491 | |
| 492 | // recalc recalculates the position and size of this scale inside its parent |
| 493 | func (sx *chartScaleX) recalc() { |
no test coverage detected