ofxHistoryPlot
ofxHistoryPlot copied to clipboard
issue in drawing horizontalGuides
hey armadillu, thank you for the addon. using it i realize the following:
- horizontalGuides get drawn at bad y-location due to issues in ofMap. i guess values are clamped to outputMin in case of FLT_EPSILON or there is a general float issue. it works with ofMap in double:
double ofMapDouble(double value, double inputMin, double inputMax, double outputMin, double outputMax, bool clamp) {
if (std::abs(inputMin - inputMax) < DBL_EPSILON) {
return outputMin;
}
else {
double outVal = ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin);
if (clamp) {
if (outputMax < outputMin) {
if (outVal < outputMax)outVal = outputMax;
else if (outVal > outputMin)outVal = outputMin;
}
else {
if (outVal > outputMax)outVal = outputMax;
else if (outVal < outputMin)outVal = outputMin;
}
}
return outVal;
}
}
- furthermore, plotting values are shifted off horizontalGuides with the same y in case of respectBorders == true.
example: setting the range to [-0.00000001, +0.00000001] places a horizontalGuides with y=0 not in the center. once i correct that using ofMapDouble, drawing plotting values with y= 0 are not exactly on the horizontalGuide, but shifted due to respectBorders .
hmmm it seems you are using really small values; OpenFrameworks doesn't really have support for float/double across the board, so I recommend you feed in larger values to the plot... Alternatively I could make a float/double version of it, but I think ofMesh only handles float so it would probably give trouble at draw time anyway
yes, i am using a wide range of numbers. there is no need to change the whole addon to double, as i indicated, a substitution of ofMap() with double precision does the job in ofxHistoryPlot::draw():
for(size_t i = 0; i < horizontalGuides.size(); i++){
float myY = horizontalGuides[i];
if (myY > plotLow && myY < plotHigh){ //TODO negative!
float yy = ofMapDouble(myY, plotLow, plotHigh, 0, h, true); // MS was ofMap
if(drawGuideValues){
ofSetColor(horizontalGuideColors[i], 111); // 50
ofDrawBitmapString(ofToString(horizontalGuides[i], precision), 10 + x, y + h - yy + 10 );
}
ofSetColor(horizontalGuideColors[i], 64 );
ofDrawLine(x, y + h - yy, x + w, y + h - yy); // orig
}
}
ofMap chops small values to outputMin at FLT_EPSILON. that's all
I see, thx! Do you want to make a PR with the necessary changes? I'm cool with replacing all ofMap() calls to a custom ofMap().