Пример #1
0
CWindowDialogPlots::CWindowDialogPlots(
    CDisplayWindowPlots *winPlots,
    WxSubsystem::CWXMainFrame* parent,
    wxWindowID id,
    const std::string &caption,
    wxSize initialSize )
    :
    m_winPlots( winPlots ),
    m_mainFrame(parent),
	m_firstSubmenu(true)
{
    Create(
        parent,
        id,
        _U(caption.c_str()),
        wxDefaultPosition,
        initialSize,
        wxDEFAULT_FRAME_STYLE,
        _T("id"));

    SetClientSize(initialSize);

	wxIcon FrameIcon;
	FrameIcon.CopyFromBitmap(mrpt::gui::WxSubsystem::getMRPTDefaultIcon());
	SetIcon(FrameIcon);


    // Create the mpWindow object:
    m_plot = new mpWindow( this, ID_PLOT );
    m_plot->AddLayer( new mpScaleX() );
    m_plot->AddLayer( new mpScaleY() );
    m_plot->LockAspect( false );
    m_plot->EnableDoubleBuffer(true);

    m_plot->Fit( -10,10,-10,10 );

    // Menu:
    wxMenuBar *MenuBar1 = new wxMenuBar();

    wxMenu *Menu1 = new wxMenu();
    wxMenuItem *MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Close"), _(""), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);

    wxMenuItem *MenuItemPrint = new wxMenuItem(Menu1, ID_MENU_PRINT, _("Print..."), _(""), wxITEM_NORMAL);
    Menu1->Append(MenuItemPrint);

    MenuBar1->Append(Menu1, _("&File"));

    wxMenu *Menu2 = new wxMenu();
    wxMenuItem *MenuItem2 = new wxMenuItem(Menu2, ID_MENUITEM2, _("About..."), _(""), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("&Help"));

    SetMenuBar(MenuBar1);


    // Events:
    Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&CWindowDialogPlots::OnClose);
    Connect(ID_MENUITEM1,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&CWindowDialogPlots::OnMenuClose);
    Connect(ID_MENU_PRINT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&CWindowDialogPlots::OnMenuPrint);
    Connect(ID_MENUITEM2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&CWindowDialogPlots::OnMenuAbout);

	Connect(wxID_ANY,wxEVT_SIZE,(wxObjectEventFunction)&CWindowDialogPlots::OnResize);

	Connect(wxID_ANY,wxEVT_CHAR,(wxObjectEventFunction)&CWindowDialogPlots::OnChar);
	m_plot->Connect(wxEVT_CHAR,(wxObjectEventFunction)&CWindowDialogPlots::OnChar,0,this);
	m_plot->Connect(wxEVT_MOTION,(wxObjectEventFunction)&CWindowDialogPlots::OnMouseMove,0,this);

	m_plot->Connect(wxEVT_LEFT_DOWN,(wxObjectEventFunction)&CWindowDialogPlots::OnMouseDown,NULL,this);
	m_plot->Connect(wxEVT_RIGHT_DOWN,(wxObjectEventFunction)&CWindowDialogPlots::OnMouseDown,NULL,this);

    // Increment number of windows:
    //int winCount =
    WxSubsystem::CWXMainFrame::notifyWindowCreation();
    //cout << "[CWindowDialogPlots] Notifying new window: " << winCount << endl;

	//this->Iconize(false);

#if 0
	// JL: TEST CODE: This is the seed of the future new implementation based on wxFreeChart...
	double data[][2] = {
			{ 10, 20, },
			{ 13, 16, },
			{ 7, 30, },
			{ 15, 34, },
			{ 25, 4, },
	};
	// first step: create plot
	XYPlot *plot = new XYPlot();
	// create dataset
	XYSimpleDataset *dataset = new XYSimpleDataset();
	// and add serie to it
	dataset->AddSerie((double *) data, WXSIZEOF(data));
	// set line renderer to dataset
	dataset->SetRenderer(new XYLineRenderer());
	// add our dataset to plot
	plot->AddDataset(dataset);
	// create left and bottom number axes
	NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT);
	NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);
	// optional: set axis titles
	leftAxis->SetTitle(wxT("X"));
	bottomAxis->SetTitle(wxT("Y"));
	// add axes to plot
	plot->AddAxis(leftAxis);
	plot->AddAxis(bottomAxis);
	// link axes and dataset
	plot->LinkDataVerticalAxis(0, 0);
	plot->LinkDataHorizontalAxis(0, 0);
	// and finally create chart
	Chart* chart = new Chart(plot, wxT("my title"));
	wxChartPanel *m_chartPanel = new wxChartPanel( this ); //, ID_PLOT );
	m_chartPanel->SetChart( chart );
