summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-04-16 20:10:04 (GMT)
committerjoye <joye>2014-04-16 20:10:04 (GMT)
commitcdde867c45b792ff12329e3dfea8c0ef81331b81 (patch)
treedbb5fb1b5991dd216779c9659f81f2baef6e3f16 /src
parent1b85ba58a3cd5e1ee3109b377fd96d70bb19595d (diff)
downloadblt-cdde867c45b792ff12329e3dfea8c0ef81331b81.zip
blt-cdde867c45b792ff12329e3dfea8c0ef81331b81.tar.gz
blt-cdde867c45b792ff12329e3dfea8c0ef81331b81.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltGrAxisOp.C159
-rw-r--r--src/bltGrAxisOp.h5
-rw-r--r--src/bltGrElemOp.C2
-rw-r--r--src/bltGraph.C170
-rw-r--r--src/bltGraph.h7
-rw-r--r--src/bltGraphOp.C20
6 files changed, 183 insertions, 180 deletions
diff --git a/src/bltGrAxisOp.C b/src/bltGrAxisOp.C
index 017b2cd..5ec3ff8 100644
--- a/src/bltGrAxisOp.C
+++ b/src/bltGrAxisOp.C
@@ -167,7 +167,7 @@ int AxisInvTransformOp(Tcl_Interp* interp, Axis* axisPtr,
Graph* graphPtr = axisPtr->graphPtr_;
if (graphPtr->flags & RESET_AXES)
- Blt_ResetAxes(graphPtr);
+ graphPtr->resetAxes();
int sy;
if (Tcl_GetIntFromObj(interp, objv[3], &sy) != TCL_OK)
@@ -191,7 +191,7 @@ int AxisLimitsOp(Tcl_Interp* interp, Axis* axisPtr,
Graph* graphPtr = axisPtr->graphPtr_;
if (graphPtr->flags & RESET_AXES)
- Blt_ResetAxes(graphPtr);
+ graphPtr->resetAxes();
double min, max;
if (ops->logScale) {
@@ -228,7 +228,7 @@ int AxisTransformOp(Tcl_Interp* interp, Axis* axisPtr,
Graph* graphPtr = axisPtr->graphPtr_;
if (graphPtr->flags & RESET_AXES)
- Blt_ResetAxes(graphPtr);
+ graphPtr->resetAxes();
double x;
if (Blt_ExprDoubleFromObj(interp, objv[3], &x) != TCL_OK)
@@ -626,23 +626,6 @@ int Blt_AxisOp(Graph* graphPtr, Tcl_Interp* interp,
// Support
-void Blt_DestroyAxes(Graph* graphPtr)
-{
- Tcl_HashSearch cursor;
- for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor); hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
- Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
- axisPtr->hashPtr_ = NULL;
- delete axisPtr;
- }
- Tcl_DeleteHashTable(&graphPtr->axes_.table);
-
- for (int ii=0; ii<4; ii++)
- Blt_Chain_Destroy(graphPtr->axisChain_[ii]);
-
- Tcl_DeleteHashTable(&graphPtr->axes_.tagTable);
- Blt_Chain_Destroy(graphPtr->axes_.displayList);
-}
-
int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
Axis **axisPtrPtr)
{
@@ -672,82 +655,6 @@ void FreeAxis(char* data)
delete axisPtr;
}
-void Blt_ResetAxes(Graph* graphPtr)
-{
- GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
-
- /* FIXME: This should be called whenever the display list of
- * elements change. Maybe yet another flag INIT_STACKS to
- * indicate that the element display list has changed.
- * Needs to be done before the axis limits are set.
- */
- Blt_InitBarSetTable(graphPtr);
- if ((gops->barMode == BARS_STACKED) && (graphPtr->nBarGroups_ > 0))
- Blt_ComputeBarStacks(graphPtr);
-
- /*
- * Step 1: Reset all axes. Initialize the data limits of the axis to
- * impossible values.
- */
- Tcl_HashSearch cursor;
- for (Tcl_HashEntry* hPtr = Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor);
- hPtr; hPtr = Tcl_NextHashEntry(&cursor)) {
- Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
- axisPtr->min_ = axisPtr->valueRange_.min = DBL_MAX;
- axisPtr->max_ = axisPtr->valueRange_.max = -DBL_MAX;
- }
-
- /*
- * Step 2: For each element that's to be displayed, get the smallest
- * and largest data values mapped to each X and Y-axis. This
- * will be the axis limits if the user doesn't override them
- * with -min and -max options.
- */
- for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->elements_.displayList);
- link; link = Blt_Chain_NextLink(link)) {
- Region2d exts;
-
- Element* elemPtr = (Element*)Blt_Chain_GetValue(link);
- ElementOptions* elemops = (ElementOptions*)elemPtr->ops();
- elemPtr->extents(&exts);
- elemops->axes.x->getDataLimits(exts.left, exts.right);
- elemops->axes.y->getDataLimits(exts.top, exts.bottom);
- }
- /*
- * Step 3: Now that we know the range of data values for each axis,
- * set axis limits and compute a sweep to generate tick values.
- */
- 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();
- axisPtr->fixRange();
-
- /* Calculate min/max tick (major/minor) layouts */
- double min = axisPtr->min_;
- double max = axisPtr->max_;
- if ((!isnan(axisPtr->scrollMin_)) && (min < axisPtr->scrollMin_))
- min = axisPtr->scrollMin_;
-
- if ((!isnan(axisPtr->scrollMax_)) && (max > axisPtr->scrollMax_))
- max = axisPtr->scrollMax_;
-
- if (ops->logScale)
- axisPtr->logScale(min, max);
- else
- axisPtr->linearScale(min, max);
-
- if (axisPtr->use_ && (axisPtr->flags & DIRTY))
- graphPtr->flags |= CACHE_DIRTY;
- }
-
- graphPtr->flags &= ~RESET_AXES;
-
- // When any axis changes, we need to layout the entire graph.
- graphPtr->flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | MAP_ALL |
- REDRAW_WORLD);
-}
-
Point2d Blt_Map2D(Graph* graphPtr, double x, double y, Axis2d *axesPtr)
{
GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
@@ -780,56 +687,6 @@ Point2d Blt_InvMap2D(Graph* graphPtr, double x, double y, Axis2d *axesPtr)
return point;
}
-void Blt_MapAxes(Graph* graphPtr)
-{
- GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
- for (int margin = 0; margin < 4; margin++) {
- int count =0;
- int offset =0;
- Blt_Chain chain = gops->margins[margin].axes;
- for (Blt_ChainLink link=Blt_Chain_FirstLink(chain); link;
- link = Blt_Chain_NextLink(link)) {
- Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link);
- AxisOptions* ops = (AxisOptions*)axisPtr->ops();
- if (!axisPtr->use_ || (axisPtr->flags & DELETE_PENDING))
- continue;
-
- if (gops->stackAxes) {
- if (ops->reqNumMajorTicks <= 0)
- ops->reqNumMajorTicks = 4;
-
- axisPtr->mapStacked(count, margin);
- }
- else {
- if (ops->reqNumMajorTicks <= 0)
- ops->reqNumMajorTicks = 4;
-
- axisPtr->map(offset, margin);
- }
-
- if (ops->showGrid)
- axisPtr->mapGridlines();
-
- offset += axisPtr->isHorizontal() ? axisPtr->height_ : axisPtr->width_;
- count++;
- }
- }
-}
-
-void Blt_DrawAxes(Graph* graphPtr, Drawable drawable)
-{
- GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
- for (int i = 0; i < 4; i++) {
- for (Blt_ChainLink link = Blt_Chain_LastLink(gops->margins[i].axes);
- link != NULL; link = Blt_Chain_PrevLink(link)) {
- Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link);
- AxisOptions* ops = (AxisOptions*)axisPtr->ops();
- if (!ops->hide && axisPtr->use_ && !(axisPtr->flags & DELETE_PENDING))
- axisPtr->draw(drawable);
- }
- }
-}
-
void Blt_DrawAxisLimits(Graph* graphPtr, Drawable drawable)
{
GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
@@ -992,16 +849,6 @@ void Blt_AxisLimitsToPostScript(Graph* graphPtr, Blt_Ps ps)
}
}
-void Blt_ConfigureAxes(Graph* graphPtr)
-{
- Tcl_HashSearch cursor;
- for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor);
- hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
- Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
- axisPtr->configure();
- }
-}
-
void Blt_DrawGrids(Graph* graphPtr, Drawable drawable)
{
GraphOptions* gops = (GraphOptions*)graphPtr->ops_;
diff --git a/src/bltGrAxisOp.h b/src/bltGrAxisOp.h
index 01985ef..aa5e80b 100644
--- a/src/bltGrAxisOp.h
+++ b/src/bltGrAxisOp.h
@@ -37,12 +37,7 @@ extern Tcl_FreeProc FreeAxis;
extern int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
Axis **axisPtrPtr);
-extern void Blt_ResetAxes(Graph* graphPtr);
-extern void Blt_MapAxes(Graph* graphPtr);
-extern void Blt_ConfigureAxes(Graph* graphPtr);
extern void Blt_AdjustAxisPointers(Graph* graphPtr);
-extern void Blt_DestroyAxes(Graph* graphPtr);
-extern void Blt_DrawAxes(Graph* graphPtr, Drawable drawable);
extern void Blt_DrawAxisLimits(Graph* graphPtr, Drawable drawable);
extern void Blt_DrawGrids(Graph* graphPtr, Drawable drawable);
extern void Blt_UpdateAxisBackgrounds(Graph* graphPtr);
diff --git a/src/bltGrElemOp.C b/src/bltGrElemOp.C
index 11f2472..1879e59 100644
--- a/src/bltGrElemOp.C
+++ b/src/bltGrElemOp.C
@@ -278,7 +278,7 @@ static int ClosestOp(Graph* graphPtr, Tcl_Interp* interp,
ClosestSearch* searchPtr = &gops->search;
if (graphPtr->flags & RESET_AXES)
- Blt_ResetAxes(graphPtr);
+ graphPtr->resetAxes();
int x;
if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK) {
diff --git a/src/bltGraph.C b/src/bltGraph.C
index ef5d42a..8feec62 100644
--- a/src/bltGraph.C
+++ b/src/bltGraph.C
@@ -334,7 +334,7 @@ Graph::~Graph()
if (legend_)
delete legend_;
- Blt_DestroyAxes(this);
+ destroyAxes();
Blt_DestroyPens(this);
Blt_DestroyPageSetup(this);
Blt_DestroyBarSets(this);
@@ -512,9 +512,9 @@ void Graph::display()
void Graph::map()
{
- if (flags & RESET_AXES) {
- Blt_ResetAxes(this);
- }
+ if (flags & RESET_AXES)
+ resetAxes();
+
if (flags & LAYOUT_NEEDED) {
Blt_LayoutGraph(this);
flags &= ~LAYOUT_NEEDED;
@@ -522,7 +522,7 @@ void Graph::map()
if ((vRange_ > 1) && (hRange_ > 1)) {
if (flags & MAP_WORLD)
- Blt_MapAxes(this);
+ mapAxes();
mapElements();
Blt::MapMarkers(this);
@@ -544,7 +544,7 @@ void Graph::drawPlot(Drawable drawable)
ops->plotBW, ops->plotRelief);
// Draw the elements, markers, legend, and axis limits
- Blt_DrawAxes(this, drawable);
+ drawAxes(drawable);
Blt_DrawGrids(this, drawable);
Blt::DrawMarkers(this, drawable, MARKER_UNDER);
@@ -669,7 +669,7 @@ void Graph::drawMargins(Drawable drawable)
Blt_DrawText(tkwin_, drawable, ops->title,
&ops->titleTextStyle, titleX_, titleY_);
- Blt_DrawAxes(this, drawable);
+ drawAxes(drawable);
flags &= ~DRAW_MARGINS;
}
@@ -737,7 +737,7 @@ void Graph::reconfigure()
configure();
legend_->configure();
configureElements();
- Blt_ConfigureAxes(this);
+ configureAxes();
Blt::ConfigureMarkers(this);
}
@@ -979,3 +979,157 @@ void Graph::printActiveElements(Blt_Ps ps)
}
}
+// Axis
+
+void Graph::destroyAxes()
+{
+ Tcl_HashSearch cursor;
+ for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&axes_.table, &cursor); hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
+ Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
+ axisPtr->hashPtr_ = NULL;
+ delete axisPtr;
+ }
+ Tcl_DeleteHashTable(&axes_.table);
+
+ for (int ii=0; ii<4; ii++)
+ Blt_Chain_Destroy(axisChain_[ii]);
+
+ Tcl_DeleteHashTable(&axes_.tagTable);
+ Blt_Chain_Destroy(axes_.displayList);
+}
+
+void Graph::configureAxes()
+{
+ Tcl_HashSearch cursor;
+ for (Tcl_HashEntry *hPtr=Tcl_FirstHashEntry(&axes_.table, &cursor);
+ hPtr; hPtr = Tcl_NextHashEntry(&cursor)) {
+ Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
+ axisPtr->configure();
+ }
+}
+
+void Graph::mapAxes()
+{
+ GraphOptions* gops = (GraphOptions*)ops_;
+ for (int margin = 0; margin < 4; margin++) {
+ int count =0;
+ int offset =0;
+ Blt_Chain chain = gops->margins[margin].axes;
+ for (Blt_ChainLink link=Blt_Chain_FirstLink(chain); link;
+ link = Blt_Chain_NextLink(link)) {
+ Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link);
+ AxisOptions* ops = (AxisOptions*)axisPtr->ops();
+ if (!axisPtr->use_ || (axisPtr->flags & DELETE_PENDING))
+ continue;
+
+ if (gops->stackAxes) {
+ if (ops->reqNumMajorTicks <= 0)
+ ops->reqNumMajorTicks = 4;
+
+ axisPtr->mapStacked(count, margin);
+ }
+ else {
+ if (ops->reqNumMajorTicks <= 0)
+ ops->reqNumMajorTicks = 4;
+
+ axisPtr->map(offset, margin);
+ }
+
+ if (ops->showGrid)
+ axisPtr->mapGridlines();
+
+ offset += axisPtr->isHorizontal() ? axisPtr->height_ : axisPtr->width_;
+ count++;
+ }
+ }
+}
+
+void Graph::drawAxes(Drawable drawable)
+{
+ GraphOptions* gops = (GraphOptions*)ops_;
+ for (int i = 0; i < 4; i++) {
+ for (Blt_ChainLink link = Blt_Chain_LastLink(gops->margins[i].axes);
+ link != NULL; link = Blt_Chain_PrevLink(link)) {
+ Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link);
+ AxisOptions* ops = (AxisOptions*)axisPtr->ops();
+ if (!ops->hide && axisPtr->use_ && !(axisPtr->flags & DELETE_PENDING))
+ axisPtr->draw(drawable);
+ }
+ }
+}
+
+void Graph::resetAxes()
+{
+ GraphOptions* gops = (GraphOptions*)ops_;
+
+ /* FIXME: This should be called whenever the display list of
+ * elements change. Maybe yet another flag INIT_STACKS to
+ * indicate that the element display list has changed.
+ * Needs to be done before the axis limits are set.
+ */
+ Blt_InitBarSetTable(this);
+ if ((gops->barMode == BARS_STACKED) && (nBarGroups_ > 0))
+ Blt_ComputeBarStacks(this);
+
+ /*
+ * Step 1: Reset all axes. Initialize the data limits of the axis to
+ * impossible values.
+ */
+ Tcl_HashSearch cursor;
+ for (Tcl_HashEntry* hPtr = Tcl_FirstHashEntry(&axes_.table, &cursor);
+ hPtr; hPtr = Tcl_NextHashEntry(&cursor)) {
+ Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
+ axisPtr->min_ = axisPtr->valueRange_.min = DBL_MAX;
+ axisPtr->max_ = axisPtr->valueRange_.max = -DBL_MAX;
+ }
+
+ /*
+ * Step 2: For each element that's to be displayed, get the smallest
+ * and largest data values mapped to each X and Y-axis. This
+ * will be the axis limits if the user doesn't override them
+ * with -min and -max options.
+ */
+ for (Blt_ChainLink link = Blt_Chain_FirstLink(elements_.displayList);
+ link; link = Blt_Chain_NextLink(link)) {
+ Region2d exts;
+
+ Element* elemPtr = (Element*)Blt_Chain_GetValue(link);
+ ElementOptions* elemops = (ElementOptions*)elemPtr->ops();
+ elemPtr->extents(&exts);
+ elemops->axes.x->getDataLimits(exts.left, exts.right);
+ elemops->axes.y->getDataLimits(exts.top, exts.bottom);
+ }
+ /*
+ * Step 3: Now that we know the range of data values for each axis,
+ * set axis limits and compute a sweep to generate tick values.
+ */
+ 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();
+ axisPtr->fixRange();
+
+ /* Calculate min/max tick (major/minor) layouts */
+ double min = axisPtr->min_;
+ double max = axisPtr->max_;
+ if ((!isnan(axisPtr->scrollMin_)) && (min < axisPtr->scrollMin_))
+ min = axisPtr->scrollMin_;
+
+ if ((!isnan(axisPtr->scrollMax_)) && (max > axisPtr->scrollMax_))
+ max = axisPtr->scrollMax_;
+
+ if (ops->logScale)
+ axisPtr->logScale(min, max);
+ else
+ axisPtr->linearScale(min, max);
+
+ if (axisPtr->use_ && (axisPtr->flags & DIRTY))
+ flags |= CACHE_DIRTY;
+ }
+
+ flags &= ~RESET_AXES;
+
+ // When any axis changes, we need to layout the entire graph.
+ flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | MAP_ALL | REDRAW_WORLD);
+}
+
diff --git a/src/bltGraph.h b/src/bltGraph.h
index a7397b4..9ba8640 100644
--- a/src/bltGraph.h
+++ b/src/bltGraph.h
@@ -206,6 +206,11 @@ class Graph {
void printElements(Blt_Ps);
void printActiveElements(Blt_Ps);
+ void destroyAxes();
+ void configureAxes();
+ void mapAxes();
+ void drawAxes(Drawable);
+
public:
Graph(ClientData clientData, Tcl_Interp*interp,
int objc, Tcl_Obj* const objv[], ClassId classId);
@@ -221,6 +226,8 @@ class Graph {
void enableCrosshairs();
void disableCrosshairs();
+
+ void resetAxes();
};
extern void Blt_ReconfigureGraph(Graph* graphPtr);
diff --git a/src/bltGraphOp.C b/src/bltGraphOp.C
index f70950d..68aa224 100644
--- a/src/bltGraphOp.C
+++ b/src/bltGraphOp.C
@@ -342,12 +342,12 @@ static int InvtransformOp(Graph* graphPtr, Tcl_Interp* interp, int objc,
{
double x, y;
if ((Blt_ExprDoubleFromObj(interp, objv[2], &x) != TCL_OK) ||
- (Blt_ExprDoubleFromObj(interp, objv[3], &y) != TCL_OK)) {
+ (Blt_ExprDoubleFromObj(interp, objv[3], &y) != TCL_OK))
return TCL_ERROR;
- }
- if (graphPtr->flags & RESET_AXES) {
- Blt_ResetAxes(graphPtr);
- }
+
+ if (graphPtr->flags & RESET_AXES)
+ graphPtr->resetAxes();
+
/* Perform the reverse transformation, converting from window coordinates
* to graph data coordinates. Note that the point is always mapped to the
* bottom and left axes (which may not be what the user wants). */
@@ -371,12 +371,12 @@ static int TransformOp(Graph* graphPtr, Tcl_Interp* interp, int objc,
{
double x, y;
if ((Blt_ExprDoubleFromObj(interp, objv[2], &x) != TCL_OK) ||
- (Blt_ExprDoubleFromObj(interp, objv[3], &y) != TCL_OK)) {
+ (Blt_ExprDoubleFromObj(interp, objv[3], &y) != TCL_OK))
return TCL_ERROR;
- }
- if (graphPtr->flags & RESET_AXES) {
- Blt_ResetAxes(graphPtr);
- }
+
+ if (graphPtr->flags & RESET_AXES)
+ graphPtr->resetAxes();
+
/*
* Perform the transformation from window to graph coordinates. Note that
* the points are always mapped onto the bottom and left axes (which may