Working ylegend now
This commit is contained in:
parent
95f563aa0e
commit
9e4d46ee99
@ -3,13 +3,49 @@
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/home/tobias/v/SeSim/src/chart/OHLCChartPainter.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/sesim/OHLCData.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/sesim/MinMax.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/chart/Chart.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/chart/XLegendChartPainter.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/gui/MainChart.java</file>
|
||||
<file>file:/home/tobias/v/SeSim/src/chart/ChartTestDialog.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderA.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/test/sesim/Test.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/MasterChart.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/ChartCrossPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/StatisticsPanel.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/tools/NummericCellRenderer.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderInterface.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/ManTrader/ManTraderConsoleDialog.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderLoader.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/ManTrader/ManTrader.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/SeSimApplication.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/Globals.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/ChartPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/OHLCChartPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderB.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Logger.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/EditPreferencesDialog.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/QuotePanel.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderBase.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/Statistics.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/EditStrategies.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/MainChart.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/Chart.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Clock.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartDef.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/OHLCData.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/IDGenerator.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/MinMax.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/XLegendPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/LineChartPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderGui.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Exchange.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/jp99.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Locker.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartPanel.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/orderbook/OrderBook.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/OHLCDataItem.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/AboutDialog.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/CandleStickChartPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/painter/YLegendPainter.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/SuperDlg.java</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/README.md</file>
|
||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/TestChartdialog.java</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#Thu, 05 Oct 2017 22:01:54 +0200
|
||||
#Sat, 07 Oct 2017 02:38:10 +0200
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -70,14 +70,15 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch
|
||||
|
||||
chart.addChartPainter(pc);
|
||||
chart.setXSCrollBar(xScrollBar);
|
||||
chart.addChartPainter(new ChartCrossPainter());
|
||||
|
||||
ChartPainter yp = new YLegendPainter(chart);
|
||||
yp.setDataProvider(this);
|
||||
|
||||
this.chart.addChartPainter(yp);
|
||||
this.yLegend.addChartPainter(yp);
|
||||
|
||||
this.yLegend.addChartPainter(p);
|
||||
this.yLegend.addChartPainter(pc);
|
||||
// this.yLegend.addChartPainter(p);
|
||||
//this.yLegend.addChartPainter(pc);
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import chart.ChartDef;
|
||||
import chart.ChartPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import sesim.MinMax;
|
||||
import sesim.OHLCData;
|
||||
|
||||
/**
|
||||
@ -37,24 +38,25 @@ import sesim.OHLCData;
|
||||
*/
|
||||
abstract public class ChartPainter {
|
||||
|
||||
int em_size;
|
||||
//OHLCData data=null;
|
||||
|
||||
protected int em_size;
|
||||
|
||||
public abstract interface DataProvider {
|
||||
|
||||
abstract OHLCData get();
|
||||
}
|
||||
|
||||
DataProvider dataProvider=null;
|
||||
|
||||
public void setDataProvider(DataProvider dataProvider){
|
||||
DataProvider dataProvider = null;
|
||||
|
||||
public void setDataProvider(DataProvider dataProvider) {
|
||||
this.dataProvider = dataProvider;
|
||||
}
|
||||
|
||||
protected OHLCData getData(){
|
||||
if (dataProvider==null)
|
||||
return null;
|
||||
return dataProvider.get();
|
||||
}
|
||||
|
||||
protected OHLCData getData() {
|
||||
if (dataProvider == null) {
|
||||
return null;
|
||||
}
|
||||
return dataProvider.get();
|
||||
}
|
||||
|
||||
protected int getFirstBar(ChartPanel p) {
|
||||
if (p.x_scrollbar != null) {
|
||||
@ -62,14 +64,15 @@ abstract public class ChartPainter {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected int getBars(ChartPanel p, ChartDef def){
|
||||
Dimension dim = p.getSize();
|
||||
|
||||
protected int getBars(ChartPanel p, ChartDef def) {
|
||||
Dimension dim = p.getSize();
|
||||
return (int) (dim.width / (def.x_unit_width * em_size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method scould be called before painting the chart
|
||||
* Init method scould be called before painting the chart
|
||||
*
|
||||
* @param g Graphics context
|
||||
*/
|
||||
protected final void init(Graphics2D g) {
|
||||
@ -79,6 +82,42 @@ abstract public class ChartPainter {
|
||||
|
||||
}
|
||||
|
||||
protected float y_scaling;
|
||||
protected int y_height;
|
||||
protected float y_min;
|
||||
|
||||
float getY(float y) {
|
||||
//c_yscaling = ctx.rect.height / c_mm.getDiff();
|
||||
// float ys = dim.height / mm.getDiff();
|
||||
/* if (minmax.isLog()) {
|
||||
// return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||
}
|
||||
*/
|
||||
// return (dim.height - ((y - minmax.getMin()) * y_scaling));
|
||||
return (y_height - ((y - y_min) * y_scaling));
|
||||
|
||||
}
|
||||
|
||||
double getValAtY(float y) {
|
||||
float val = 0;
|
||||
|
||||
/* if (c_mm.isLog()) {
|
||||
float ys = rect.height / c_mm.getDiff();
|
||||
|
||||
return Math.exp((rect.height + rect.y) / ys + c_mm.getMin() - y / ys);
|
||||
|
||||
}
|
||||
*/
|
||||
return (-(y - y_height)) / y_scaling + y_min;
|
||||
|
||||
}
|
||||
|
||||
void initGetY(MinMax minmax, Dimension dim) {
|
||||
y_height = dim.height;
|
||||
y_scaling = dim.height / minmax.getDiff();
|
||||
y_min = minmax.getMin();
|
||||
}
|
||||
|
||||
abstract public void drawChart(Graphics2D g, ChartPanel p, ChartDef def);
|
||||
|
||||
}
|
||||
|
@ -44,23 +44,13 @@ import sesim.OHLCDataItem;
|
||||
public abstract class OHLCChartPainter extends ChartPainter {
|
||||
|
||||
protected float iwidth;
|
||||
private MinMax mm;
|
||||
private Dimension dim;
|
||||
private float y_scaling;
|
||||
|
||||
float getY(float y) {
|
||||
//c_yscaling = ctx.rect.height / c_mm.getDiff();
|
||||
// float ys = dim.height / mm.getDiff();
|
||||
if (mm.isLog()) {
|
||||
// return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||
}
|
||||
return (dim.height - ((y - mm.getMin()) * y_scaling));
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
@ -75,19 +65,25 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
||||
int first_bar = getFirstBar(p);
|
||||
|
||||
|
||||
dim = p.getSize();
|
||||
int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||
|
||||
Dimension dim = p.getSize();
|
||||
//int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||
int bars = this.getBars(p, def);
|
||||
|
||||
|
||||
int last_bar = first_bar + bars+1;
|
||||
|
||||
mm = data.getMinMax(first_bar, last_bar);
|
||||
|
||||
y_scaling = dim.height / mm.getDiff();
|
||||
MinMax minmax = data.getMinMax(first_bar, last_bar);
|
||||
|
||||
this.initGetY(minmax, dim);
|
||||
|
||||
// y_scaling = dim.height / minmax.getDiff();
|
||||
|
||||
|
||||
|
||||
OHLCDataItem prevd = null;
|
||||
int prevx;
|
||||
|
||||
System.out.printf("Firstbar %d - %d",first_bar,last_bar);
|
||||
|
||||
|
||||
if (data.size() > 0 && first_bar < data.size()) {
|
||||
prevd = data.get(first_bar);
|
||||
|
@ -61,8 +61,10 @@ public class XLegendPainter extends ChartPainter {
|
||||
g.setColor(Color.black);
|
||||
Dimension size = p.getSize();
|
||||
|
||||
int bars = (int) (size.width / (def.x_unit_width * em_size));
|
||||
//int bars = (int) (size.width / (def.x_unit_width * em_size));
|
||||
|
||||
int bars = this.getBars(p, def);
|
||||
|
||||
int first_bar = getFirstBar(p);
|
||||
|
||||
int n;
|
||||
|
@ -31,6 +31,8 @@ import chart.ChartPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import sesim.MinMax;
|
||||
import sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -50,7 +52,11 @@ public class YLegendPainter extends ChartPainter {
|
||||
|
||||
Dimension dim = master.getSize();
|
||||
int first_bar = getFirstBar(master);
|
||||
int bars = getBars(master,def);
|
||||
int last_bar = first_bar + getBars(master,def);
|
||||
MinMax minmax = this.getData().getMinMax(first_bar, last_bar);
|
||||
|
||||
this.initGetY(minmax, dim);
|
||||
|
||||
|
||||
//Rectangle dim;
|
||||
// dim = p.getSize();
|
||||
@ -61,25 +67,27 @@ public class YLegendPainter extends ChartPainter {
|
||||
|
||||
// g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
|
||||
|
||||
/*
|
||||
float y1 = ctx.getY(mm.getMin(false));
|
||||
float y2 = ctx.getY(c_mm.getMax(false));
|
||||
|
||||
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);
|
||||
|
||||
for (int yp = (int) y2; yp < y1; yp += em_width * 5) {
|
||||
g.drawLine(dim.width + dim.x - yw, yp, dim.width + dim.x - yw + em_width, yp);
|
||||
double v1 = ctx.getValAtY(yp);
|
||||
g.drawString(String.format("%.2f", v1), dim.width + dim.x - yw + em_width * 1.5f, yp + c_font_height / 3);
|
||||
int c_font_height = g.getFontMetrics().getHeight();
|
||||
|
||||
for (int yp = (int) y2; yp < y1; yp += em_size * 3) {
|
||||
g.drawLine(0, yp, em_size, yp);
|
||||
double v1 = getValAtY(yp);
|
||||
g.drawString(String.format("%.2f", v1), em_size * 1.5f, yp + c_font_height / 3);
|
||||
}
|
||||
|
||||
double v1, v2;
|
||||
v1 = ctx.getValAtY(y1);
|
||||
v2 = ctx.getValAtY(y2);
|
||||
*/
|
||||
// v1 = ctx.getValAtY(y1);
|
||||
// v2 = ctx.getValAtY(y2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user