Changeset 181
- Timestamp:
- 01/23/10 18:57:21 (2 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
CHANGELOG (modified) (1 diff)
-
src/org/jergometer/diagram/BikeDiagram.java (modified) (1 diff)
-
src/org/jergometer/gui/Diagram.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG
r179 r181 7 7 * [stefan] * fixed some I18N issues 8 8 * solved issue #161: design an icon for JErgometer 9 * implemented feature #154: add legend to the diagram 9 10 10 11 2010-01-22 -
trunk/src/org/jergometer/diagram/BikeDiagram.java
r175 r181 17 17 suffix = "-dest"; 18 18 } 19 diagram.addGraph("pulse" + suffix, new Diagram.Graph("Pulse", Diagram.brighten(b, new Color(255,0,0, a)), s ), Diagram.Side.left);20 diagram.addGraph("pedalRPM" + suffix, new Diagram.Graph("Pedal RPM", Diagram.brighten(b, new Color(0,255,0, a)), s ), Diagram.Side.left);21 diagram.addGraph("power" + suffix, new Diagram.Graph("Power", Diagram.brighten(b, new Color(0,0,255, a)), s ), Diagram.Side.left);22 diagram.addGraph("performance" + suffix, new Diagram.Graph("Performance", Diagram.brighten(b, new Color(0,0,0, a)), s ), Diagram.Side.left);19 diagram.addGraph("pulse" + suffix, new Diagram.Graph("Pulse", Diagram.brighten(b, new Color(255,0,0, a)), s, bright), Diagram.Side.left); 20 diagram.addGraph("pedalRPM" + suffix, new Diagram.Graph("Pedal RPM", Diagram.brighten(b, new Color(0,255,0, a)), s, bright), Diagram.Side.left); 21 diagram.addGraph("power" + suffix, new Diagram.Graph("Power", Diagram.brighten(b, new Color(0,0,255, a)), s, bright), Diagram.Side.left); 22 diagram.addGraph("performance" + suffix, new Diagram.Graph("Performance", Diagram.brighten(b, new Color(0,0,0, a)), s, bright), Diagram.Side.left); 23 23 } 24 24 } -
trunk/src/org/jergometer/gui/Diagram.java
r180 r181 142 142 graphs[lr.getInt()].add(graph); 143 143 key2Graph.put(key, graph); 144 145 drawLegend(backgroundImage.createGraphics()); 146 147 redrawImage(); 148 repaint(); 144 149 } 145 150 … … 212 217 for(Graph graph : graphs[lr.getInt()]) drawGraph(g, graph, lr); 213 218 } 219 drawLegend(g); 214 220 215 221 // axis … … 346 352 } 347 353 354 private void drawLegend(Graphics2D g) { 355 int width = backgroundImage.getWidth(); 356 int height = backgroundImage.getHeight(); 357 358 int y = height - margin.bottom + 22; 359 Range range = timeRange; 360 int minX = margin.left; 361 int maxX = width - margin.right; 362 363 // font metrics 364 FontMetrics fm = g.getFontMetrics(); 365 366 int spacing = 30; 367 368 // determine total with of the legend 369 int totalWidth = -10; 370 for (ArrayList<Graph> graphs2 : graphs) { 371 for (Graph graph : graphs2) { 372 if (!graph.hideInLegend) { 373 Rectangle2D bounds = fm.getStringBounds(graph.name, g); 374 totalWidth += bounds.getWidth() + spacing; 375 } 376 } 377 } 378 379 // draw legend 380 int x = minX + ((maxX-minX) - totalWidth)/2; 381 for (ArrayList<Graph> graphs2 : graphs) { 382 for (Graph graph : graphs2) { 383 if (!graph.hideInLegend) { 384 Rectangle2D bounds = fm.getStringBounds(graph.name, g); 385 g.setColor(graph.color); 386 g.setStroke(normalStroke); 387 g.drawString(graph.name, x, y + (int) bounds.getHeight() + markerSize + 1); 388 g.setColor(Color.BLACK); 389 g.setStroke(normalStroke); 390 391 x += bounds.getWidth() + spacing; 392 } 393 } 394 } 395 } 396 348 397 private void drawGraph(Graphics2D g, Graph graph, Side lr) { 349 398 g.setPaint(graph.color); … … 443 492 public Color color; 444 493 public Stroke stroke; 494 public boolean hideInLegend; 445 495 public ArrayList<Point> timedValues; 446 496 447 public Graph(String name, Color color, Stroke stroke ) {497 public Graph(String name, Color color, Stroke stroke, boolean hideInLegend) { 448 498 this.name = name; 449 499 this.color = color; 450 500 this.stroke = stroke; 501 this.hideInLegend = hideInLegend; 451 502 timedValues = new ArrayList<Point>(); 452 503 } 453 504 454 505 public Graph(String name, Color color) { 455 this(name, color, new BasicStroke(0.5f) );506 this(name, color, new BasicStroke(0.5f), false); 456 507 } 457 508 }
![(please configure the [header_logo] section in trac.ini)](https://jergometer.org/images/fork_me_on_github.png)