⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plotobs.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	int i, j;
	long n;
	bool dValid;
	lfPOINT *val;

	if(nPoints <2 || !Symbols || 
		!(val = (lfPOINT*)calloc(nPoints, sizeof(lfPOINT)))) return;
	for(i = 0, n = 0; i < nPoints; i++){
		if(Symbols[i] && Symbols[i]->Id == GO_SYMBOL) {
			val[j = (int)n].fx = Symbols[i]->GetSize(SIZE_XPOS);
			val[j].fy = Symbols[i]->GetSize(SIZE_YPOS);
			dValid = true;
			switch(type & 0x700) {
			case 0x100:					//logarithmic x
				if(dValid = val[j].fx > defs.min4log) val[j].fx = log10(val[j].fx);
				break;
			case 0x200:					//reciprocal x
				if(dValid = fabs(val[j].fx) >defs.min4log) val[j].fx = 1.0/val[j].fx;
				break;
			case 0x300:					//square root x
				if(dValid = fabs(val[j].fx) >defs.min4log) val[j].fx = sqrt(val[j].fx);
				break;
				}
			if(dValid) switch(type & 0x7000) {
			case 0x1000:				//logarithmic y
				if(dValid = val[j].fy > defs.min4log) val[j].fy = log10(val[j].fy);
				break;
			case 0x2000:				//reciprocal y
				if(dValid = fabs(val[j].fy) >defs.min4log) val[j].fy = 1.0/val[j].fy;
				break;
			case 0x3000:				//square root y
				if(dValid = fabs(val[j].fy) >defs.min4log) val[j].fy = sqrt(val[j].fy);
				break;
				}
			if(dValid) n++;
			}
		}
	if(sde && sde->Id == GO_SDELLIPSE) sde->Recalc(val, n);
	if(rLine && rLine->Id == GO_REGLINE) rLine->Recalc(val, n);
	free(val);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BubblePlot is a Plot-Class
BubblePlot::BubblePlot(GraphObj *par, DataObj *d):Plot(par, d)
{
	FileIO(INIT_VARS);
	Id = GO_BUBBLEPLOT;
	if (!d && parent) parent->Command(CMD_DELOBJ, this, NULL);
}

BubblePlot::BubblePlot(int src):Plot(0L, 0L)
{
	long i;

	FileIO(INIT_VARS);
	if(src == FILE_READ) {
		FileIO(FILE_READ);
		BubbleFill.hatch = &BubbleFillLine;
		if(Bubbles)for(i = 0; i< nPoints; i++) {
			if(Bubbles[i])Bubbles[i]->parent = this;
			}
		}
}

BubblePlot::~BubblePlot()
{
	int i;

	if(Bubbles) {
		for(i = 0; i < nPoints; i++) if(Bubbles[i]) DeleteGO(Bubbles[i]);
		free (Bubbles);
		}
	if(name) free(name);		name=0L;
	Undo.InvalidGO(this);
}

DWORD
BubblePlot::GetColor(int select)
{
	switch(select) {
	case COL_BUBBLE_FILL:			return BubbleFill.color;
	case COL_BUBBLE_LINE:			return BubbleLine.color;
	case COL_BUBBLE_FILLLINE:	   	return BubbleFillLine.color;
	default:
		return Plot::GetColor(select);
	}
}

void
BubblePlot::DoPlot(anyOutput *o)
{
	int i;

	parent->Command(CMD_REG_AXISPLOT, (void*)this, o);
	if(use_xaxis || use_yaxis) {
		ApplyAxes(o);
		if(Bubbles) for(i = 0; i < nPoints; i++) 
			if(Bubbles[i]) Bubbles[i]->DoPlot(o);
		parent->Command(CMD_AXIS, 0L, o);
		}
	else {
		if(Bubbles) for(i = 0; i < nPoints; i++) 
			if(Bubbles[i]) Bubbles[i]->DoPlot(o);
		}
	dirty = false;
}

