summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-05-05 16:21:27 (GMT)
committerjoye <joye>2014-05-05 16:21:27 (GMT)
commitfefb3855ea88bea66eea1310084e38a8f6744502 (patch)
tree6c3ac1f908f1c7dde55d61f1c4b2fbc23b2d31f0 /src
parentca2e0a59b9e6727fde8fb2162ec874ee7a3e2fa4 (diff)
downloadblt-fefb3855ea88bea66eea1310084e38a8f6744502.zip
blt-fefb3855ea88bea66eea1310084e38a8f6744502.tar.gz
blt-fefb3855ea88bea66eea1310084e38a8f6744502.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltGrElemBar.C2
-rw-r--r--src/bltGrElemBar.h5
-rw-r--r--src/bltGraphBar.C104
-rw-r--r--src/bltGraphBar.h10
4 files changed, 63 insertions, 58 deletions
diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C
index 9452781..124072d 100644
--- a/src/bltGrElemBar.C
+++ b/src/bltGrElemBar.C
@@ -321,7 +321,7 @@ void BarElement::map()
if (hPtr) {
double slice, width, offset;
- BarGroup *groupPtr = (BarGroup*)Tcl_GetHashValue(hPtr);
+ BarGroup* groupPtr = (BarGroup*)Tcl_GetHashValue(hPtr);
slice = barWidth / (double)barGraphPtr_->maxBarSetSize_;
offset = (slice * groupPtr->index);
if (barGraphPtr_->maxBarSetSize_ > 1) {
diff --git a/src/bltGrElemBar.h b/src/bltGrElemBar.h
index 302dc58..103bd56 100644
--- a/src/bltGrElemBar.h
+++ b/src/bltGrElemBar.h
@@ -39,7 +39,10 @@
#include "bltGrPenBar.h"
typedef struct {
- float x1, y1, x2, y2;
+ float x1;
+ float y1;
+ float x2;
+ float y2;
} BarRegion;
typedef struct {
diff --git a/src/bltGraphBar.C b/src/bltGraphBar.C
index 5e64b89..ffc45f1 100644
--- a/src/bltGraphBar.C
+++ b/src/bltGraphBar.C
@@ -47,6 +47,21 @@
using namespace Blt;
+// BarGroup
+
+BarGroup::BarGroup()
+{
+ nSegments =0;
+ xAxis =NULL;
+ yAxis =NULL;
+ sum =0;
+ count =0;
+ lastY =0;
+ index =0;
+}
+
+// BarGraph
+
static const char* barmodeObjOption[] =
{"normal", "stacked", "aligned", "overlap", NULL};
static const char* searchModeObjOption[] = {"points", "traces", "auto", NULL};
@@ -329,47 +344,32 @@ void BarGraph::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
- */
+
+ // 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.
- */
+ // 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_HashTable setTable;
Tcl_InitHashTable(&setTable, sizeof(BarSetKey) / sizeof(int));
- nSegs = nStacks = 0;
- for (link = Blt_Chain_FirstLink(elements_.displayList);
+ int nSegs =0;
+ for (Blt_ChainLink 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 (ops->hide)
continue;
nSegs++;
-
if (ops->coords.x) {
- nPoints = ops->coords.x->nValues;
+ int nPoints = ops->coords.x->nValues;
+ double *x, *xend;
for (x = ops->coords.x->values, xend = x + nPoints; x < xend; x++) {
- size_t count;
- const char *name;
-
BarSetKey key;
key.value = *x;
key.xAxis = ops->xAxis;
@@ -385,8 +385,10 @@ void BarGraph::initBarSetTable()
else
tablePtr = (Tcl_HashTable*)Tcl_GetHashValue(hPtr);
- name = (ops->groupName) ? ops->groupName : ops->yAxis->name_;
+ const char* name =
+ (ops->groupName) ? ops->groupName : ops->yAxis->name_;
hPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew);
+ size_t count;
if (isNew)
count = 1;
else {
@@ -401,41 +403,36 @@ void BarGraph::initBarSetTable()
if (setTable.numEntries == 0)
return;
- sum = max = 0;
- for (hPtr = Tcl_FirstHashEntry(&setTable, &iter); hPtr;
+ int sum =0;
+ int max = 0;
+ Tcl_HashSearch iter;
+ for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&setTable, &iter); hPtr;
hPtr = Tcl_NextHashEntry(&iter)) {
- BarSetKey *keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr);
+ 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_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. */
- }
+ 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));
+ barGroups_ = new BarGroup[sum];
BarGroup* groupPtr = barGroups_;
- for (hPtr = Tcl_FirstHashEntry(&setTable_, &iter);
+ Tcl_HashSearch iter;
+ for (Tcl_HashEntry *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);
+ BarSetKey *keyPtr = (BarSetKey *)Tcl_GetHashKey(&setTable, hPtr);
+ size_t xcount = 0;
+ Tcl_HashSearch iter2;
+ for (Tcl_HashEntry *hPtr2 = Tcl_FirstHashEntry(tablePtr, &iter2);
+ hPtr2; hPtr2 = Tcl_NextHashEntry(&iter2)) {
+ size_t count = (size_t)Tcl_GetHashValue(hPtr2);
groupPtr->nSegments = count;
groupPtr->xAxis = keyPtr->xAxis;
groupPtr->yAxis = keyPtr->yAxis;
@@ -445,6 +442,7 @@ void BarGraph::initBarSetTable()
}
}
}
+
maxBarSetSize_ = max;
nBarGroups_ = sum;
}
@@ -452,7 +450,7 @@ void BarGraph::initBarSetTable()
void BarGraph::destroyBarSets()
{
if (barGroups_) {
- free(barGroups_);
+ delete [] barGroups_;
barGroups_ = NULL;
}
diff --git a/src/bltGraphBar.h b/src/bltGraphBar.h
index 4c1479c..a8816da 100644
--- a/src/bltGraphBar.h
+++ b/src/bltGraphBar.h
@@ -34,7 +34,8 @@
#include "bltGraph.h"
-typedef struct {
+class BarGroup {
+ public:
int nSegments;
Axis* xAxis;
Axis* yAxis;
@@ -42,7 +43,10 @@ typedef struct {
int count;
float lastY;
size_t index;
-} BarGroup;
+
+ public:
+ BarGroup();
+};
typedef struct {
float value;
@@ -90,7 +94,7 @@ typedef struct {
class BarGraph : public Graph {
public:
- BarGroup *barGroups_;
+ BarGroup* barGroups_;
int nBarGroups_;
Tcl_HashTable setTable_;
int maxBarSetSize_;