From b6a17c50c2b0722cec7c63876ac28f3f66e47293 Mon Sep 17 00:00:00 2001 From: joye Date: Thu, 17 Apr 2014 16:40:55 +0000 Subject: *** empty log message *** --- src/bltGrAxis.C | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++----- src/bltGrAxis.h | 1 + src/bltGrAxisOp.C | 88 ----------------------------------------------------- src/bltGrAxisOp.h | 2 -- src/bltGraph.C | 61 +++++++++++++++++++++++++++---------- src/bltGraph.h | 2 ++ 6 files changed, 132 insertions(+), 113 deletions(-) diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index 7827510..fed9fb9 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -627,7 +627,6 @@ void Axis::drawLimits(Drawable drawable) AxisOptions* ops = (AxisOptions*)ops_; GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; -#define SPACING 8 int vMin = graphPtr_->left_ + gops->xPad + 2; int vMax = vMin; int hMin = graphPtr_->bottom_ - gops->yPad - 2; @@ -635,16 +634,17 @@ void Axis::drawLimits(Drawable drawable) ops->limitsTextStyle.flags |= UPDATE_GC; + const int spacing =8; int isHoriz = isHorizontal(); char* minPtr =NULL; char* maxPtr =NULL; + char minString[200]; + char maxString[200]; const char* fmt = ops->limitsFormat; if (fmt && *fmt) { - char minString[200]; minPtr = minString; sprintf_s(minString, 200, fmt, axisRange_.min); - char maxString[200]; maxPtr = maxString; sprintf_s(maxString, 200, fmt, axisRange_.max); } @@ -662,7 +662,7 @@ void Axis::drawLimits(Drawable drawable) Dim2D textDim; Blt_DrawText2(graphPtr_->tkwin_, drawable, maxPtr, &ops->limitsTextStyle, graphPtr_->right_, hMax, &textDim); - hMax -= (textDim.height + SPACING); + hMax -= (textDim.height + spacing); } else { ops->limitsTextStyle.angle = 0.0; @@ -671,7 +671,7 @@ void Axis::drawLimits(Drawable drawable) Dim2D textDim; Blt_DrawText2(graphPtr_->tkwin_, drawable, maxPtr, &ops->limitsTextStyle, vMax, graphPtr_->top_, &textDim); - vMax += (textDim.width + SPACING); + vMax += (textDim.width + spacing); } } if (minPtr) { @@ -683,7 +683,7 @@ void Axis::drawLimits(Drawable drawable) Dim2D textDim; Blt_DrawText2(graphPtr_->tkwin_, drawable, minPtr, &ops->limitsTextStyle, graphPtr_->left_, hMin, &textDim); - hMin -= (textDim.height + SPACING); + hMin -= (textDim.height + spacing); } else { ops->limitsTextStyle.angle = 0.0; @@ -691,7 +691,7 @@ void Axis::drawLimits(Drawable drawable) Dim2D textDim; Blt_DrawText2(graphPtr_->tkwin_, drawable, minPtr, &ops->limitsTextStyle, vMin, graphPtr_->bottom_, &textDim); - vMin += (textDim.width + SPACING); + vMin += (textDim.width + spacing); } } } @@ -1718,6 +1718,83 @@ void Axis::print(Blt_Ps ps) } } +void Axis::printLimits(Blt_Ps ps) +{ + AxisOptions* ops = (AxisOptions*)ops_; + GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; + + double vMin = graphPtr_->left_ + gops->xPad + 2; + double vMax = vMin; + double hMin = graphPtr_->bottom_ - gops->yPad - 2; + double hMax = hMin; + + const int spacing =8; + int isHoriz = isHorizontal(); + char* minPtr =NULL; + char* maxPtr =NULL; + char minString[200]; + char maxString[200]; + const char* fmt = ops->limitsFormat; + if (fmt && *fmt) { + minPtr = minString; + sprintf_s(minString, 200, fmt, axisRange_.min); + + maxPtr = maxString; + sprintf_s(maxString, 200, fmt, axisRange_.max); + } + if (ops->descending) { + char *tmp = minPtr; + minPtr = maxPtr; + maxPtr = tmp; + } + + unsigned int textWidth; + unsigned int textHeight; + if (maxPtr) { + Blt_GetTextExtents(ops->tickFont, 0, maxPtr, -1, &textWidth, &textHeight); + if ((textWidth > 0) && (textHeight > 0)) { + if (isHoriz) { + ops->limitsTextStyle.angle = 90.0; + ops->limitsTextStyle.anchor = TK_ANCHOR_SE; + + Blt_Ps_DrawText(ps, maxPtr, &ops->limitsTextStyle, + (double)graphPtr_->right_, hMax); + hMax -= (textWidth + spacing); + } + else { + ops->limitsTextStyle.angle = 0.0; + ops->limitsTextStyle.anchor = TK_ANCHOR_NW; + + Blt_Ps_DrawText(ps, maxPtr, &ops->limitsTextStyle, + vMax, (double)graphPtr_->top_); + vMax += (textWidth + spacing); + } + } + } + + if (minPtr) { + Blt_GetTextExtents(ops->tickFont, 0, minPtr, -1, &textWidth, &textHeight); + if ((textWidth > 0) && (textHeight > 0)) { + ops->limitsTextStyle.anchor = TK_ANCHOR_SW; + + if (isHoriz) { + ops->limitsTextStyle.angle = 90.0; + + Blt_Ps_DrawText(ps, minPtr, &ops->limitsTextStyle, + (double)graphPtr_->left_, hMin); + hMin -= (textWidth + spacing); + } + else { + ops->limitsTextStyle.angle = 0.0; + + Blt_Ps_DrawText(ps, minPtr, &ops->limitsTextStyle, + vMin, (double)graphPtr_->bottom_); + vMin += (textWidth + spacing); + } + } + } +} + void Axis::updateScrollbar(Tcl_Interp* interp, Tcl_Obj *scrollCmdObjPtr, int first, int last, int width) { diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h index 67b2056..fa42aa0 100644 --- a/src/bltGrAxis.h +++ b/src/bltGrAxis.h @@ -226,6 +226,7 @@ class Axis { void draw(Drawable); void drawLimits(Drawable); void print(Blt_Ps); + void printLimits(Blt_Ps); void mapStacked(int, int); void mapGridlines(); diff --git a/src/bltGrAxisOp.C b/src/bltGrAxisOp.C index 75adf84..2ff33f5 100644 --- a/src/bltGrAxisOp.C +++ b/src/bltGrAxisOp.C @@ -687,94 +687,6 @@ Point2d Blt_InvMap2D(Graph* graphPtr, double x, double y, Axis2d *axesPtr) return point; } -void Blt_DrawAxisLimits(Graph* graphPtr, Drawable drawable) -{ - Tcl_HashSearch cursor; - for (Tcl_HashEntry* hPtr=Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor); - hPtr; hPtr = Tcl_NextHashEntry(&cursor)) { - Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr); - AxisOptions* ops = (AxisOptions*)axisPtr->ops(); - - if ((axisPtr->flags & DELETE_PENDING) || (!ops->limitsFormat)) - continue; - axisPtr->drawLimits(drawable); - } -} - -void Blt_AxisLimitsToPostScript(Graph* graphPtr, Blt_Ps ps) -{ - GraphOptions* gops = (GraphOptions*)graphPtr->ops_; - Tcl_HashEntry *hPtr; - Tcl_HashSearch cursor; - double vMin, hMin, vMax, hMax; - char string[200]; - -#define SPACING 8 - vMin = vMax = graphPtr->left_ + gops->xPad + 2; - hMin = hMax = graphPtr->bottom_ - gops->yPad - 2; /* Offsets */ - for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) { - const char *minFmt, *maxFmt; - unsigned int textWidth, textHeight; - - Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr); - AxisOptions* ops = (AxisOptions*)axisPtr->ops(); - - if (axisPtr->flags & DELETE_PENDING) - continue; - - if (!ops->limitsFormat) - continue; - - minFmt = maxFmt = ops->limitsFormat; - if (*maxFmt != '\0') { - sprintf_s(string, 200, maxFmt, axisPtr->axisRange_.max); - Blt_GetTextExtents(ops->tickFont, 0, string, -1, &textWidth, - &textHeight); - if ((textWidth > 0) && (textHeight > 0)) { - if (axisPtr->classId() == CID_AXIS_X) { - ops->limitsTextStyle.angle = 90.0; - ops->limitsTextStyle.anchor = TK_ANCHOR_SE; - - Blt_Ps_DrawText(ps, string, &ops->limitsTextStyle, - (double)graphPtr->right_, hMax); - hMax -= (textWidth + SPACING); - } - else { - ops->limitsTextStyle.angle = 0.0; - ops->limitsTextStyle.anchor = TK_ANCHOR_NW; - - Blt_Ps_DrawText(ps, string, &ops->limitsTextStyle, - vMax, (double)graphPtr->top_); - vMax += (textWidth + SPACING); - } - } - } - if (*minFmt != '\0') { - sprintf_s(string, 200, minFmt, axisPtr->axisRange_.min); - Blt_GetTextExtents(ops->tickFont, 0, string, -1, &textWidth, - &textHeight); - if ((textWidth > 0) && (textHeight > 0)) { - ops->limitsTextStyle.anchor = TK_ANCHOR_SW; - if (axisPtr->classId() == CID_AXIS_X) { - ops->limitsTextStyle.angle = 90.0; - - Blt_Ps_DrawText(ps, string, &ops->limitsTextStyle, - (double)graphPtr->left_, hMin); - hMin -= (textWidth + SPACING); - } - else { - ops->limitsTextStyle.angle = 0.0; - - Blt_Ps_DrawText(ps, string, &ops->limitsTextStyle, - vMin, (double)graphPtr->bottom_); - vMin += (textWidth + SPACING); - } - } - } - } -} - void Blt_DrawGrids(Graph* graphPtr, Drawable drawable) { GraphOptions* gops = (GraphOptions*)graphPtr->ops_; diff --git a/src/bltGrAxisOp.h b/src/bltGrAxisOp.h index 8d8970d..50ea064 100644 --- a/src/bltGrAxisOp.h +++ b/src/bltGrAxisOp.h @@ -42,10 +42,8 @@ extern Point2d Blt_Map2D(Graph* graphPtr, double x, double y, Axis2d *pairPtr); extern void Blt_AdjustAxisPointers(Graph* graphPtr); -extern void Blt_DrawAxisLimits(Graph* graphPtr, Drawable drawable); extern void Blt_DrawGrids(Graph* graphPtr, Drawable drawable); extern void Blt_UpdateAxisBackgrounds(Graph* graphPtr); -extern void Blt_AxisLimitsToPostScript(Graph* graphPtr, Blt_Ps ps); extern void Blt_GridsToPostScript(Graph* graphPtr, Blt_Ps ps); extern Axis *Blt_GetFirstAxis(Blt_Chain chain); extern Axis *Blt_NearestAxis(Graph* graphPtr, int x, int y); diff --git a/src/bltGraph.C b/src/bltGraph.C index 3fe076f..0a14ed8 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -559,7 +559,7 @@ void Graph::drawPlot(Drawable drawable) } } - Blt_DrawAxisLimits(this, drawable); + drawAxesLimits(drawable); drawElements(drawable); } @@ -1193,6 +1193,50 @@ void Graph::drawAxes(Drawable drawable) } } +void Graph::drawAxesLimits(Drawable drawable) +{ + Tcl_HashSearch cursor; + for (Tcl_HashEntry* hPtr=Tcl_FirstHashEntry(&axes_.table, &cursor); + hPtr; hPtr = Tcl_NextHashEntry(&cursor)) { + Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr); + AxisOptions* ops = (AxisOptions*)axisPtr->ops(); + + if ((axisPtr->flags & DELETE_PENDING) || (!ops->limitsFormat)) + continue; + axisPtr->drawLimits(drawable); + } +} + +void Graph::printAxes(Blt_Ps ps) +{ + GraphOptions* gops = (GraphOptions*)ops_; + + Margin *mp, *mend; + for (mp = gops->margins, mend = mp + 4; mp < mend; mp++) { + for (Blt_ChainLink link=Blt_Chain_FirstLink(mp->axes); link; + link = Blt_Chain_NextLink(link)) { + Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link); + AxisOptions* ops = (AxisOptions*)axisPtr->ops(); + if (!ops->hide && axisPtr->use_ && !(axisPtr->flags & DELETE_PENDING)) + axisPtr->print(ps); + } + } +} + +void Graph::printAxesLimits(Blt_Ps ps) +{ + Tcl_HashSearch cursor; + for (Tcl_HashEntry* hPtr=Tcl_FirstHashEntry(&axes_.table, &cursor); + hPtr; hPtr = Tcl_NextHashEntry(&cursor)) { + Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr); + AxisOptions* ops = (AxisOptions*)axisPtr->ops(); + + if ((axisPtr->flags & DELETE_PENDING) || (!ops->limitsFormat)) + continue; + axisPtr->printLimits(ps); + } +} + void Graph::resetAxes() { GraphOptions* gops = (GraphOptions*)ops_; @@ -1268,19 +1312,4 @@ void Graph::resetAxes() flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | MAP_ALL | REDRAW_WORLD); } -void Graph::printAxes(Blt_Ps ps) -{ - GraphOptions* gops = (GraphOptions*)ops_; - - Margin *mp, *mend; - for (mp = gops->margins, mend = mp + 4; mp < mend; mp++) { - for (Blt_ChainLink link=Blt_Chain_FirstLink(mp->axes); link; - link = Blt_Chain_NextLink(link)) { - Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link); - AxisOptions* ops = (AxisOptions*)axisPtr->ops(); - if (!ops->hide && axisPtr->use_ && !(axisPtr->flags & DELETE_PENDING)) - axisPtr->print(ps); - } - } -} diff --git a/src/bltGraph.h b/src/bltGraph.h index 22f1705..e0ca4db 100644 --- a/src/bltGraph.h +++ b/src/bltGraph.h @@ -222,6 +222,7 @@ class Graph { void configureAxes(); void mapAxes(); void drawAxes(Drawable); + void drawAxesLimits(Drawable); public: Graph(ClientData clientData, Tcl_Interp*interp, @@ -241,6 +242,7 @@ class Graph { void resetAxes(); void printAxes(Blt_Ps); + void printAxesLimits(Blt_Ps); int isElementHidden(Blt::Marker*); Blt::Marker* nearestMarker(int, int, int); -- cgit v0.12