bool
BubblePlot::Command(int cmd, void *tmpl, anyOutput *o)
{
	int i;
	static MouseEvent *mev;
	GraphObj **tmpPlots;

	switch (cmd) {
	case CMD_MOUSE_EVENT:
		if(hidden) return false;
		mev = (MouseEvent *) tmpl;
		switch(mev->Action) {
		case MOUSE_LBUP:
			//select objects invers to plot order
			if(Bubbles && !CurrGO) for(i = nPoints-1; i >=0; i--)
				if(Bubbles[i]) if(Bubbles[i]->Command(cmd, tmpl, o))break;
			break;
			}
		break;
	case CMD_REPL_GO:
		if((tmpPlots = (GraphObj **)tmpl) && tmpPlots[0] && tmpPlots[1] && Bubbles) {
			for(i = 0; i < nPoints; i++) if(Bubbles[i] && Bubbles[i] == tmpPlots[0]) { 
				return ReplaceGO((GraphObj**)&Bubbles[i], tmpPlots);
				}
			}
		return false;
	case CMD_LEGEND:
		if(((GraphObj*)tmpl)->Id != GO_LEGEND) return false;
		if(Bubbles) for (i = 0; i < nPoints; i++)
			if(Bubbles[i]) Bubbles[i]->Command(cmd, tmpl, o);
		return true;
	case CMD_MRK_DIRTY:
		dirty = true;
	case CMD_SETSCROLL:		case CMD_REDRAW:
		if(parent) return parent->Command(cmd, tmpl, o);
		return false;
	case CMD_USEAXIS:
		UseAxis(*((int*)tmpl));
		return true;
	case CMD_SET_DATAOBJ:
		Id = GO_BUBBLEPLOT;
		data = (DataObj *)tmpl;
	case CMD_UPDATE:
		if(cmd == CMD_UPDATE && Bubbles) SavVarObs((GraphObj **)Bubbles, nPoints, UNDO_CONTINUE);
	case CMD_AUTOSCALE:
		if(cmd == CMD_AUTOSCALE && Bubbles) {
			Bounds.Xmax = Bounds.Ymax = -HUGE_VAL;		Bounds.Xmin = Bounds.Ymin = HUGE_VAL;
			}
	case CMD_BUBBLE_ATTRIB:		case CMD_BUBBLE_TYPE:		case CMD_BUBBLE_FILL:
	case CMD_BUBBLE_LINE:
		if(Bubbles) for(i = 0; i < nPoints; i++)
			if(Bubbles[i]) Bubbles[i]->Command(cmd, tmpl, o);
		return true;
	case CMD_DELOBJ:
		if(Bubbles && parent) for(i = 0; i < nPoints; i++) {
			o->HideMark();
			if(Bubbles[i] && tmpl == (void *)Bubbles[i]) {
				Undo.DeleteGO((GraphObj**)(&Bubbles[i]), 0L, o);
				parent->Command(CMD_REDRAW, 0L, o);
				return true;
				}
			}
		break;
	case CMD_SAVE_SYMBOLS:
		return SavVarObs((GraphObj **)Bubbles, nPoints, 0L);
		}
	return false;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// PolarPlot is a Plot-Class
PolarPlot::PolarPlot(GraphObj *par, DataObj *d):Plot(par, d)
{
	FileIO(INIT_VARS);
	Id = GO_POLARPLOT;
	if (!d && parent) parent->Command(CMD_DELOBJ, this, NULL);
}

PolarPlot::PolarPlot(int src):Plot(0L, 0L)
{
	int i;

	FileIO(INIT_VARS);
	if(src == FILE_READ) {
		FileIO(FILE_READ);
		Fill.hatch = &FillLine;
		//now set parent in all children
		if(Plots) 
			for(i = 0; i < nPlots; i++) if(Plots[i]) Plots[i]->parent = this;
		if(Axes) 
			for(i = 0; i < nAxes; i++) if(Axes[i]) Axes[i]->parent = this;
		}
}

PolarPlot::~PolarPlot()
{
	int i;

	if(Plots){
		for(i = 0; i < nPlots; i++) if(Plots[i]) DeleteGO(Plots[i]);
		free(Plots);		Plots = 0L;
		}
	if(Axes){
		for(i = 0; i < nAxes; i++) if(Axes[i]) DeleteGO(Axes[i]);
		free(Axes);			Axes = 0L;
		}
	if(name) free(name);	name=0L;
	Undo.InvalidGO(this);
}

double
PolarPlot::GetSize(int select)
{
	switch(select) {
	case SIZE_BOUNDS_XMIN:		return Bounds.Xmin;
	case SIZE_BOUNDS_XMAX:		return Bounds.Xmax;
	case SIZE_BOUNDS_YMIN:		return Bounds.Ymin;
	case SIZE_BOUNDS_YMAX:		return Bounds.Ymax;
	case SIZE_BOUNDS_LEFT:		return (Axes && Axes[0])?(((Axis*)Axes[0])->GetAxis())->min:0.0;
	case SIZE_BOUNDS_RIGHT:		return (Axes && Axes[0])?(((Axis*)Axes[0])->GetAxis())->max:0.0;
	case SIZE_BOUNDS_TOP:		return (Axes && Axes[1])?(((Axis*)Axes[1])->GetAxis())->max:0.0;
	case SIZE_BOUNDS_BOTTOM:	return (Axes && Axes[1])?(((Axis*)Axes[1])->GetAxis())->min:0.0;
	case SIZE_YAXISX:
		if(!CurrDisp) return 0.0;
		if((((Axis*)Axes[1])->GetAxis())->flags & AXIS_X_DATA) 
			return CurrDisp->fx2fix((((Axis*)Axes[1])->GetAxis())->loc[0].fx);
		else return CurrDisp->co2fix((((Axis*)Axes[1])->GetAxis())->loc[0].fx);
	case SIZE_XAXISY:
		if(!CurrDisp) return 0.0;
		if((((Axis*)Axes[0])->GetAxis())->flags & AXIS_Y_DATA) 
			return CurrDisp->fy2fiy((((Axis*)Axes[0])->GetAxis())->loc[0].fy);
		else return CurrDisp->co2fiy((((Axis*)Axes[0])->GetAxis())->loc[0].fy);
	case SIZE_XCENTER:			return (((Axis*)Axes[0])->GetAxis())->Center.fx;
	case SIZE_YCENTER:			return (((Axis*)Axes[0])->GetAxis())->Center.fy;
	default:
		if(parent) return parent->GetSize(select);
		}
	return defs.GetSize(select);
}

void
PolarPlot::DoPlot(anyOutput *o)
{
	int i;

	if(o) CurrDisp = o;
	else return;
	if(!parent) return;
	CurrRect.Xmin = CurrRect.Xmax = (((Axis*)Axes[1])->GetAxis())->Center.fx + 
		parent->GetSize(SIZE_GRECT_LEFT);
	CurrRect.Xmin -= (((Axis*)Axes[0])->GetAxis())->Radius;	
	CurrRect.Xmax += (((Axis*)Axes[0])->GetAxis())->Radius;
	CurrRect.Ymin = CurrRect.Ymax = (((Axis*)Axes[0])->GetAxis())->Center.fy +
		parent->GetSize(SIZE_GRECT_TOP);
	CurrRect.Ymin -= (((Axis*)Axes[0])->GetAxis())->Radius;
	CurrRect.Ymax += (((Axis*)Axes[0])->GetAxis())->Radius;
	(((Axis*)Axes[0])->GetAxis())->Start = ((((Axis*)Axes[0])->GetAxis())->flags & AXIS_INVERT) ? -offs : offs;
	o->SetRect(CurrRect, defs.cUnits, ((Axis*)Axes[0])->GetAxis(), ((Axis*)Axes[1])->GetAxis());
	o->SetFill(&Fill);
	if(Axes) for(i = 0; i < nAxes; i++) {
		if(i == 1) {
			if(!(type & 0x01) && Axes[i]) Axes[i]->DoPlot(o);
			}
		else if(Axes[i]) Axes[i]->DoPlot(o);
		}
	if(Plots) for(i = 0; i < nPlots; i++) if(Plots[i]) {
		if(Plots[i]->Id >= GO_PLOT && Plots[i]->Id < GO_GRAPH) {
			if(((Plot*)Plots[i])->hidden == 0) Plots[i]->DoPlot(o);
			}
		else Plots[i]->DoPlot(o);
		}
	rDims.left = o->co2ix(CurrRect.Xmin);	rDims.right = o->co2ix(CurrRect.Xmax);
	rDims.top = o->co2iy(CurrRect.Ymin);	rDims.bottom = o->co2iy(CurrRect.Ymax);
	if(parent) parent->Command(CMD_AXIS, 0L, o);
}

bool
PolarPlot::Command(int cmd, void *tmpl, anyOutput *o)
{
	GraphObj **tmpPlots;
	int i;
	AxisDEF *ad0, *ad1;
	double tmp;

	switch (cmd) {
	case CMD_CONFIG:
		Config();
		return true;
	case CMD_SET_DATAOBJ:
		Id = GO_POLARPLOT;
		data = (DataObj *)tmpl;	
	case CMD_UPDATE:
		if(Axes) for(i = 0; i< nAxes; i++) if(Axes[i]) Axes[i]->Command(cmd, tmpl, o);
	case CMD_LEGEND:
		if(Plots) for(i = 0; i < nPlots; i++) if(Plots[i]) Plots[i]->Command(cmd, tmpl, o);
		return false;
	case CMD_OBJTREE:
		if(!tmpl) return false;
		if(Plots) for(i = 0; i < nPlots; i++) if(Plots[i]) 
			((ObjTree*)tmpl)->Command(CMD_UPDATE, Plots[i], 0L);
		return true;
	case CMD_HIDE_MARK:
		if(!tmpl || !o) return false;
		//do all axes
		if(Axes)for(i = nAxes-1; i>=0; i--) {
			if(tmpl == (void*)Axes[i]){
				Axes[i]->DoMark(CurrDisp, false);		return true;
				}
			else if(Axes[i]->Id == GO_AXIS) {
				if(Axes[i]->Command(cmd, tmpl, o))		return true;
				}
			}
		//do all plots
		if(Plots)for(i = nPlots-1; i>=0; i--) {
			if(tmpl == (void*)Plots[i]){
				Plots[i]->DoMark(CurrDisp, false);		return true;
				}
			else if(Plots[i] && (Plots[i]->Id == GO_MLABEL || Plots[i]->Id == GO_LEGEND || 
				(Plots[i]->Id >= GO_PLOT && Plots[i]->Id < GO_GRAPH))) {
				if(Plots[i]->Command(cmd, tmpl, o))		return true;
				}
			}
		return false;
	case CMD_MOUSE_EVENT:
		if(hidden) return false;
		if(o) switch(((MouseEvent*)tmpl)->Action) {
		case MOUSE_LBUP:
			if(Axes) for(i = 0; i< nAxes; i++) if(Axes[i])
				if(Axes[i]->Command(cmd, tmpl, o))return true;
			if(Plots) for(i = 0; i < nPlots; i++) if(Plots[i]) 
				Plots[i]->Command(cmd, tmpl, o);
			if(!CurrGO && IsInRect(&rDims, ((MouseEvent*)tmpl)->x, ((MouseEvent*)tmpl)->y)){
				CurrGO = this;
				o->ShowMark(&rDims, MRK_INVERT);
				return true;
				}
			break;
			}
		return false;
	case CMD_REPL_GO:
		if(!(tmpPlots = (GraphObj **)tmpl) || !tmpPlots[0] || !tmpPlots[1]) return false;
		if(Axes) for(i = 0; i < nAxes; i++) if(Axes[i] && Axes[i] == tmpPlots[0]){
			return ReplaceGO(&Axes[i], tmpPlots);
			}
		break;
	case CMD_SETSCROLL:
	case CMD_REDRAW:
		if(parent) return parent->Command(cmd, tmpl, o);
		return false;
	case CMD_DELOBJ_CONT:
	case CMD_DELOBJ:
		if(Plots && nPlots) for(i = 0; i < nPlots; i++) if(tmpl == (void*)Plots[i]) {
			Undo.DeleteGO((GraphObj**)(&Plots[i]), cmd == CMD_DELOBJ_CONT ? UNDO_CONTINUE : 0L, o);
			if(parent)parent->Command(CMD_REDRAW, NULL, o);
			return true;
			}
		if(Axes && nAxes > 1 && (tmpl == (void*)Axes[0] || tmpl == (void*)Axes[1]))
			InfoBox("Axes required for scaling\ncannot be deleted.");
		break;
	case CMD_AXIS:		//axis changed: reconstruct corresponding axis
		if(Axes && nAxes >1 && tmpl && Axes[0] && Axes[1]) {
			ad0 = ((Axis*)Axes[0])->GetAxis();		ad1 = ((Axis*)Axes[1])->GetAxis();
			if(tmpl == Axes[0]) {
				CheckNewFloat(&ad1->loc[1].fy, ad1->loc[1].fy, ad0->Center.fy, this, UNDO_CONTINUE);
				tmp = ad1->loc[1].fy - ad0->Radius;
				CheckNewFloat(&ad1->loc[0].fy, ad1->loc[0].fy, tmp, this, UNDO_CONTINUE);
				}
			if(tmpl == Axes[1]) {
				CheckNewFloat(&ad0->Center.fy, ad0->Center.fy, ad1->loc[1].fy, this, UNDO_CONTINUE);
				tmp = fabs(ad1->loc[1].fy - ad1->loc[0].fy);
				CheckNewFloat(&ad0->Radius, ad0->Radius, tmp, this, UNDO_CONTINUE);
				}
			}
		break;	
		}
	return false;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BoxPlot is a Plot-Class
BoxPlot::BoxPlot(GraphObj *par, DataObj *d):Plot(par, d)
{
	FileIO(INIT_VARS);
	Id = GO_BOXPLOT;
	if (!d && parent) parent->Command(CMD_DELOBJ, this, NULL);
}

BoxPlot::BoxPlot(int src):Plot(0L, 0L)
{
	int i;

	FileIO(INIT_VARS);
	if(src == FILE_READ) {
		FileIO(FILE_READ);
		//now set parent in all children
		if(Boxes) 
			for(i = 0; i < nPoints; i++) if(Boxes[i]) Boxes[i]->parent = this;
		if(Whiskers) 
			for(i = 0; i < nPoints; i++) if(Whiskers[i]) Whiskers[i]->parent = this;
		if(Symbols) 
			for(i = 0; i < nPoints; i++) if(Symbols[i]) Symbols[i]->parent = this;
		if(Labels) 
			for(i = 0; i < nPoints; i++) if(Labels[i]) Labels[i]->parent = this;
		if(TheLine) TheLine->parent = this;
		}
}

BoxPlot::BoxPlot(GraphObj *par, DataObj *dt, int mode, int c1, int c2, int c3):Plot(par, dt)
{
	int i, nr;
	lfPOINT fp;

	FileIO(INIT_VARS);		Id = GO_BOXPLOT;	fp.fx = fp.fy = 0.0;
	if(data && data->GetSize(&i, &nr)) {
		nPoints = nr;
		Bounds.Xmin = Bounds.Ymin = HUGE_VAL;
		Bounds.Xmax = Bounds.Ymax = -HUGE_VAL;
		if(Boxes = (Box**)calloc(nr, sizeof(Box*))) for(i = 0; i < nr; i++) {
			if(mode == 1) Boxes[i] = new Box(this, data, fp, fp, 0, c1, i, c2, i, c1, i, c3, i);
			else Boxes[i] = new Box(this, data, fp, fp, 0, c2, i, c1, i, c3, i, c1, i);
			if(Boxes[i]) Boxes[i]->Command(CMD_AUTOSCALE, 0L, 0L);
			}
		}
	BoxDist.fx = BoxDist.fy = GetSize(mode == 2  ? SIZE_BOXMINY : SIZE_BOXMINX);
}

BoxPlot::~BoxPlot()
{
	int i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -