From 3a6fe8503067084554250dae3a1bbcb4247784c4 Mon Sep 17 00:00:00 2001 From: joye Date: Mon, 21 Apr 2014 18:17:05 +0000 Subject: *** empty log message *** --- src/bltGrElem.h | 4 - src/bltGrElemBar.C | 217 ----------------------------------------------------- src/bltGraph.C | 9 ++- src/bltGraphBar.C | 208 +++++++++++++++++++++++++++++++++++++++++++++++++- src/bltGraphBar.h | 4 + 5 files changed, 215 insertions(+), 227 deletions(-) diff --git a/src/bltGrElem.h b/src/bltGrElem.h index f73f662..214e427 100644 --- a/src/bltGrElem.h +++ b/src/bltGrElem.h @@ -166,9 +166,5 @@ class Element { }; extern void Blt_FreeStylePalette (Blt_Chain stylePalette); -extern void Blt_InitBarSetTable(Graph* graphPtr); -extern void Blt_ComputeBarStacks(Graph* graphPtr); -extern void Blt_ResetBarGroups(Graph* graphPtr); -extern void Blt_DestroyBarSets(Graph* graphPtr); #endif diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index ea193db..6a1475d 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -1440,220 +1440,3 @@ void BarElement::BarValuesToPostScript(Blt_Ps ps, BarPen* penPtr, } } -// External - -void Blt_InitBarSetTable(Graph* graphPtr) -{ - BarGraph* barGraphPtr = (BarGraph*)graphPtr; - BarGraphOptions* gops = (BarGraphOptions*)graphPtr->ops_; - Blt_ChainLink link; - int nStacks, nSegs; - Tcl_HashTable setTable; - int sum, max; - Tcl_HashEntry *hPtr; - Tcl_HashSearch iter; - - /* - * Free resources associated with a previous frequency table. This includes - * the array of frequency information and the table itself - */ - Blt_DestroyBarSets(graphPtr); - if (gops->barMode == BARS_INFRONT) - return; - Tcl_InitHashTable(&barGraphPtr->setTable_, sizeof(BarSetKey) / sizeof(int)); - - /* - * Initialize a hash table and fill it with unique abscissas. Keep track - * of the frequency of each x-coordinate and how many abscissas have - * duplicate mappings. - */ - Tcl_InitHashTable(&setTable, sizeof(BarSetKey) / sizeof(int)); - nSegs = nStacks = 0; - for (link = Blt_Chain_FirstLink(graphPtr->elements_.displayList); - link; link = Blt_Chain_NextLink(link)) { - double *x, *xend; - int nPoints; - - BarElement* bePtr = (BarElement*)Blt_Chain_GetValue(link); - BarElementOptions* ops = (BarElementOptions*)bePtr->ops(); - if ((bePtr->hide_) || (bePtr->classId() != CID_ELEM_BAR)) - continue; - - nSegs++; - - if (ops->coords.x) { - nPoints = ops->coords.x->nValues; - for (x = ops->coords.x->values, xend = x + nPoints; x < xend; x++) { - Tcl_HashEntry *hPtr; - BarSetKey key; - int isNew; - size_t count; - const char *name; - - key.value = *x; - key.axes = ops->axes; - key.axes.y = NULL; - hPtr = Tcl_CreateHashEntry(&setTable, (char *)&key, &isNew); - Tcl_HashTable *tablePtr; - if (isNew) { - tablePtr = (Tcl_HashTable*)malloc(sizeof(Tcl_HashTable)); - Tcl_InitHashTable(tablePtr, TCL_STRING_KEYS); - Tcl_SetHashValue(hPtr, tablePtr); - } - else - tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); - - name = (ops->groupName) ? ops->groupName : ops->axes.y->name_; - hPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew); - if (isNew) - count = 1; - else { - count = (size_t)Tcl_GetHashValue(hPtr); - count++; - } - Tcl_SetHashValue(hPtr, (ClientData)count); - } - } - } - - if (setTable.numEntries == 0) - return; - - sum = max = 0; - for (hPtr = Tcl_FirstHashEntry(&setTable, &iter); hPtr; - hPtr = Tcl_NextHashEntry(&iter)) { - Tcl_HashEntry *hPtr2; - BarSetKey *keyPtr; - int isNew; - - keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr); - hPtr2 = Tcl_CreateHashEntry(&barGraphPtr->setTable_, (char *)keyPtr,&isNew); - Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); - Tcl_SetHashValue(hPtr2, tablePtr); - if (max < tablePtr->numEntries) { - max = tablePtr->numEntries; /* # of stacks in group. */ - } - sum += tablePtr->numEntries; - } - Tcl_DeleteHashTable(&setTable); - if (sum > 0) { - Tcl_HashEntry *hPtr; - Tcl_HashSearch iter; - - barGraphPtr->barGroups_ = (BarGroup*)calloc(sum, sizeof(BarGroup)); - BarGroup* groupPtr = barGraphPtr->barGroups_; - for (hPtr = Tcl_FirstHashEntry(&barGraphPtr->setTable_, &iter); - hPtr; hPtr = Tcl_NextHashEntry(&iter)) { - BarSetKey *keyPtr; - Tcl_HashEntry *hPtr2; - Tcl_HashSearch iter2; - size_t xcount; - - Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); - keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr); - xcount = 0; - for (hPtr2 = Tcl_FirstHashEntry(tablePtr, &iter2); hPtr2!=NULL; - hPtr2 = Tcl_NextHashEntry(&iter2)) { - size_t count; - - count = (size_t)Tcl_GetHashValue(hPtr2); - groupPtr->nSegments = count; - groupPtr->axes = keyPtr->axes; - Tcl_SetHashValue(hPtr2, groupPtr); - groupPtr->index = xcount++; - groupPtr++; - } - } - } - barGraphPtr->maxBarSetSize_ = max; - barGraphPtr->nBarGroups_ = sum; -} - -void Blt_ComputeBarStacks(Graph* graphPtr) -{ - BarGraph* barGraphPtr = (BarGraph*)graphPtr; - BarGraphOptions* gops = (BarGraphOptions*)graphPtr->ops_; - - Blt_ChainLink link; - if ((gops->barMode != BARS_STACKED) || (barGraphPtr->nBarGroups_ == 0)) - return; - - /* Initialize the stack sums to zero. */ - { - BarGroup *gp, *gend; - for (gp = barGraphPtr->barGroups_, gend = gp + barGraphPtr->nBarGroups_; - gp < gend; gp++) { - gp->sum = 0.0; - } - } - - /* Consider each bar x-y coordinate. Add the ordinates of duplicate - * abscissas. */ - - for (link = Blt_Chain_FirstLink(graphPtr->elements_.displayList); - link; link = Blt_Chain_NextLink(link)) { - double *x, *y, *xend; - - BarElement* bePtr = (BarElement*)Blt_Chain_GetValue(link); - BarElementOptions* ops = (BarElementOptions*)bePtr->ops(); - if ((bePtr->hide_) || (bePtr->classId() != CID_ELEM_BAR)) - continue; - - if (ops->coords.x && ops->coords.y) { - for (x = ops->coords.x->values, y = ops->coords.y->values, - xend = x + ops->coords.x->nValues; x < xend; x++, y++) { - BarSetKey key; - Tcl_HashEntry *hPtr; - const char *name; - - key.value = *x; - key.axes = ops->axes; - key.axes.y = NULL; - hPtr = Tcl_FindHashEntry(&barGraphPtr->setTable_, (char *)&key); - if (!hPtr) - continue; - - Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); - name = (ops->groupName) ? ops->groupName : ops->axes.y->name_; - hPtr = Tcl_FindHashEntry(tablePtr, name); - if (!hPtr) - continue; - - BarGroup *groupPtr = (BarGroup*)Tcl_GetHashValue(hPtr); - groupPtr->sum += *y; - } - } - } -} - -void Blt_ResetBarGroups(Graph* graphPtr) -{ - BarGraph* barGraphPtr = (BarGraph*)graphPtr; - BarGroup* gp; - BarGroup* gend; - for (gp = barGraphPtr->barGroups_, gend = gp + barGraphPtr->nBarGroups_; gp < gend; - gp++) { - gp->lastY = 0.0; - gp->count = 0; - } -} - -void Blt_DestroyBarSets(Graph* graphPtr) -{ - BarGraph* barGraphPtr = (BarGraph*)graphPtr; - if (barGraphPtr->barGroups_) { - free(barGraphPtr->barGroups_); - barGraphPtr->barGroups_ = NULL; - } - - barGraphPtr->nBarGroups_ = 0; - Tcl_HashSearch iter; - for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&barGraphPtr->setTable_, &iter); - hPtr; hPtr = Tcl_NextHashEntry(&iter)) { - Tcl_HashTable* tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); - Tcl_DeleteHashTable(tablePtr); - free(tablePtr); - } - Tcl_DeleteHashTable(&barGraphPtr->setTable_); - Tcl_InitHashTable(&barGraphPtr->setTable_, sizeof(BarSetKey) / sizeof(int)); -} diff --git a/src/bltGraph.C b/src/bltGraph.C index 463c2e6..dbfc820 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -125,14 +125,19 @@ Graph::Graph(ClientData clientData, Tcl_Interp* interp, axes_.displayList = Blt_Chain_Create(); elements_.displayList = Blt_Chain_Create(); markers_.displayList = Blt_Chain_Create(); - bindTable_ = Blt_CreateBindingTable(interp_, tkwin_, this, - PickEntry, Blt_GraphTags); + bindTable_ = Blt_CreateBindingTable(interp_, tkwin_, this, PickEntry, + Blt_GraphTags); if (createAxes() != TCL_OK) { valid_ =0; return; } + if (Blt_CreatePageSetup(this) != TCL_OK) { + valid_ =0; + return; + } + // Keep a hold of the associated tkwin until we destroy the graph, // otherwise Tk might free it while we still need it. Tcl_Preserve(tkwin_); diff --git a/src/bltGraphBar.C b/src/bltGraphBar.C index 39ab46b..a70c09c 100644 --- a/src/bltGraphBar.C +++ b/src/bltGraphBar.C @@ -232,7 +232,7 @@ BarGraph::BarGraph(ClientData clientData, Tcl_Interp* interp, BarGraph::~BarGraph() { - Blt_DestroyBarSets(this); + destroyBarSets(); } void BarGraph::configure() @@ -312,7 +312,7 @@ void BarGraph::mapElements() { BarGraphOptions* ops = (BarGraphOptions*)ops_; if (ops->barMode != BARS_INFRONT) - Blt_ResetBarGroups(this); + resetBarGroups(); Graph::mapElements(); } @@ -326,9 +326,209 @@ void BarGraph::resetAxes() * indicate that the element display list has changed. * Needs to be done before the axis limits are set. */ - Blt_InitBarSetTable(this); + initBarSetTable(); if ((ops->barMode == BARS_STACKED) && (nBarGroups_ > 0)) - Blt_ComputeBarStacks(this); + computeBarStacks(); Graph::resetAxes(); } + +void BarGraph::initBarSetTable() +{ + BarGraphOptions* ops = (BarGraphOptions*)ops_; + Blt_ChainLink link; + int nStacks, nSegs; + Tcl_HashTable setTable; + int sum, max; + Tcl_HashEntry *hPtr; + Tcl_HashSearch iter; + + /* + * Free resources associated with a previous frequency table. This includes + * the array of frequency information and the table itself + */ + destroyBarSets(); + if (ops->barMode == BARS_INFRONT) + return; + Tcl_InitHashTable(&setTable_, sizeof(BarSetKey) / sizeof(int)); + + /* + * Initialize a hash table and fill it with unique abscissas. Keep track + * of the frequency of each x-coordinate and how many abscissas have + * duplicate mappings. + */ + Tcl_InitHashTable(&setTable, sizeof(BarSetKey) / sizeof(int)); + nSegs = nStacks = 0; + for (link = Blt_Chain_FirstLink(elements_.displayList); + link; link = Blt_Chain_NextLink(link)) { + double *x, *xend; + int nPoints; + + BarElement* bePtr = (BarElement*)Blt_Chain_GetValue(link); + BarElementOptions* ops = (BarElementOptions*)bePtr->ops(); + if ((bePtr->hide_) || (bePtr->classId() != CID_ELEM_BAR)) + continue; + + nSegs++; + + if (ops->coords.x) { + nPoints = ops->coords.x->nValues; + for (x = ops->coords.x->values, xend = x + nPoints; x < xend; x++) { + size_t count; + const char *name; + + BarSetKey key; + key.value = *x; + key.axes = ops->axes; + key.axes.y = NULL; + int isNew; + Tcl_HashEntry* hPtr = Tcl_CreateHashEntry(&setTable, (char *)&key, &isNew); + Tcl_HashTable *tablePtr; + if (isNew) { + tablePtr = (Tcl_HashTable*)malloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(tablePtr, TCL_STRING_KEYS); + Tcl_SetHashValue(hPtr, tablePtr); + } + else + tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); + + name = (ops->groupName) ? ops->groupName : ops->axes.y->name_; + hPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew); + if (isNew) + count = 1; + else { + count = (size_t)Tcl_GetHashValue(hPtr); + count++; + } + Tcl_SetHashValue(hPtr, (ClientData)count); + } + } + } + + if (setTable.numEntries == 0) + return; + + sum = max = 0; + for (hPtr = Tcl_FirstHashEntry(&setTable, &iter); hPtr; + hPtr = Tcl_NextHashEntry(&iter)) { + BarSetKey *keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr); + int isNew; + Tcl_HashEntry *hPtr2 = Tcl_CreateHashEntry(&setTable_, (char *)keyPtr,&isNew); + Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); + Tcl_SetHashValue(hPtr2, tablePtr); + if (max < tablePtr->numEntries) { + max = tablePtr->numEntries; /* # of stacks in group. */ + } + sum += tablePtr->numEntries; + } + Tcl_DeleteHashTable(&setTable); + if (sum > 0) { + Tcl_HashEntry *hPtr; + Tcl_HashSearch iter; + + barGroups_ = (BarGroup*)calloc(sum, sizeof(BarGroup)); + BarGroup* groupPtr = barGroups_; + for (hPtr = Tcl_FirstHashEntry(&setTable_, &iter); + hPtr; hPtr = Tcl_NextHashEntry(&iter)) { + BarSetKey *keyPtr; + Tcl_HashEntry *hPtr2; + Tcl_HashSearch iter2; + size_t xcount; + + Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); + keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr); + xcount = 0; + for (hPtr2 = Tcl_FirstHashEntry(tablePtr, &iter2); hPtr2!=NULL; + hPtr2 = Tcl_NextHashEntry(&iter2)) { + size_t count; + + count = (size_t)Tcl_GetHashValue(hPtr2); + groupPtr->nSegments = count; + groupPtr->axes = keyPtr->axes; + Tcl_SetHashValue(hPtr2, groupPtr); + groupPtr->index = xcount++; + groupPtr++; + } + } + } + maxBarSetSize_ = max; + nBarGroups_ = sum; +} + +void BarGraph::destroyBarSets() +{ + if (barGroups_) { + free(barGroups_); + barGroups_ = NULL; + } + + nBarGroups_ = 0; + Tcl_HashSearch iter; + for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&setTable_, &iter); + hPtr; hPtr = Tcl_NextHashEntry(&iter)) { + Tcl_HashTable* tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); + Tcl_DeleteHashTable(tablePtr); + free(tablePtr); + } + Tcl_DeleteHashTable(&setTable_); + Tcl_InitHashTable(&setTable_, sizeof(BarSetKey) / sizeof(int)); +} + +void BarGraph::resetBarGroups() +{ + BarGroup *gp, *gend; + for (gp = barGroups_, gend = gp + nBarGroups_; gp < gend; gp++) { + gp->lastY = 0.0; + gp->count = 0; + } +} + +void BarGraph::computeBarStacks() +{ + BarGraphOptions* ops = (BarGraphOptions*)ops_; + + Blt_ChainLink link; + if ((ops->barMode != BARS_STACKED) || (nBarGroups_ == 0)) + return; + + // Initialize the stack sums to zero + BarGroup *gp, *gend; + for (gp = barGroups_, gend = gp + nBarGroups_; gp < gend; gp++) + gp->sum = 0.0; + + // Consider each bar x-y coordinate. Add the ordinates of duplicate + // abscissas + + for (link = Blt_Chain_FirstLink(elements_.displayList); + link; link = Blt_Chain_NextLink(link)) { + BarElement* bePtr = (BarElement*)Blt_Chain_GetValue(link); + BarElementOptions* ops = (BarElementOptions*)bePtr->ops(); + if ((bePtr->hide_) || (bePtr->classId() != CID_ELEM_BAR)) + continue; + + if (ops->coords.x && ops->coords.y) { + double *x, *y, *xend; + for (x = ops->coords.x->values, y = ops->coords.y->values, + xend = x + ops->coords.x->nValues; x < xend; x++, y++) { + BarSetKey key; + key.value = *x; + key.axes = ops->axes; + key.axes.y = NULL; + Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&setTable_, (char *)&key); + if (!hPtr) + continue; + + Tcl_HashTable *tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr); + const char *name = (ops->groupName) ? + ops->groupName : ops->axes.y->name_; + hPtr = Tcl_FindHashEntry(tablePtr, name); + if (!hPtr) + continue; + + BarGroup *groupPtr = (BarGroup*)Tcl_GetHashValue(hPtr); + groupPtr->sum += *y; + } + } + } +} + diff --git a/src/bltGraphBar.h b/src/bltGraphBar.h index 4caae15..6b34184 100644 --- a/src/bltGraphBar.h +++ b/src/bltGraphBar.h @@ -96,6 +96,10 @@ class BarGraph : public Graph { protected: void resetAxes(); void mapElements(); + void initBarSetTable(); + void destroyBarSets(); + void resetBarGroups(); + void computeBarStacks(); public: BarGraph(ClientData, Tcl_Interp*, int, Tcl_Obj* const []); -- cgit v0.12