#endif
}
Пример #2
0
	virtual Chart *Create()
	{
		// first dataset values
		double values1[][2] = {
				{ 1, 1 },
				{ 2, 3 },
				{ 5, 4 },
				{ 6, 3 },
				{ 7, 6 },
				{ 8, 6 },
				{ 9, 4 },
		};

		// second dataset values
		double values2[][2] = {
				{ 0, 0 },
				{ 2, -1 },
				{ 4, 6 },
				{ 5, 2 },
				{ 7, 8 },
				{ 8, 4 },
				{ 9, -2 },
		};

		// colors for first and second datasets
		wxColour color1 = wxColour(255, 0, 0);
		wxColour color2 = wxColour(0, 0, 255);

		// create xy plot
		XYPlot *plot = new XYPlot();

		// create first dataset
		XYSimpleDataset *dataset1 = new XYSimpleDataset();
		// add serie to it
		dataset1->AddSerie((double *) values1, WXSIZEOF(values1));

		// create second dataset
		XYSimpleDataset *dataset2 = new XYSimpleDataset();
		// add serie to it
		dataset2->AddSerie((double *) values2, WXSIZEOF(values2));

		// create renderer for first dataset
		XYLineRenderer *renderer1 = new XYLineRenderer();
		renderer1->SetSerieColour(0, &color1);

		// add first dataset to plot
		plot->AddDataset(dataset1);

		// set it to first dataset
		dataset1->SetRenderer(renderer1);

		// create renderer for second dataset
		XYLineRenderer *renderer2 = new XYLineRenderer();
		renderer2->SetSerieColour(0, &color2);

		// set it to second dataset
		dataset2->SetRenderer(renderer2);

		// add second dataset to plot
		plot->AddDataset(dataset2);

		// create left axis for first dataset
		NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT);
		leftAxis->SetLabelTextColour(color1);
        leftAxis->SetTitle("Left Axis");
		plot->AddAxis(leftAxis);

		// create left axis for second dataset
		NumberAxis *rightAxis = new NumberAxis(AXIS_RIGHT);
		rightAxis->SetLabelTextColour(color2);
        rightAxis->SetTitle("Right Axis");
		plot->AddAxis(rightAxis);

		// create top axis for first dataset
		NumberAxis *topAxis = new NumberAxis(AXIS_TOP);
		topAxis->SetLabelTextColour(color1);
        topAxis->SetTitle("Top Axis");
		plot->AddAxis(topAxis);

		// create bottom axis for second dataset
		NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);
		bottomAxis->SetLabelTextColour(color2);
		bottomAxis->SetTitle("Bottom Axis");
        plot->AddAxis(bottomAxis);

		// link first dataset with left axis
		plot->LinkDataVerticalAxis(0, 0);
		// link second dataset with right axis
		plot->LinkDataVerticalAxis(1, 1);

		// link first dataset with top axis
		plot->LinkDataHorizontalAxis(0, 0);

		// link second dataset with bottom axis
		plot->LinkDataHorizontalAxis(1, 1);

		return new Chart(plot, GetName());
	}
