some work

This commit is contained in:
2018-01-02 00:55:54 +01:00
parent 54d499cd18
commit 16468c4b3d
8 changed files with 171 additions and 49 deletions

View File

@ -29,13 +29,14 @@ import sesim.ChartDef;
import sesim.ChartPanel;
import java.awt.Graphics2D;
import java.awt.Point;
import sesim.OHLCDataItem;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ChartCrossPainter extends ChartPainter{
public class ChartCrossPainter extends OHLCChartPainter{
@Override
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
@ -49,6 +50,12 @@ public class ChartCrossPainter extends ChartPainter{
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
}
@Override
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View File

@ -36,7 +36,6 @@ import sesim.MinMax;
import sesim.OHLCData;
import sesim.OHLCDataItem;
/**
*
* @author 7u83 <7u83@mail.ru>
@ -45,23 +44,21 @@ public abstract class OHLCChartPainter extends ChartPainter {
protected float iwidth;
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
protected OHLCData data;
public void setOHLCData(OHLCData data){
public void setOHLCData(OHLCData data) {
this.data = data;
}
protected OHLCData getData() {
protected OHLCData getData() {
return this.data;
/*if (dataProvider == null) {
return null;
}
return dataProvider.get();
*/
*/
}
protected int getFirstBar(ChartPanel p) {
@ -71,6 +68,25 @@ public abstract class OHLCChartPainter extends ChartPainter {
return 0;
}
protected int x2Time(ChartPanel p, ChartDef def, int x) {
// int first_bar = getFirstBar(p);
// OHLCDataItem d = data.get(first_bar);
long t = 0;
int xbar = (int)((float)x/def.x_unit_width);
System.out.printf("XBAR: %d\n",xbar);
return 0;
}
/**
* Get the number of bars needed to fill the ChartPanel object
* @param p ChartPanel object
* @param def ChartDef
* @return Number of bars
*/
protected int getBars(ChartPanel p, ChartDef def) {
Dimension dim = p.getSize();
return (int) (dim.width / (def.x_unit_width * em_size));
@ -102,7 +118,7 @@ public abstract class OHLCChartPainter extends ChartPainter {
}
*/
return (-(y - y_height)) / y_scaling + y_min;
return (-(y - y_height)) / y_scaling + y_min;
}
@ -112,45 +128,36 @@ public abstract class OHLCChartPainter extends ChartPainter {
y_min = minmax.getMin();
}
@Override
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
OHLCData data = getData();
if (data==null)
if (data == null) {
return;
}
init(g);
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
int first_bar = getFirstBar(p);
int first_bar = getFirstBar(p);
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;
int last_bar = first_bar + bars + 1;
MinMax minmax = data.getMinMax(first_bar, last_bar);
this.initGetY(minmax, dim);
// y_scaling = dim.height / minmax.getDiff();
this.initGetY(minmax, dim);
// y_scaling = dim.height / minmax.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);

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package chart.painter;
import java.awt.Graphics2D;
import java.awt.Point;
import sesim.ChartDef;
import sesim.ChartPanel;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class XLegendDetail extends XLegendPainter{
public XLegendDetail(){
}
static int ctr=0;
@Override
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
// System.out.printf("Xlegend Deatil drawchart called %d\n",ctr);
// ctr++;
init (g);
if (def==null)
return;
if (def.mainChart==null)
return;
if (def.mainChart.mouse == null)
return;
Point mouse = def.mainChart.mouse;
int x = def.mainChart.mouse.x;
this.x2Time(p, def, x);
g.drawLine(mouse.x, 0, mouse.x, p.getSize().height);
System.out.printf("Detail Mous X: %d\n",x);
// super.drawChart(g, p, def); //To change body of generated methods, choose Tools | Templates.
}
}