int graph_zoom(Quark *gr, int type) { RunTime *rt = rt_from_quark(gr); double dx, dy; double xmax, xmin, ymax, ymin; world w; if (graph_get_world(gr, &w) == RETURN_SUCCESS) { if (islogx(gr) == TRUE) { xmin = log10(w.xg1); xmax = log10(w.xg2); } else { xmin = w.xg1; xmax = w.xg2; } if (islogy(gr) == TRUE) { ymin = log10(w.yg1); ymax = log10(w.yg2); } else { ymin = w.yg1; ymax = w.yg2; } dx = rt->shexper * (xmax - xmin); dy = rt->shexper * (ymax - ymin); if (type == GZOOM_SHRINK) { dx *= -1; dy *= -1; } xmin -= dx; xmax += dx; ymin -= dy; ymax += dy; if (islogx(gr) == TRUE) { w.xg1 = pow(10.0, xmin); w.xg2 = pow(10.0, xmax); } else { w.xg1 = xmin; w.xg2 = xmax; } if (islogy(gr) == TRUE) { w.yg1 = pow(10.0, ymin); w.yg2 = pow(10.0, ymax); } else { w.yg1 = ymin; w.yg2 = ymax; } graph_set_world(gr, &w); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
static void autorange_bysets(Quark **sets, int nsets, int autos_type) { Quark *gr; world w; double xmax, xmin, ymax, ymin; int scale; if (autos_type == AUTOSCALE_NONE || nsets <= 0) { return; } gr = get_parent_graph(sets[0]); graph_get_world(gr, &w); if (graph_get_type(gr) == GRAPH_SMITH) { if (autos_type == AUTOSCALE_X || autos_type == AUTOSCALE_XY) { w.xg1 = -1.0; w.yg1 = -1.0; } if (autos_type == AUTOSCALE_Y || autos_type == AUTOSCALE_XY) { w.xg2 = 1.0; w.yg2 = 1.0; } graph_set_world(gr, &w); return; } xmin = w.xg1; xmax = w.xg2; ymin = w.yg1; ymax = w.yg2; if (autos_type == AUTOSCALE_XY) { getsetminmax(sets, nsets, &xmin, &xmax, &ymin, &ymax); } else if (autos_type == AUTOSCALE_X) { getsetminmax_c(sets, nsets, &xmin, &xmax, &ymin, &ymax, 2); } else if (autos_type == AUTOSCALE_Y) { getsetminmax_c(sets, nsets, &xmin, &xmax, &ymin, &ymax, 1); } if (autos_type == AUTOSCALE_X || autos_type == AUTOSCALE_XY) { scale = graph_get_xscale(gr); round_axis_limits(&xmin, &xmax, scale); w.xg1 = xmin; w.xg2 = xmax; } if (autos_type == AUTOSCALE_Y || autos_type == AUTOSCALE_XY) { scale = graph_get_yscale(gr); round_axis_limits(&ymin, &ymax, scale); w.yg1 = ymin; w.yg2 = ymax; } graph_set_world(gr, &w); }
void update_graph_ui(GraphUI *ui, Quark *q) { if (q && quark_fid_get(q) == QFlavorGraph) { char buf[32]; world w; GLocator *locator; graph_get_world(q, &w); locator = graph_get_locator(q); SetOptionChoice(ui->graph_type, graph_get_type(q)); SetToggleButtonState(ui->stacked, graph_is_stacked(q)); SetToggleButtonState(ui->flip_xy, graph_get_xyflip(q)); sprintf(buf, "%.9g", w.xg1); xv_setstr(ui->start_x, buf); sprintf(buf, "%.9g", w.xg2); xv_setstr(ui->stop_x, buf); SetOptionChoice(ui->scale_x, graph_get_xscale(q)); SetToggleButtonState(ui->invert_x, graph_is_xinvert(q)); sprintf(buf, "%.9g", w.yg1); xv_setstr(ui->start_y, buf); sprintf(buf, "%.9g", w.yg2); xv_setstr(ui->stop_y, buf); SetOptionChoice(ui->scale_y, graph_get_yscale(q)); SetToggleButtonState(ui->invert_y, graph_is_yinvert(q)); sprintf(buf, "%g", graph_get_znorm(q)); xv_setstr(ui->znorm, buf); SetSpinChoice(ui->bargap, graph_get_bargap(q)); SetToggleButtonState(ui->fixedp, locator->pointset); SetOptionChoice(ui->loc_type, locator->type); SetFormatChoice(ui->loc_fx, &locator->fx); SetFormatChoice(ui->loc_fy, &locator->fy); sprintf(buf, "%g", locator->origin.x); xv_setstr(ui->locx, buf); sprintf(buf, "%g", locator->origin.y); xv_setstr(ui->locy, buf); } }
double set_get_ybase(Quark *pset) { double ybase = 0.0; double xmin, xmax, ymin, ymax; Quark *gr; set *p; world w; if (!pset) { return 0.0; } gr = get_parent_graph(pset); p = set_get_data(pset); graph_get_world(gr, &w); set_get_minmax(pset, &xmin, &xmax, &ymin, &ymax); switch (p->line.baseline_type) { case BASELINE_TYPE_0: ybase = 0.0; break; case BASELINE_TYPE_SMIN: ybase = ymin; break; case BASELINE_TYPE_SMAX: ybase = ymax; break; case BASELINE_TYPE_GMIN: ybase = w.yg1; break; case BASELINE_TYPE_GMAX: ybase = w.yg2; break; default: errmsg("Wrong type of baseline"); } return ybase; }
/* * pan through world coordinates */ int graph_scroll(Quark *gr, int type) { RunTime *rt = rt_from_quark(gr); world w; double xmax, xmin, ymax, ymin; double dwc; if (graph_get_world(gr, &w) == RETURN_SUCCESS) { if (islogx(gr) == TRUE) { xmin = log10(w.xg1); xmax = log10(w.xg2); } else { xmin = w.xg1; xmax = w.xg2; } if (islogy(gr) == TRUE) { ymin = log10(w.yg1); ymax = log10(w.yg2); } else { ymin = w.yg1; ymax = w.yg2; } dwc = 1.0; switch (type) { case GSCROLL_LEFT: dwc = -1.0; case GSCROLL_RIGHT: dwc *= rt->scrollper * (xmax - xmin); xmin += dwc; xmax += dwc; break; case GSCROLL_DOWN: dwc = -1.0; case GSCROLL_UP: dwc *= rt->scrollper * (ymax - ymin); ymin += dwc; ymax += dwc; break; } if (islogx(gr) == TRUE) { w.xg1 = pow(10.0, xmin); w.xg2 = pow(10.0, xmax); } else { w.xg1 = xmin; w.xg2 = xmax; } if (islogy(gr) == TRUE) { w.yg1 = pow(10.0, ymin); w.yg2 = pow(10.0, ymax); } else { w.yg1 = ymin; w.yg2 = ymax; } graph_set_world(gr, &w); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int graph_set_data(GraphUI *ui, Quark *q, void *caller) { if (quark_fid_get(q) == QFlavorGraph) { double axislim, znorm; world w; GLocator *locator; graph_get_world(q, &w); locator = graph_get_locator(q); if (!caller || caller == ui->graph_type) { graph_set_type(q, GetOptionChoice(ui->graph_type)); } if (!caller || caller == ui->stacked) { graph_set_stacked(q, GetToggleButtonState(ui->stacked)); } if (!caller || caller == ui->flip_xy) { graph_set_xyflip(q, GetToggleButtonState(ui->flip_xy)); } if (!caller || caller == ui->start_x) { if (xv_evalexpr(ui->start_x, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.xg1 = axislim; } if (!caller || caller == ui->stop_x) { if (xv_evalexpr(ui->stop_x, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.xg2 = axislim; } if (!caller || caller == ui->start_y) { if (xv_evalexpr(ui->start_y, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.yg1 = axislim; } if (!caller || caller == ui->stop_y) { if (xv_evalexpr(ui->stop_y, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.yg2 = axislim; } if (!caller || caller == ui->start_x || caller == ui->stop_x || caller == ui->start_y || caller == ui->stop_y) { graph_set_world(q, &w); } if (!caller || caller == ui->scale_x) { graph_set_xscale(q, GetOptionChoice(ui->scale_x)); } if (!caller || caller == ui->invert_x) { graph_set_xinvert(q, GetToggleButtonState(ui->invert_x)); } if (!caller || caller == ui->scale_y) { graph_set_yscale(q, GetOptionChoice(ui->scale_y)); } if (!caller || caller == ui->invert_y) { graph_set_yinvert(q, GetToggleButtonState(ui->invert_y)); } if (!caller || caller == ui->bargap) { graph_set_bargap(q, GetSpinChoice(ui->bargap)); } if (!caller || caller == ui->znorm) { xv_evalexpr(ui->znorm, &znorm); graph_set_znorm(q, znorm); } if (!caller || caller == ui->loc_type) { locator->type = GetOptionChoice(ui->loc_type); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->loc_fx) { Format *format = GetFormatChoice(ui->loc_fx); AMem *amem = quark_get_amem(q); amem_free(amem, locator->fx.fstring); locator->fx = *format; locator->fx.fstring = amem_strdup(amem, format->fstring); format_free(format); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->loc_fy) { Format *format = GetFormatChoice(ui->loc_fy); AMem *amem = quark_get_amem(q); amem_free(amem, locator->fy.fstring); locator->fy = *format; locator->fy.fstring = amem_strdup(amem, format->fstring); format_free(format); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->fixedp) { locator->pointset = GetToggleButtonState(ui->fixedp); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->locx) { xv_evalexpr(ui->locx, &locator->origin.x); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->locy) { xv_evalexpr(ui->locy, &locator->origin.y); quark_dirtystate_set(q, TRUE); } return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }