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.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -38,7 +38,7 @@ import sesim.OHLCData;
|
||||
public class ChartCrossPainter extends ChartPainter{
|
||||
|
||||
@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;
|
||||
if (mp==null)
|
||||
return;
|
||||
@ -48,4 +48,5 @@ public class ChartCrossPainter extends ChartPainter{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import javax.swing.JScrollBar;
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartDef {
|
||||
JScrollBar x_scrollbar=null;
|
||||
// JScrollBar x_scrollbar=null;
|
||||
|
||||
/**
|
||||
* width of an x unit in em
|
||||
|
@ -39,6 +39,30 @@ import sesim.OHLCData;
|
||||
abstract public class ChartPainter {
|
||||
|
||||
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) {
|
||||
|
||||
@ -50,6 +74,6 @@ abstract public class ChartPainter {
|
||||
int big_tick = 10;
|
||||
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>
|
||||
*/
|
||||
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
|
||||
@ -37,6 +37,14 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen
|
||||
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
@ -58,16 +66,16 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen
|
||||
return;
|
||||
}
|
||||
|
||||
//this.xbar.setMaximum(994000);
|
||||
//this.x_scrollbar.setMaximum(994000);
|
||||
XLegendChartPainter p = new XLegendChartPainter();
|
||||
data = Globals.se.getOHLCdata(60000 * 60);
|
||||
|
||||
ChartDef def = new ChartDef();
|
||||
def.x_unit_width = 1.0;
|
||||
def.x_scrollbar = xbar;
|
||||
// def.x_scrollbar = x_scrollbar;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -34,30 +34,44 @@ import sesim.Quote;
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public MasterChart() {
|
||||
initComponents();
|
||||
|
||||
|
||||
ChartDef def = new ChartDef();
|
||||
def.x_unit_width=1.0;
|
||||
def.x_scrollbar=xScrollBar;
|
||||
|
||||
if (Globals.se==null)
|
||||
def.x_unit_width = 1.0;
|
||||
|
||||
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
|
||||
data = Globals.se.getOHLCdata(60000);
|
||||
|
||||
ChartPainter p = new CandleStickChartPainter();
|
||||
}
|
||||
|
||||
// data = Globals.se.getOHLCdata(60000*60);
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
|
||||
ChartPainter p = new CandleStickChartPainter();
|
||||
//this.chart.addChartPainter(p);
|
||||
|
||||
this.xScrollBar.setMaximum(0);
|
||||
|
||||
p = new XLegendChartPainter();
|
||||
p.setDataProvider(this);
|
||||
|
||||
xLegend.addChartPainter(p);
|
||||
xLegend.setXSCrollBar(xScrollBar);
|
||||
|
||||
p = new CandleStickChartPainter();
|
||||
p.setDataProvider(this);
|
||||
|
||||
|
||||
chart.addChartPainter(p);
|
||||
chart.setXSCrollBar(xScrollBar);
|
||||
|
||||
p = new ChartCrossPainter();
|
||||
this.chart.addChartPainter(p);
|
||||
@ -169,6 +183,15 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
OHLCData data = this.get();
|
||||
int s = data.size();
|
||||
this.xScrollBar.setMaximum(s);
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OHLCData get() {
|
||||
return Globals.se.getOHLCdata(60000*60);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -61,12 +61,18 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
||||
|
||||
|
||||
@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);
|
||||
|
||||
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();
|
||||
int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||
|
||||
@ -79,11 +85,13 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
||||
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);
|
||||
}
|
||||
|
||||
prevd=null;
|
||||
|
||||
|
||||
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
||||
OHLCDataItem d = data.get(b);
|
||||
|
@ -44,25 +44,23 @@ public class XLegendChartPainter extends ChartPainter {
|
||||
return sesim.Scheduler.formatTimeMillis(0 + unit * fs);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g.setColor(Color.black);
|
||||
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));
|
||||
System.out.printf("Units = %d\n", bars);
|
||||
|
||||
int first_bar;
|
||||
if (def.x_scrollbar!=null)
|
||||
first_bar = def.x_scrollbar.getValue();
|
||||
else
|
||||
first_bar=0;
|
||||
int first_bar = getFirstBar(p);
|
||||
|
||||
int n;
|
||||
int x;
|
||||
|
Loading…
Reference in New Issue
Block a user