| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "bltGraph.h" |
| 29 |
#include "bltGrElem.h" |
| 30 |
#include <X11/Xutil.h> |
| 31 |
|
| 32 |
#define DEF_NUM_TICKS 4 |
| 33 |
#define STATIC_TICK_SPACE 10 |
| 34 |
|
| 35 |
#define TICK_LABEL_SIZE 200 |
| 36 |
#define MAXTICKS 10001 |
| 37 |
|
| 38 |
#define CLAMP(val,low,high) \ |
| 39 |
(((val) < (low)) ? (low) : ((val) > (high)) ? (high) : (val)) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define UROUND(x,u) (Round((x)/(u))*(u)) |
| 45 |
#define UCEIL(x,u) (ceil((x)/(u))*(u)) |
| 46 |
#define UFLOOR(x,u) (floor((x)/(u))*(u)) |
| 47 |
|
| 48 |
#define LENGTH_MAJOR_TICK 0.030 |
| 49 |
#define LENGTH_MINOR_TICK 0.015 |
| 50 |
#define LENGTH_LABEL_TICK 0.040 |
| 51 |
|
| 52 |
#define NUMDIGITS 15 |
| 53 |
|
| 54 |
|
| 55 |
#define AVG_TICK_NUM_CHARS 16 |
| 56 |
|
| 57 |
#define TICK_RANGE_TIGHT 0 |
| 58 |
#define TICK_RANGE_LOOSE 1 |
| 59 |
#define TICK_RANGE_ALWAYS_LOOSE 2 |
| 60 |
|
| 61 |
#define AXIS_TITLE_PAD 2 |
| 62 |
#define AXIS_LINE_PAD 1 |
| 63 |
|
| 64 |
#define HORIZMARGIN(m) (!((m)->site & 0x1)) |
| 65 |
|
| 66 |
typedef enum AxisComponents { |
| 67 |
MAJOR_TICK, MINOR_TICK, TICK_LABEL, AXIS_LINE |
| 68 |
} AxisComponent; |
| 69 |
|
| 70 |
|
| 71 |
typedef struct { |
| 72 |
int axis; |
| 73 |
int t1; |
| 74 |
int t2; |
| 75 |
int label; |
| 76 |
} AxisInfo; |
| 77 |
|
| 78 |
extern Tk_CustomOption bltDistanceOption; |
| 79 |
extern Tk_CustomOption bltPositiveDistanceOption; |
| 80 |
extern Tk_CustomOption bltShadowOption; |
| 81 |
extern Tk_CustomOption bltListOption; |
| 82 |
|
| 83 |
static Tk_OptionParseProc StringToLimit; |
| 84 |
static Tk_OptionPrintProc LimitToString; |
| 85 |
static Tk_OptionParseProc StringToTicks; |
| 86 |
static Tk_OptionPrintProc TicksToString; |
| 87 |
static Tk_OptionParseProc StringToAxis; |
| 88 |
static Tk_OptionPrintProc AxisToString; |
| 89 |
static Tk_OptionParseProc StringToAnyAxis; |
| 90 |
static Tk_OptionParseProc StringToFormat; |
| 91 |
static Tk_OptionPrintProc FormatToString; |
| 92 |
static Tk_OptionParseProc StringToLoose; |
| 93 |
static Tk_OptionPrintProc LooseToString; |
| 94 |
|
| 95 |
static Tk_CustomOption limitOption = |
| 96 |
{ |
| 97 |
StringToLimit, LimitToString, (ClientData)0 |
| 98 |
}; |
| 99 |
|
| 100 |
static Tk_CustomOption majorTicksOption = |
| 101 |
{ |
| 102 |
StringToTicks, TicksToString, (ClientData)AXIS_CONFIG_MAJOR, |
| 103 |
}; |
| 104 |
static Tk_CustomOption minorTicksOption = |
| 105 |
{ |
| 106 |
StringToTicks, TicksToString, (ClientData)AXIS_CONFIG_MINOR, |
| 107 |
}; |
| 108 |
Tk_CustomOption bltXAxisOption = |
| 109 |
{ |
| 110 |
StringToAxis, AxisToString, (ClientData)&bltXAxisUid |
| 111 |
}; |
| 112 |
Tk_CustomOption bltYAxisOption = |
| 113 |
{ |
| 114 |
StringToAxis, AxisToString, (ClientData)&bltYAxisUid |
| 115 |
}; |
| 116 |
Tk_CustomOption bltAnyXAxisOption = |
| 117 |
{ |
| 118 |
StringToAnyAxis, AxisToString, (ClientData)&bltXAxisUid |
| 119 |
}; |
| 120 |
Tk_CustomOption bltAnyYAxisOption = |
| 121 |
{ |
| 122 |
StringToAnyAxis, AxisToString, (ClientData)&bltYAxisUid |
| 123 |
}; |
| 124 |
static Tk_CustomOption formatOption = |
| 125 |
{ |
| 126 |
StringToFormat, FormatToString, (ClientData)0, |
| 127 |
}; |
| 128 |
static Tk_CustomOption looseOption = |
| 129 |
{ |
| 130 |
StringToLoose, LooseToString, (ClientData)0, |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
#define DEF_AXIS_COMMAND (char *)NULL |
| 136 |
#define DEF_AXIS_DESCENDING "no" |
| 137 |
#define DEF_AXIS_FOREGROUND RGB_BLACK |
| 138 |
#define DEF_AXIS_FG_MONO RGB_BLACK |
| 139 |
#define DEF_AXIS_HIDE "no" |
| 140 |
#define DEF_AXIS_JUSTIFY "center" |
| 141 |
#define DEF_AXIS_LIMITS_FORMAT (char *)NULL |
| 142 |
#define DEF_AXIS_LINE_WIDTH "1" |
| 143 |
#define DEF_AXIS_LOGSCALE "no" |
| 144 |
#define DEF_AXIS_LOOSE "no" |
| 145 |
#define DEF_AXIS_RANGE "0.0" |
| 146 |
#define DEF_AXIS_ROTATE "0.0" |
| 147 |
#define DEF_AXIS_SCROLL_INCREMENT "10" |
| 148 |
#define DEF_AXIS_SHIFTBY "0.0" |
| 149 |
#define DEF_AXIS_SHOWTICKS "yes" |
| 150 |
#define DEF_AXIS_STEP "0.0" |
| 151 |
#define DEF_AXIS_STEP "0.0" |
| 152 |
#define DEF_AXIS_SUBDIVISIONS "2" |
| 153 |
#define DEF_AXIS_TAGS "all" |
| 154 |
#define DEF_AXIS_TICKS "0" |
| 155 |
#ifdef WIN32 |
| 156 |
#define DEF_AXIS_TICK_FONT "{Arial Narrow} 8" |
| 157 |
#else |
| 158 |
#define DEF_AXIS_TICK_FONT "*-Helvetica-Medium-R-Normal-*-10-*" |
| 159 |
#endif |
| 160 |
#define DEF_AXIS_TICK_LENGTH "8" |
| 161 |
#define DEF_AXIS_TITLE_ALTERNATE "0" |
| 162 |
#define DEF_AXIS_TITLE_FG RGB_BLACK |
| 163 |
#define DEF_AXIS_TITLE_FONT STD_FONT |
| 164 |
#define DEF_AXIS_X_STEP_BARCHART "1.0" |
| 165 |
#define DEF_AXIS_X_SUBDIVISIONS_BARCHART "0" |
| 166 |
#define DEF_AXIS_BACKGROUND (char *)NULL |
| 167 |
#define DEF_AXIS_BORDERWIDTH "0" |
| 168 |
#define DEF_AXIS_RELIEF "flat" |
| 169 |
|
| 170 |
static Tk_ConfigSpec configSpecs[] = |
| 171 |
{ |
| 172 |
{TK_CONFIG_DOUBLE, "-autorange", "autoRange", "AutoRange", |
| 173 |
DEF_AXIS_RANGE, Tk_Offset(Axis, windowSize), |
| 174 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 175 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 176 |
DEF_AXIS_BACKGROUND, Tk_Offset(Axis, border), |
| 177 |
ALL_GRAPHS | TK_CONFIG_NULL_OK}, |
| 178 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0}, |
| 179 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 180 |
DEF_AXIS_TAGS, Tk_Offset(Axis, tags), |
| 181 |
ALL_GRAPHS | TK_CONFIG_NULL_OK, &bltListOption}, |
| 182 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, |
| 183 |
(char *)NULL, 0, ALL_GRAPHS}, |
| 184 |
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth", |
| 185 |
DEF_AXIS_BORDERWIDTH, Tk_Offset(Axis, borderWidth), |
| 186 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 187 |
{TK_CONFIG_COLOR, "-color", "color", "Color", |
| 188 |
DEF_AXIS_FOREGROUND, Tk_Offset(Axis, tickTextStyle.color), |
| 189 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS}, |
| 190 |
{TK_CONFIG_COLOR, "-color", "color", "Color", |
| 191 |
DEF_AXIS_FG_MONO, Tk_Offset(Axis, tickTextStyle.color), |
| 192 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS}, |
| 193 |
{TK_CONFIG_STRING, "-command", "command", "Command", |
| 194 |
DEF_AXIS_COMMAND, Tk_Offset(Axis, formatCmd), |
| 195 |
TK_CONFIG_NULL_OK | ALL_GRAPHS}, |
| 196 |
{TK_CONFIG_BOOLEAN, "-descending", "descending", "Descending", |
| 197 |
DEF_AXIS_DESCENDING, Tk_Offset(Axis, descending), |
| 198 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 199 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 200 |
DEF_AXIS_HIDE, Tk_Offset(Axis, hidden), |
| 201 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 202 |
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", |
| 203 |
DEF_AXIS_JUSTIFY, Tk_Offset(Axis, titleTextStyle.justify), |
| 204 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 205 |
{TK_CONFIG_BOOLEAN, "-labeloffset", "labelOffset", "LabelOffset", |
| 206 |
(char *)NULL, Tk_Offset(Axis, labelOffset), ALL_GRAPHS}, |
| 207 |
{TK_CONFIG_COLOR, "-limitscolor", "limitsColor", "Color", |
| 208 |
DEF_AXIS_FOREGROUND, Tk_Offset(Axis, limitsTextStyle.color), |
| 209 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS}, |
| 210 |
{TK_CONFIG_COLOR, "-limitscolor", "limitsColor", "Color", |
| 211 |
DEF_AXIS_FG_MONO, Tk_Offset(Axis, limitsTextStyle.color), |
| 212 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS}, |
| 213 |
{TK_CONFIG_FONT, "-limitsfont", "limitsFont", "Font", |
| 214 |
DEF_AXIS_TICK_FONT, Tk_Offset(Axis, limitsTextStyle.font), ALL_GRAPHS}, |
| 215 |
{TK_CONFIG_CUSTOM, "-limitsformat", "limitsFormat", "LimitsFormat", |
| 216 |
(char *)NULL, Tk_Offset(Axis, limitsFormats), |
| 217 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &formatOption}, |
| 218 |
{TK_CONFIG_CUSTOM, "-limitsshadow", "limitsShadow", "Shadow", |
| 219 |
(char *)NULL, Tk_Offset(Axis, limitsTextStyle.shadow), |
| 220 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 221 |
{TK_CONFIG_CUSTOM, "-limitsshadow", "limitsShadow", "Shadow", |
| 222 |
(char *)NULL, Tk_Offset(Axis, limitsTextStyle.shadow), |
| 223 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 224 |
{TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth", |
| 225 |
DEF_AXIS_LINE_WIDTH, Tk_Offset(Axis, lineWidth), |
| 226 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 227 |
{TK_CONFIG_BOOLEAN, "-logscale", "logScale", "LogScale", |
| 228 |
DEF_AXIS_LOGSCALE, Tk_Offset(Axis, logScale), |
| 229 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 230 |
{TK_CONFIG_CUSTOM, "-loose", "loose", "Loose", |
| 231 |
DEF_AXIS_LOOSE, 0, ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, |
| 232 |
&looseOption}, |
| 233 |
{TK_CONFIG_CUSTOM, "-majorticks", "majorTicks", "MajorTicks", |
| 234 |
(char *)NULL, Tk_Offset(Axis, t1Ptr), |
| 235 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &majorTicksOption}, |
| 236 |
{TK_CONFIG_CUSTOM, "-max", "max", "Max", |
| 237 |
(char *)NULL, Tk_Offset(Axis, reqMax), |
| 238 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &limitOption}, |
| 239 |
{TK_CONFIG_CUSTOM, "-min", "min", "Min", |
| 240 |
(char *)NULL, Tk_Offset(Axis, reqMin), |
| 241 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &limitOption}, |
| 242 |
{TK_CONFIG_CUSTOM, "-minorticks", "minorTicks", "MinorTicks", |
| 243 |
(char *)NULL, Tk_Offset(Axis, t2Ptr), |
| 244 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &minorTicksOption}, |
| 245 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 246 |
DEF_AXIS_RELIEF, Tk_Offset(Axis, relief), |
| 247 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 248 |
{TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate", |
| 249 |
DEF_AXIS_ROTATE, Tk_Offset(Axis, tickTextStyle.theta), |
| 250 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 251 |
{TK_CONFIG_STRING, "-scrollcommand", "scrollCommand", "ScrollCommand", |
| 252 |
(char *)NULL, Tk_Offset(Axis, scrollCmdPrefix), |
| 253 |
ALL_GRAPHS | TK_CONFIG_NULL_OK}, |
| 254 |
{TK_CONFIG_CUSTOM, "-scrollincrement", "scrollIncrement", "ScrollIncrement", |
| 255 |
DEF_AXIS_SCROLL_INCREMENT, Tk_Offset(Axis, scrollUnits), |
| 256 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveDistanceOption}, |
| 257 |
{TK_CONFIG_CUSTOM, "-scrollmax", "scrollMax", "ScrollMax", |
| 258 |
(char *)NULL, Tk_Offset(Axis, scrollMax), |
| 259 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &limitOption}, |
| 260 |
{TK_CONFIG_CUSTOM, "-scrollmin", "scrollMin", "ScrollMin", |
| 261 |
(char *)NULL, Tk_Offset(Axis, scrollMin), |
| 262 |
TK_CONFIG_NULL_OK | ALL_GRAPHS, &limitOption}, |
| 263 |
{TK_CONFIG_DOUBLE, "-shiftby", "shiftBy", "ShiftBy", |
| 264 |
DEF_AXIS_SHIFTBY, Tk_Offset(Axis, shiftBy), |
| 265 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 266 |
{TK_CONFIG_BOOLEAN, "-showticks", "showTicks", "ShowTicks", |
| 267 |
DEF_AXIS_SHOWTICKS, Tk_Offset(Axis, showTicks), |
| 268 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 269 |
{TK_CONFIG_DOUBLE, "-stepsize", "stepSize", "StepSize", |
| 270 |
DEF_AXIS_STEP, Tk_Offset(Axis, reqStep), |
| 271 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 272 |
{TK_CONFIG_DOUBLE, "-tickdivider", "tickDivider", "TickDivider", |
| 273 |
DEF_AXIS_STEP, Tk_Offset(Axis, tickZoom), |
| 274 |
ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT}, |
| 275 |
{TK_CONFIG_INT, "-subdivisions", "subdivisions", "Subdivisions", |
| 276 |
DEF_AXIS_SUBDIVISIONS, Tk_Offset(Axis, reqNumMinorTicks), |
| 277 |
ALL_GRAPHS}, |
| 278 |
{TK_CONFIG_FONT, "-tickfont", "tickFont", "Font", |
| 279 |
DEF_AXIS_TICK_FONT, Tk_Offset(Axis, tickTextStyle.font), ALL_GRAPHS}, |
| 280 |
{TK_CONFIG_PIXELS, "-ticklength", "tickLength", "TickLength", |
| 281 |
DEF_AXIS_TICK_LENGTH, Tk_Offset(Axis, tickLength), ALL_GRAPHS}, |
| 282 |
{TK_CONFIG_CUSTOM, "-tickshadow", "tickShadow", "Shadow", |
| 283 |
(char *)NULL, Tk_Offset(Axis, tickTextStyle.shadow), |
| 284 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 285 |
{TK_CONFIG_CUSTOM, "-tickshadow", "tickShadow", "Shadow", |
| 286 |
(char *)NULL, Tk_Offset(Axis, tickTextStyle.shadow), |
| 287 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 288 |
{TK_CONFIG_STRING, "-title", "title", "Title", |
| 289 |
(char *)NULL, Tk_Offset(Axis, title), |
| 290 |
TK_CONFIG_DONT_SET_DEFAULT | TK_CONFIG_NULL_OK | ALL_GRAPHS}, |
| 291 |
{TK_CONFIG_BOOLEAN, "-titlealternate", "titleAlternate", "TitleAlternate", |
| 292 |
DEF_AXIS_TITLE_ALTERNATE, Tk_Offset(Axis, titleAlternate), |
| 293 |
TK_CONFIG_DONT_SET_DEFAULT | ALL_GRAPHS}, |
| 294 |
{TK_CONFIG_COLOR, "-titlecolor", "titleColor", "Color", |
| 295 |
DEF_AXIS_FOREGROUND, Tk_Offset(Axis, titleTextStyle.color), |
| 296 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS}, |
| 297 |
{TK_CONFIG_COLOR, "-titlecolor", "titleColor", "TitleColor", |
| 298 |
DEF_AXIS_FG_MONO, Tk_Offset(Axis, titleTextStyle.color), |
| 299 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS}, |
| 300 |
{TK_CONFIG_FONT, "-titlefont", "titleFont", "Font", |
| 301 |
DEF_AXIS_TITLE_FONT, Tk_Offset(Axis, titleTextStyle.font), ALL_GRAPHS}, |
| 302 |
{TK_CONFIG_CUSTOM, "-titleshadow", "titleShadow", "Shadow", |
| 303 |
(char *)NULL, Tk_Offset(Axis, titleTextStyle.shadow), |
| 304 |
TK_CONFIG_COLOR_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 305 |
{TK_CONFIG_CUSTOM, "-titleshadow", "titleShadow", "Shadow", |
| 306 |
(char *)NULL, Tk_Offset(Axis, titleTextStyle.shadow), |
| 307 |
TK_CONFIG_MONO_ONLY | ALL_GRAPHS, &bltShadowOption}, |
| 308 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 309 |
}; |
| 310 |
|
| 311 |
|
| 312 |
static void DestroyAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr)); |
| 313 |
static int GetAxis _ANSI_ARGS_((Graph *graphPtr, char *name, Blt_Uid classUid, |
| 314 |
Axis **axisPtrPtr)); |
| 315 |
static void FreeAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr)); |
| 316 |
|
| 317 |
INLINE static int |
| 318 |
Round(register double x) |
| 319 |
{ |
| 320 |
return (int) (x + ((x < 0.0) ? -0.5 : 0.5)); |
| 321 |
} |
| 322 |
|
| 323 |
static void |
| 324 |
SetAxisRange(AxisRange *rangePtr, double min, double max) |
| 325 |
{ |
| 326 |
rangePtr->min = min; |
| 327 |
rangePtr->max = max; |
| 328 |
rangePtr->range = max - min; |
| 329 |
if (FABS(rangePtr->range) < DBL_EPSILON) { |
| 330 |
rangePtr->range = 1.0; |
| 331 |
} |
| 332 |
rangePtr->scale = 1.0 / rangePtr->range; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
INLINE static int |
| 356 |
InRange(x, rangePtr) |
| 357 |
register double x; |
| 358 |
AxisRange *rangePtr; |
| 359 |
{ |
| 360 |
if (rangePtr->range < DBL_EPSILON) { |
| 361 |
#ifdef notdef |
| 362 |
return (((rangePtr->max - x) >= (FABS(x) * DBL_EPSILON)) && |
| 363 |
((x - rangePtr->min) >= (FABS(x) * DBL_EPSILON))); |
| 364 |
#endif |
| 365 |
return (FABS(rangePtr->max - x) >= DBL_EPSILON); |
| 366 |
} else { |
| 367 |
double norm; |
| 368 |
|
| 369 |
norm = (x - rangePtr->min) * rangePtr->scale; |
| 370 |
return ((norm >= -DBL_EPSILON) && ((norm - 1.0) < DBL_EPSILON)); |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
INLINE static int |
| 375 |
AxisIsHorizontal(graphPtr, axisPtr) |
| 376 |
Graph *graphPtr; |
| 377 |
Axis *axisPtr; |
| 378 |
{ |
| 379 |
return ((axisPtr->classUid == bltYAxisUid) == graphPtr->inverted); |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
static int |
| 403 |
StringToAnyAxis(clientData, interp, tkwin, string, widgRec, offset) |
| 404 |
ClientData clientData; |
| 405 |
|
| 406 |
Tcl_Interp *interp; |
| 407 |
Tk_Window tkwin; |
| 408 |
char *string; |
| 409 |
char *widgRec; |
| 410 |
int offset; |
| 411 |
{ |
| 412 |
Axis **axisPtrPtr = (Axis **)(widgRec + offset); |
| 413 |
Blt_Uid classUid = *(Blt_Uid *)clientData; |
| 414 |
Graph *graphPtr; |
| 415 |
Axis *axisPtr; |
| 416 |
|
| 417 |
graphPtr = Blt_GetGraphFromWindowData(tkwin); |
| 418 |
if (*axisPtrPtr != NULL) { |
| 419 |
FreeAxis(graphPtr, *axisPtrPtr); |
| 420 |
} |
| 421 |
if (string[0] == '\0') { |
| 422 |
axisPtr = NULL; |
| 423 |
} else if (GetAxis(graphPtr, string, classUid, &axisPtr) != TCL_OK) { |
| 424 |
return TCL_ERROR; |
| 425 |
} |
| 426 |
*axisPtrPtr = axisPtr; |
| 427 |
return TCL_OK; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
static int |
| 445 |
StringToAxis(clientData, interp, tkwin, string, widgRec, offset) |
| 446 |
ClientData clientData; |
| 447 |
|
| 448 |
Tcl_Interp *interp; |
| 449 |
Tk_Window tkwin; |
| 450 |
char *string; |
| 451 |
char *widgRec; |
| 452 |
int offset; |
| 453 |
{ |
| 454 |
Axis **axisPtrPtr = (Axis **)(widgRec + offset); |
| 455 |
Blt_Uid classUid = *(Blt_Uid *)clientData; |
| 456 |
Graph *graphPtr; |
| 457 |
|
| 458 |
graphPtr = Blt_GetGraphFromWindowData(tkwin); |
| 459 |
if (*axisPtrPtr != NULL) { |
| 460 |
FreeAxis(graphPtr, *axisPtrPtr); |
| 461 |
} |
| 462 |
if (GetAxis(graphPtr, string, classUid, axisPtrPtr) != TCL_OK) { |
| 463 |
return TCL_ERROR; |
| 464 |
} |
| 465 |
return TCL_OK; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
static char * |
| 482 |
AxisToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 483 |
ClientData clientData; |
| 484 |
Tk_Window tkwin; |
| 485 |
char *widgRec; |
| 486 |
int offset; |
| 487 |
Tcl_FreeProc **freeProcPtr; |
| 488 |
{ |
| 489 |
Axis *axisPtr = *(Axis **)(widgRec + offset); |
| 490 |
|
| 491 |
if (axisPtr == NULL) { |
| 492 |
return ""; |
| 493 |
} |
| 494 |
return axisPtr->name; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
static int |
| 512 |
StringToFormat(clientData, interp, tkwin, string, widgRec, offset) |
| 513 |
ClientData clientData; |
| 514 |
Tcl_Interp *interp; |
| 515 |
Tk_Window tkwin; |
| 516 |
char *string; |
| 517 |
char *widgRec; |
| 518 |
int offset; |
| 519 |
{ |
| 520 |
Axis *axisPtr = (Axis *)(widgRec); |
| 521 |
char **argv; |
| 522 |
int argc; |
| 523 |
|
| 524 |
if (axisPtr->limitsFormats != NULL) { |
| 525 |
Blt_Free(axisPtr->limitsFormats); |
| 526 |
} |
| 527 |
axisPtr->limitsFormats = NULL; |
| 528 |
axisPtr->nFormats = 0; |
| 529 |
|
| 530 |
if ((string == NULL) || (*string == '\0')) { |
| 531 |
return TCL_OK; |
| 532 |
} |
| 533 |
if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) { |
| 534 |
return TCL_ERROR; |
| 535 |
} |
| 536 |
if (argc > 2) { |
| 537 |
Tcl_AppendResult(interp, "too many elements in limits format list \"", |
| 538 |
string, "\"", (char *)NULL); |
| 539 |
Blt_Free(argv); |
| 540 |
return TCL_ERROR; |
| 541 |
} |
| 542 |
axisPtr->limitsFormats = argv; |
| 543 |
axisPtr->nFormats = argc; |
| 544 |
return TCL_OK; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
static char * |
| 561 |
FormatToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 562 |
ClientData clientData; |
| 563 |
Tk_Window tkwin; |
| 564 |
char *widgRec; |
| 565 |
int offset; |
| 566 |
Tcl_FreeProc **freeProcPtr; |
| 567 |
{ |
| 568 |
Axis *axisPtr = (Axis *)(widgRec); |
| 569 |
|
| 570 |
if (axisPtr->nFormats == 0) { |
| 571 |
return ""; |
| 572 |
} |
| 573 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 574 |
return Tcl_Merge(axisPtr->nFormats, axisPtr->limitsFormats); |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
static int |
| 593 |
StringToLimit(clientData, interp, tkwin, string, widgRec, offset) |
| 594 |
ClientData clientData; |
| 595 |
|
| 596 |
Tcl_Interp *interp; |
| 597 |
Tk_Window tkwin; |
| 598 |
char *string; |
| 599 |
char *widgRec; |
| 600 |
int offset; |
| 601 |
{ |
| 602 |
double *limitPtr = (double *)(widgRec + offset); |
| 603 |
|
| 604 |
if ((string == NULL) || (*string == '\0')) { |
| 605 |
*limitPtr = VALUE_UNDEFINED; |
| 606 |
} else if (Tcl_ExprDouble(interp, string, limitPtr) != TCL_OK) { |
| 607 |
return TCL_ERROR; |
| 608 |
} |
| 609 |
return TCL_OK; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
static char * |
| 626 |
LimitToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 627 |
ClientData clientData; |
| 628 |
Tk_Window tkwin; |
| 629 |
char *widgRec; |
| 630 |
int offset; |
| 631 |
Tcl_FreeProc **freeProcPtr; |
| 632 |
{ |
| 633 |
double limit = *(double *)(widgRec + offset); |
| 634 |
char *result; |
| 635 |
|
| 636 |
result = ""; |
| 637 |
if (DEFINED(limit)) { |
| 638 |
char string[TCL_DOUBLE_SPACE + 1]; |
| 639 |
Graph *graphPtr; |
| 640 |
|
| 641 |
graphPtr = Blt_GetGraphFromWindowData(tkwin); |
| 642 |
Tcl_PrintDouble(graphPtr->interp, limit, string); |
| 643 |
result = Blt_Strdup(string); |
| 644 |
if (result == NULL) { |
| 645 |
return ""; |
| 646 |
} |
| 647 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 648 |
} |
| 649 |
return result; |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
static int |
| 664 |
StringToTicks(clientData, interp, tkwin, string, widgRec, offset) |
| 665 |
ClientData clientData; |
| 666 |
Tcl_Interp *interp; |
| 667 |
Tk_Window tkwin; |
| 668 |
char *string; |
| 669 |
char *widgRec; |
| 670 |
int offset; |
| 671 |
{ |
| •672 |
unsigned int mask = (uintptr_t)clientData; |
| 673 |
Axis *axisPtr = (Axis *)widgRec; |
| 674 |
Ticks **ticksPtrPtr = (Ticks **) (widgRec + offset); |
| 675 |
int nTicks; |
| 676 |
Ticks *ticksPtr; |
| 677 |
|
| 678 |
nTicks = 0; |
| 679 |
ticksPtr = NULL; |
| 680 |
if ((string != NULL) && (*string != '\0')) { |
| 681 |
int nExprs; |
| 682 |
char **exprArr; |
| 683 |
|
| 684 |
if (Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK) { |
| 685 |
return TCL_ERROR; |
| 686 |
} |
| 687 |
if (nExprs > 0) { |
| 688 |
register int i; |
| 689 |
int result = TCL_ERROR; |
| 690 |
double value; |
| 691 |
|
| 692 |
ticksPtr = Blt_Malloc(sizeof(Ticks) + (nExprs * sizeof(double))); |
| 693 |
assert(ticksPtr); |
| 694 |
for (i = 0; i < nExprs; i++) { |
| 695 |
result = Tcl_ExprDouble(interp, exprArr[i], &value); |
| 696 |
if (result != TCL_OK) { |
| 697 |
break; |
| 698 |
} |
| 699 |
ticksPtr->values[i] = value; |
| 700 |
} |
| 701 |
Blt_Free(exprArr); |
| 702 |
if (result != TCL_OK) { |
| 703 |
Blt_Free(ticksPtr); |
| 704 |
return TCL_ERROR; |
| 705 |
} |
| 706 |
nTicks = nExprs; |
| 707 |
} |
| 708 |
} |
| 709 |
axisPtr->flags &= ~mask; |
| 710 |
if (ticksPtr != NULL) { |
| 711 |
axisPtr->flags |= mask; |
| 712 |
ticksPtr->nTicks = nTicks; |
| 713 |
} |
| 714 |
if (*ticksPtrPtr != NULL) { |
| 715 |
Blt_Free(*ticksPtrPtr); |
| 716 |
} |
| 717 |
*ticksPtrPtr = ticksPtr; |
| 718 |
return TCL_OK; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
static char * |
| 734 |
TicksToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 735 |
ClientData clientData; |
| 736 |
Tk_Window tkwin; |
| 737 |
char *widgRec; |
| 738 |
int offset; |
| 739 |
Tcl_FreeProc **freeProcPtr; |
| 740 |
{ |
| 741 |
Ticks *ticksPtr = *(Ticks **) (widgRec + offset); |
| 742 |
char string[TCL_DOUBLE_SPACE + 1]; |
| 743 |
register int i; |
| 744 |
char *result; |
| 745 |
Tcl_DString dString; |
| 746 |
Graph *graphPtr; |
| 747 |
|
| 748 |
if (ticksPtr == NULL) { |
| 749 |
return ""; |
| 750 |
} |
| 751 |
Tcl_DStringInit(&dString); |
| 752 |
graphPtr = Blt_GetGraphFromWindowData(tkwin); |
| 753 |
for (i = 0; i < ticksPtr->nTicks; i++) { |
| 754 |
Tcl_PrintDouble(graphPtr->interp, ticksPtr->values[i], string); |
| 755 |
Tcl_DStringAppendElement(&dString, string); |
| 756 |
} |
| 757 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 758 |
result = Blt_Strdup(Tcl_DStringValue(&dString)); |
| 759 |
Tcl_DStringFree(&dString); |
| 760 |
return result; |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
static int |
| 781 |
StringToLoose(clientData, interp, tkwin, string, widgRec, offset) |
| 782 |
ClientData clientData; |
| 783 |
Tcl_Interp *interp; |
| 784 |
Tk_Window tkwin; |
| 785 |
char *string; |
| 786 |
char *widgRec; |
| 787 |
int offset; |
| 788 |
{ |
| 789 |
Axis *axisPtr = (Axis *)(widgRec); |
| 790 |
register int i; |
| 791 |
int argc; |
| 792 |
char **argv; |
| 793 |
int values[2]; |
| 794 |
|
| 795 |
if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) { |
| 796 |
return TCL_ERROR; |
| 797 |
} |
| 798 |
if ((argc < 1) || (argc > 2)) { |
| 799 |
Tcl_AppendResult(interp, "wrong # elements in loose value \"", |
| 800 |
string, "\"", (char *)NULL); |
| 801 |
return TCL_ERROR; |
| 802 |
} |
| 803 |
for (i = 0; i < argc; i++) { |
| 804 |
if ((argv[i][0] == 'a') && (strcmp(argv[i], "always") == 0)) { |
| 805 |
values[i] = TICK_RANGE_ALWAYS_LOOSE; |
| 806 |
} else { |
| 807 |
int bool; |
| 808 |
|
| 809 |
if (Tcl_GetBoolean(interp, argv[i], &bool) != TCL_OK) { |
| 810 |
Blt_Free(argv); |
| 811 |
return TCL_ERROR; |
| 812 |
} |
| 813 |
values[i] = bool; |
| 814 |
} |
| 815 |
} |
| 816 |
axisPtr->looseMin = axisPtr->looseMax = values[0]; |
| 817 |
if (argc > 1) { |
| 818 |
axisPtr->looseMax = values[1]; |
| 819 |
} |
| 820 |
Blt_Free(argv); |
| 821 |
return TCL_OK; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
static char * |
| 836 |
LooseToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 837 |
ClientData clientData; |
| 838 |
Tk_Window tkwin; |
| 839 |
char *widgRec; |
| 840 |
int offset; |
| 841 |
Tcl_FreeProc **freeProcPtr; |
| 842 |
{ |
| 843 |
Axis *axisPtr = (Axis *)widgRec; |
| 844 |
Tcl_DString dString; |
| 845 |
char *result; |
| 846 |
|
| 847 |
Tcl_DStringInit(&dString); |
| 848 |
if (axisPtr->looseMin == TICK_RANGE_TIGHT) { |
| 849 |
Tcl_DStringAppendElement(&dString, "0"); |
| 850 |
} else if (axisPtr->looseMin == TICK_RANGE_LOOSE) { |
| 851 |
Tcl_DStringAppendElement(&dString, "1"); |
| 852 |
} else if (axisPtr->looseMin == TICK_RANGE_ALWAYS_LOOSE) { |
| 853 |
Tcl_DStringAppendElement(&dString, "always"); |
| 854 |
} |
| 855 |
if (axisPtr->looseMin != axisPtr->looseMax) { |
| 856 |
if (axisPtr->looseMax == TICK_RANGE_TIGHT) { |
| 857 |
Tcl_DStringAppendElement(&dString, "0"); |
| 858 |
} else if (axisPtr->looseMax == TICK_RANGE_LOOSE) { |
| 859 |
Tcl_DStringAppendElement(&dString, "1"); |
| 860 |
} else if (axisPtr->looseMax == TICK_RANGE_ALWAYS_LOOSE) { |
| 861 |
Tcl_DStringAppendElement(&dString, "always"); |
| 862 |
} |
| 863 |
} |
| 864 |
result = Blt_Strdup(Tcl_DStringValue(&dString)); |
| 865 |
Tcl_DStringFree(&dString); |
| 866 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 867 |
return result; |
| 868 |
} |
| 869 |
|
| 870 |
static void |
| 871 |
FreeLabels(chainPtr) |
| 872 |
Blt_Chain *chainPtr; |
| 873 |
{ |
| 874 |
Blt_ChainLink *linkPtr; |
| 875 |
TickLabel *labelPtr; |
| 876 |
|
| 877 |
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL; |
| 878 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 879 |
labelPtr = Blt_ChainGetValue(linkPtr); |
| 880 |
Blt_Free(labelPtr); |
| 881 |
} |
| 882 |
Blt_ChainReset(chainPtr); |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
static TickLabel * |
| 903 |
MakeLabel(graphPtr, axisPtr, value) |
| 904 |
Graph *graphPtr; |
| 905 |
Axis *axisPtr; |
| 906 |
double value; |
| 907 |
{ |
| 908 |
char string[TICK_LABEL_SIZE + 1]; |
| 909 |
TickLabel *labelPtr; |
| 910 |
|
| 911 |
|
| 912 |
if (axisPtr->logScale) { |
| 913 |
sprintf(string, "1E%d", ROUND(value)); |
| 914 |
} else { |
| 915 |
sprintf(string, "%.*g", NUMDIGITS, value); |
| 916 |
} |
| 917 |
|
| 918 |
if (axisPtr->formatCmd != NULL) { |
| 919 |
Tcl_Interp *interp = graphPtr->interp; |
| 920 |
Tk_Window tkwin = graphPtr->tkwin; |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
Tcl_ResetResult(interp); |
| 928 |
if (Tcl_VarEval(interp, axisPtr->formatCmd, " ", Tk_PathName(tkwin), |
| 929 |
" ", string, (char *)NULL) != TCL_OK) { |
| 930 |
Tcl_BackgroundError(interp); |
| 931 |
} else { |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
strncpy(string, Tcl_GetStringResult(interp), TICK_LABEL_SIZE); |
| 937 |
string[TICK_LABEL_SIZE] = '\0'; |
| 938 |
|
| 939 |
Tcl_ResetResult(interp); |
| 940 |
} |
| 941 |
} |
| 942 |
labelPtr = Blt_Malloc(sizeof(TickLabel) + strlen(string)); |
| 943 |
assert(labelPtr); |
| 944 |
strcpy(labelPtr->string, string); |
| 945 |
labelPtr->anchorPos.x = labelPtr->anchorPos.y = DBL_MAX; |
| 946 |
return labelPtr; |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
double |
| 964 |
Blt_InvHMap(graphPtr, axisPtr, x) |
| 965 |
Graph *graphPtr; |
| 966 |
Axis *axisPtr; |
| 967 |
double x; |
| 968 |
{ |
| 969 |
double value; |
| 970 |
|
| 971 |
x = (double)(x - graphPtr->hOffset) * graphPtr->hScale; |
| 972 |
if (axisPtr->descending) { |
| 973 |
x = 1.0 - x; |
| 974 |
} |
| 975 |
value = (x * axisPtr->axisRange.range) + axisPtr->axisRange.min; |
| 976 |
if (axisPtr->logScale) { |
| 977 |
value = EXP10(value); |
| 978 |
} |
| 979 |
return value; |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
double |
| 997 |
Blt_InvVMap(graphPtr, axisPtr, y) |
| 998 |
Graph *graphPtr; |
| 999 |
Axis *axisPtr; |
| 1000 |
double y; |
| 1001 |
{ |
| 1002 |
double value; |
| 1003 |
|
| 1004 |
y = (double)(y - graphPtr->vOffset) * graphPtr->vScale; |
| 1005 |
if (axisPtr->descending) { |
| 1006 |
y = 1.0 - y; |
| 1007 |
} |
| 1008 |
value = ((1.0 - y) * axisPtr->axisRange.range) + axisPtr->axisRange.min; |
| 1009 |
if (axisPtr->logScale) { |
| 1010 |
value = EXP10(value); |
| 1011 |
} |
| 1012 |
return value; |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
double |
| 1030 |
Blt_HMap(graphPtr, axisPtr, x) |
| 1031 |
Graph *graphPtr; |
| 1032 |
Axis *axisPtr; |
| 1033 |
double x; |
| 1034 |
{ |
| 1035 |
if ((axisPtr->logScale) && (x != 0.0)) { |
| 1036 |
x = log10(FABS(x)); |
| 1037 |
} |
| 1038 |
|
| 1039 |
x = (x - axisPtr->axisRange.min) * axisPtr->axisRange.scale; |
| 1040 |
if (axisPtr->descending) { |
| 1041 |
x = 1.0 - x; |
| 1042 |
} |
| 1043 |
return (x * graphPtr->hRange + graphPtr->hOffset); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
double |
| 1061 |
Blt_VMap(graphPtr, axisPtr, y) |
| 1062 |
Graph *graphPtr; |
| 1063 |
Axis *axisPtr; |
| 1064 |
double y; |
| 1065 |
{ |
| 1066 |
if ((axisPtr->logScale) && (y != 0.0)) { |
| 1067 |
y = log10(FABS(y)); |
| 1068 |
} |
| 1069 |
|
| 1070 |
y = (y - axisPtr->axisRange.min) * axisPtr->axisRange.scale; |
| 1071 |
if (axisPtr->descending) { |
| 1072 |
y = 1.0 - y; |
| 1073 |
} |
| 1074 |
return (((1.0 - y) * graphPtr->vRange) + graphPtr->vOffset); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
Point2D |
| 1091 |
Blt_Map2D(graphPtr, x, y, axesPtr) |
| 1092 |
Graph *graphPtr; |
| 1093 |
double x, y; |
| 1094 |
Axis2D *axesPtr; |
| 1095 |
{ |
| 1096 |
Point2D point; |
| 1097 |
|
| 1098 |
if (graphPtr->inverted) { |
| 1099 |
point.x = Blt_HMap(graphPtr, axesPtr->y, y); |
| 1100 |
point.y = Blt_VMap(graphPtr, axesPtr->x, x); |
| 1101 |
} else { |
| 1102 |
point.x = Blt_HMap(graphPtr, axesPtr->x, x); |
| 1103 |
point.y = Blt_VMap(graphPtr, axesPtr->y, y); |
| 1104 |
} |
| 1105 |
return point; |
| 1106 |
} |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
Point2D |
| 1122 |
Blt_InvMap2D(graphPtr, x, y, axesPtr) |
| 1123 |
Graph *graphPtr; |
| 1124 |
double x, y; |
| 1125 |
Axis2D *axesPtr; |
| 1126 |
{ |
| 1127 |
Point2D point; |
| 1128 |
|
| 1129 |
if (graphPtr->inverted) { |
| 1130 |
point.x = Blt_InvVMap(graphPtr, axesPtr->x, y); |
| 1131 |
point.y = Blt_InvHMap(graphPtr, axesPtr->y, x); |
| 1132 |
} else { |
| 1133 |
point.x = Blt_InvHMap(graphPtr, axesPtr->x, x); |
| 1134 |
point.y = Blt_InvVMap(graphPtr, axesPtr->y, y); |
| 1135 |
} |
| 1136 |
return point; |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
static void |
| 1141 |
GetDataLimits(axisPtr, min, max) |
| 1142 |
Axis *axisPtr; |
| 1143 |
double min, max; |
| 1144 |
{ |
| 1145 |
if (axisPtr->valueRange.min > min) { |
| 1146 |
axisPtr->valueRange.min = min; |
| 1147 |
} |
| 1148 |
if (axisPtr->valueRange.max < max) { |
| 1149 |
axisPtr->valueRange.max = max; |
| 1150 |
} |
| 1151 |
} |
| 1152 |
|
| 1153 |
static void |
| 1154 |
FixAxisRange(axisPtr) |
| 1155 |
Axis *axisPtr; |
| 1156 |
{ |
| 1157 |
double min, max; |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
min = axisPtr->valueRange.min; |
| 1164 |
max = axisPtr->valueRange.max; |
| 1165 |
|
| 1166 |
if (min == DBL_MAX) { |
| 1167 |
if (DEFINED(axisPtr->reqMin)) { |
| 1168 |
min = axisPtr->reqMin; |
| 1169 |
} else { |
| 1170 |
min = (axisPtr->logScale) ? 0.001 : 0.0; |
| 1171 |
} |
| 1172 |
} |
| 1173 |
if (max == -DBL_MAX) { |
| 1174 |
if (DEFINED(axisPtr->reqMax)) { |
| 1175 |
max = axisPtr->reqMax; |
| 1176 |
} else { |
| 1177 |
max = 1.0; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
if (min >= max) { |
| 1181 |
double value; |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
value = min; |
| 1188 |
if (value == 0.0) { |
| 1189 |
min = -0.1, max = 0.1; |
| 1190 |
} else { |
| 1191 |
double x; |
| 1192 |
|
| 1193 |
x = FABS(value) * 0.1; |
| 1194 |
min = value - x, max = value + x; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
SetAxisRange(&axisPtr->valueRange, min, max); |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
axisPtr->min = min; |
| 1205 |
axisPtr->max = max; |
| 1206 |
if (DEFINED(axisPtr->reqMin)) { |
| 1207 |
axisPtr->min = axisPtr->reqMin; |
| 1208 |
} |
| 1209 |
if (DEFINED(axisPtr->reqMax)) { |
| 1210 |
axisPtr->max = axisPtr->reqMax; |
| 1211 |
} |
| 1212 |
|
| 1213 |
if (axisPtr->max < axisPtr->min) { |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
if (!DEFINED(axisPtr->reqMin)) { |
| 1224 |
axisPtr->min = axisPtr->max - (FABS(axisPtr->max) * 0.1); |
| 1225 |
} |
| 1226 |
if (!DEFINED(axisPtr->reqMax)) { |
| 1227 |
axisPtr->max = axisPtr->min + (FABS(axisPtr->max) * 0.1); |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
if ((axisPtr->windowSize > 0.0) && |
| 1235 |
(!DEFINED(axisPtr->reqMin)) && (!DEFINED(axisPtr->reqMax))) { |
| 1236 |
if (axisPtr->shiftBy < 0.0) { |
| 1237 |
axisPtr->shiftBy = 0.0; |
| 1238 |
} |
| 1239 |
max = axisPtr->min + axisPtr->windowSize; |
| 1240 |
if (axisPtr->max >= max) { |
| 1241 |
if (axisPtr->shiftBy > 0.0) { |
| 1242 |
max = UCEIL(axisPtr->max, axisPtr->shiftBy); |
| 1243 |
} |
| 1244 |
axisPtr->min = max - axisPtr->windowSize; |
| 1245 |
} |
| 1246 |
axisPtr->max = max; |
| 1247 |
} |
| 1248 |
if ((axisPtr->max != axisPtr->prevMax) || |
| 1249 |
(axisPtr->min != axisPtr->prevMin)) { |
| 1250 |
|
| 1251 |
axisPtr->flags |= AXIS_DIRTY; |
| 1252 |
|
| 1253 |
axisPtr->prevMin = axisPtr->min; |
| 1254 |
axisPtr->prevMax = axisPtr->max; |
| 1255 |
} |
| 1256 |
} |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
static double |
| 1271 |
NiceNum(x, doround) |
| 1272 |
double x; |
| 1273 |
int doround; |
| 1274 |
|
| 1275 |
{ |
| 1276 |
double expt; |
| 1277 |
double frac; |
| 1278 |
double fnice; |
| 1279 |
|
| 1280 |
expt = floor(log10(x)); |
| 1281 |
frac = x / EXP10(expt); |
| 1282 |
if (doround) { |
| 1283 |
if (frac < 1.5) { |
| 1284 |
fnice = 1.0; |
| 1285 |
} else if (frac < 3.0) { |
| 1286 |
fnice = 2.0; |
| 1287 |
} else if (frac < 7.0) { |
| 1288 |
fnice = 5.0; |
| 1289 |
} else { |
| 1290 |
fnice = 10.0; |
| 1291 |
} |
| 1292 |
} else { |
| 1293 |
if (frac <= 1.0) { |
| 1294 |
fnice = 1.0; |
| 1295 |
} else if (frac <= 2.0) { |
| 1296 |
fnice = 2.0; |
| 1297 |
} else if (frac <= 5.0) { |
| 1298 |
fnice = 5.0; |
| 1299 |
} else { |
| 1300 |
fnice = 10.0; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
return fnice * EXP10(expt); |
| 1304 |
} |
| 1305 |
|
| 1306 |
static Ticks * |
| 1307 |
GenerateTicks(sweepPtr) |
| 1308 |
TickSweep *sweepPtr; |
| 1309 |
{ |
| 1310 |
Ticks *ticksPtr; |
| 1311 |
register int i; |
| 1312 |
|
| 1313 |
ticksPtr = Blt_Malloc(sizeof(Ticks) + (sweepPtr->nSteps * sizeof(double))); |
| 1314 |
assert(ticksPtr); |
| 1315 |
|
| 1316 |
if (sweepPtr->step == 0.0) { |
| 1317 |
static double logTable[] = |
| 1318 |
{ |
| 1319 |
0.0, |
| 1320 |
0.301029995663981, 0.477121254719662, |
| 1321 |
0.602059991327962, 0.698970004336019, |
| 1322 |
0.778151250383644, 0.845098040014257, |
| 1323 |
0.903089986991944, 0.954242509439325, |
| 1324 |
1.0 |
| 1325 |
}; |
| 1326 |
|
| 1327 |
for (i = 0; i < sweepPtr->nSteps; i++) { |
| 1328 |
ticksPtr->values[i] = logTable[i]; |
| 1329 |
} |
| 1330 |
} else { |
| 1331 |
double value; |
| 1332 |
|
| 1333 |
value = sweepPtr->initial; |
| 1334 |
for (i = 0; i < sweepPtr->nSteps; i++) { |
| 1335 |
value = UROUND(value, sweepPtr->step); |
| 1336 |
ticksPtr->values[i] = value; |
| 1337 |
value += sweepPtr->step; |
| 1338 |
} |
| 1339 |
} |
| 1340 |
ticksPtr->nTicks = sweepPtr->nSteps; |
| 1341 |
return ticksPtr; |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
static void |
| 1418 |
LogScaleAxis(axisPtr, min, max) |
| 1419 |
Axis *axisPtr; |
| 1420 |
double min, max; |
| 1421 |
{ |
| 1422 |
double range; |
| 1423 |
double tickMin, tickMax; |
| 1424 |
double majorStep, minorStep; |
| 1425 |
int nMajor, nMinor; |
| 1426 |
|
| 1427 |
nMajor = nMinor = 0; |
| 1428 |
majorStep = minorStep = 0.0; |
| •1429 |
if (min > max) { |
| 1430 |
double m; |
| 1431 |
m = min; |
| 1432 |
min = max; |
| 1433 |
max = m; |
| 1434 |
} else if (min == max) { |
| 1435 |
max = min + 1.0; |
| 1436 |
} |
| 1437 |
|
| 1438 |
min = (min != 0.0) ? log10(FABS(min)) : 0.0; |
| 1439 |
max = (max != 0.0) ? log10(FABS(max)) : 1.0; |
| 1440 |
|
| 1441 |
tickMin = floor(min); |
| 1442 |
tickMax = ceil(max); |
| 1443 |
range = tickMax - tickMin; |
| 1444 |
|
| 1445 |
if (range > 10) { |
| 1446 |
|
| 1447 |
|
| 1448 |
range = NiceNum(range, 0); |
| 1449 |
majorStep = NiceNum(range / DEF_NUM_TICKS, 1); |
| 1450 |
tickMin = UFLOOR(tickMin, majorStep); |
| 1451 |
tickMax = UCEIL(tickMax, majorStep); |
| 1452 |
nMajor = (int)((tickMax - tickMin) / majorStep) + 1; |
| 1453 |
minorStep = EXP10(floor(log10(majorStep))); |
| 1454 |
if (minorStep == majorStep) { |
| 1455 |
nMinor = 4, minorStep = 0.2; |
| 1456 |
} else { |
| 1457 |
nMinor = Round(majorStep / minorStep) - 1; |
| 1458 |
} |
| 1459 |
} else { |
| 1460 |
if (tickMin == tickMax) { |
| 1461 |
tickMax++; |
| 1462 |
} |
| 1463 |
majorStep = 1.0; |
| 1464 |
nMajor = (int)(tickMax - tickMin + 1); |
| 1465 |
|
| 1466 |
minorStep = 0.0; |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
nMinor = 10; |
| 1473 |
} |
| 1474 |
if ((axisPtr->looseMin == TICK_RANGE_TIGHT) || |
| 1475 |
((axisPtr->looseMin == TICK_RANGE_LOOSE) && |
| 1476 |
(DEFINED(axisPtr->reqMin)))) { |
| 1477 |
tickMin = min; |
| 1478 |
nMajor++; |
| 1479 |
} |
| 1480 |
if ((axisPtr->looseMax == TICK_RANGE_TIGHT) || |
| 1481 |
((axisPtr->looseMax == TICK_RANGE_LOOSE) && |
| 1482 |
(DEFINED(axisPtr->reqMax)))) { |
| 1483 |
tickMax = max; |
| 1484 |
} |
| •1485 |
|
| 1486 |
axisPtr->majorSweep.step = majorStep; |
| 1487 |
axisPtr->majorSweep.initial = floor(tickMin); |
| 1488 |
axisPtr->majorSweep.nSteps = nMajor; |
| 1489 |
axisPtr->minorSweep.initial = axisPtr->minorSweep.step = minorStep; |
| 1490 |
axisPtr->minorSweep.nSteps = nMinor; |
| 1491 |
SetAxisRange(&axisPtr->axisRange, tickMin, tickMax); |
| 1492 |
} |
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
static void |
| 1556 |
LinearScaleAxis(axisPtr, min, max) |
| 1557 |
Axis *axisPtr; |
| 1558 |
double min, max; |
| 1559 |
{ |
| 1560 |
double range, step; |
| 1561 |
double tickMin, tickMax; |
| 1562 |
double axisMin, axisMax; |
| 1563 |
int nTicks; |
| 1564 |
|
| 1565 |
nTicks = 0; |
| 1566 |
tickMin = tickMax = 0.0; |
| •1567 |
if (min > max) { |
| 1568 |
double m; |
| 1569 |
m = min; |
| 1570 |
min = max; |
| 1571 |
max = m; |
| 1572 |
} else if (min == max) { |
| 1573 |
max = min + 1.0; |
| 1574 |
} |
| 1575 |
|
| 1576 |
range = max - min; |
| 1577 |
|
| 1578 |
|
| 1579 |
if (axisPtr->reqStep > 0.0) { |
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
step = axisPtr->reqStep; |
| 1584 |
while ((2 * step) >= range) { |
| 1585 |
step *= 0.5; |
| 1586 |
} |
| 1587 |
} else { |
| 1588 |
range = NiceNum(range, 0); |
| 1589 |
step = NiceNum(range / DEF_NUM_TICKS, 1); |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
axisMin = tickMin = floor(min / step) * step + 0.0; |
| 1594 |
axisMax = tickMax = ceil(max / step) * step + 0.0; |
| 1595 |
|
| 1596 |
nTicks = Round((tickMax - tickMin) / step) + 1; |
| •1597 |
|
| 1598 |
axisPtr->majorSweep.step = step; |
| 1599 |
axisPtr->majorSweep.initial = tickMin; |
| 1600 |
axisPtr->majorSweep.nSteps = nTicks; |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
if ((axisPtr->looseMin == TICK_RANGE_TIGHT) || |
| 1612 |
((axisPtr->looseMin == TICK_RANGE_LOOSE) && |
| 1613 |
(DEFINED(axisPtr->reqMin)))) { |
| 1614 |
axisMin = min; |
| 1615 |
} |
| 1616 |
if ((axisPtr->looseMax == TICK_RANGE_TIGHT) || |
| 1617 |
((axisPtr->looseMax == TICK_RANGE_LOOSE) && |
| 1618 |
(DEFINED(axisPtr->reqMax)))) { |
| 1619 |
axisMax = max; |
| 1620 |
} |
| 1621 |
SetAxisRange(&axisPtr->axisRange, axisMin, axisMax); |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
if ((axisPtr->reqNumMinorTicks > 0) && |
| 1626 |
((axisPtr->flags & AXIS_CONFIG_MAJOR) == 0)) { |
| 1627 |
nTicks = axisPtr->reqNumMinorTicks - 1; |
| 1628 |
step = 1.0 / (nTicks + 1); |
| 1629 |
} else { |
| 1630 |
nTicks = 0; |
| 1631 |
step = 0.5; |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
} |
| 1636 |
axisPtr->minorSweep.initial = axisPtr->minorSweep.step = step; |
| 1637 |
axisPtr->minorSweep.nSteps = nTicks; |
| 1638 |
} |
| 1639 |
|
| 1640 |
static void |
| 1641 |
SweepTicks(axisPtr) |
| 1642 |
Axis *axisPtr; |
| 1643 |
{ |
| 1644 |
if ((axisPtr->flags & AXIS_CONFIG_MAJOR) == 0) { |
| 1645 |
if (axisPtr->t1Ptr != NULL) { |
| 1646 |
Blt_Free(axisPtr->t1Ptr); |
| 1647 |
} |
| 1648 |
axisPtr->t1Ptr = GenerateTicks(&axisPtr->majorSweep); |
| 1649 |
} |
| 1650 |
if ((axisPtr->flags & AXIS_CONFIG_MINOR) == 0) { |
| 1651 |
if (axisPtr->t2Ptr != NULL) { |
| 1652 |
Blt_Free(axisPtr->t2Ptr); |
| 1653 |
} |
| 1654 |
axisPtr->t2Ptr = GenerateTicks(&axisPtr->minorSweep); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
void |
| 1669 |
Blt_ResetAxes(graphPtr) |
| 1670 |
Graph *graphPtr; |
| 1671 |
{ |
| 1672 |
Blt_ChainLink *linkPtr; |
| 1673 |
Element *elemPtr; |
| 1674 |
Axis *axisPtr; |
| 1675 |
Blt_HashEntry *hPtr; |
| 1676 |
Blt_HashSearch cursor; |
| 1677 |
Extents2D exts; |
| 1678 |
double min, max; |
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
Blt_InitFreqTable(graphPtr); |
| 1686 |
if ((graphPtr->mode == MODE_STACKED) && (graphPtr->nStacks > 0)) { |
| 1687 |
Blt_ComputeStacks(graphPtr); |
| 1688 |
} |
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 1694 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 1695 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 1696 |
axisPtr->min = axisPtr->valueRange.min = DBL_MAX; |
| 1697 |
axisPtr->max = axisPtr->valueRange.max = -DBL_MAX; |
| 1698 |
} |
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->elements.displayList); |
| 1707 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 1708 |
elemPtr = Blt_ChainGetValue(linkPtr); |
| 1709 |
if (!elemPtr->hidden) { |
| 1710 |
(*elemPtr->procsPtr->extentsProc) (elemPtr, &exts); |
| 1711 |
GetDataLimits(elemPtr->axes.x, exts.left, exts.right); |
| 1712 |
GetDataLimits(elemPtr->axes.y, exts.top, exts.bottom); |
| 1713 |
} |
| 1714 |
} |
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 1720 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 1721 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 1722 |
FixAxisRange(axisPtr); |
| 1723 |
|
| 1724 |
|
| 1725 |
min = axisPtr->min; |
| 1726 |
max = axisPtr->max; |
| 1727 |
if ((DEFINED(axisPtr->scrollMin)) && (min < axisPtr->scrollMin)) { |
| 1728 |
min = axisPtr->scrollMin; |
| 1729 |
} |
| 1730 |
if ((DEFINED(axisPtr->scrollMax)) && (max > axisPtr->scrollMax)) { |
| 1731 |
max = axisPtr->scrollMax; |
| 1732 |
} |
| 1733 |
if (axisPtr->logScale) { |
| 1734 |
LogScaleAxis(axisPtr, min, max); |
| 1735 |
} else { |
| 1736 |
LinearScaleAxis(axisPtr, min, max); |
| 1737 |
} |
| 1738 |
|
| 1739 |
if ((axisPtr->flags & (AXIS_DIRTY | AXIS_ONSCREEN)) == |
| 1740 |
(AXIS_DIRTY | AXIS_ONSCREEN)) { |
| 1741 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 1742 |
} |
| 1743 |
} |
| 1744 |
|
| 1745 |
graphPtr->flags &= ~RESET_AXES; |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
graphPtr->flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | |
| 1751 |
MAP_ALL | REDRAW_WORLD); |
| 1752 |
} |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
static void |
| 1774 |
ResetTextStyles(graphPtr, axisPtr) |
| 1775 |
Graph *graphPtr; |
| 1776 |
Axis *axisPtr; |
| 1777 |
{ |
| 1778 |
GC newGC; |
| 1779 |
XGCValues gcValues; |
| 1780 |
unsigned long gcMask; |
| 1781 |
|
| 1782 |
Blt_ResetTextStyle(graphPtr->tkwin, &axisPtr->titleTextStyle); |
| 1783 |
Blt_ResetTextStyle(graphPtr->tkwin, &axisPtr->tickTextStyle); |
| 1784 |
Blt_ResetTextStyle(graphPtr->tkwin, &axisPtr->limitsTextStyle); |
| 1785 |
|
| 1786 |
gcMask = (GCForeground | GCLineWidth | GCCapStyle); |
| 1787 |
gcValues.foreground = axisPtr->tickTextStyle.color->pixel; |
| 1788 |
gcValues.line_width = LineWidth(axisPtr->lineWidth); |
| 1789 |
gcValues.cap_style = CapProjecting; |
| 1790 |
|
| 1791 |
newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); |
| 1792 |
if (axisPtr->tickGC != NULL) { |
| 1793 |
Tk_FreeGC(graphPtr->display, axisPtr->tickGC); |
| 1794 |
} |
| 1795 |
axisPtr->tickGC = newGC; |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
static void |
| 1813 |
DestroyAxis(graphPtr, axisPtr) |
| 1814 |
Graph *graphPtr; |
| 1815 |
Axis *axisPtr; |
| 1816 |
{ |
| 1817 |
int flags; |
| 1818 |
|
| 1819 |
flags = Blt_GraphType(graphPtr); |
| 1820 |
Tk_FreeOptions(configSpecs, (char *)axisPtr, graphPtr->display, flags); |
| 1821 |
if (graphPtr->bindTable != NULL) { |
| 1822 |
Blt_DeleteBindings(graphPtr->bindTable, axisPtr); |
| 1823 |
} |
| 1824 |
if (axisPtr->linkPtr != NULL) { |
| 1825 |
Blt_ChainDeleteLink(axisPtr->chainPtr, axisPtr->linkPtr); |
| 1826 |
} |
| 1827 |
if (axisPtr->name != NULL) { |
| 1828 |
Blt_Free(axisPtr->name); |
| 1829 |
} |
| 1830 |
if (axisPtr->hashPtr != NULL) { |
| 1831 |
Blt_DeleteHashEntry(&graphPtr->axes.table, axisPtr->hashPtr); |
| 1832 |
} |
| 1833 |
Blt_FreeTextStyle(graphPtr->display, &axisPtr->titleTextStyle); |
| 1834 |
Blt_FreeTextStyle(graphPtr->display, &axisPtr->limitsTextStyle); |
| 1835 |
Blt_FreeTextStyle(graphPtr->display, &axisPtr->tickTextStyle); |
| 1836 |
|
| 1837 |
if (axisPtr->tickGC != NULL) { |
| 1838 |
Tk_FreeGC(graphPtr->display, axisPtr->tickGC); |
| 1839 |
} |
| 1840 |
if (axisPtr->t1Ptr != NULL) { |
| 1841 |
Blt_Free(axisPtr->t1Ptr); |
| 1842 |
} |
| 1843 |
if (axisPtr->t2Ptr != NULL) { |
| 1844 |
Blt_Free(axisPtr->t2Ptr); |
| 1845 |
} |
| 1846 |
if (axisPtr->limitsFormats != NULL) { |
| 1847 |
Blt_Free(axisPtr->limitsFormats); |
| 1848 |
} |
| 1849 |
FreeLabels(axisPtr->tickLabels); |
| 1850 |
Blt_ChainDestroy(axisPtr->tickLabels); |
| 1851 |
if (axisPtr->segments != NULL) { |
| 1852 |
Blt_Free(axisPtr->segments); |
| 1853 |
} |
| 1854 |
if (axisPtr->tags != NULL) { |
| 1855 |
Blt_Free(axisPtr->tags); |
| 1856 |
} |
| 1857 |
Blt_Free(axisPtr); |
| 1858 |
} |
| 1859 |
|
| 1860 |
static double titleRotate[4] = |
| 1861 |
{ |
| 1862 |
0.0, 90.0, 0.0, 270.0 |
| 1863 |
}; |
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
static void |
| 1879 |
AxisOffsets(graphPtr, axisPtr, margin, axisOffset, infoPtr) |
| 1880 |
Graph *graphPtr; |
| 1881 |
Axis *axisPtr; |
| 1882 |
int margin; |
| 1883 |
int axisOffset; |
| 1884 |
AxisInfo *infoPtr; |
| 1885 |
{ |
| 1886 |
int pad; |
| 1887 |
|
| 1888 |
|
| 1889 |
int p; |
| 1890 |
int majorOffset, minorOffset, labelOffset; |
| 1891 |
int offset; |
| 1892 |
int x, y; |
| 1893 |
|
| 1894 |
axisPtr->titleTextStyle.theta = titleRotate[margin]; |
| 1895 |
|
| 1896 |
majorOffset = minorOffset = 0; |
| 1897 |
labelOffset = AXIS_TITLE_PAD; |
| 1898 |
if (axisPtr->lineWidth > 0) { |
| 1899 |
majorOffset = ABS(axisPtr->tickLength); |
| 1900 |
minorOffset = 10 * majorOffset / 15; |
| 1901 |
labelOffset = majorOffset + AXIS_TITLE_PAD + axisPtr->lineWidth / 2; |
| 1902 |
} |
| 1903 |
|
| 1904 |
pad = axisPtr->lineWidth + 1; |
| 1905 |
if (graphPtr->plotBorderWidth > 0) { |
| 1906 |
pad += graphPtr->plotBorderWidth + 1; |
| 1907 |
} |
| 1908 |
offset = axisOffset + 1 + pad; |
| 1909 |
if ((margin == MARGIN_LEFT) || (margin == MARGIN_TOP)) { |
| 1910 |
majorOffset = -majorOffset; |
| 1911 |
minorOffset = -minorOffset; |
| 1912 |
labelOffset = -labelOffset; |
| 1913 |
} |
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
p = 0; |
| 1919 |
|
| 1920 |
switch (margin) { |
| 1921 |
case MARGIN_TOP: |
| 1922 |
p = graphPtr->top - axisOffset - pad; |
| 1923 |
if (axisPtr->titleAlternate) { |
| 1924 |
x = graphPtr->right + AXIS_TITLE_PAD; |
| 1925 |
y = graphPtr->top - axisOffset - (axisPtr->height / 2); |
| 1926 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_W; |
| 1927 |
} else { |
| 1928 |
x = (graphPtr->right + graphPtr->left) / 2; |
| 1929 |
y = graphPtr->top - axisOffset - axisPtr->height - AXIS_TITLE_PAD; |
| 1930 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_N; |
| 1931 |
} |
| 1932 |
axisPtr->tickTextStyle.anchor = TK_ANCHOR_S; |
| 1933 |
offset = axisPtr->borderWidth + axisPtr->lineWidth / 2; |
| 1934 |
axisPtr->region.left = graphPtr->hOffset - offset - 2; |
| 1935 |
axisPtr->region.right = graphPtr->hOffset + graphPtr->hRange + |
| 1936 |
offset - 1; |
| 1937 |
axisPtr->region.top = p + labelOffset - 1; |
| 1938 |
axisPtr->region.bottom = p; |
| 1939 |
axisPtr->titlePos.x = x; |
| 1940 |
axisPtr->titlePos.y = y; |
| 1941 |
break; |
| 1942 |
|
| 1943 |
case MARGIN_BOTTOM: |
| 1944 |
p = graphPtr->bottom + axisOffset + pad; |
| 1945 |
if (axisPtr->titleAlternate) { |
| 1946 |
x = graphPtr->right + AXIS_TITLE_PAD; |
| 1947 |
y = graphPtr->bottom + axisOffset + (axisPtr->height / 2); |
| 1948 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_W; |
| 1949 |
} else { |
| 1950 |
x = (graphPtr->right + graphPtr->left) / 2; |
| 1951 |
y = graphPtr->bottom + axisOffset + axisPtr->height + |
| 1952 |
AXIS_TITLE_PAD; |
| 1953 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_S; |
| 1954 |
} |
| 1955 |
axisPtr->tickTextStyle.anchor = TK_ANCHOR_N; |
| 1956 |
offset = axisPtr->borderWidth + axisPtr->lineWidth / 2; |
| 1957 |
axisPtr->region.left = graphPtr->hOffset - offset - 2; |
| 1958 |
axisPtr->region.right = graphPtr->hOffset + graphPtr->hRange + |
| 1959 |
offset - 1; |
| 1960 |
|
| 1961 |
axisPtr->region.top = graphPtr->bottom + axisOffset + |
| 1962 |
axisPtr->lineWidth - axisPtr->lineWidth / 2; |
| 1963 |
axisPtr->region.bottom = graphPtr->bottom + axisOffset + |
| 1964 |
axisPtr->lineWidth + labelOffset + 1; |
| 1965 |
axisPtr->titlePos.x = x; |
| 1966 |
axisPtr->titlePos.y = y; |
| 1967 |
break; |
| 1968 |
|
| 1969 |
case MARGIN_LEFT: |
| 1970 |
p = graphPtr->left - axisOffset - pad; |
| 1971 |
if (axisPtr->titleAlternate) { |
| 1972 |
x = graphPtr->left - axisOffset - (axisPtr->width / 2); |
| 1973 |
y = graphPtr->top - AXIS_TITLE_PAD; |
| 1974 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_SW; |
| 1975 |
} else { |
| 1976 |
x = graphPtr->left - axisOffset - axisPtr->width - |
| 1977 |
graphPtr->plotBorderWidth; |
| 1978 |
y = (graphPtr->bottom + graphPtr->top) / 2; |
| 1979 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_W; |
| 1980 |
} |
| 1981 |
axisPtr->tickTextStyle.anchor = TK_ANCHOR_E; |
| 1982 |
axisPtr->region.left = graphPtr->left - offset + labelOffset - 1; |
| 1983 |
axisPtr->region.right = graphPtr->left - offset + 2; |
| 1984 |
|
| 1985 |
offset = axisPtr->borderWidth + axisPtr->lineWidth / 2; |
| 1986 |
axisPtr->region.top = graphPtr->vOffset - offset - 2; |
| 1987 |
axisPtr->region.bottom = graphPtr->vOffset + graphPtr->vRange + |
| 1988 |
offset - 1; |
| 1989 |
axisPtr->titlePos.x = x; |
| 1990 |
axisPtr->titlePos.y = y; |
| 1991 |
break; |
| 1992 |
|
| 1993 |
case MARGIN_RIGHT: |
| 1994 |
p = graphPtr->right + axisOffset + pad; |
| 1995 |
if (axisPtr->titleAlternate) { |
| 1996 |
x = graphPtr->right + axisOffset + (axisPtr->width / 2); |
| 1997 |
y = graphPtr->top - AXIS_TITLE_PAD; |
| 1998 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_SE; |
| 1999 |
} else { |
| 2000 |
x = graphPtr->right + axisOffset + axisPtr->width + |
| 2001 |
AXIS_TITLE_PAD; |
| 2002 |
y = (graphPtr->bottom + graphPtr->top) / 2; |
| 2003 |
axisPtr->titleTextStyle.anchor = TK_ANCHOR_E; |
| 2004 |
} |
| 2005 |
axisPtr->tickTextStyle.anchor = TK_ANCHOR_W; |
| 2006 |
|
| 2007 |
axisPtr->region.left = graphPtr->right + axisOffset + |
| 2008 |
axisPtr->lineWidth - axisPtr->lineWidth / 2; |
| 2009 |
axisPtr->region.right = graphPtr->right + axisOffset + |
| 2010 |
labelOffset + axisPtr->lineWidth + 1; |
| 2011 |
|
| 2012 |
offset = axisPtr->borderWidth + axisPtr->lineWidth / 2; |
| 2013 |
axisPtr->region.top = graphPtr->vOffset - offset - 2; |
| 2014 |
axisPtr->region.bottom = graphPtr->vOffset + graphPtr->vRange + |
| 2015 |
offset - 1; |
| 2016 |
axisPtr->titlePos.x = x; |
| 2017 |
axisPtr->titlePos.y = y; |
| 2018 |
break; |
| 2019 |
|
| 2020 |
case MARGIN_NONE: |
| 2021 |
break; |
| 2022 |
} |
| 2023 |
infoPtr->axis = p - (axisPtr->lineWidth / 2); |
| 2024 |
infoPtr->t1 = p + majorOffset; |
| 2025 |
infoPtr->t2 = p + minorOffset; |
| 2026 |
infoPtr->label = p + labelOffset; |
| 2027 |
|
| 2028 |
if (axisPtr->tickLength < 0) { |
| 2029 |
int hold; |
| 2030 |
|
| 2031 |
hold = infoPtr->t1; |
| 2032 |
infoPtr->t1 = infoPtr->axis; |
| 2033 |
infoPtr->axis = hold; |
| 2034 |
} |
| 2035 |
} |
| 2036 |
|
| 2037 |
static void |
| 2038 |
MakeAxisLine(graphPtr, axisPtr, line, segPtr) |
| 2039 |
Graph *graphPtr; |
| 2040 |
Axis *axisPtr; |
| 2041 |
int line; |
| 2042 |
Segment2D *segPtr; |
| 2043 |
{ |
| 2044 |
double min, max; |
| 2045 |
|
| 2046 |
min = axisPtr->axisRange.min; |
| 2047 |
max = axisPtr->axisRange.max; |
| 2048 |
if (axisPtr->logScale) { |
| 2049 |
min = EXP10(min); |
| 2050 |
max = EXP10(max); |
| 2051 |
} |
| 2052 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2053 |
segPtr->p.x = Blt_HMap(graphPtr, axisPtr, min); |
| 2054 |
segPtr->q.x = Blt_HMap(graphPtr, axisPtr, max); |
| 2055 |
segPtr->p.y = segPtr->q.y = line; |
| 2056 |
} else { |
| 2057 |
segPtr->q.x = segPtr->p.x = line; |
| 2058 |
segPtr->p.y = Blt_VMap(graphPtr, axisPtr, min); |
| 2059 |
segPtr->q.y = Blt_VMap(graphPtr, axisPtr, max); |
| 2060 |
} |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
static void |
| 2065 |
MakeTick(graphPtr, axisPtr, value, tick, line, segPtr) |
| 2066 |
Graph *graphPtr; |
| 2067 |
Axis *axisPtr; |
| 2068 |
double value; |
| 2069 |
int tick, line; |
| 2070 |
Segment2D *segPtr; |
| 2071 |
{ |
| 2072 |
if (axisPtr->logScale) { |
| 2073 |
value = EXP10(value); |
| 2074 |
} |
| 2075 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2076 |
segPtr->p.x = segPtr->q.x = Blt_HMap(graphPtr, axisPtr, value); |
| 2077 |
segPtr->p.y = line; |
| 2078 |
segPtr->q.y = tick; |
| 2079 |
} else { |
| 2080 |
segPtr->p.x = line; |
| 2081 |
segPtr->p.y = segPtr->q.y = Blt_VMap(graphPtr, axisPtr, value); |
| 2082 |
segPtr->q.x = tick; |
| 2083 |
} |
| 2084 |
} |
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
static void |
| 2112 |
MapAxis(graphPtr, axisPtr, offset, margin) |
| 2113 |
Graph *graphPtr; |
| 2114 |
Axis *axisPtr; |
| 2115 |
int offset; |
| 2116 |
int margin; |
| 2117 |
{ |
| 2118 |
int arraySize; |
| 2119 |
int nMajorTicks, nMinorTicks; |
| 2120 |
AxisInfo info; |
| 2121 |
Segment2D *segments; |
| 2122 |
Segment2D *segPtr; |
| 2123 |
|
| 2124 |
AxisOffsets(graphPtr, axisPtr, margin, offset, &info); |
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
if (axisPtr->segments != NULL) { |
| 2129 |
Blt_Free(axisPtr->segments); |
| 2130 |
} |
| 2131 |
nMajorTicks = nMinorTicks = 0; |
| 2132 |
if (axisPtr->t1Ptr != NULL) { |
| 2133 |
nMajorTicks = axisPtr->t1Ptr->nTicks; |
| 2134 |
} |
| 2135 |
if (axisPtr->t2Ptr != NULL) { |
| 2136 |
nMinorTicks = axisPtr->t2Ptr->nTicks; |
| 2137 |
} |
| 2138 |
arraySize = 1 + (nMajorTicks * (nMinorTicks + 1)); |
| 2139 |
segments = Blt_Malloc(arraySize * sizeof(Segment2D)); |
| 2140 |
assert(segments); |
| 2141 |
|
| 2142 |
segPtr = segments; |
| 2143 |
if (axisPtr->lineWidth > 0) { |
| 2144 |
|
| 2145 |
MakeAxisLine(graphPtr, axisPtr, info.axis, segPtr); |
| 2146 |
segPtr++; |
| 2147 |
} |
| 2148 |
if (axisPtr->showTicks) { |
| 2149 |
double t1, t2; |
| 2150 |
double labelPos; |
| 2151 |
register int i, j; |
| 2152 |
int isHoriz; |
| 2153 |
TickLabel *labelPtr; |
| 2154 |
Blt_ChainLink *linkPtr; |
| 2155 |
Segment2D seg; |
| 2156 |
|
| 2157 |
isHoriz = AxisIsHorizontal(graphPtr, axisPtr); |
| 2158 |
for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) { |
| 2159 |
t1 = axisPtr->t1Ptr->values[i]; |
| 2160 |
|
| 2161 |
for (j = 0; j < axisPtr->t2Ptr->nTicks; j++) { |
| 2162 |
t2 = t1 + |
| 2163 |
(axisPtr->majorSweep.step * axisPtr->t2Ptr->values[j]); |
| 2164 |
if (InRange(t2, &axisPtr->axisRange)) { |
| 2165 |
MakeTick(graphPtr, axisPtr, t2, info.t2, info.axis, |
| 2166 |
segPtr); |
| 2167 |
segPtr++; |
| 2168 |
} |
| 2169 |
} |
| 2170 |
if (!InRange(t1, &axisPtr->axisRange)) { |
| 2171 |
continue; |
| 2172 |
} |
| 2173 |
|
| 2174 |
MakeTick(graphPtr, axisPtr, t1, info.t1, info.axis, segPtr); |
| 2175 |
segPtr++; |
| 2176 |
} |
| 2177 |
|
| 2178 |
linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); |
| 2179 |
labelPos = (double)info.label; |
| 2180 |
|
| 2181 |
for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) { |
| 2182 |
t1 = axisPtr->t1Ptr->values[i]; |
| 2183 |
if (axisPtr->labelOffset) { |
| 2184 |
t1 += axisPtr->majorSweep.step * 0.5; |
| 2185 |
} |
| 2186 |
if (!InRange(t1, &axisPtr->axisRange)) { |
| 2187 |
continue; |
| 2188 |
} |
| 2189 |
labelPtr = Blt_ChainGetValue(linkPtr); |
| 2190 |
linkPtr = Blt_ChainNextLink(linkPtr); |
| 2191 |
MakeTick(graphPtr, axisPtr, t1, info.t1, info.axis, &seg); |
| 2192 |
|
| 2193 |
if (isHoriz) { |
| 2194 |
labelPtr->anchorPos.x = seg.p.x; |
| 2195 |
labelPtr->anchorPos.y = labelPos; |
| 2196 |
} else { |
| 2197 |
labelPtr->anchorPos.x = labelPos; |
| 2198 |
labelPtr->anchorPos.y = seg.p.y; |
| 2199 |
} |
| 2200 |
} |
| 2201 |
} |
| 2202 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2203 |
axisPtr->width = graphPtr->right - graphPtr->left; |
| 2204 |
} else { |
| 2205 |
axisPtr->height = graphPtr->bottom - graphPtr->top; |
| 2206 |
} |
| 2207 |
axisPtr->segments = segments; |
| 2208 |
axisPtr->nSegments = segPtr - segments; |
| 2209 |
assert(axisPtr->nSegments <= arraySize); |
| 2210 |
} |
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
static double |
| 2239 |
AdjustViewport(offset, windowSize) |
| 2240 |
double offset, windowSize; |
| 2241 |
{ |
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
if (windowSize > 1.0) { |
| 2247 |
if (windowSize < (1.0 - offset)) { |
| 2248 |
offset = 1.0 - windowSize; |
| 2249 |
} |
| 2250 |
if (offset > 0.0) { |
| 2251 |
offset = 0.0; |
| 2252 |
} |
| 2253 |
} else { |
| 2254 |
if ((offset + windowSize) > 1.0) { |
| 2255 |
offset = 1.0 - windowSize; |
| 2256 |
} |
| 2257 |
if (offset < 0.0) { |
| 2258 |
offset = 0.0; |
| 2259 |
} |
| 2260 |
} |
| 2261 |
return offset; |
| 2262 |
} |
| 2263 |
|
| 2264 |
static int |
| 2265 |
GetAxisScrollInfo(interp, argc, argv, offsetPtr, windowSize, scrollUnits) |
| 2266 |
Tcl_Interp *interp; |
| 2267 |
int argc; |
| 2268 |
char **argv; |
| 2269 |
double *offsetPtr; |
| 2270 |
double windowSize; |
| 2271 |
double scrollUnits; |
| 2272 |
{ |
| 2273 |
char c; |
| 2274 |
unsigned int length; |
| 2275 |
double offset; |
| 2276 |
int count; |
| 2277 |
double fract; |
| 2278 |
|
| 2279 |
offset = *offsetPtr; |
| 2280 |
c = argv[0][0]; |
| 2281 |
length = strlen(argv[0]); |
| 2282 |
if ((c == 's') && (strncmp(argv[0], "scroll", length) == 0)) { |
| 2283 |
|
| 2284 |
if (argc != 3) { |
| 2285 |
Tcl_AppendResult(interp, "expected arg", 0); |
| 2286 |
return TCL_ERROR; |
| 2287 |
} |
| 2288 |
|
| 2289 |
if (Tcl_GetInt(interp, argv[1], &count) != TCL_OK) { |
| 2290 |
return TCL_ERROR; |
| 2291 |
} |
| 2292 |
c = argv[2][0]; |
| 2293 |
length = strlen(argv[2]); |
| 2294 |
if ((c == 'u') && (strncmp(argv[2], "units", length) == 0)) { |
| 2295 |
fract = (double)count * scrollUnits; |
| 2296 |
} else if ((c == 'p') && (strncmp(argv[2], "pages", length) == 0)) { |
| 2297 |
|
| 2298 |
fract = (double)count * windowSize * 0.9; |
| 2299 |
} else { |
| 2300 |
Tcl_AppendResult(interp, "unknown \"scroll\" units \"", argv[2], |
| 2301 |
"\"", (char *)NULL); |
| 2302 |
return TCL_ERROR; |
| 2303 |
} |
| 2304 |
offset += fract; |
| 2305 |
} else if ((c == 'm') && (strncmp(argv[0], "moveto", length) == 0)) { |
| 2306 |
|
| 2307 |
if (argc != 2) { |
| 2308 |
Tcl_AppendResult(interp, "expected arg", 0); |
| 2309 |
return TCL_ERROR; |
| 2310 |
} |
| 2311 |
|
| 2312 |
if (Tcl_GetDouble(interp, argv[1], &fract) != TCL_OK) { |
| 2313 |
return TCL_ERROR; |
| 2314 |
} |
| 2315 |
offset = fract; |
| 2316 |
} else { |
| 2317 |
|
| 2318 |
if (Tcl_GetInt(interp, argv[0], &count) != TCL_OK) { |
| 2319 |
return TCL_ERROR; |
| 2320 |
} |
| 2321 |
fract = (double)count * scrollUnits; |
| 2322 |
offset += fract; |
| 2323 |
|
| 2324 |
} |
| 2325 |
*offsetPtr = AdjustViewport(offset, windowSize); |
| 2326 |
return TCL_OK; |
| 2327 |
} |
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
static void |
| 2348 |
DrawAxis(graphPtr, drawable, axisPtr) |
| 2349 |
Graph *graphPtr; |
| 2350 |
Drawable drawable; |
| 2351 |
Axis *axisPtr; |
| 2352 |
{ |
| 2353 |
if (axisPtr->border != NULL) { |
| 2354 |
Blt_Fill3DRectangle(graphPtr->tkwin, drawable, axisPtr->border, |
| 2355 |
axisPtr->region.left + graphPtr->plotBorderWidth, |
| 2356 |
axisPtr->region.top + graphPtr->plotBorderWidth, |
| 2357 |
axisPtr->region.right - axisPtr->region.left, |
| 2358 |
axisPtr->region.bottom - axisPtr->region.top, |
| 2359 |
axisPtr->borderWidth, axisPtr->relief); |
| 2360 |
} |
| 2361 |
if (axisPtr->title != NULL) { |
| 2362 |
Blt_DrawText(graphPtr->tkwin, drawable, axisPtr->title, |
| 2363 |
&axisPtr->titleTextStyle, (int)axisPtr->titlePos.x, |
| 2364 |
(int)axisPtr->titlePos.y); |
| 2365 |
} |
| 2366 |
if (axisPtr->scrollCmdPrefix != NULL) { |
| 2367 |
double viewWidth, viewMin, viewMax; |
| 2368 |
double worldWidth, worldMin, worldMax; |
| 2369 |
double fract; |
| 2370 |
int isHoriz; |
| 2371 |
|
| 2372 |
worldMin = axisPtr->valueRange.min; |
| 2373 |
worldMax = axisPtr->valueRange.max; |
| 2374 |
if (DEFINED(axisPtr->scrollMin)) { |
| 2375 |
worldMin = axisPtr->scrollMin; |
| 2376 |
} |
| 2377 |
if (DEFINED(axisPtr->scrollMax)) { |
| 2378 |
worldMax = axisPtr->scrollMax; |
| 2379 |
} |
| 2380 |
viewMin = axisPtr->min; |
| 2381 |
viewMax = axisPtr->max; |
| 2382 |
if (viewMin < worldMin) { |
| 2383 |
viewMin = worldMin; |
| 2384 |
} |
| 2385 |
if (viewMax > worldMax) { |
| 2386 |
viewMax = worldMax; |
| 2387 |
} |
| 2388 |
if (axisPtr->logScale) { |
| 2389 |
worldMin = log10(worldMin); |
| 2390 |
worldMax = log10(worldMax); |
| 2391 |
viewMin = log10(viewMin); |
| 2392 |
viewMax = log10(viewMax); |
| 2393 |
} |
| 2394 |
worldWidth = worldMax - worldMin; |
| 2395 |
viewWidth = viewMax - viewMin; |
| 2396 |
isHoriz = AxisIsHorizontal(graphPtr, axisPtr); |
| 2397 |
|
| 2398 |
if (isHoriz != axisPtr->descending) { |
| 2399 |
fract = (viewMin - worldMin) / worldWidth; |
| 2400 |
} else { |
| 2401 |
fract = (worldMax - viewMax) / worldWidth; |
| 2402 |
} |
| 2403 |
fract = AdjustViewport(fract, viewWidth / worldWidth); |
| 2404 |
|
| 2405 |
if (isHoriz != axisPtr->descending) { |
| 2406 |
viewMin = (fract * worldWidth); |
| 2407 |
axisPtr->min = viewMin + worldMin; |
| 2408 |
axisPtr->max = axisPtr->min + viewWidth; |
| 2409 |
viewMax = viewMin + viewWidth; |
| 2410 |
if (axisPtr->logScale) { |
| 2411 |
axisPtr->min = EXP10(axisPtr->min); |
| 2412 |
axisPtr->max = EXP10(axisPtr->max); |
| 2413 |
} |
| 2414 |
Blt_UpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix, |
| 2415 |
(viewMin / worldWidth), (viewMax / worldWidth)); |
| 2416 |
} else { |
| 2417 |
viewMax = (fract * worldWidth); |
| 2418 |
axisPtr->max = worldMax - viewMax; |
| 2419 |
axisPtr->min = axisPtr->max - viewWidth; |
| 2420 |
viewMin = viewMax + viewWidth; |
| 2421 |
if (axisPtr->logScale) { |
| 2422 |
axisPtr->min = EXP10(axisPtr->min); |
| 2423 |
axisPtr->max = EXP10(axisPtr->max); |
| 2424 |
} |
| 2425 |
Blt_UpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix, |
| 2426 |
(viewMax / worldWidth), (viewMin / worldWidth)); |
| 2427 |
} |
| 2428 |
} |
| 2429 |
if (axisPtr->showTicks) { |
| 2430 |
register Blt_ChainLink *linkPtr; |
| 2431 |
TickLabel *labelPtr; |
| 2432 |
|
| 2433 |
for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); linkPtr != NULL; |
| 2434 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 2435 |
|
| 2436 |
labelPtr = Blt_ChainGetValue(linkPtr); |
| 2437 |
Blt_DrawText(graphPtr->tkwin, drawable, labelPtr->string, |
| 2438 |
&axisPtr->tickTextStyle, (int)labelPtr->anchorPos.x, |
| 2439 |
(int)labelPtr->anchorPos.y); |
| 2440 |
} |
| 2441 |
} |
| 2442 |
if ((axisPtr->nSegments > 0) && (axisPtr->lineWidth > 0)) { |
| 2443 |
|
| 2444 |
Blt_Draw2DSegments(graphPtr->display, drawable, axisPtr->tickGC, |
| 2445 |
axisPtr->segments, axisPtr->nSegments); |
| 2446 |
} |
| 2447 |
} |
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
static void |
| 2470 |
AxisToPostScript(psToken, axisPtr) |
| 2471 |
PsToken psToken; |
| 2472 |
Axis *axisPtr; |
| 2473 |
{ |
| 2474 |
if (axisPtr->title != NULL) { |
| 2475 |
Blt_TextToPostScript(psToken, axisPtr->title, &axisPtr->titleTextStyle, |
| 2476 |
axisPtr->titlePos.x, axisPtr->titlePos.y); |
| 2477 |
} |
| 2478 |
if (axisPtr->showTicks) { |
| 2479 |
register Blt_ChainLink *linkPtr; |
| 2480 |
TickLabel *labelPtr; |
| 2481 |
|
| 2482 |
for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); |
| 2483 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 2484 |
labelPtr = Blt_ChainGetValue(linkPtr); |
| 2485 |
Blt_TextToPostScript(psToken, labelPtr->string, |
| 2486 |
&axisPtr->tickTextStyle, labelPtr->anchorPos.x, |
| 2487 |
labelPtr->anchorPos.y); |
| 2488 |
} |
| 2489 |
} |
| 2490 |
if ((axisPtr->nSegments > 0) && (axisPtr->lineWidth > 0)) { |
| 2491 |
Blt_LineAttributesToPostScript(psToken, axisPtr->tickTextStyle.color, |
| 2492 |
axisPtr->lineWidth, (Blt_Dashes *)NULL, CapButt, JoinMiter); |
| 2493 |
Blt_2DSegmentsToPostScript(psToken, axisPtr->segments, |
| 2494 |
axisPtr->nSegments); |
| 2495 |
} |
| 2496 |
} |
| 2497 |
|
| 2498 |
static void |
| 2499 |
MakeGridLine(graphPtr, axisPtr, value, segPtr) |
| 2500 |
Graph *graphPtr; |
| 2501 |
Axis *axisPtr; |
| 2502 |
double value; |
| 2503 |
Segment2D *segPtr; |
| 2504 |
{ |
| 2505 |
if (axisPtr->logScale) { |
| 2506 |
value = EXP10(value); |
| 2507 |
} |
| 2508 |
|
| 2509 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2510 |
segPtr->p.y = graphPtr->top; |
| 2511 |
segPtr->q.y = graphPtr->bottom; |
| 2512 |
segPtr->p.x = segPtr->q.x = Blt_HMap(graphPtr, axisPtr, value); |
| 2513 |
} else { |
| 2514 |
segPtr->p.x = graphPtr->left; |
| 2515 |
segPtr->q.x = graphPtr->right; |
| 2516 |
segPtr->p.y = segPtr->q.y = Blt_VMap(graphPtr, axisPtr, value); |
| 2517 |
} |
| 2518 |
} |
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
void |
| 2535 |
Blt_GetAxisSegments(graphPtr, axisPtr, segPtrPtr, nSegmentsPtr) |
| 2536 |
Graph *graphPtr; |
| 2537 |
Axis *axisPtr; |
| 2538 |
Segment2D **segPtrPtr; |
| 2539 |
int *nSegmentsPtr; |
| 2540 |
{ |
| 2541 |
int needed; |
| 2542 |
Ticks *t1Ptr, *t2Ptr; |
| 2543 |
register int i; |
| 2544 |
double value; |
| 2545 |
Segment2D *segments, *segPtr; |
| 2546 |
|
| 2547 |
*nSegmentsPtr = 0; |
| 2548 |
*segPtrPtr = NULL; |
| 2549 |
if (axisPtr == NULL) { |
| 2550 |
return; |
| 2551 |
} |
| 2552 |
t1Ptr = axisPtr->t1Ptr; |
| 2553 |
if (t1Ptr == NULL) { |
| 2554 |
t1Ptr = GenerateTicks(&axisPtr->majorSweep); |
| 2555 |
} |
| 2556 |
t2Ptr = axisPtr->t2Ptr; |
| 2557 |
if (t2Ptr == NULL) { |
| 2558 |
t2Ptr = GenerateTicks(&axisPtr->minorSweep); |
| 2559 |
} |
| 2560 |
|
| 2561 |
needed = t1Ptr->nTicks; |
| 2562 |
if (graphPtr->gridPtr->minorGrid) { |
| 2563 |
needed += (t1Ptr->nTicks * t2Ptr->nTicks); |
| 2564 |
} |
| 2565 |
if (needed == 0) { |
| 2566 |
return; |
| 2567 |
} |
| 2568 |
segments = Blt_Malloc(sizeof(Segment2D) * needed); |
| 2569 |
if (segments == NULL) { |
| 2570 |
return; |
| 2571 |
} |
| 2572 |
|
| 2573 |
segPtr = segments; |
| 2574 |
for (i = 0; i < t1Ptr->nTicks; i++) { |
| 2575 |
value = t1Ptr->values[i]; |
| 2576 |
if (graphPtr->gridPtr->minorGrid) { |
| 2577 |
register int j; |
| 2578 |
double subValue; |
| 2579 |
|
| 2580 |
for (j = 0; j < t2Ptr->nTicks; j++) { |
| 2581 |
subValue = value + |
| 2582 |
(axisPtr->majorSweep.step * t2Ptr->values[j]); |
| 2583 |
if (InRange(subValue, &axisPtr->axisRange)) { |
| 2584 |
MakeGridLine(graphPtr, axisPtr, subValue, segPtr); |
| 2585 |
segPtr++; |
| 2586 |
} |
| 2587 |
} |
| 2588 |
} |
| 2589 |
if (InRange(value, &axisPtr->axisRange)) { |
| 2590 |
MakeGridLine(graphPtr, axisPtr, value, segPtr); |
| 2591 |
segPtr++; |
| 2592 |
} |
| 2593 |
} |
| 2594 |
|
| 2595 |
if (t1Ptr != axisPtr->t1Ptr) { |
| 2596 |
Blt_Free(t1Ptr); |
| 2597 |
} |
| 2598 |
if (t2Ptr != axisPtr->t2Ptr) { |
| 2599 |
Blt_Free(t2Ptr); |
| 2600 |
} |
| 2601 |
*nSegmentsPtr = segPtr - segments; |
| 2602 |
assert(*nSegmentsPtr <= needed); |
| 2603 |
*segPtrPtr = segments; |
| 2604 |
} |
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
static void |
| 2617 |
GetAxisGeometry(graphPtr, axisPtr) |
| 2618 |
Graph *graphPtr; |
| 2619 |
Axis *axisPtr; |
| 2620 |
{ |
| 2621 |
int height; |
| 2622 |
|
| 2623 |
FreeLabels(axisPtr->tickLabels); |
| 2624 |
height = 0; |
| 2625 |
if (axisPtr->lineWidth > 0) { |
| 2626 |
|
| 2627 |
height += axisPtr->lineWidth + 2; |
| 2628 |
} |
| 2629 |
if (axisPtr->showTicks) { |
| 2630 |
int pad; |
| 2631 |
register int i, nLabels; |
| 2632 |
int lw, lh; |
| 2633 |
double x, x2; |
| 2634 |
int maxWidth, maxHeight; |
| 2635 |
TickLabel *labelPtr; |
| 2636 |
|
| 2637 |
SweepTicks(axisPtr); |
| 2638 |
|
| 2639 |
if (axisPtr->t1Ptr->nTicks < 0) { |
| 2640 |
fprintf(stderr, "%s major ticks can't be %d\n", |
| 2641 |
axisPtr->name, axisPtr->t1Ptr->nTicks); |
| 2642 |
abort(); |
| 2643 |
} |
| 2644 |
if (axisPtr->t1Ptr->nTicks > MAXTICKS) { |
| 2645 |
fprintf(stderr, "too big, %s major ticks can't be %d\n", |
| 2646 |
axisPtr->name, axisPtr->t1Ptr->nTicks); |
| 2647 |
abort(); |
| 2648 |
} |
| 2649 |
|
| 2650 |
maxHeight = maxWidth = 0; |
| 2651 |
nLabels = 0; |
| 2652 |
for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) { |
| 2653 |
x2 = x = axisPtr->t1Ptr->values[i]; |
| 2654 |
if (axisPtr->labelOffset) { |
| 2655 |
x2 += axisPtr->majorSweep.step * 0.5; |
| 2656 |
} |
| 2657 |
if (!InRange(x2, &axisPtr->axisRange)) { |
| 2658 |
continue; |
| 2659 |
} |
| 2660 |
labelPtr = MakeLabel(graphPtr, axisPtr, x); |
| 2661 |
Blt_ChainAppend(axisPtr->tickLabels, labelPtr); |
| 2662 |
nLabels++; |
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
Blt_GetTextExtents(&axisPtr->tickTextStyle, labelPtr->string, |
| 2668 |
&lw, &lh); |
| 2669 |
labelPtr->width = lw; |
| 2670 |
labelPtr->height = lh; |
| 2671 |
|
| 2672 |
if (axisPtr->tickTextStyle.theta > 0.0) { |
| 2673 |
double rotWidth, rotHeight; |
| 2674 |
|
| 2675 |
Blt_GetBoundingBox(lw, lh, axisPtr->tickTextStyle.theta, |
| 2676 |
&rotWidth, &rotHeight, (Point2D *)NULL); |
| 2677 |
lw = ROUND(rotWidth); |
| 2678 |
lh = ROUND(rotHeight); |
| 2679 |
} |
| 2680 |
if (maxWidth < lw) { |
| 2681 |
maxWidth = lw; |
| 2682 |
} |
| 2683 |
if (maxHeight < lh) { |
| 2684 |
maxHeight = lh; |
| 2685 |
} |
| 2686 |
} |
| 2687 |
assert(nLabels <= axisPtr->t1Ptr->nTicks); |
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
pad = ((axisPtr->lineWidth * 15) / 10); |
| 2694 |
|
| 2695 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2696 |
height += maxHeight + pad; |
| 2697 |
} else { |
| 2698 |
height += maxWidth + pad; |
| 2699 |
} |
| 2700 |
if (axisPtr->lineWidth > 0) { |
| 2701 |
|
| 2702 |
height += AXIS_TITLE_PAD; |
| 2703 |
height += ABS(axisPtr->tickLength); |
| 2704 |
} |
| 2705 |
} |
| 2706 |
|
| 2707 |
if (axisPtr->title != NULL) { |
| 2708 |
if (axisPtr->titleAlternate) { |
| 2709 |
if (height < axisPtr->titleHeight) { |
| 2710 |
height = axisPtr->titleHeight; |
| 2711 |
} |
| 2712 |
} else { |
| 2713 |
height += axisPtr->titleHeight + AXIS_TITLE_PAD; |
| 2714 |
} |
| 2715 |
} |
| 2716 |
|
| 2717 |
|
| 2718 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 2719 |
axisPtr->height = height; |
| 2720 |
} else { |
| 2721 |
axisPtr->width = height; |
| 2722 |
} |
| 2723 |
} |
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
static int |
| 2748 |
GetMarginGeometry(graphPtr, marginPtr) |
| 2749 |
Graph *graphPtr; |
| 2750 |
Margin *marginPtr; |
| 2751 |
{ |
| 2752 |
Blt_ChainLink *linkPtr; |
| 2753 |
Axis *axisPtr; |
| 2754 |
int width, height; |
| 2755 |
int isHoriz; |
| 2756 |
int length, count; |
| 2757 |
|
| 2758 |
isHoriz = HORIZMARGIN(marginPtr); |
| 2759 |
|
| 2760 |
count = 0; |
| 2761 |
length = width = height = 0; |
| 2762 |
for (linkPtr = Blt_ChainFirstLink(marginPtr->axes); linkPtr != NULL; |
| 2763 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 2764 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 2765 |
if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) { |
| 2766 |
count++; |
| 2767 |
if (graphPtr->flags & GET_AXIS_GEOMETRY) { |
| 2768 |
GetAxisGeometry(graphPtr, axisPtr); |
| 2769 |
} |
| 2770 |
if ((axisPtr->titleAlternate) && (length < axisPtr->titleWidth)) { |
| 2771 |
length = axisPtr->titleWidth; |
| 2772 |
} |
| 2773 |
if (isHoriz) { |
| 2774 |
height += axisPtr->height; |
| 2775 |
} else { |
| 2776 |
width += axisPtr->width; |
| 2777 |
} |
| 2778 |
} |
| 2779 |
} |
| 2780 |
|
| 2781 |
if (width < 3) { |
| 2782 |
width = 3; |
| 2783 |
} |
| 2784 |
if (height < 3) { |
| 2785 |
height = 3; |
| 2786 |
} |
| 2787 |
marginPtr->nAxes = count; |
| 2788 |
marginPtr->axesTitleLength = length; |
| 2789 |
marginPtr->width = width; |
| 2790 |
marginPtr->height = height; |
| 2791 |
marginPtr->axesOffset = (HORIZMARGIN(marginPtr)) ? height : width; |
| 2792 |
return marginPtr->axesOffset; |
| 2793 |
} |
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
static void |
| 2810 |
ComputeMargins(graphPtr) |
| 2811 |
Graph *graphPtr; |
| 2812 |
{ |
| 2813 |
int left, right, top, bottom; |
| 2814 |
int width, height; |
| 2815 |
int insets; |
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
top = GetMarginGeometry(graphPtr, &graphPtr->topMargin); |
| 2823 |
bottom = GetMarginGeometry(graphPtr, &graphPtr->bottomMargin); |
| 2824 |
left = GetMarginGeometry(graphPtr, &graphPtr->leftMargin); |
| 2825 |
right = GetMarginGeometry(graphPtr, &graphPtr->rightMargin); |
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
if (graphPtr->title != NULL) { |
| 2831 |
top += graphPtr->titleTextStyle.height; |
| 2832 |
} |
| 2833 |
insets = 2 * (graphPtr->inset + graphPtr->plotBorderWidth); |
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
width = graphPtr->width - (insets + left + right); |
| 2840 |
height = graphPtr->height - (insets + top + bottom); |
| 2841 |
Blt_MapLegend(graphPtr->legend, width, height); |
| 2842 |
if (!Blt_LegendIsHidden(graphPtr->legend)) { |
| 2843 |
switch (Blt_LegendSite(graphPtr->legend)) { |
| 2844 |
case LEGEND_RIGHT: |
| 2845 |
right += Blt_LegendWidth(graphPtr->legend) + 2; |
| 2846 |
break; |
| 2847 |
case LEGEND_LEFT: |
| 2848 |
left += Blt_LegendWidth(graphPtr->legend) + 2; |
| 2849 |
break; |
| 2850 |
case LEGEND_TOP: |
| 2851 |
top += Blt_LegendHeight(graphPtr->legend) + 2; |
| 2852 |
break; |
| 2853 |
case LEGEND_BOTTOM: |
| 2854 |
bottom += Blt_LegendHeight(graphPtr->legend) + 2; |
| 2855 |
break; |
| 2856 |
case LEGEND_XY: |
| 2857 |
case LEGEND_PLOT: |
| 2858 |
case LEGEND_WINDOW: |
| 2859 |
|
| 2860 |
break; |
| 2861 |
} |
| 2862 |
} |
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
width = graphPtr->width - (insets + left + right); |
| 2868 |
height = graphPtr->height - (insets + top + bottom); |
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
if (graphPtr->aspect > 0.0) { |
| 2875 |
double ratio; |
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
ratio = (double)width / (double)height; |
| 2882 |
if (ratio > graphPtr->aspect) { |
| 2883 |
int scaledWidth; |
| 2884 |
|
| 2885 |
|
| 2886 |
scaledWidth = (int)(height * graphPtr->aspect); |
| 2887 |
if (scaledWidth < 1) { |
| 2888 |
scaledWidth = 1; |
| 2889 |
} |
| 2890 |
right += (width - scaledWidth); |
| 2891 |
|
| 2892 |
|
| 2893 |
} else { |
| 2894 |
int scaledHeight; |
| 2895 |
|
| 2896 |
|
| 2897 |
scaledHeight = (int)(width / graphPtr->aspect); |
| 2898 |
if (scaledHeight < 1) { |
| 2899 |
scaledHeight = 1; |
| 2900 |
} |
| 2901 |
top += (height - scaledHeight); |
| 2902 |
|
| 2903 |
|
| 2904 |
} |
| 2905 |
} |
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
if (top < graphPtr->leftMargin.axesTitleLength) { |
| 2914 |
top = graphPtr->leftMargin.axesTitleLength; |
| 2915 |
} |
| 2916 |
if (right < graphPtr->bottomMargin.axesTitleLength) { |
| 2917 |
right = graphPtr->bottomMargin.axesTitleLength; |
| 2918 |
} |
| 2919 |
if (top < graphPtr->rightMargin.axesTitleLength) { |
| 2920 |
top = graphPtr->rightMargin.axesTitleLength; |
| 2921 |
} |
| 2922 |
if (right < graphPtr->topMargin.axesTitleLength) { |
| 2923 |
right = graphPtr->topMargin.axesTitleLength; |
| 2924 |
} |
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
graphPtr->leftMargin.width = left; |
| 2932 |
graphPtr->rightMargin.width = right; |
| 2933 |
graphPtr->topMargin.height = top; |
| 2934 |
graphPtr->bottomMargin.height = bottom; |
| 2935 |
|
| 2936 |
if (graphPtr->leftMargin.reqSize > 0) { |
| 2937 |
graphPtr->leftMargin.width = graphPtr->leftMargin.reqSize; |
| 2938 |
} |
| 2939 |
if (graphPtr->rightMargin.reqSize > 0) { |
| 2940 |
graphPtr->rightMargin.width = graphPtr->rightMargin.reqSize; |
| 2941 |
} |
| 2942 |
if (graphPtr->topMargin.reqSize > 0) { |
| 2943 |
graphPtr->topMargin.height = graphPtr->topMargin.reqSize; |
| 2944 |
} |
| 2945 |
if (graphPtr->bottomMargin.reqSize > 0) { |
| 2946 |
graphPtr->bottomMargin.height = graphPtr->bottomMargin.reqSize; |
| 2947 |
} |
| 2948 |
} |
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
void |
| 3034 |
Blt_LayoutMargins(graphPtr) |
| 3035 |
Graph *graphPtr; |
| 3036 |
{ |
| 3037 |
int width, height; |
| 3038 |
int titleY; |
| 3039 |
int left, right, top, bottom; |
| 3040 |
|
| 3041 |
ComputeMargins(graphPtr); |
| 3042 |
left = graphPtr->leftMargin.width + graphPtr->inset + |
| 3043 |
graphPtr->plotBorderWidth; |
| 3044 |
right = graphPtr->rightMargin.width + graphPtr->inset + |
| 3045 |
graphPtr->plotBorderWidth; |
| 3046 |
top = graphPtr->topMargin.height + graphPtr->inset + |
| 3047 |
graphPtr->plotBorderWidth; |
| 3048 |
bottom = graphPtr->bottomMargin.height + graphPtr->inset + |
| 3049 |
graphPtr->plotBorderWidth; |
| 3050 |
|
| 3051 |
|
| 3052 |
width = graphPtr->width - (left + right); |
| 3053 |
height = graphPtr->height - (top + bottom); |
| 3054 |
if (width < 1) { |
| 3055 |
width = 1; |
| 3056 |
} |
| 3057 |
if (height < 1) { |
| 3058 |
height = 1; |
| 3059 |
} |
| 3060 |
graphPtr->left = left; |
| 3061 |
graphPtr->right = left + width; |
| 3062 |
graphPtr->bottom = top + height; |
| 3063 |
graphPtr->top = top; |
| 3064 |
|
| 3065 |
graphPtr->vOffset = top + graphPtr->padTop; |
| 3066 |
graphPtr->vRange = height - PADDING(graphPtr->padY); |
| 3067 |
graphPtr->hOffset = left + graphPtr->padLeft; |
| 3068 |
graphPtr->hRange = width - PADDING(graphPtr->padX); |
| 3069 |
|
| 3070 |
if (graphPtr->vRange < 1) { |
| 3071 |
graphPtr->vRange = 1; |
| 3072 |
} |
| 3073 |
if (graphPtr->hRange < 1) { |
| 3074 |
graphPtr->hRange = 1; |
| 3075 |
} |
| 3076 |
graphPtr->hScale = 1.0 / (double)graphPtr->hRange; |
| 3077 |
graphPtr->vScale = 1.0 / (double)graphPtr->vRange; |
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
|
| 3082 |
|
| 3083 |
titleY = graphPtr->titleTextStyle.height; |
| 3084 |
graphPtr->titleY = (titleY / 2) + graphPtr->inset; |
| 3085 |
graphPtr->titleX = (graphPtr->right + graphPtr->left) / 2; |
| 3086 |
|
| 3087 |
} |
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
static int |
| 3107 |
ConfigureAxis(graphPtr, axisPtr) |
| 3108 |
Graph *graphPtr; |
| 3109 |
Axis *axisPtr; |
| 3110 |
{ |
| 3111 |
char errMsg[200]; |
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
if (((DEFINED(axisPtr->reqMin)) && (DEFINED(axisPtr->reqMax))) && |
| 3116 |
(axisPtr->reqMin >= axisPtr->reqMax)) { |
| 3117 |
sprintf(errMsg, "impossible limits (min %g >= max %g) for axis \"%s\"", |
| 3118 |
axisPtr->reqMin, axisPtr->reqMax, axisPtr->name); |
| 3119 |
Tcl_AppendResult(graphPtr->interp, errMsg, (char *)NULL); |
| 3120 |
|
| 3121 |
axisPtr->reqMin = axisPtr->reqMax = VALUE_UNDEFINED; |
| 3122 |
return TCL_ERROR; |
| 3123 |
} |
| 3124 |
if ((axisPtr->logScale) && (DEFINED(axisPtr->reqMin)) && |
| 3125 |
(axisPtr->reqMin <= 0.0)) { |
| 3126 |
sprintf(errMsg, "bad logscale limits (min=%g,max=%g) for axis \"%s\"", |
| 3127 |
axisPtr->reqMin, axisPtr->reqMax, axisPtr->name); |
| 3128 |
Tcl_AppendResult(graphPtr->interp, errMsg, (char *)NULL); |
| 3129 |
|
| 3130 |
axisPtr->reqMin = VALUE_UNDEFINED; |
| 3131 |
return TCL_ERROR; |
| 3132 |
} |
| 3133 |
axisPtr->tickTextStyle.theta = FMOD(axisPtr->tickTextStyle.theta, 360.0); |
| 3134 |
if (axisPtr->tickTextStyle.theta < 0.0) { |
| 3135 |
axisPtr->tickTextStyle.theta += 360.0; |
| 3136 |
} |
| 3137 |
ResetTextStyles(graphPtr, axisPtr); |
| 3138 |
|
| 3139 |
axisPtr->titleWidth = axisPtr->titleHeight = 0; |
| 3140 |
if (axisPtr->title != NULL) { |
| 3141 |
int w, h; |
| 3142 |
|
| 3143 |
Blt_GetTextExtents(&axisPtr->titleTextStyle, axisPtr->title, &w, &h); |
| 3144 |
axisPtr->titleWidth = (short int)w; |
| 3145 |
axisPtr->titleHeight = (short int)h; |
| 3146 |
} |
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
graphPtr->flags |= REDRAW_WORLD; |
| 3158 |
if (!Blt_ConfigModified(configSpecs, graphPtr->interp, "-*color", "-background", "-bg", |
| 3159 |
(char *)NULL)) { |
| 3160 |
graphPtr->flags |= (MAP_WORLD | RESET_AXES); |
| 3161 |
axisPtr->flags |= AXIS_DIRTY; |
| 3162 |
} |
| 3163 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 3164 |
|
| 3165 |
return TCL_OK; |
| 3166 |
} |
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
static Axis * |
| 3182 |
CreateAxis(graphPtr, name, margin) |
| 3183 |
Graph *graphPtr; |
| 3184 |
char *name; |
| 3185 |
int margin; |
| 3186 |
{ |
| 3187 |
Axis *axisPtr; |
| 3188 |
Blt_HashEntry *hPtr; |
| 3189 |
int isNew; |
| 3190 |
|
| 3191 |
if (name[0] == '-') { |
| 3192 |
Tcl_AppendResult(graphPtr->interp, "name of axis \"", name, |
| 3193 |
"\" can't start with a '-'", (char *)NULL); |
| 3194 |
return NULL; |
| 3195 |
} |
| 3196 |
hPtr = Blt_CreateHashEntry(&graphPtr->axes.table, name, &isNew); |
| 3197 |
if (!isNew) { |
| 3198 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 3199 |
if (!axisPtr->deletePending) { |
| 3200 |
Tcl_AppendResult(graphPtr->interp, "axis \"", name, |
| 3201 |
"\" already exists in \"", Tk_PathName(graphPtr->tkwin), "\"", |
| 3202 |
(char *)NULL); |
| 3203 |
return NULL; |
| 3204 |
} |
| 3205 |
axisPtr->deletePending = FALSE; |
| 3206 |
} else { |
| 3207 |
axisPtr = Blt_Calloc(1, sizeof(Axis)); |
| 3208 |
assert(axisPtr); |
| 3209 |
|
| 3210 |
axisPtr->name = Blt_Strdup(name); |
| 3211 |
axisPtr->hashPtr = hPtr; |
| 3212 |
axisPtr->classUid = NULL; |
| 3213 |
axisPtr->looseMin = axisPtr->looseMax = TICK_RANGE_TIGHT; |
| 3214 |
axisPtr->reqNumMinorTicks = 2; |
| 3215 |
axisPtr->scrollUnits = 10; |
| 3216 |
axisPtr->showTicks = TRUE; |
| 3217 |
axisPtr->reqMin = axisPtr->reqMax = VALUE_UNDEFINED; |
| 3218 |
axisPtr->scrollMin = axisPtr->scrollMax = VALUE_UNDEFINED; |
| 3219 |
|
| 3220 |
if ((graphPtr->classUid == bltBarElementUid) && |
| 3221 |
((margin == MARGIN_TOP) || (margin == MARGIN_BOTTOM))) { |
| 3222 |
axisPtr->reqStep = 1.0; |
| 3223 |
axisPtr->reqNumMinorTicks = 0; |
| 3224 |
} |
| 3225 |
if ((margin == MARGIN_RIGHT) || (margin == MARGIN_TOP)) { |
| 3226 |
axisPtr->hidden = TRUE; |
| 3227 |
} |
| 3228 |
Blt_InitTextStyle(&axisPtr->titleTextStyle); |
| 3229 |
Blt_InitTextStyle(&axisPtr->limitsTextStyle); |
| 3230 |
Blt_InitTextStyle(&axisPtr->tickTextStyle); |
| 3231 |
axisPtr->tickLabels = Blt_ChainCreate(); |
| 3232 |
axisPtr->lineWidth = 1; |
| 3233 |
axisPtr->tickTextStyle.padX.side1 = 2; |
| 3234 |
axisPtr->tickTextStyle.padX.side2 = 2; |
| 3235 |
Blt_SetHashValue(hPtr, axisPtr); |
| 3236 |
} |
| 3237 |
return axisPtr; |
| 3238 |
} |
| 3239 |
|
| 3240 |
static int |
| 3241 |
NameToAxis(graphPtr, name, axisPtrPtr) |
| 3242 |
Graph *graphPtr; |
| 3243 |
char *name; |
| 3244 |
Axis **axisPtrPtr; |
| 3245 |
{ |
| 3246 |
Blt_HashEntry *hPtr; |
| 3247 |
|
| 3248 |
hPtr = Blt_FindHashEntry(&graphPtr->axes.table, name); |
| 3249 |
if (hPtr != NULL) { |
| 3250 |
Axis *axisPtr; |
| 3251 |
|
| 3252 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 3253 |
if (!axisPtr->deletePending) { |
| 3254 |
*axisPtrPtr = axisPtr; |
| 3255 |
return TCL_OK; |
| 3256 |
} |
| 3257 |
} |
| 3258 |
Tcl_AppendResult(graphPtr->interp, "can't find axis \"", name, |
| 3259 |
"\" in \"", Tk_PathName(graphPtr->tkwin), "\"", (char *)NULL); |
| 3260 |
*axisPtrPtr = NULL; |
| 3261 |
return TCL_ERROR; |
| 3262 |
} |
| 3263 |
|
| 3264 |
static int |
| 3265 |
GetAxis(graphPtr, axisName, classUid, axisPtrPtr) |
| 3266 |
Graph *graphPtr; |
| 3267 |
char *axisName; |
| 3268 |
Blt_Uid classUid; |
| 3269 |
Axis **axisPtrPtr; |
| 3270 |
{ |
| 3271 |
Axis *axisPtr; |
| 3272 |
|
| 3273 |
if (NameToAxis(graphPtr, axisName, &axisPtr) != TCL_OK) { |
| 3274 |
return TCL_ERROR; |
| 3275 |
} |
| 3276 |
if (classUid != NULL) { |
| 3277 |
if ((axisPtr->refCount == 0) || (axisPtr->classUid == NULL)) { |
| 3278 |
|
| 3279 |
axisPtr->classUid = classUid; |
| 3280 |
} else if (axisPtr->classUid != classUid) { |
| 3281 |
Tcl_AppendResult(graphPtr->interp, "axis \"", axisName, |
| 3282 |
"\" is already in use on an opposite ", axisPtr->classUid, |
| 3283 |
"-axis", (char *)NULL); |
| 3284 |
return TCL_ERROR; |
| 3285 |
} |
| 3286 |
axisPtr->refCount++; |
| 3287 |
} |
| 3288 |
*axisPtrPtr = axisPtr; |
| 3289 |
return TCL_OK; |
| 3290 |
} |
| 3291 |
|
| 3292 |
static void |
| 3293 |
FreeAxis(graphPtr, axisPtr) |
| 3294 |
Graph *graphPtr; |
| 3295 |
Axis *axisPtr; |
| 3296 |
{ |
| 3297 |
axisPtr->refCount--; |
| 3298 |
if ((axisPtr->deletePending) && (axisPtr->refCount == 0)) { |
| 3299 |
DestroyAxis(graphPtr, axisPtr); |
| 3300 |
} |
| 3301 |
} |
| 3302 |
|
| 3303 |
|
| 3304 |
void |
| 3305 |
Blt_DestroyAxes(graphPtr) |
| 3306 |
Graph *graphPtr; |
| 3307 |
{ |
| 3308 |
Blt_HashEntry *hPtr; |
| 3309 |
Blt_HashSearch cursor; |
| 3310 |
Axis *axisPtr; |
| 3311 |
int i; |
| 3312 |
|
| 3313 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 3314 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 3315 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 3316 |
axisPtr->hashPtr = NULL; |
| 3317 |
DestroyAxis(graphPtr, axisPtr); |
| 3318 |
} |
| 3319 |
Blt_DeleteHashTable(&graphPtr->axes.table); |
| 3320 |
for (i = 0; i < 4; i++) { |
| 3321 |
Blt_ChainDestroy(graphPtr->axisChain[i]); |
| 3322 |
} |
| 3323 |
Blt_DeleteHashTable(&graphPtr->axes.tagTable); |
| 3324 |
Blt_ChainDestroy(graphPtr->axes.displayList); |
| 3325 |
} |
| 3326 |
|
| 3327 |
int Blt_ConfigureAxes(graphPtr) |
| 3328 |
Graph *graphPtr; |
| 3329 |
{ |
| 3330 |
Blt_HashEntry *hPtr; |
| 3331 |
Blt_HashSearch cursor; |
| 3332 |
Axis *axisPtr; |
| 3333 |
|
| 3334 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 3335 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 3336 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 3337 |
ConfigureAxis(graphPtr, axisPtr); |
| 3338 |
} |
| 3339 |
return TCL_OK; |
| 3340 |
} |
| 3341 |
|
| 3342 |
int |
| 3343 |
Blt_DefaultAxes(graphPtr) |
| 3344 |
Graph *graphPtr; |
| 3345 |
{ |
| 3346 |
register int i; |
| 3347 |
Axis *axisPtr; |
| 3348 |
Blt_Chain *chainPtr; |
| 3349 |
static char *axisNames[4] = { "x", "y", "x2", "y2" } ; |
| 3350 |
int flags; |
| 3351 |
|
| 3352 |
flags = Blt_GraphType(graphPtr); |
| 3353 |
for (i = 0; i < 4; i++) { |
| 3354 |
chainPtr = Blt_ChainCreate(); |
| 3355 |
graphPtr->axisChain[i] = chainPtr; |
| 3356 |
|
| 3357 |
|
| 3358 |
axisPtr = CreateAxis(graphPtr, axisNames[i], i); |
| 3359 |
if (axisPtr == NULL) { |
| 3360 |
return TCL_ERROR; |
| 3361 |
} |
| 3362 |
axisPtr->refCount = 1; |
| 3363 |
axisPtr->classUid = (i & 1) ? bltYAxisUid : bltXAxisUid; |
| 3364 |
axisPtr->flags |= AXIS_ONSCREEN; |
| 3365 |
|
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin, |
| 3373 |
axisPtr->name, "Axis", configSpecs, 0, (char **)NULL, |
| 3374 |
(char *)axisPtr, flags) != TCL_OK) { |
| 3375 |
return TCL_ERROR; |
| 3376 |
} |
| 3377 |
if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) { |
| 3378 |
return TCL_ERROR; |
| 3379 |
} |
| 3380 |
axisPtr->linkPtr = Blt_ChainAppend(chainPtr, axisPtr); |
| 3381 |
axisPtr->chainPtr = chainPtr; |
| 3382 |
} |
| 3383 |
return TCL_OK; |
| 3384 |
} |
| 3385 |
|
| 3386 |
|
| 3387 |
|
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
static int |
| 3396 |
BindOp(graphPtr, axisPtr, argc, argv) |
| 3397 |
Graph *graphPtr; |
| 3398 |
Axis *axisPtr; |
| 3399 |
int argc; |
| 3400 |
char **argv; |
| 3401 |
{ |
| 3402 |
Tcl_Interp *interp = graphPtr->interp; |
| 3403 |
|
| 3404 |
return Blt_ConfigureBindings(interp, graphPtr->bindTable, |
| 3405 |
Blt_MakeAxisTag(graphPtr, axisPtr->name), argc, argv); |
| 3406 |
} |
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
static int |
| 3423 |
CgetOp(graphPtr, axisPtr, argc, argv) |
| 3424 |
Graph *graphPtr; |
| 3425 |
Axis *axisPtr; |
| 3426 |
int argc; |
| 3427 |
char *argv[]; |
| 3428 |
{ |
| 3429 |
return Tk_ConfigureValue(graphPtr->interp, graphPtr->tkwin, configSpecs, |
| 3430 |
(char *)axisPtr, argv[0], Blt_GraphType(graphPtr)); |
| 3431 |
} |
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
static int |
| 3451 |
ConfigureOp(graphPtr, axisPtr, argc, argv) |
| 3452 |
Graph *graphPtr; |
| 3453 |
Axis *axisPtr; |
| 3454 |
int argc; |
| •3455 |
CONST char *argv[]; |
| 3456 |
{ |
| 3457 |
int flags; |
| 3458 |
|
| 3459 |
flags = TK_CONFIG_ARGV_ONLY | Blt_GraphType(graphPtr); |
| 3460 |
if (argc == 0) { |
| 3461 |
return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs, |
| 3462 |
(char *)axisPtr, (char *)NULL, flags); |
| 3463 |
} else if (argc == 1) { |
| 3464 |
return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs, |
| 3465 |
(char *)axisPtr, argv[0], flags); |
| 3466 |
} |
| •3467 |
if (Blt_ConfigureWidget(graphPtr->interp, graphPtr->tkwin, configSpecs, |
| 3468 |
argc, argv, (char *)axisPtr, flags) != TCL_OK) { |
| 3469 |
return TCL_ERROR; |
| 3470 |
} |
| 3471 |
if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) { |
| 3472 |
return TCL_ERROR; |
| 3473 |
} |
| 3474 |
if (axisPtr->flags & AXIS_ONSCREEN) { |
| 3475 |
if (!Blt_ConfigModified(configSpecs, graphPtr->interp, "-*color", "-background", "-bg", |
| 3476 |
(char *)NULL)) { |
| 3477 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 3478 |
} |
| 3479 |
graphPtr->flags |= DRAW_MARGINS; |
| 3480 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 3481 |
} |
| 3482 |
return TCL_OK; |
| 3483 |
} |
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
static int |
| 3503 |
GetOp(graphPtr, argc, argv) |
| 3504 |
Graph *graphPtr; |
| 3505 |
int argc; |
| 3506 |
char *argv[]; |
| 3507 |
{ |
| 3508 |
Tcl_Interp *interp = graphPtr->interp; |
| 3509 |
register Axis *axisPtr; |
| 3510 |
|
| 3511 |
axisPtr = (Axis *)Blt_GetCurrentItem(graphPtr->bindTable); |
| 3512 |
|
| 3513 |
if ((axisPtr != NULL) && |
| 3514 |
((axisPtr->classUid == bltXAxisUid) || |
| 3515 |
(axisPtr->classUid == bltYAxisUid) || |
| 3516 |
(axisPtr->classUid == NULL))) { |
| 3517 |
char c; |
| 3518 |
|
| 3519 |
c = argv[3][0]; |
| 3520 |
if ((c == 'c') && (strcmp(argv[3], "current") == 0)) { |
| 3521 |
Tcl_SetResult(interp, axisPtr->name, TCL_VOLATILE); |
| 3522 |
} else if ((c == 'd') && (strcmp(argv[3], "detail") == 0)) { |
| 3523 |
Tcl_SetResult(interp, axisPtr->detail, TCL_VOLATILE); |
| 3524 |
} |
| 3525 |
} |
| 3526 |
return TCL_OK; |
| 3527 |
} |
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
static int |
| 3545 |
LimitsOp(graphPtr, axisPtr, argc, argv) |
| 3546 |
Graph *graphPtr; |
| 3547 |
Axis *axisPtr; |
| 3548 |
int argc; |
| 3549 |
char **argv; |
| 3550 |
|
| 3551 |
{ |
| 3552 |
Tcl_Interp *interp = graphPtr->interp; |
| 3553 |
double min, max; |
| 3554 |
|
| 3555 |
if (graphPtr->flags & RESET_AXES) { |
| 3556 |
Blt_ResetAxes(graphPtr); |
| 3557 |
} |
| 3558 |
if (axisPtr->logScale) { |
| 3559 |
min = EXP10(axisPtr->axisRange.min); |
| 3560 |
max = EXP10(axisPtr->axisRange.max); |
| 3561 |
} else { |
| 3562 |
min = axisPtr->axisRange.min; |
| 3563 |
max = axisPtr->axisRange.max; |
| 3564 |
} |
| 3565 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, min)); |
| 3566 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, max)); |
| 3567 |
return TCL_OK; |
| 3568 |
} |
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
static int |
| 3586 |
InvTransformOp(graphPtr, axisPtr, argc, argv) |
| 3587 |
Graph *graphPtr; |
| 3588 |
Axis *axisPtr; |
| 3589 |
int argc; |
| 3590 |
char **argv; |
| 3591 |
{ |
| 3592 |
int x; |
| 3593 |
double y; |
| 3594 |
|
| 3595 |
if (graphPtr->flags & RESET_AXES) { |
| 3596 |
Blt_ResetAxes(graphPtr); |
| 3597 |
} |
| 3598 |
if (Tcl_GetInt(graphPtr->interp, argv[0], &x) != TCL_OK) { |
| 3599 |
return TCL_ERROR; |
| 3600 |
} |
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 3609 |
y = Blt_InvHMap(graphPtr, axisPtr, (double)x); |
| 3610 |
} else { |
| 3611 |
y = Blt_InvVMap(graphPtr, axisPtr, (double)x); |
| 3612 |
} |
| 3613 |
Tcl_AppendElement(graphPtr->interp, Blt_Dtoa(graphPtr->interp, y)); |
| 3614 |
return TCL_OK; |
| 3615 |
} |
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
|
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
static int |
| 3634 |
TransformOp(graphPtr, axisPtr, argc, argv) |
| 3635 |
Graph *graphPtr; |
| 3636 |
Axis *axisPtr; |
| 3637 |
int argc; |
| 3638 |
char **argv; |
| 3639 |
{ |
| 3640 |
double x; |
| 3641 |
|
| 3642 |
if (graphPtr->flags & RESET_AXES) { |
| 3643 |
Blt_ResetAxes(graphPtr); |
| 3644 |
} |
| 3645 |
if (Tcl_ExprDouble(graphPtr->interp, argv[0], &x) != TCL_OK) { |
| 3646 |
return TCL_ERROR; |
| 3647 |
} |
| 3648 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 3649 |
x = Blt_HMap(graphPtr, axisPtr, x); |
| 3650 |
} else { |
| 3651 |
x = Blt_VMap(graphPtr, axisPtr, x); |
| 3652 |
} |
| 3653 |
Tcl_SetResult(graphPtr->interp, Blt_Itoa((int)x), TCL_VOLATILE); |
| 3654 |
return TCL_OK; |
| 3655 |
} |
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
static int |
| 3675 |
UseOp(graphPtr, axisPtr, argc, argv) |
| 3676 |
Graph *graphPtr; |
| 3677 |
Axis *axisPtr; |
| 3678 |
int argc; |
| 3679 |
char **argv; |
| 3680 |
{ |
| 3681 |
Blt_Chain *chainPtr; |
| 3682 |
int nNames; |
| 3683 |
char **names; |
| 3684 |
Blt_ChainLink *linkPtr; |
| 3685 |
int i; |
| 3686 |
Blt_Uid classUid; |
| 3687 |
int margin; |
| 3688 |
|
| 3689 |
|
| •3690 |
margin = (intptr_t)argv[-1]; |
| 3691 |
chainPtr = graphPtr->margins[margin].axes; |
| 3692 |
if (argc == 0) { |
| 3693 |
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr!= NULL; |
| 3694 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 3695 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 3696 |
Tcl_AppendElement(graphPtr->interp, axisPtr->name); |
| 3697 |
} |
| 3698 |
return TCL_OK; |
| 3699 |
} |
| 3700 |
if ((margin == MARGIN_BOTTOM) || (margin == MARGIN_TOP)) { |
| 3701 |
classUid = (graphPtr->inverted) ? bltYAxisUid : bltXAxisUid; |
| 3702 |
} else { |
| 3703 |
classUid = (graphPtr->inverted) ? bltXAxisUid : bltYAxisUid; |
| 3704 |
} |
| 3705 |
if (Tcl_SplitList(graphPtr->interp, argv[0], &nNames, &names) != TCL_OK) { |
| 3706 |
return TCL_ERROR; |
| 3707 |
} |
| 3708 |
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr!= NULL; |
| 3709 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 3710 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 3711 |
axisPtr->linkPtr = NULL; |
| 3712 |
axisPtr->flags &= ~AXIS_ONSCREEN; |
| 3713 |
|
| 3714 |
if (axisPtr->refCount == 0) { |
| 3715 |
axisPtr->classUid = NULL; |
| 3716 |
} |
| 3717 |
} |
| 3718 |
Blt_ChainReset(chainPtr); |
| 3719 |
for (i = 0; i < nNames; i++) { |
| 3720 |
if (NameToAxis(graphPtr, names[i], &axisPtr) != TCL_OK) { |
| 3721 |
Blt_Free(names); |
| 3722 |
return TCL_ERROR; |
| 3723 |
} |
| 3724 |
if (axisPtr->classUid == NULL) { |
| 3725 |
axisPtr->classUid = classUid; |
| 3726 |
} else if (axisPtr->classUid != classUid) { |
| 3727 |
Tcl_AppendResult(graphPtr->interp, "wrong type axis \"", |
| 3728 |
axisPtr->name, "\": can't use ", classUid, " type axis.", |
| 3729 |
(char *)NULL); |
| 3730 |
Blt_Free(names); |
| 3731 |
return TCL_ERROR; |
| 3732 |
} |
| 3733 |
if (axisPtr->linkPtr != NULL) { |
| 3734 |
|
| 3735 |
Blt_ChainUnlinkLink(axisPtr->chainPtr, axisPtr->linkPtr); |
| 3736 |
Blt_ChainAppendLink(chainPtr, axisPtr->linkPtr); |
| 3737 |
} else { |
| 3738 |
axisPtr->linkPtr = Blt_ChainAppend(chainPtr, axisPtr); |
| 3739 |
} |
| 3740 |
axisPtr->chainPtr = chainPtr; |
| 3741 |
axisPtr->flags |= AXIS_ONSCREEN; |
| 3742 |
} |
| 3743 |
graphPtr->flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | RESET_AXES); |
| 3744 |
|
| 3745 |
graphPtr->flags |= (MAP_WORLD | REDRAW_WORLD); |
| 3746 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 3747 |
|
| 3748 |
Blt_Free(names); |
| 3749 |
return TCL_OK; |
| 3750 |
} |
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
static int |
| 3766 |
CreateVirtualOp(graphPtr, argc, argv) |
| 3767 |
Graph *graphPtr; |
| 3768 |
int argc; |
| 3769 |
char **argv; |
| 3770 |
{ |
| 3771 |
Axis *axisPtr; |
| 3772 |
int flags; |
| 3773 |
|
| 3774 |
axisPtr = CreateAxis(graphPtr, argv[3], MARGIN_NONE); |
| 3775 |
if (axisPtr == NULL) { |
| 3776 |
return TCL_ERROR; |
| 3777 |
} |
| 3778 |
flags = Blt_GraphType(graphPtr); |
| 3779 |
if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin, |
| 3780 |
axisPtr->name, "Axis", configSpecs, argc - 4, argv + 4, |
| 3781 |
(char *)axisPtr, flags) != TCL_OK) { |
| 3782 |
goto error; |
| 3783 |
} |
| 3784 |
if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) { |
| 3785 |
goto error; |
| 3786 |
} |
| 3787 |
Tcl_SetResult(graphPtr->interp, axisPtr->name, TCL_VOLATILE); |
| 3788 |
return TCL_OK; |
| 3789 |
error: |
| 3790 |
DestroyAxis(graphPtr, axisPtr); |
| 3791 |
return TCL_ERROR; |
| 3792 |
} |
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
static int |
| 3804 |
BindVirtualOp(graphPtr, argc, argv) |
| 3805 |
Graph *graphPtr; |
| 3806 |
int argc; |
| 3807 |
char **argv; |
| 3808 |
{ |
| 3809 |
Tcl_Interp *interp = graphPtr->interp; |
| 3810 |
|
| 3811 |
if (argc == 3) { |
| 3812 |
Blt_HashEntry *hPtr; |
| 3813 |
Blt_HashSearch cursor; |
| 3814 |
char *tagName; |
| 3815 |
|
| 3816 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.tagTable, &cursor); |
| 3817 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 3818 |
tagName = Blt_GetHashKey(&graphPtr->axes.tagTable, hPtr); |
| 3819 |
Tcl_AppendElement(interp, tagName); |
| 3820 |
} |
| 3821 |
return TCL_OK; |
| 3822 |
} |
| 3823 |
return Blt_ConfigureBindings(interp, graphPtr->bindTable, |
| 3824 |
Blt_MakeAxisTag(graphPtr, argv[3]), argc - 4, argv + 4); |
| 3825 |
} |
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
static int |
| 3843 |
CgetVirtualOp(graphPtr, argc, argv) |
| 3844 |
Graph *graphPtr; |
| 3845 |
int argc; |
| 3846 |
char *argv[]; |
| 3847 |
{ |
| 3848 |
Axis *axisPtr; |
| 3849 |
|
| 3850 |
if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) { |
| 3851 |
return TCL_ERROR; |
| 3852 |
} |
| 3853 |
return CgetOp(graphPtr, axisPtr, argc - 4, argv + 4); |
| 3854 |
} |
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
static int |
| 3874 |
ConfigureVirtualOp(graphPtr, argc, argv) |
| 3875 |
Graph *graphPtr; |
| 3876 |
int argc; |
| 3877 |
char *argv[]; |
| 3878 |
{ |
| 3879 |
Axis *axisPtr; |
| 3880 |
int nNames, nOpts; |
| 3881 |
char **options; |
| 3882 |
register int i; |
| 3883 |
|
| 3884 |
|
| 3885 |
argc -= 3; |
| 3886 |
argv += 3; |
| 3887 |
for (i = 0; i < argc; i++) { |
| 3888 |
if (argv[i][0] == '-') { |
| 3889 |
break; |
| 3890 |
} |
| 3891 |
if (NameToAxis(graphPtr, argv[i], &axisPtr) != TCL_OK) { |
| 3892 |
return TCL_ERROR; |
| 3893 |
} |
| 3894 |
} |
| 3895 |
nNames = i; |
| 3896 |
nOpts = argc - i; |
| 3897 |
options = argv + i; |
| 3898 |
|
| 3899 |
for (i = 0; i < nNames; i++) { |
| 3900 |
if (NameToAxis(graphPtr, argv[i], &axisPtr) != TCL_OK) { |
| 3901 |
return TCL_ERROR; |
| 3902 |
} |
| 3903 |
if (ConfigureOp(graphPtr, axisPtr, nOpts, options) != TCL_OK) { |
| 3904 |
break; |
| 3905 |
} |
| 3906 |
} |
| 3907 |
if (i < nNames) { |
| 3908 |
return TCL_ERROR; |
| 3909 |
} |
| 3910 |
return TCL_OK; |
| 3911 |
} |
| 3912 |
|
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
static int |
| 3930 |
DeleteVirtualOp(graphPtr, argc, argv) |
| 3931 |
Graph *graphPtr; |
| 3932 |
int argc; |
| 3933 |
char **argv; |
| 3934 |
{ |
| 3935 |
register int i; |
| 3936 |
Axis *axisPtr; |
| 3937 |
|
| 3938 |
for (i = 3; i < argc; i++) { |
| 3939 |
if (NameToAxis(graphPtr, argv[i], &axisPtr) != TCL_OK) { |
| 3940 |
return TCL_ERROR; |
| 3941 |
} |
| 3942 |
axisPtr->deletePending = TRUE; |
| 3943 |
if (axisPtr->refCount == 0) { |
| 3944 |
DestroyAxis(graphPtr, axisPtr); |
| 3945 |
} |
| 3946 |
} |
| 3947 |
return TCL_OK; |
| 3948 |
} |
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
|
| 3954 |
|
| 3955 |
|
| 3956 |
|
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
static int |
| 3966 |
InvTransformVirtualOp(graphPtr, argc, argv) |
| 3967 |
Graph *graphPtr; |
| 3968 |
int argc; |
| 3969 |
char **argv; |
| 3970 |
{ |
| 3971 |
Axis *axisPtr; |
| 3972 |
|
| 3973 |
if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) { |
| 3974 |
return TCL_ERROR; |
| 3975 |
} |
| 3976 |
return InvTransformOp(graphPtr, axisPtr, argc - 4, argv + 4); |
| 3977 |
} |
| 3978 |
|
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
static int |
| 3995 |
LimitsVirtualOp(graphPtr, argc, argv) |
| 3996 |
Graph *graphPtr; |
| 3997 |
int argc; |
| 3998 |
char **argv; |
| 3999 |
|
| 4000 |
{ |
| 4001 |
Axis *axisPtr; |
| 4002 |
|
| 4003 |
if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) { |
| 4004 |
return TCL_ERROR; |
| 4005 |
} |
| 4006 |
return LimitsOp(graphPtr, axisPtr, argc - 4, argv + 4); |
| 4007 |
} |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
static int |
| 4024 |
NamesVirtualOp(graphPtr, argc, argv) |
| 4025 |
Graph *graphPtr; |
| 4026 |
int argc; |
| 4027 |
char **argv; |
| 4028 |
{ |
| 4029 |
Blt_HashEntry *hPtr; |
| 4030 |
Blt_HashSearch cursor; |
| 4031 |
Axis *axisPtr; |
| 4032 |
register int i; |
| 4033 |
|
| 4034 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 4035 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4036 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 4037 |
if (axisPtr->deletePending) { |
| 4038 |
continue; |
| 4039 |
} |
| 4040 |
if (argc == 3) { |
| 4041 |
Tcl_AppendElement(graphPtr->interp, axisPtr->name); |
| 4042 |
continue; |
| 4043 |
} |
| 4044 |
for (i = 3; i < argc; i++) { |
| 4045 |
if (Tcl_StringMatch(axisPtr->name, argv[i])) { |
| 4046 |
Tcl_AppendElement(graphPtr->interp, axisPtr->name); |
| 4047 |
break; |
| 4048 |
} |
| 4049 |
} |
| 4050 |
} |
| 4051 |
return TCL_OK; |
| 4052 |
} |
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
static int |
| 4071 |
TransformVirtualOp(graphPtr, argc, argv) |
| 4072 |
Graph *graphPtr; |
| 4073 |
int argc; |
| 4074 |
char **argv; |
| 4075 |
{ |
| 4076 |
Axis *axisPtr; |
| 4077 |
|
| 4078 |
if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) { |
| 4079 |
return TCL_ERROR; |
| 4080 |
} |
| 4081 |
return TransformOp(graphPtr, axisPtr, argc - 4, argv + 4); |
| 4082 |
} |
| 4083 |
|
| 4084 |
static int |
| 4085 |
ViewOp(graphPtr, argc, argv) |
| 4086 |
Graph *graphPtr; |
| 4087 |
int argc; |
| 4088 |
char **argv; |
| 4089 |
{ |
| 4090 |
Axis *axisPtr; |
| 4091 |
Tcl_Interp *interp = graphPtr->interp; |
| 4092 |
double axisOffset, scrollUnits; |
| 4093 |
double fract; |
| 4094 |
double viewMin, viewMax, worldMin, worldMax; |
| 4095 |
double viewWidth, worldWidth; |
| 4096 |
|
| 4097 |
if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) { |
| 4098 |
return TCL_ERROR; |
| 4099 |
} |
| 4100 |
worldMin = axisPtr->valueRange.min; |
| 4101 |
worldMax = axisPtr->valueRange.max; |
| 4102 |
|
| 4103 |
if (DEFINED(axisPtr->scrollMin)) { |
| 4104 |
worldMin = axisPtr->scrollMin; |
| 4105 |
} |
| 4106 |
if (DEFINED(axisPtr->scrollMax)) { |
| 4107 |
worldMax = axisPtr->scrollMax; |
| 4108 |
} |
| 4109 |
viewMin = axisPtr->min; |
| 4110 |
viewMax = axisPtr->max; |
| 4111 |
|
| 4112 |
if (viewMin < worldMin) { |
| 4113 |
viewMin = worldMin; |
| 4114 |
} |
| 4115 |
if (viewMax > worldMax) { |
| 4116 |
viewMax = worldMax; |
| 4117 |
} |
| 4118 |
if (axisPtr->logScale) { |
| 4119 |
worldMin = log10(worldMin); |
| 4120 |
worldMax = log10(worldMax); |
| 4121 |
viewMin = log10(viewMin); |
| 4122 |
viewMax = log10(viewMax); |
| 4123 |
} |
| 4124 |
worldWidth = worldMax - worldMin; |
| 4125 |
viewWidth = viewMax - viewMin; |
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
if (AxisIsHorizontal(graphPtr, axisPtr) != axisPtr->descending) { |
| 4132 |
axisOffset = viewMin - worldMin; |
| 4133 |
scrollUnits = (double)axisPtr->scrollUnits * graphPtr->hScale; |
| 4134 |
} else { |
| 4135 |
axisOffset = worldMax - viewMax; |
| 4136 |
scrollUnits = (double)axisPtr->scrollUnits * graphPtr->vScale; |
| 4137 |
} |
| 4138 |
if (argc == 4) { |
| 4139 |
|
| 4140 |
|
| 4141 |
fract = axisOffset / worldWidth; |
| 4142 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 4143 |
fract = (axisOffset + viewWidth) / worldWidth; |
| 4144 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 4145 |
return TCL_OK; |
| 4146 |
} |
| 4147 |
fract = axisOffset / worldWidth; |
| 4148 |
if (GetAxisScrollInfo(interp, argc - 4, argv + 4, &fract, |
| 4149 |
viewWidth / worldWidth, scrollUnits) != TCL_OK) { |
| 4150 |
return TCL_ERROR; |
| 4151 |
} |
| 4152 |
if (AxisIsHorizontal(graphPtr, axisPtr) != axisPtr->descending) { |
| 4153 |
axisPtr->reqMin = (fract * worldWidth) + worldMin; |
| 4154 |
axisPtr->reqMax = axisPtr->reqMin + viewWidth; |
| 4155 |
} else { |
| 4156 |
axisPtr->reqMax = worldMax - (fract * worldWidth); |
| 4157 |
axisPtr->reqMin = axisPtr->reqMax - viewWidth; |
| 4158 |
} |
| 4159 |
if (axisPtr->logScale) { |
| 4160 |
axisPtr->reqMin = EXP10(axisPtr->reqMin); |
| 4161 |
axisPtr->reqMax = EXP10(axisPtr->reqMax); |
| 4162 |
} |
| 4163 |
graphPtr->flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | RESET_AXES); |
| 4164 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 4165 |
return TCL_OK; |
| 4166 |
} |
| 4167 |
|
| 4168 |
int |
| 4169 |
Blt_VirtualAxisOp(graphPtr, interp, argc, argv) |
| 4170 |
Graph *graphPtr; |
| 4171 |
Tcl_Interp *interp; |
| 4172 |
int argc; |
| 4173 |
char **argv; |
| 4174 |
{ |
| 4175 |
Blt_Op proc; |
| 4176 |
int result; |
| 4177 |
static Blt_OpSpec axisOps[] = |
| 4178 |
{ |
| 4179 |
{"bind", 1, (Blt_Op)BindVirtualOp, 3, 6, |
| 4180 |
"axisName sequence command",}, |
| 4181 |
{"cget", 2, (Blt_Op)CgetVirtualOp, 5, 5, "axisName option",}, |
| 4182 |
{"configure", 2, (Blt_Op)ConfigureVirtualOp, 4, 0, |
| 4183 |
"axisName ?axisName?... ?option value?...",}, |
| 4184 |
{"create", 2, (Blt_Op)CreateVirtualOp, 4, 0, |
| 4185 |
"axisName ?option value?...",}, |
| 4186 |
{"delete", 1, (Blt_Op)DeleteVirtualOp, 3, 0, "?axisName?...",}, |
| 4187 |
{"get", 1, (Blt_Op)GetOp, 4, 4, "name",}, |
| 4188 |
{"invtransform", 1, (Blt_Op)InvTransformVirtualOp, 5, 5, |
| 4189 |
"axisName value",}, |
| 4190 |
{"limits", 1, (Blt_Op)LimitsVirtualOp, 4, 4, "axisName",}, |
| 4191 |
{"names", 1, (Blt_Op)NamesVirtualOp, 3, 0, "?pattern?...",}, |
| 4192 |
{"transform", 1, (Blt_Op)TransformVirtualOp, 5, 5, "axisName value",}, |
| 4193 |
{"view", 1, (Blt_Op)ViewOp, 4, 7, |
| 4194 |
"axisName ?moveto fract? ?scroll number what?",}, |
| 4195 |
}; |
| 4196 |
static int nAxisOps = sizeof(axisOps) / sizeof(Blt_OpSpec); |
| 4197 |
|
| 4198 |
proc = Blt_GetOp(interp, nAxisOps, axisOps, BLT_OP_ARG2, argc, argv, 0); |
| 4199 |
if (proc == NULL) { |
| 4200 |
return TCL_ERROR; |
| 4201 |
} |
| 4202 |
result = (*proc) (graphPtr, argc, argv); |
| 4203 |
return result; |
| 4204 |
} |
| 4205 |
|
| 4206 |
int |
| 4207 |
Blt_AxisOp(graphPtr, margin, argc, argv) |
| 4208 |
Graph *graphPtr; |
| 4209 |
int margin; |
| 4210 |
int argc; |
| 4211 |
char **argv; |
| 4212 |
{ |
| 4213 |
int result; |
| 4214 |
Blt_Op proc; |
| 4215 |
Axis *axisPtr; |
| 4216 |
static Blt_OpSpec axisOps[] = |
| 4217 |
{ |
| 4218 |
{"bind", 1, (Blt_Op)BindOp, 2, 5, "sequence command",}, |
| 4219 |
{"cget", 2, (Blt_Op)CgetOp, 4, 4, "option",}, |
| 4220 |
{"configure", 2, (Blt_Op)ConfigureOp, 3, 0, "?option value?...",}, |
| 4221 |
{"invtransform", 1, (Blt_Op)InvTransformOp, 4, 4, "value",}, |
| 4222 |
{"limits", 1, (Blt_Op)LimitsOp, 3, 3, "",}, |
| 4223 |
{"transform", 1, (Blt_Op)TransformOp, 4, 4, "value",}, |
| 4224 |
{"use", 1, (Blt_Op)UseOp, 3, 4, "?axisName?",}, |
| 4225 |
}; |
| 4226 |
static int nAxisOps = sizeof(axisOps) / sizeof(Blt_OpSpec); |
| 4227 |
|
| 4228 |
proc = Blt_GetOp(graphPtr->interp, nAxisOps, axisOps, BLT_OP_ARG2, |
| 4229 |
argc, argv, 0); |
| 4230 |
if (proc == NULL) { |
| 4231 |
return TCL_ERROR; |
| 4232 |
} |
| 4233 |
if (proc == UseOp) { |
| •4234 |
argv[2] = (char *)(intptr_t)margin; |
| 4235 |
|
| 4236 |
|
| 4237 |
result = (*proc)(graphPtr, NULL, argc - 3, argv +3); |
| 4238 |
} else { |
| 4239 |
axisPtr = Blt_GetFirstAxis(graphPtr->margins[margin].axes); |
| 4240 |
if (axisPtr == NULL) { |
| 4241 |
Tcl_AppendResult(graphPtr->interp, "bad axis", (char *)NULL); |
| 4242 |
return TCL_ERROR; |
| 4243 |
} |
| 4244 |
result = (*proc)(graphPtr, axisPtr, argc - 3, argv + 3); |
| 4245 |
} |
| 4246 |
return result; |
| 4247 |
} |
| 4248 |
|
| 4249 |
void |
| 4250 |
Blt_MapAxes(graphPtr) |
| 4251 |
Graph *graphPtr; |
| 4252 |
{ |
| 4253 |
Axis *axisPtr; |
| 4254 |
Blt_Chain *chainPtr; |
| 4255 |
Blt_ChainLink *linkPtr; |
| 4256 |
register int margin; |
| 4257 |
int offset; |
| 4258 |
|
| 4259 |
for (margin = 0; margin < 4; margin++) { |
| 4260 |
chainPtr = graphPtr->margins[margin].axes; |
| 4261 |
offset = 0; |
| 4262 |
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL; |
| 4263 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4264 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 4265 |
if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) { |
| 4266 |
MapAxis(graphPtr, axisPtr, offset, margin); |
| 4267 |
if (AxisIsHorizontal(graphPtr, axisPtr)) { |
| 4268 |
offset += axisPtr->height; |
| 4269 |
} else { |
| 4270 |
offset += axisPtr->width; |
| 4271 |
} |
| 4272 |
} |
| 4273 |
} |
| 4274 |
} |
| 4275 |
} |
| 4276 |
|
| 4277 |
void |
| 4278 |
Blt_DrawAxes(graphPtr, drawable) |
| 4279 |
Graph *graphPtr; |
| 4280 |
Drawable drawable; |
| 4281 |
{ |
| 4282 |
Axis *axisPtr; |
| 4283 |
Blt_ChainLink *linkPtr; |
| 4284 |
register int i; |
| 4285 |
|
| 4286 |
for (i = 0; i < 4; i++) { |
| 4287 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); |
| 4288 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4289 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 4290 |
if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) { |
| 4291 |
DrawAxis(graphPtr, drawable, axisPtr); |
| 4292 |
} |
| 4293 |
} |
| 4294 |
} |
| 4295 |
} |
| 4296 |
|
| 4297 |
void |
| 4298 |
Blt_AxesToPostScript(graphPtr, psToken) |
| 4299 |
Graph *graphPtr; |
| 4300 |
PsToken psToken; |
| 4301 |
{ |
| 4302 |
Axis *axisPtr; |
| 4303 |
Blt_ChainLink *linkPtr; |
| 4304 |
register int i; |
| 4305 |
|
| 4306 |
for (i = 0; i < 4; i++) { |
| 4307 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); |
| 4308 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4309 |
axisPtr = Blt_ChainGetValue(linkPtr); |
| 4310 |
if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) { |
| 4311 |
AxisToPostScript(psToken, axisPtr); |
| 4312 |
} |
| 4313 |
} |
| 4314 |
} |
| 4315 |
} |
| 4316 |
|
| 4317 |
|
| 4318 |
|
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
|
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
|
| 4330 |
|
| 4331 |
|
| 4332 |
|
| 4333 |
|
| 4334 |
|
| 4335 |
|
| 4336 |
void |
| 4337 |
Blt_DrawAxisLimits(graphPtr, drawable) |
| 4338 |
Graph *graphPtr; |
| 4339 |
Drawable drawable; |
| 4340 |
{ |
| 4341 |
Axis *axisPtr; |
| 4342 |
Blt_HashEntry *hPtr; |
| 4343 |
Blt_HashSearch cursor; |
| 4344 |
Dim2D textDim; |
| 4345 |
int isHoriz; |
| 4346 |
char *minPtr, *maxPtr; |
| 4347 |
char *minFormat, *maxFormat; |
| 4348 |
char minString[200], maxString[200]; |
| 4349 |
int vMin, hMin, vMax, hMax; |
| 4350 |
|
| 4351 |
#define SPACING 8 |
| 4352 |
vMin = vMax = graphPtr->left + graphPtr->padLeft + 2; |
| 4353 |
hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2; |
| 4354 |
|
| 4355 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 4356 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4357 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 4358 |
|
| 4359 |
if (axisPtr->nFormats == 0) { |
| 4360 |
continue; |
| 4361 |
} |
| 4362 |
isHoriz = AxisIsHorizontal(graphPtr, axisPtr); |
| 4363 |
minPtr = maxPtr = NULL; |
| 4364 |
minFormat = maxFormat = axisPtr->limitsFormats[0]; |
| 4365 |
if (axisPtr->nFormats > 1) { |
| 4366 |
maxFormat = axisPtr->limitsFormats[1]; |
| 4367 |
} |
| 4368 |
if (minFormat[0] != '\0') { |
| 4369 |
minPtr = minString; |
| 4370 |
sprintf(minString, minFormat, axisPtr->axisRange.min); |
| 4371 |
} |
| 4372 |
if (maxFormat[0] != '\0') { |
| 4373 |
maxPtr = maxString; |
| 4374 |
sprintf(maxString, maxFormat, axisPtr->axisRange.max); |
| 4375 |
} |
| 4376 |
if (axisPtr->descending) { |
| 4377 |
char *tmp; |
| 4378 |
|
| 4379 |
tmp = minPtr, minPtr = maxPtr, maxPtr = tmp; |
| 4380 |
} |
| 4381 |
if (maxPtr != NULL) { |
| 4382 |
if (isHoriz) { |
| 4383 |
axisPtr->limitsTextStyle.theta = 90.0; |
| 4384 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_SE; |
| 4385 |
Blt_DrawText2(graphPtr->tkwin, drawable, maxPtr, |
| 4386 |
&axisPtr->limitsTextStyle, graphPtr->right, hMax, &textDim); |
| 4387 |
hMax -= (textDim.height + SPACING); |
| 4388 |
} else { |
| 4389 |
axisPtr->limitsTextStyle.theta = 0.0; |
| 4390 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_NW; |
| 4391 |
Blt_DrawText2(graphPtr->tkwin, drawable, maxPtr, |
| 4392 |
&axisPtr->limitsTextStyle, vMax, graphPtr->top, &textDim); |
| 4393 |
vMax += (textDim.width + SPACING); |
| 4394 |
} |
| 4395 |
} |
| 4396 |
if (minPtr != NULL) { |
| 4397 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_SW; |
| 4398 |
if (isHoriz) { |
| 4399 |
axisPtr->limitsTextStyle.theta = 90.0; |
| 4400 |
Blt_DrawText2(graphPtr->tkwin, drawable, minPtr, |
| 4401 |
&axisPtr->limitsTextStyle, graphPtr->left, hMin, &textDim); |
| 4402 |
hMin -= (textDim.height + SPACING); |
| 4403 |
} else { |
| 4404 |
axisPtr->limitsTextStyle.theta = 0.0; |
| 4405 |
Blt_DrawText2(graphPtr->tkwin, drawable, minPtr, |
| 4406 |
&axisPtr->limitsTextStyle, vMin, graphPtr->bottom, &textDim); |
| 4407 |
vMin += (textDim.width + SPACING); |
| 4408 |
} |
| 4409 |
} |
| 4410 |
} |
| 4411 |
} |
| 4412 |
|
| 4413 |
void |
| 4414 |
Blt_AxisLimitsToPostScript(graphPtr, psToken) |
| 4415 |
Graph *graphPtr; |
| 4416 |
PsToken psToken; |
| 4417 |
{ |
| 4418 |
Axis *axisPtr; |
| 4419 |
Blt_HashEntry *hPtr; |
| 4420 |
Blt_HashSearch cursor; |
| 4421 |
double vMin, hMin, vMax, hMax; |
| 4422 |
char string[200]; |
| 4423 |
int textWidth, textHeight; |
| 4424 |
char *minFmt, *maxFmt; |
| 4425 |
|
| 4426 |
#define SPACING 8 |
| 4427 |
vMin = vMax = graphPtr->left + graphPtr->padLeft + 2; |
| 4428 |
hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2; |
| 4429 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 4430 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4431 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 4432 |
|
| 4433 |
if (axisPtr->nFormats == 0) { |
| 4434 |
continue; |
| 4435 |
} |
| 4436 |
minFmt = maxFmt = axisPtr->limitsFormats[0]; |
| 4437 |
if (axisPtr->nFormats > 1) { |
| 4438 |
maxFmt = axisPtr->limitsFormats[1]; |
| 4439 |
} |
| 4440 |
if (*maxFmt != '\0') { |
| 4441 |
sprintf(string, maxFmt, axisPtr->axisRange.max); |
| 4442 |
Blt_GetTextExtents(&axisPtr->tickTextStyle, string, &textWidth, |
| 4443 |
&textHeight); |
| 4444 |
if ((textWidth > 0) && (textHeight > 0)) { |
| 4445 |
if (axisPtr->classUid == bltXAxisUid) { |
| 4446 |
axisPtr->limitsTextStyle.theta = 90.0; |
| 4447 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_SE; |
| 4448 |
Blt_TextToPostScript(psToken, string, |
| 4449 |
&axisPtr->limitsTextStyle, |
| 4450 |
(double)graphPtr->right, hMax); |
| 4451 |
hMax -= (textWidth + SPACING); |
| 4452 |
} else { |
| 4453 |
axisPtr->limitsTextStyle.theta = 0.0; |
| 4454 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_NW; |
| 4455 |
Blt_TextToPostScript(psToken, string, |
| 4456 |
&axisPtr->limitsTextStyle, vMax, (double)graphPtr->top); |
| 4457 |
vMax += (textWidth + SPACING); |
| 4458 |
} |
| 4459 |
} |
| 4460 |
} |
| 4461 |
if (*minFmt != '\0') { |
| 4462 |
sprintf(string, minFmt, axisPtr->axisRange.min); |
| 4463 |
Blt_GetTextExtents(&axisPtr->tickTextStyle, string, &textWidth, |
| 4464 |
&textHeight); |
| 4465 |
if ((textWidth > 0) && (textHeight > 0)) { |
| 4466 |
axisPtr->limitsTextStyle.anchor = TK_ANCHOR_SW; |
| 4467 |
if (axisPtr->classUid == bltXAxisUid) { |
| 4468 |
axisPtr->limitsTextStyle.theta = 90.0; |
| 4469 |
Blt_TextToPostScript(psToken, string, |
| 4470 |
&axisPtr->limitsTextStyle, |
| 4471 |
(double)graphPtr->left, hMin); |
| 4472 |
hMin -= (textWidth + SPACING); |
| 4473 |
} else { |
| 4474 |
axisPtr->limitsTextStyle.theta = 0.0; |
| 4475 |
Blt_TextToPostScript(psToken, string, |
| 4476 |
&axisPtr->limitsTextStyle, |
| 4477 |
vMin, (double)graphPtr->bottom); |
| 4478 |
vMin += (textWidth + SPACING); |
| 4479 |
} |
| 4480 |
} |
| 4481 |
} |
| 4482 |
} |
| 4483 |
} |
| 4484 |
|
| 4485 |
Axis * |
| 4486 |
Blt_GetFirstAxis(chainPtr) |
| 4487 |
Blt_Chain *chainPtr; |
| 4488 |
{ |
| 4489 |
Blt_ChainLink *linkPtr; |
| 4490 |
|
| 4491 |
linkPtr = Blt_ChainFirstLink(chainPtr); |
| 4492 |
if (linkPtr == NULL) { |
| 4493 |
return NULL; |
| 4494 |
} |
| 4495 |
return Blt_ChainGetValue(linkPtr); |
| 4496 |
} |
| 4497 |
|
| 4498 |
Axis * |
| 4499 |
Blt_NearestAxis(graphPtr, x, y) |
| 4500 |
Graph *graphPtr; |
| 4501 |
int x, y; |
| 4502 |
{ |
| 4503 |
register Blt_HashEntry *hPtr; |
| 4504 |
Blt_HashSearch cursor; |
| 4505 |
Axis *axisPtr; |
| 4506 |
int width, height; |
| 4507 |
double rotWidth, rotHeight; |
| 4508 |
Point2D bbox[5]; |
| 4509 |
|
| 4510 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor); |
| 4511 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4512 |
axisPtr = (Axis *)Blt_GetHashValue(hPtr); |
| 4513 |
if ((axisPtr->hidden) || (!(axisPtr->flags & AXIS_ONSCREEN))) { |
| 4514 |
continue; |
| 4515 |
|
| 4516 |
} |
| 4517 |
if (axisPtr->showTicks) { |
| 4518 |
register Blt_ChainLink *linkPtr; |
| 4519 |
TickLabel *labelPtr; |
| 4520 |
Point2D t; |
| 4521 |
|
| 4522 |
for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); |
| 4523 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4524 |
labelPtr = Blt_ChainGetValue(linkPtr); |
| 4525 |
Blt_GetBoundingBox(labelPtr->width, labelPtr->height, |
| 4526 |
axisPtr->tickTextStyle.theta, &rotWidth, &rotHeight, bbox); |
| 4527 |
width = ROUND(rotWidth); |
| 4528 |
height = ROUND(rotHeight); |
| 4529 |
t = Blt_TranslatePoint(&labelPtr->anchorPos, width, height, |
| 4530 |
axisPtr->tickTextStyle.anchor); |
| 4531 |
t.x = x - t.x - (width * 0.5); |
| 4532 |
t.y = y - t.y - (height * 0.5); |
| 4533 |
|
| 4534 |
bbox[4] = bbox[0]; |
| 4535 |
if (Blt_PointInPolygon(&t, bbox, 5)) { |
| 4536 |
axisPtr->detail = "label"; |
| 4537 |
return axisPtr; |
| 4538 |
} |
| 4539 |
} |
| 4540 |
} |
| 4541 |
if (axisPtr->title != NULL) { |
| 4542 |
Point2D t; |
| 4543 |
|
| 4544 |
Blt_GetTextExtents(&axisPtr->titleTextStyle, axisPtr->title,&width, |
| 4545 |
&height); |
| 4546 |
Blt_GetBoundingBox(width, height, axisPtr->titleTextStyle.theta, |
| 4547 |
&rotWidth, &rotHeight, bbox); |
| 4548 |
width = ROUND(rotWidth); |
| 4549 |
height = ROUND(rotHeight); |
| 4550 |
t = Blt_TranslatePoint(&axisPtr->titlePos, width, height, |
| 4551 |
axisPtr->titleTextStyle.anchor); |
| 4552 |
|
| 4553 |
|
| 4554 |
t.x = x - t.x - (width / 2); |
| 4555 |
t.y = y - t.y - (height / 2); |
| 4556 |
|
| 4557 |
bbox[4] = bbox[0]; |
| 4558 |
if (Blt_PointInPolygon(&t, bbox, 5)) { |
| 4559 |
axisPtr->detail = "title"; |
| 4560 |
return axisPtr; |
| 4561 |
} |
| 4562 |
} |
| 4563 |
if (axisPtr->lineWidth > 0) { |
| 4564 |
if (PointInRegion(&axisPtr->region, x, y)) { |
| 4565 |
axisPtr->detail = "line"; |
| 4566 |
return axisPtr; |
| 4567 |
} |
| 4568 |
} |
| 4569 |
} |
| 4570 |
return NULL; |
| 4571 |
} |
| 4572 |
|
| 4573 |
ClientData |
| 4574 |
Blt_MakeAxisTag(graphPtr, tagName) |
| 4575 |
Graph *graphPtr; |
| 4576 |
char *tagName; |
| 4577 |
{ |
| 4578 |
Blt_HashEntry *hPtr; |
| 4579 |
int isNew; |
| 4580 |
|
| 4581 |
hPtr = Blt_CreateHashEntry(&graphPtr->axes.tagTable, tagName, &isNew); |
| 4582 |
assert(hPtr); |
| 4583 |
return Blt_GetHashKey(&graphPtr->axes.tagTable, hPtr); |
| 4584 |
} |