Added some javadoc

This commit is contained in:
7u83 2017-03-27 01:31:55 +02:00
parent 27aee1c43c
commit 2a5f9070e3
2 changed files with 81 additions and 106 deletions

View File

@ -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);
@ -193,8 +190,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
} 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) {
if (n % big_tick == 1) { if (n % big_tick == 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,13 +237,10 @@ 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();
float fac = (float) c_rect.height / (float) Math.log(m); float fac = (float) c_rect.height / (float) Math.log(m);
@ -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);
} }
@ -277,31 +265,22 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
// 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();
} }
@ -317,7 +296,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
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,7 +384,6 @@ 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;
@ -418,14 +395,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
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; double v1, v2;
v1 = getValAtY(y1); v1 = getValAtY(y1);
v2 = getValAtY(y2); v2 = getValAtY(y2);
@ -441,13 +412,11 @@ 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");
@ -592,8 +560,6 @@ System.out.printf("v1 %f, v2 %f\n",v1,v2);
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;

View File

@ -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()) {