more chartwork for better charts
This commit is contained in:
parent
70f7c092dd
commit
56ed56bd00
@ -3,43 +3,10 @@
|
|||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<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">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderA.java</file>
|
<file>file:/home/tobias/v/SeSim/src/chart/OHLCChartPainter.java</file>
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/test/sesim/Test.java</file>
|
<file>file:/home/tobias/v/SeSim/src/chart/Chart.java</file>
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/StatisticsPanel.java</file>
|
<file>file:/home/tobias/v/SeSim/src/chart/XLegendChartPainter.java</file>
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/tools/NummericCellRenderer.java</file>
|
<file>file:/home/tobias/v/SeSim/src/chart/NewPanel.java</file>
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderInterface.java</file>
|
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartTestDialog.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/chart/NewPanel.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/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/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/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/gui/orderbook/OrderBook.java</file>
|
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartPanal.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/Chart1.java</file>
|
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartPainter.java</file>
|
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/README.md</file>
|
|
||||||
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/TestChartdialog.java</file>
|
|
||||||
</group>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#Sun, 01 Oct 2017 22:43:43 +0200
|
#Mon, 02 Oct 2017 16:12:59 +0200
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
|
||||||
<Dimension value="[800, 600]"/>
|
|
||||||
</Property>
|
|
||||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||||
<Dimension value="[100, 100]"/>
|
<Dimension value="[100, 100]"/>
|
||||||
</Property>
|
</Property>
|
||||||
|
@ -49,6 +49,15 @@ public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceive
|
|||||||
ChartPainter p = new XLegendChartPainter();
|
ChartPainter p = new XLegendChartPainter();
|
||||||
chart12.addChartPainter(p);
|
chart12.addChartPainter(p);
|
||||||
Globals.se.addQuoteReceiver(this);
|
Globals.se.addQuoteReceiver(this);
|
||||||
|
|
||||||
|
|
||||||
|
this.chart11.xbar=this.jScrollBar1;
|
||||||
|
this.jScrollBar1.addAdjustmentListener(chart11);
|
||||||
|
p = new OHLCChartPainter();
|
||||||
|
this.chart11.addChartPainter(p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,11 +25,15 @@
|
|||||||
*/
|
*/
|
||||||
package chart;
|
package chart;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
|
import sesim.MinMax;
|
||||||
import sesim.OHLCData;
|
import sesim.OHLCData;
|
||||||
|
import sesim.OHLCDataItem;
|
||||||
|
import static sun.awt.geom.Curve.prev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -37,13 +41,88 @@ import sesim.OHLCData;
|
|||||||
*/
|
*/
|
||||||
public class OHLCChartPainter extends ChartPainter {
|
public class OHLCChartPainter extends ChartPainter {
|
||||||
|
|
||||||
|
private 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)) ;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawCandleItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||||
|
|
||||||
|
if (i.open < i.close) {
|
||||||
|
int xl = (int) (x + iwidth / 2);
|
||||||
|
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawLine(xl, (int) getY(i.close), xl, (int) getY(i.high));
|
||||||
|
g.drawLine(xl, (int) getY(i.low), xl, (int) getY(i.open));
|
||||||
|
|
||||||
|
float w = iwidth;
|
||||||
|
float h = (int) (getY(i.open) - getY(i.close));
|
||||||
|
|
||||||
|
g.setColor(Color.GREEN);
|
||||||
|
g.fillRect((int) (x), (int) getY(i.close), (int) w, (int) h);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawRect((int) (x), (int) getY(i.close), (int) w, (int) h);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
int xl = (int) (x + iwidth / 2);
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
g.drawLine(xl, (int) getY(i.high), xl, (int) getY(i.close));
|
||||||
|
g.drawLine(xl, (int) getY(i.open), xl, (int) getY(i.low));
|
||||||
|
|
||||||
|
float w = iwidth;
|
||||||
|
float h = (int) (getY(i.close) - getY(i.open));
|
||||||
|
|
||||||
|
g.fillRect((int) (x), (int) getY(i.open), (int) w, (int) h);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawRect((int) (x), (int) getY(i.open), (int) w, (int) h);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, JPanel p, ChartDef def) {
|
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, JPanel p, ChartDef def) {
|
||||||
init(g);
|
init(g);
|
||||||
|
|
||||||
|
iwidth = (float) ((def.x_unit_width * em_width) * 0.9f);
|
||||||
|
|
||||||
int first_bar = def.x_scrollbar.getValue();
|
int first_bar = def.x_scrollbar.getValue();
|
||||||
Dimension size = p.getSize();
|
dim = p.getSize();
|
||||||
int bars = (int) (size.width / (def.x_unit_width * em_width));
|
int bars = (int) (dim.width / (def.x_unit_width * em_width));
|
||||||
for (int b=0; b<bars; b++){
|
|
||||||
|
int last_bar = first_bar+bars;
|
||||||
|
|
||||||
|
mm = data.getMinMax(first_bar, first_bar+bars);
|
||||||
|
|
||||||
|
y_scaling = dim.height / mm.getDiff();
|
||||||
|
|
||||||
|
OHLCDataItem prevd=null;
|
||||||
|
int prevx;
|
||||||
|
|
||||||
|
if (data.size()>0 && first_bar<data.size()){
|
||||||
|
prevd = data.get(first_bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int b = first_bar,n=0; b < last_bar && b<data.size(); b++,n++) {
|
||||||
|
OHLCDataItem d = data.get(b);
|
||||||
|
|
||||||
|
int x = (int) (n * em_width * def.x_unit_width); //em_width;
|
||||||
|
this.drawCandleItem(g, (int) (x - em_width * def.x_unit_width), x, prevd, d);
|
||||||
|
|
||||||
|
|
||||||
|
//this.drawCandleItem(g, (int)((n-1)*def.x_unit_width*em_width), (int)(n*def.x_unit_width*em_width), prevd, d);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,9 @@ public class OHLCData {
|
|||||||
*/
|
*/
|
||||||
public MinMax getMinMax(int first, int last) {
|
public MinMax getMinMax(int first, int last) {
|
||||||
|
|
||||||
|
if (data.isEmpty())
|
||||||
|
return new MinMax(0,0);
|
||||||
|
|
||||||
if (first >= data.size()) {
|
if (first >= data.size()) {
|
||||||
OHLCDataItem di = data.get(data.size() - 1);
|
OHLCDataItem di = data.get(data.size() - 1);
|
||||||
return new MinMax(di.low, di.high);
|
return new MinMax(di.low, di.high);
|
||||||
|
Loading…
Reference in New Issue
Block a user