How to draw different symbols with wxPlotCtrl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

How to draw different symbols with wxPlotCtrl

Post by orbitcowboy » Tue Jan 20, 2009 3:14 pm

<!-- --><!-- -->Hi,

i am playing around with wxPlotCtrl. I want to plot different symbols in one plot.

I have the following situation:

Code: Select all

	m_pPlotData[HIT]->SetXValue(static_cast<int>(m_dx),m_dx);
    m_pPlotData[HIT]->SetYValue(static_cast<int>(m_dx),cos(m_dx));


    if(m_pPlotData[HIT]->Ok())
	{

			wxGenericPen pen(wxColour(255,0,0,0), 1 ,wxSOLID , wxCAP_ROUND, wxJOIN_ROUND);
			//wxPen symb_pen(wxColour(255,0,0,0), 1, wxSOLID);
			//wxBrush symb_brush(wxColour(0,255,0),wxSOLID);
			m_pPlotCtrl->AddCurve(m_pPlotData[HIT], false, false); 
		  	m_pPlotCurve = m_pPlotCtrl->GetCurve(m_pPlotCtrl->GetCurveCount()-1);
		    m_pPlotCurve->SetPen( wxPLOTPEN_NORMAL,pen);
		    m_pPlotCtrl->AddCurve(m_pPlotCurve, true, true);
		    m_pPlotCtrl->Redraw(wxPLOTCTRL_REDRAW_PLOT);
		
	}


	m_pPlotData[VERIFIED_HIT]->SetXValue(static_cast<int>(m_dx),m_dx);
    m_pPlotData[VERIFIED_HIT]->SetYValue(static_cast<int>(m_dx),-cos(m_dx));

    if(m_pPlotData[VERIFIED_HIT]->Ok())
	{
			wxGenericPen pen(wxColour(0,0,255,0), 1 ,wxSOLID , wxCAP_ROUND, wxJOIN_ROUND);
			m_pPlotCtrl->AddCurve(m_pPlotData[VERIFIED_HIT], false, false); 
			m_pPlotCurve = m_pPlotCtrl->GetCurve(m_pPlotCtrl->GetCurveCount()-1);
			m_pPlotCurve->SetPen( wxPLOTPEN_NORMAL,pen);
			m_pPlotCtrl->AddCurve(m_pPlotCurve, true, true);
			m_pPlotCtrl->Redraw(wxPLOTCTRL_REDRAW_PLOT);
		
	}
all points are plotted well, but with the same symbol ("a circle"). Is it possible to use symbols like crosses or rectangles? Has anybody done that allready?

Thanks in advance

Regards

Orbitcowboy
Attachments
screenshot.jpeg
the result
screenshot.jpeg (15.95 KiB) Viewed 1453 times
Last edited by orbitcowboy on Wed Jan 21, 2009 2:42 pm, edited 1 time in total.

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Tue Jan 20, 2009 5:58 pm

I'm sure it's possible to do it, but you would need to modify the sources yourself. Currently it only draws circles.

orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy » Tue Jan 20, 2009 9:41 pm

Thanks for the answer. I will keep you posted when i have found out...

Regards

Orbitcowboy

orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy » Wed Jan 21, 2009 2:41 pm

Hey friends,

i found it!
in file plotdraw.cpp at line 954:

Code: Select all

            if (draw_symbols && !WXPC_HASBIT(clipped, ClippedSecond) &&
                ((i0 != i1) || (j0 != j1) || (n == min_sel) || (n == n_start)))
            {
                //dc->DrawBitmap( bitmap, i1 - bitmapHalfWidth, j1 - bitmapHalfHeight, true );
                wxPLOTCTRL_DRAW_ELLIPSE(dc, window, pen, i1, j1, 1, 1);
	    }			

if replaced the wxPLOTCTRL_DRAW_ELLPISE(...)-macro by a own written

Code: Select all

	// Rectangles are drawn with  gdk_draw_rectangle()
	// The filled argument indicates whether to fill the rectangle; TRUE  means to fill it.
	// #include <gdk/gdk.h>
	// void gdk_draw_rectangle(GdkDrawable* drawable, GdkGC* gc, gint filled, gint x, gint y, gint width, gint height);
    #define wxPLOTCTRL_DRAW_RECTANGLE(dc, win, pen, x0, y0, w, h) \
        if (win && pen) \
            gdk_draw_rectangle( win, pen, true, x0, y0, w, h);  \
        else \
            dc->DrawRectangle(x0, y0, w, h);
            
Now, each datapoint is represended by a rectangle.



Regards

Orbitcowboy

orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy » Wed Jan 21, 2009 4:28 pm

here how to draw other symbols:
+,x , *

Code: Select all

	/// Draw a plus symbol
	#define wxPLOTCTRL_DRAW_PLUS(dc, win, pen, x0, y0, w, h)\
			wxPLOTCTRL_DRAW_LINE(dc, win, pen, (x0-w/2), y0, (x0+w/2), y0)\
			wxPLOTCTRL_DRAW_LINE(dc, win, pen,  x0, (y0-h/2), x0, (y0+h/2))

	/// Draw a cross symbol
	#define wxPLOTCTRL_DRAW_CROSS(dc, win, pen, x0, y0, w, h)\
			wxPLOTCTRL_DRAW_LINE(dc, win, pen, (x0-w/2), (y0+h/2), (x0+w/2), (y0-h/2))\
			wxPLOTCTRL_DRAW_LINE(dc, win, pen, (x0-w/2), (y0-h/2), (x0+w/2), (y0+h/2))
           
	/// Draw a star symbol
	#define wxPLOTCTRL_DRAW_STAR(dc, win, pen, x0, y0, w, h)\
			wxPLOTCTRL_DRAW_PLUS(dc, win, pen, x0, y0, w, h)\
			wxPLOTCTRL_DRAW_CROSS(dc, win, pen, x0, y0, w, h)

Agucho
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sat Jul 09, 2011 8:20 pm

Re: How to draw different symbols with wxPlotCtrl

Post by Agucho » Fri Aug 05, 2011 5:05 pm

Hey! and if I want to draw characters or numbers??

Post Reply