📄 candlestickrenderer.java
字号:
else {
return;
}
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
OHLCDataset highLowData = (OHLCDataset) dataset;
double x = highLowData.getXValue(series, item);
double yHigh = highLowData.getHighValue(series, item);
double yLow = highLowData.getLowValue(series, item);
double yOpen = highLowData.getOpenValue(series, item);
double yClose = highLowData.getCloseValue(series, item);
RectangleEdge domainEdge = plot.getDomainAxisEdge();
double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);
RectangleEdge edge = plot.getRangeAxisEdge();
double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);
double volumeWidth;
double stickWidth;
if (this.candleWidth > 0) {
// These are deliberately not bounded to minimums/maxCandleWidth to
// retain old behaviour.
volumeWidth = this.candleWidth;
stickWidth = this.candleWidth;
}
else {
double xxWidth = 0;
int itemCount;
switch (this.autoWidthMethod) {
case WIDTHMETHOD_AVERAGE:
itemCount = highLowData.getItemCount(series);
if (horiz) {
xxWidth = dataArea.getHeight() / itemCount;
}
else {
xxWidth = dataArea.getWidth() / itemCount;
}
break;
case WIDTHMETHOD_SMALLEST:
// Note: It would be nice to pre-calculate this per series
itemCount = highLowData.getItemCount(series);
double lastPos = -1;
xxWidth = dataArea.getWidth();
for (int i = 0; i < itemCount; i++) {
double pos = domainAxis.valueToJava2D(
highLowData.getXValue(series, i), dataArea,
domainEdge);
if (lastPos != -1) {
xxWidth = Math.min(xxWidth,
Math.abs(pos - lastPos));
}
lastPos = pos;
}
break;
case WIDTHMETHOD_INTERVALDATA:
IntervalXYDataset intervalXYData
= (IntervalXYDataset) dataset;
double startPos = domainAxis.valueToJava2D(
intervalXYData.getStartXValue(series, item),
dataArea, plot.getDomainAxisEdge());
double endPos = domainAxis.valueToJava2D(
intervalXYData.getEndXValue(series, item),
dataArea, plot.getDomainAxisEdge());
xxWidth = Math.abs(endPos - startPos);
break;
}
xxWidth -= 2 * this.autoWidthGap;
xxWidth *= this.autoWidthFactor;
xxWidth = Math.min(xxWidth, this.maxCandleWidth);
volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth);
stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);
}
Paint p = getItemPaint(series, item);
Paint outlinePaint = null;
if (this.useOutlinePaint) {
outlinePaint = getItemOutlinePaint(series, item);
}
Stroke s = getItemStroke(series, item);
g2.setStroke(s);
if (this.drawVolume) {
int volume = (int) highLowData.getVolumeValue(series, item);
double volumeHeight = volume / this.maxVolume;
double min, max;
if (horiz) {
min = dataArea.getMinX();
max = dataArea.getMaxX();
}
else {
min = dataArea.getMinY();
max = dataArea.getMaxY();
}
double zzVolume = volumeHeight * (max - min);
g2.setPaint(getVolumePaint());
Composite originalComposite = g2.getComposite();
g2.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)
);
if (horiz) {
g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2,
zzVolume, volumeWidth));
}
else {
g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2,
max - zzVolume, volumeWidth, zzVolume));
}
g2.setComposite(originalComposite);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
}
else {
g2.setPaint(p);
}
double yyMaxOpenClose = Math.max(yyOpen, yyClose);
double yyMinOpenClose = Math.min(yyOpen, yyClose);
double maxOpenClose = Math.max(yOpen, yClose);
double minOpenClose = Math.min(yOpen, yClose);
// draw the upper shadow
if (yHigh > maxOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx));
}
else {
g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
}
}
// draw the lower shadow
if (yLow < minOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx));
}
else {
g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
}
}
// draw the body
Shape body = null;
if (horiz) {
body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2,
yyMaxOpenClose - yyMinOpenClose, stickWidth);
}
else {
body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose,
stickWidth, yyMaxOpenClose - yyMinOpenClose);
}
if (yClose > yOpen) {
if (this.upPaint != null) {
g2.setPaint(this.upPaint);
}
else {
g2.setPaint(p);
}
g2.fill(body);
}
else {
if (this.downPaint != null) {
g2.setPaint(this.downPaint);
}
else {
g2.setPaint(p);
}
g2.fill(body);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
}
else {
g2.setPaint(p);
}
g2.draw(body);
// add an entity for the item...
if (entities != null) {
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(body, dataset, series, item,
tip, url);
entities.add(entity);
}
}
/**
* Tests this renderer for equality with another object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CandlestickRenderer)) {
return false;
}
CandlestickRenderer that = (CandlestickRenderer) obj;
if (this.candleWidth != that.candleWidth) {
return false;
}
if (!PaintUtilities.equal(this.upPaint, that.upPaint)) {
return false;
}
if (!PaintUtilities.equal(this.downPaint, that.downPaint)) {
return false;
}
if (this.drawVolume != that.drawVolume) {
return false;
}
if (this.maxCandleWidthInMilliseconds
!= that.maxCandleWidthInMilliseconds) {
return false;
}
if (this.autoWidthMethod != that.autoWidthMethod) {
return false;
}
if (this.autoWidthFactor != that.autoWidthFactor) {
return false;
}
if (this.autoWidthGap != that.autoWidthGap) {
return false;
}
if (this.useOutlinePaint != that.useOutlinePaint) {
return false;
}
if (!PaintUtilities.equal(this.volumePaint, that.volumePaint)) {
return false;
}
return super.equals(obj);
}
/**
* Returns a clone of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the renderer cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtilities.writePaint(this.upPaint, stream);
SerialUtilities.writePaint(this.downPaint, stream);
SerialUtilities.writePaint(this.volumePaint, stream);
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.upPaint = SerialUtilities.readPaint(stream);
this.downPaint = SerialUtilities.readPaint(stream);
this.volumePaint = SerialUtilities.readPaint(stream);
}
// --- DEPRECATED CODE ----------------------------------------------------
/**
* Returns a flag indicating whether or not volume bars are drawn on the
* chart.
*
* @return <code>true</code> if volume bars are drawn on the chart.
*
* @deprecated As of 1.0.5, you should use the {@link #getDrawVolume()}
* method.
*/
public boolean drawVolume() {
return this.drawVolume;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -