From 29c5a95811e807404742b0e9a034d9cc87d3316a Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Sat, 20 Jan 2018 09:15:56 +0100 Subject: [PATCH] nice -legend --- nbproject/project.properties | 2 +- src/chart/MasterChart.java | 2 +- src/chart/painter/YLegendPainter.java | 41 ++++++++++++++++++--------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index b278698..106576b 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Thu, 18 Jan 2018 10:46:19 +0100 +#Sat, 20 Jan 2018 00:00:54 +0100 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/chart/MasterChart.java b/src/chart/MasterChart.java index 3d04877..855a874 100644 --- a/src/chart/MasterChart.java +++ b/src/chart/MasterChart.java @@ -152,7 +152,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver { this.yLegend.setChartDef(chartDef); OHLCChartPainter p; - mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000*60*24); + mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000*1); this.xScrollBar.setMaximum(0); diff --git a/src/chart/painter/YLegendPainter.java b/src/chart/painter/YLegendPainter.java index 77a6c54..76672c7 100644 --- a/src/chart/painter/YLegendPainter.java +++ b/src/chart/painter/YLegendPainter.java @@ -64,20 +64,35 @@ public class YLegendPainter extends OHLCChartPainter { // calculate the number of captionable bars int ldist = em_size * 2; int steps = y_height / ldist; + + // distance between bars + float stepsize = (y_max - y_min) / steps; + + // round stepsize to power of 10 + float stepsize10 = (float)Math.pow(10,Math.ceil(Math.log10(stepsize))); + // build inverse of stepsize + float stepsize10i = 1 / stepsize10; - this.getRoundNumber(90); - - //Rectangle dim; - // dim = p.getSize(); - // dim = this.clip_bounds; - // Dimension rv = this.getSize(); -// int yw = (int) (this.yl_width * em_size); -// g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height); + // calculate the first y value + float firstyv = (float)Math.ceil(y_min * stepsize10i) / stepsize10i; + float y1 = getY(minmax.getMin(false)); - float y2 = getY(minmax.getMax(false)); - float ydiff = y1 - y2; -// System.out.printf("%s y1: %f, y2: %f, diff %f\n", Boolean.toString(c_mm.isLog()), y1, y2, ydiff); + float y2 = getY(minmax.getMax(false)); + + int c_font_height = g.getFontMetrics().getHeight(); + + for (float yv=firstyv; yv