clickedCandle bug
Posted: Thu Mar 20, 2008 8:54 am
Hi,
There is a bug in 'clickedCandle' method in Candle class. It is used by 'clicked' method and also mouse events I think.
The existing clickedCandle works fine for candles with open price higher than close. For the second case with close higher than open it only returns true when the point passed as the argument lies in the middle of the candle or within 3 points distance from it. If the candle is wide, the sensitive area is not sufficient.
We were able to fix it by replacing the code in line #524 of Candle.java:
int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(vOpenValues.value[valueIndex]);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);
int yClose=calcYPosValue(getCloseValues().value[valueIndex]);
by the code:
double openPrice = vOpenValues.value[valueIndex];
double closePrice = getCloseValues().value[valueIndex];
int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(openPrice);
int yClose=calcYPosValue(closePrice);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);
and also replacing code in line 578:
Rectangle tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
by the code:
Rectangle tmpR;
if (openPrice > closePrice)
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
}
else
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yClose,tmpX+tmpRightWidth+1,yOpen);
}
We were only trying to fix the 2D chart/2D candles case.
There is a bug in 'clickedCandle' method in Candle class. It is used by 'clicked' method and also mouse events I think.
The existing clickedCandle works fine for candles with open price higher than close. For the second case with close higher than open it only returns true when the point passed as the argument lies in the middle of the candle or within 3 points distance from it. If the candle is wide, the sensitive area is not sufficient.
We were able to fix it by replacing the code in line #524 of Candle.java:
int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(vOpenValues.value[valueIndex]);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);
int yClose=calcYPosValue(getCloseValues().value[valueIndex]);
by the code:
double openPrice = vOpenValues.value[valueIndex];
double closePrice = getCloseValues().value[valueIndex];
int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(openPrice);
int yClose=calcYPosValue(closePrice);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);
and also replacing code in line 578:
Rectangle tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
by the code:
Rectangle tmpR;
if (openPrice > closePrice)
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
}
else
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yClose,tmpX+tmpRightWidth+1,yOpen);
}
We were only trying to fix the 2D chart/2D candles case.