New chart works in realtime now.
This commit is contained in:
parent
a352e4e841
commit
9cbfacb692
@ -1,4 +1,4 @@
|
|||||||
#Tue, 03 Oct 2017 12:34:23 +0200
|
#Tue, 03 Oct 2017 15:28:04 +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=
|
||||||
|
@ -38,7 +38,7 @@ import sesim.OHLCData;
|
|||||||
public class ChartCrossPainter extends ChartPainter{
|
public class ChartCrossPainter extends ChartPainter{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def) {
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||||
Point mp = p.mouse;
|
Point mp = p.mouse;
|
||||||
if (mp==null)
|
if (mp==null)
|
||||||
return;
|
return;
|
||||||
@ -48,4 +48,5 @@ public class ChartCrossPainter extends ChartPainter{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import javax.swing.JScrollBar;
|
|||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class ChartDef {
|
public class ChartDef {
|
||||||
JScrollBar x_scrollbar=null;
|
// JScrollBar x_scrollbar=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* width of an x unit in em
|
* width of an x unit in em
|
||||||
|
@ -39,6 +39,30 @@ import sesim.OHLCData;
|
|||||||
abstract public class ChartPainter {
|
abstract public class ChartPainter {
|
||||||
|
|
||||||
int em_size;
|
int em_size;
|
||||||
|
//OHLCData data=null;
|
||||||
|
|
||||||
|
public abstract interface DataProvider {
|
||||||
|
abstract OHLCData get();
|
||||||
|
}
|
||||||
|
|
||||||
|
DataProvider dataProvider=null;
|
||||||
|
|
||||||
|
public void setDataProvider(DataProvider dataProvider){
|
||||||
|
this.dataProvider = dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected OHLCData getData(){
|
||||||
|
if (dataProvider==null)
|
||||||
|
return null;
|
||||||
|
return dataProvider.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getFirstBar(ChartPanel p) {
|
||||||
|
if (p.x_scrollbar != null) {
|
||||||
|
return p.x_scrollbar.getValue();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected final void init(Graphics2D g) {
|
protected final void init(Graphics2D g) {
|
||||||
|
|
||||||
@ -50,6 +74,6 @@ abstract public class ChartPainter {
|
|||||||
int big_tick = 10;
|
int big_tick = 10;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
abstract public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def);
|
abstract public void drawChart(Graphics2D g, ChartPanel p, ChartDef def);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ import sesim.Quote;
|
|||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListener*/ {
|
public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener {
|
||||||
|
|
||||||
public JScrollBar xbar;
|
public JScrollBar x_scrollbar=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form Chart1
|
* Creates new form Chart1
|
||||||
@ -38,6 +38,14 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setXSCrollBar(JScrollBar x_scrollbar){
|
||||||
|
if (this.x_scrollbar!=null)
|
||||||
|
this.x_scrollbar.removeAdjustmentListener(this);
|
||||||
|
this.x_scrollbar=x_scrollbar;
|
||||||
|
if (this.x_scrollbar!=null)
|
||||||
|
this.x_scrollbar.addAdjustmentListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
|
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,16 +66,16 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.xbar.setMaximum(994000);
|
//this.x_scrollbar.setMaximum(994000);
|
||||||
XLegendChartPainter p = new XLegendChartPainter();
|
XLegendChartPainter p = new XLegendChartPainter();
|
||||||
data = Globals.se.getOHLCdata(60000 * 60);
|
data = Globals.se.getOHLCdata(60000 * 60);
|
||||||
|
|
||||||
ChartDef def = new ChartDef();
|
ChartDef def = new ChartDef();
|
||||||
def.x_unit_width = 1.0;
|
def.x_unit_width = 1.0;
|
||||||
def.x_scrollbar = xbar;
|
// def.x_scrollbar = x_scrollbar;
|
||||||
|
|
||||||
for (ChartPainter painter : chartPainters) {
|
for (ChartPainter painter : chartPainters) {
|
||||||
painter.drawChart((Graphics2D) g, xbar, data, this, def);
|
painter.drawChart((Graphics2D) g, this, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,4 +52,5 @@ public class LineChartPainter extends OHLCChartPainter{
|
|||||||
g.setColor(cur);
|
g.setColor(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ import sesim.Quote;
|
|||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{
|
public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, ChartPainter.DataProvider {
|
||||||
|
|
||||||
OHLCData data;
|
//OHLCData data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form MasterChart
|
* Creates new form MasterChart
|
||||||
@ -46,18 +46,32 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{
|
|||||||
|
|
||||||
ChartDef def = new ChartDef();
|
ChartDef def = new ChartDef();
|
||||||
def.x_unit_width = 1.0;
|
def.x_unit_width = 1.0;
|
||||||
def.x_scrollbar=xScrollBar;
|
|
||||||
|
|
||||||
if (Globals.se==null)
|
|
||||||
|
if (Globals.se == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data = Globals.se.getOHLCdata(60000);
|
// data = Globals.se.getOHLCdata(60000*60);
|
||||||
|
Globals.se.addQuoteReceiver(this);
|
||||||
|
|
||||||
ChartPainter p = new CandleStickChartPainter();
|
ChartPainter p = new CandleStickChartPainter();
|
||||||
//this.chart.addChartPainter(p);
|
//this.chart.addChartPainter(p);
|
||||||
|
|
||||||
|
this.xScrollBar.setMaximum(0);
|
||||||
|
|
||||||
p = new XLegendChartPainter();
|
p = new XLegendChartPainter();
|
||||||
|
p.setDataProvider(this);
|
||||||
|
|
||||||
xLegend.addChartPainter(p);
|
xLegend.addChartPainter(p);
|
||||||
|
xLegend.setXSCrollBar(xScrollBar);
|
||||||
|
|
||||||
|
p = new CandleStickChartPainter();
|
||||||
|
p.setDataProvider(this);
|
||||||
|
|
||||||
|
|
||||||
|
chart.addChartPainter(p);
|
||||||
|
chart.setXSCrollBar(xScrollBar);
|
||||||
|
|
||||||
p = new ChartCrossPainter();
|
p = new ChartCrossPainter();
|
||||||
this.chart.addChartPainter(p);
|
this.chart.addChartPainter(p);
|
||||||
@ -169,6 +183,15 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void UpdateQuote(Quote q) {
|
public void UpdateQuote(Quote q) {
|
||||||
|
OHLCData data = this.get();
|
||||||
|
int s = data.size();
|
||||||
|
this.xScrollBar.setMaximum(s);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OHLCData get() {
|
||||||
|
return Globals.se.getOHLCdata(60000*60);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,18 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def) {
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||||
|
OHLCData data = getData();
|
||||||
|
if (data==null)
|
||||||
|
return;
|
||||||
|
|
||||||
init(g);
|
init(g);
|
||||||
|
|
||||||
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
|
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
|
||||||
|
|
||||||
int first_bar = def.x_scrollbar.getValue();
|
int first_bar = getFirstBar(p);
|
||||||
|
|
||||||
|
|
||||||
dim = p.getSize();
|
dim = p.getSize();
|
||||||
int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||||
|
|
||||||
@ -79,11 +85,13 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
OHLCDataItem prevd = null;
|
OHLCDataItem prevd = null;
|
||||||
int prevx;
|
int prevx;
|
||||||
|
|
||||||
|
System.out.printf("Firstbar %d - %d",first_bar,last_bar);
|
||||||
|
|
||||||
if (data.size() > 0 && first_bar < data.size()) {
|
if (data.size() > 0 && first_bar < data.size()) {
|
||||||
prevd = data.get(first_bar);
|
prevd = data.get(first_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevd=null;
|
|
||||||
|
|
||||||
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
||||||
OHLCDataItem d = data.get(b);
|
OHLCDataItem d = data.get(b);
|
||||||
|
@ -45,24 +45,22 @@ public class XLegendChartPainter extends ChartPainter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def)
|
|
||||||
|
@Override
|
||||||
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def)
|
||||||
{
|
{
|
||||||
|
OHLCData data = getData();
|
||||||
|
if (data ==null)
|
||||||
|
return;
|
||||||
|
|
||||||
init(g);
|
init(g);
|
||||||
|
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
Dimension size = p.getSize();
|
Dimension size = p.getSize();
|
||||||
//g.drawLine(0, 0, size.width, 100);
|
|
||||||
|
|
||||||
System.out.printf("SIZE %d %d\n", size.width, size.height);
|
|
||||||
|
|
||||||
int bars = (int) (size.width / (def.x_unit_width * em_size));
|
int bars = (int) (size.width / (def.x_unit_width * em_size));
|
||||||
System.out.printf("Units = %d\n", bars);
|
|
||||||
|
|
||||||
int first_bar;
|
int first_bar = getFirstBar(p);
|
||||||
if (def.x_scrollbar!=null)
|
|
||||||
first_bar = def.x_scrollbar.getValue();
|
|
||||||
else
|
|
||||||
first_bar=0;
|
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
int x;
|
int x;
|
||||||
|
Loading…
Reference in New Issue
Block a user