Added some javadoc
This commit is contained in:
parent
27aee1c43c
commit
2a5f9070e3
@ -30,10 +30,10 @@ import sesim.Scheduler;
|
|||||||
*/
|
*/
|
||||||
public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollable {
|
public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollable {
|
||||||
|
|
||||||
|
|
||||||
private int em_height;
|
private int em_height;
|
||||||
private int em_width;
|
private int em_width;
|
||||||
|
|
||||||
|
protected double x_legend_height = 3;
|
||||||
|
|
||||||
protected double x_unit_width = 1.0;
|
protected double x_unit_width = 1.0;
|
||||||
|
|
||||||
@ -111,7 +111,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OHLCData data;
|
OHLCData data;
|
||||||
@ -168,9 +167,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
*/
|
*/
|
||||||
void drawXLegend(Graphics2D g, XLegendDef xld) {
|
void drawXLegend(Graphics2D g, XLegendDef xld) {
|
||||||
|
|
||||||
|
|
||||||
//g = (Graphics2D) g.create();
|
//g = (Graphics2D) g.create();
|
||||||
|
|
||||||
int yw = (int) (this.y_legend_width * this.em_width);
|
int yw = (int) (this.y_legend_width * this.em_width);
|
||||||
|
|
||||||
g.setClip(clip_bounds.x, clip_bounds.y, clip_bounds.width - yw, clip_bounds.height);
|
g.setClip(clip_bounds.x, clip_bounds.y, clip_bounds.width - yw, clip_bounds.height);
|
||||||
@ -185,15 +182,13 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
|
|
||||||
long big_tick = 1;
|
long big_tick = 1;
|
||||||
|
|
||||||
double btl,xxx;
|
double btl, xxx;
|
||||||
do {
|
do {
|
||||||
big_tick++;
|
big_tick++;
|
||||||
btl=em_width*big_tick*x_unit_width;
|
btl = em_width * big_tick * x_unit_width;
|
||||||
xxx = 7*em_width;
|
xxx = 7 * em_width;
|
||||||
|
|
||||||
}while (btl<xxx);
|
|
||||||
|
|
||||||
|
|
||||||
|
} while (btl < xxx);
|
||||||
|
|
||||||
for (n = 0, x = 0; x < dim.width; x += em_width * x_unit_width) {
|
for (n = 0, x = 0; x < dim.width; x += em_width * x_unit_width) {
|
||||||
|
|
||||||
@ -213,7 +208,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n+=1;
|
n += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,8 +229,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
|
|
||||||
boolean logs = false;
|
boolean logs = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float getY(float y) {
|
float getY(float y) {
|
||||||
|
|
||||||
float ys = c_rect.height / c_mm.getDiff();
|
float ys = c_rect.height / c_mm.getDiff();
|
||||||
@ -244,12 +237,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
if (c_mm.isLog()) {
|
if (c_mm.isLog()) {
|
||||||
|
|
||||||
// c_mm.setLog(true);
|
// c_mm.setLog(true);
|
||||||
|
|
||||||
// ys = c_rect.height / c_mm.getDiff();
|
// ys = c_rect.height / c_mm.getDiff();
|
||||||
|
|
||||||
// return (c_rect.height - (((float)Math.log(y) - c_mm.getMin()) * ys)) + c_rect.y;
|
// return (c_rect.height - (((float)Math.log(y) - c_mm.getMin()) * ys)) + c_rect.y;
|
||||||
return c_rect.height + c_rect.y - ((float)Math.log(y) - c_mm.getMin()) * ys;
|
return c_rect.height + c_rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||||
|
|
||||||
|
|
||||||
/* float m = c_mm.getMax() / c_mm.getMin();
|
/* float m = c_mm.getMax() / c_mm.getMin();
|
||||||
|
|
||||||
@ -260,8 +250,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
|
|
||||||
return fmin;
|
return fmin;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//return c_rect.height - ((float) Math.log((y - c_mm.getMin()) * c_yscaling) * fac);
|
//return c_rect.height - ((float) Math.log((y - c_mm.getMin()) * c_yscaling) * fac);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,38 +258,29 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
// return c_rect.height - ((y - c_mm.getMin()) * c_yscaling);
|
// return c_rect.height - ((y - c_mm.getMin()) * c_yscaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getValAtY(float y){
|
double getValAtY(float y) {
|
||||||
float val=0;
|
float val = 0;
|
||||||
|
|
||||||
// y = (c_rect.height - ((val - c_mm.getMin()) * c_yscaling)) + c_rect.y;
|
// y = (c_rect.height - ((val - c_mm.getMin()) * c_yscaling)) + c_rect.y;
|
||||||
// y-c_rect.y = c_rect.height - ((val - c_mm.getMin()) * c_yscaling)
|
// y-c_rect.y = c_rect.height - ((val - c_mm.getMin()) * c_yscaling)
|
||||||
// y-c_rect.y-c_rect.height = - ((val - c_mm.getMin()) * c_yscaling)
|
// y-c_rect.y-c_rect.height = - ((val - c_mm.getMin()) * c_yscaling)
|
||||||
// -(y-c_rect.y-c_rect.heigh) = (val - c_mm.getMin()) * c_yscaling
|
// -(y-c_rect.y-c_rect.heigh) = (val - c_mm.getMin()) * c_yscaling
|
||||||
|
|
||||||
// (-(y-c_rect.y-c_rect.heigh))/c_yscaling = (val - c_mm.getMin())
|
// (-(y-c_rect.y-c_rect.heigh))/c_yscaling = (val - c_mm.getMin())
|
||||||
|
if (c_mm.isLog()) {
|
||||||
if (c_mm.isLog()){
|
|
||||||
float ys = c_rect.height / c_mm.getDiff();
|
float ys = c_rect.height / c_mm.getDiff();
|
||||||
|
|
||||||
|
|
||||||
//val = return c_rect.height + c_rect.y - ((float)Math.log(y) - c_mm.getMin()) * ys;
|
//val = return c_rect.height + c_rect.y - ((float)Math.log(y) - c_mm.getMin()) * ys;
|
||||||
// val + ((float)Math.log(y) - c_mm.getMin()) * ys = c_rect.height + c_rect.y
|
// val + ((float)Math.log(y) - c_mm.getMin()) * ys = c_rect.height + c_rect.y
|
||||||
// val/ys + ((float)Math.log(y) - c_mm.getMin()) = (c_rect.height + c_rect.y)/ys
|
// val/ys + ((float)Math.log(y) - c_mm.getMin()) = (c_rect.height + c_rect.y)/ys
|
||||||
// val/ys + ((float)Math.log(y) = (c_rect.height + c_rect.y)/ys + c_mm.getMin())
|
// val/ys + ((float)Math.log(y) = (c_rect.height + c_rect.y)/ys + c_mm.getMin())
|
||||||
|
|
||||||
//return (-(Math.exp(y)-c_rect.y-c_rect.height))/ys+c_mm.getMin();
|
//return (-(Math.exp(y)-c_rect.y-c_rect.height))/ys+c_mm.getMin();
|
||||||
|
return Math.exp((c_rect.height + c_rect.y) / ys + c_mm.getMin() - y / ys);
|
||||||
return Math.exp( (c_rect.height + c_rect.y)/ys + c_mm.getMin() - y/ys);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (-(y - c_rect.y - c_rect.height)) / c_yscaling + c_mm.getMin();
|
||||||
return (-(y-c_rect.y-c_rect.height))/c_yscaling+c_mm.getMin();
|
|
||||||
|
|
||||||
// return (y+c_rect.y-c_rect.height)/c_yscaling+c_mm.getMin();
|
// return (y+c_rect.y-c_rect.height)/c_yscaling+c_mm.getMin();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -316,8 +295,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
g.drawLine(prevx, (int) ctx.getYc(prev.close), x, (int) ctx.getYc(item.close));
|
g.drawLine(prevx, (int) ctx.getYc(prev.close), x, (int) ctx.getYc(item.close));
|
||||||
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
|
g.drawLine(r.x, r.height + r.y, r.x + r.width, r.height + r.y);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void drawCandleItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
private void drawCandleItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||||
|
|
||||||
if (prev == null) {
|
if (prev == null) {
|
||||||
@ -406,30 +384,23 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
|
|||||||
|
|
||||||
g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
|
g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
|
||||||
|
|
||||||
|
|
||||||
float y1 = getY(c_mm.getMin(false));
|
float y1 = getY(c_mm.getMin(false));
|
||||||
float y2 = getY(c_mm.getMax(false));
|
float y2 = getY(c_mm.getMax(false));
|
||||||
float ydiff = y1-y2;
|
float ydiff = y1 - y2;
|
||||||
System.out.printf("%s y1: %f, y2: %f, diff %f\n",Boolean.toString(c_mm.isLog()),y1,y2,ydiff);
|
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*2) {
|
for (int yp = (int) y2; yp < y1; yp += em_width * 2) {
|
||||||
g.drawLine(dim.width + dim.x - yw, yp, dim.width + dim.x - yw + em_width , yp);
|
g.drawLine(dim.width + dim.x - yw, yp, dim.width + dim.x - yw + em_width, yp);
|
||||||
double v1 = getValAtY(yp);
|
double v1 = getValAtY(yp);
|
||||||
g.drawString(String.format("%.2f", v1), dim.width + dim.x - yw + em_width * 1.5f, yp + c_font_height / 3);
|
g.drawString(String.format("%.2f", v1), dim.width + dim.x - yw + em_width * 1.5f, yp + c_font_height / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// c_yscaling = c_rect.height / c_mm.getDiff();
|
// c_yscaling = c_rect.height / c_mm.getDiff();
|
||||||
|
|
||||||
|
|
||||||
//System.out.printf("Step: %f\n",step);
|
//System.out.printf("Step: %f\n",step);
|
||||||
|
double v1, v2;
|
||||||
|
v1 = getValAtY(y1);
|
||||||
|
v2 = getValAtY(y2);
|
||||||
double v1,v2;
|
System.out.printf("v1 %f, v2 %f\n", v1, v2);
|
||||||
v1 = getValAtY(y1);
|
|
||||||
v2 = getValAtY(y2);
|
|
||||||
System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|
||||||
|
|
||||||
|
|
||||||
/* for (float y = c_mm.getMin(); y < c_mm.getMax(); y += step) {
|
/* for (float y = c_mm.getMin(); y < c_mm.getMax(); y += step) {
|
||||||
@ -440,14 +411,12 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
|
|
||||||
g.drawString(String.format("%.2f", y), dim.width + dim.x - yw + em_width * 1.5f, my + c_font_height / 3);
|
g.drawString(String.format("%.2f", y), dim.width + dim.x - yw + em_width * 1.5f, my + c_font_height / 3);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MinMax c_mm = null;
|
private MinMax c_mm = null;
|
||||||
private Rectangle c_rect;
|
private Rectangle c_rect;
|
||||||
|
|
||||||
|
|
||||||
void drawChart(RenderCtx ctx) {
|
void drawChart(RenderCtx ctx) {
|
||||||
|
|
||||||
c_yscaling = c_rect.height / c_mm.getDiff();
|
c_yscaling = c_rect.height / c_mm.getDiff();
|
||||||
@ -498,7 +467,6 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
|
|
||||||
// c_mm.min/= 1; //-= c_mm.getMin()/ 2.0f;
|
// c_mm.min/= 1; //-= c_mm.getMin()/ 2.0f;
|
||||||
// c_mm.max *= 1; //+= c_mm.getMax() / 10.0f;
|
// c_mm.max *= 1; //+= c_mm.getMax() / 10.0f;
|
||||||
|
|
||||||
em_height = g.getFontMetrics().getHeight();
|
em_height = g.getFontMetrics().getHeight();
|
||||||
em_width = g.getFontMetrics().stringWidth("M");
|
em_width = g.getFontMetrics().stringWidth("M");
|
||||||
|
|
||||||
@ -553,7 +521,7 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);
|
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);
|
||||||
|
|
||||||
this.ct = ChartType.CANDLESTICK;
|
this.ct = ChartType.CANDLESTICK;
|
||||||
logs=true;
|
logs = true;
|
||||||
c_mm.setLog(true);
|
c_mm.setLog(true);
|
||||||
drawChart(ctx);
|
drawChart(ctx);
|
||||||
|
|
||||||
@ -577,7 +545,7 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
ctx.g = g;
|
ctx.g = g;
|
||||||
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);
|
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);
|
||||||
|
|
||||||
logs=false;
|
logs = false;
|
||||||
c_mm.setLog(false);
|
c_mm.setLog(false);
|
||||||
this.ct = ChartType.VOL;
|
this.ct = ChartType.VOL;
|
||||||
drawChart(ctx);
|
drawChart(ctx);
|
||||||
@ -588,12 +556,10 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void paintComponent(Graphics g) {
|
public final void paintComponent(Graphics g) {
|
||||||
if (Globals.se==null){
|
if (Globals.se == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
// Calculate the number of pixels for 1 em
|
// Calculate the number of pixels for 1 em
|
||||||
@ -612,9 +578,7 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
last_bar = 1 + (int) ((clip_bounds.x + clip_bounds.width - (this.y_legend_width * em_width)) / (this.x_unit_width * this.em_width));
|
last_bar = 1 + (int) ((clip_bounds.x + clip_bounds.width - (this.y_legend_width * em_width)) / (this.x_unit_width * this.em_width));
|
||||||
|
|
||||||
// num_bars = data.size(); // + (int) (clip_bounds.width / (this.x_unit_width * this.em_width))+5;
|
// num_bars = data.size(); // + (int) (clip_bounds.width / (this.x_unit_width * this.em_width))+5;
|
||||||
|
|
||||||
// num_bars=1;
|
// num_bars=1;
|
||||||
|
|
||||||
c_font_height = g.getFontMetrics().getHeight();
|
c_font_height = g.getFontMetrics().getHeight();
|
||||||
|
|
||||||
draw((Graphics2D) g);
|
draw((Graphics2D) g);
|
||||||
@ -676,8 +640,6 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
|
private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
|
||||||
System.out.printf("There was a mosue event\n");
|
System.out.printf("There was a mosue event\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!evt.isPopupTrigger() || true) {
|
if (!evt.isPopupTrigger() || true) {
|
||||||
System.out.printf("But there was no pupe trigger\n");
|
System.out.printf("But there was no pupe trigger\n");
|
||||||
return;
|
return;
|
||||||
@ -713,8 +675,6 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
|
|||||||
|
|
||||||
System.out.printf("There was a mosue event released\n");
|
System.out.printf("There was a mosue event released\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!evt.isPopupTrigger()) {
|
if (!evt.isPopupTrigger()) {
|
||||||
System.out.printf("But there was no pupe trigger\n");
|
System.out.printf("But there was no pupe trigger\n");
|
||||||
return;
|
return;
|
||||||
|
@ -43,6 +43,11 @@ public class OHLCData {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an OHLCData object that stores OHLCDataItems
|
||||||
|
*
|
||||||
|
* @param frame_size Time frame stored in one OHLCDataItem
|
||||||
|
*/
|
||||||
public OHLCData(int frame_size) {
|
public OHLCData(int frame_size) {
|
||||||
|
|
||||||
this.frame_size = frame_size;
|
this.frame_size = frame_size;
|
||||||
@ -60,10 +65,20 @@ public class OHLCData {
|
|||||||
return data.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Time frame of OHLCDataItem
|
||||||
|
*/
|
||||||
public int getFrameSize() {
|
public int getFrameSize() {
|
||||||
return this.frame_size;
|
return this.frame_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the minimum and maximum value between two OHLCDataItems
|
||||||
|
* @param first Position of first OHLCDataItem
|
||||||
|
* @param last Position of last OHCLDataItem
|
||||||
|
* @return MinMax object containing the calculated values
|
||||||
|
*/
|
||||||
public MinMax getMinMax(int first, int last) {
|
public MinMax getMinMax(int first, int last) {
|
||||||
|
|
||||||
if (first >= data.size()) {
|
if (first >= data.size()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user