Пример #3
0
	virtual Chart *Create()
	{
		// first dataset values
		double values1[][2] = {
				{ 1, 1 },
				{ 2, 3 },
				{ 5, 4 },
				{ 6, 3 },
				{ 7, 6 },
				{ 8, 6 },
				{ 9, 4 },
		};

		// second dataset values
		double values2[][2] = {
				{ 0, 0 },
				{ 2, -1 },
				{ 4, 6 },
				{ 5, 2 },
				{ 7, 8 },
				{ 8, 4 },
				{ 9, -2 },
		};

		// colors for first and second datasets
		wxColour color1 = wxColour(255, 0, 0);
		wxColour color2 = wxColour(0, 0, 255);

		// create xy plot
		XYPlot *plot = new XYPlot();

		// create first dataset
		XYSimpleDataset *dataset1 = new XYSimpleDataset();
		// add serie to it
		dataset1->AddSerie((double *) values1, WXSIZEOF(values1));

		// create second dataset
		XYSimpleDataset *dataset2 = new XYSimpleDataset();
		// add serie to it
		dataset2->AddSerie((double *) values2, WXSIZEOF(values2));

		// create renderer for first dataset
		XYLineRenderer *renderer1 = new XYLineRenderer();
		renderer1->SetSerieColour(0, &color1);

		// add first dataset to plot
		plot->AddDataset(dataset1);

		// set it to first dataset
		dataset1->SetRenderer(renderer1);

		// create renderer for second dataset
		XYLineRenderer *renderer2 = new XYLineRenderer();
		renderer2->SetSerieColour(0, &color2);

		// set it to second dataset
		dataset2->SetRenderer(renderer2);

		// add second dataset to plot
		plot->AddDataset(dataset2);

		// create left axis for first dataset
		NumberAxis *leftAxis1 = new NumberAxis(AXIS_LEFT);
		// set label text colour same as lines
		leftAxis1->SetLabelTextColour(color1);
		// set label lines colour same as lines
		leftAxis1->SetLabelPen(*wxThePenList->FindOrCreatePen(color1, 1, wxPENSTYLE_SOLID));
		plot->AddAxis(leftAxis1);

		// create left axis for second dataset
		NumberAxis *leftAxis2 = new NumberAxis(AXIS_LEFT);
		// set label text colour same as lines
		leftAxis2->SetLabelTextColour(color2);
		// set label lines colour same as lines
		leftAxis2->SetLabelPen(*wxThePenList->FindOrCreatePen(color2, 1, wxPENSTYLE_SOLID));
		plot->AddAxis(leftAxis2);

		// create bottom axis for first and second dataset
		NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);
		plot->AddAxis(bottomAxis);

		// link first dataset with first left axis
		plot->LinkDataVerticalAxis(0, 0);
		// link second dataset with second left axis
		plot->LinkDataVerticalAxis(1, 1);

		// link first and second datasets with bottom axis
		plot->LinkDataHorizontalAxis(0, 0);
		plot->LinkDataHorizontalAxis(1, 0);

		return new Chart(plot, GetName());
	}
Пример #4
0
	virtual Chart *Create()
	{
		// data
		double data[] = {
			 64.09,
			 63.34,
			 61.41,
			 62.00,
			 61.71,
			 63.39,
			 63.64,
			 63.61,
			 65.11,
			 65.72,
			 66.89,
			 66.68,
			 66.51,
			 66.40,
			 67.27,
			 67.66,
		};
		// dates
		const wxChar *strDates[] = {
			wxT("20060317"),
			wxT("20060320"),
			wxT("20060321"),
			wxT("20060322"),
			wxT("20060323"),
			wxT("20060324"),
			wxT("20060327"),
			wxT("20060328"),
			wxT("20060329"),
			wxT("20060330"),
			wxT("20060331"),
			wxT("20060403"),
			wxT("20060404"),
			wxT("20060405"),
			wxT("20060406"),
			wxT("20060407"),
		};

		time_t times[WXSIZEOF(strDates)];

		wxDateTime dt;
		for (size_t n = 0; n < WXSIZEOF(strDates); n++) {
			dt.ParseFormat(strDates[n], wxT("%Y%m%d"));
			times[n] = dt.GetTicks();
		}

		// first step: create plot
		XYPlot *plot = new XYPlot();

		TimeSeriesDataset *dataset = new TimeSeriesDataset(data, times, WXSIZEOF(data));

		dataset->SetRenderer(new XYLineRenderer());

		plot->AddDataset(dataset);

		// add left number and bottom date axes
		NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT);
		DateAxis *bottomAxis = new DateAxis(AXIS_BOTTOM);

		// setup window
		//bottomAxis->SetWindow(0, 10);
		//bottomAxis->SetUseWindow(true);

		bottomAxis->SetVerticalLabelText(true);
		bottomAxis->SetDateFormat(wxT("%d-%m"));

		// add axes to first plot
		plot->AddAxis(leftAxis);
		plot->AddAxis(bottomAxis);

		// link axes and dataset
		plot->LinkDataVerticalAxis(0, 0);
		plot->LinkDataHorizontalAxis(0, 0);

		// and finally create chart
		Chart *chart = new Chart(plot, GetName());

		//chart->SetScrolledAxis(bottomAxis);
		return chart;
	}