Add Bar plot

Добавлена отрисовка столбчатой диаграммы. Формат данных:
L  | Y
------
L1 | Y1
L2 | Y2
...
This commit is contained in:
lsv 2022-05-27 14:18:29 +05:00
parent 1431b1abdb
commit 8c123b0550
7 changed files with 304 additions and 59 deletions

View file

@ -446,6 +446,7 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
wxArrayInt cols;
wxArrayString leg;
wxArrayInt colsY;
wxString rez="Draw plot";
if (IsSelection()) {
unsigned int i;
int row, col;
@ -476,11 +477,45 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
else {
return "not select cells or columns";
}
std::vector<wxString> lbar;
size_t numRows = GetNumberRows();
if (cols.Count()>0) {
int idx = 0;
int cl1 = cols[idx];
int legC = -1;
int xC = -1;
//cols = GetSelectedCols();
if (cols.Count() == 2) {
legC = cl1; idx++;
cl1 = cols[idx];
if (colTypClasses.Item(cl1) != PGTYPCLASS_NUMERIC) {
wxMessageBox("The number of selected column 2 needed Number type\nExample: LY", "Plot");
return "";
}
std::vector<double> x, y;
double xv=0, yv;
for (int i = 0; i < numRows; i++)
{
if (GetRowSize(i) == 0) continue;
//str.Append(GetExportLine(i, cols));
wxString yVal = GetCellValue(i, cl1);
if (!yVal.ToCDouble(&yv)) { yVal.ToDouble(&yv); /* error! */ }
x.push_back(xv);
y.push_back(yv);
xv++;
lbar.push_back(GetCellValue(i, legC));
}
frmPlot* frame = new frmPlot(parent, "Plot Bar");
frame->ClearAndSetAxis(ctlSQLGrid::GetColumnName(legC), mpX_NORMAL, ctlSQLGrid::GetColumnName(cl1));
frame->AddSeries("Bar", x, y, lbar);
frame->Go();
return rez;
}
if (cols.Count() < 3) {
wxMessageBox("The number of selected columns must be more than 2\nExample: LXY or XYYYY...", "Plot");
wxMessageBox("The number of selected columns must be more than 1\nExample: LXY or XYYYY...", "Plot");
return "";
}
}
@ -519,9 +554,9 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
frmPlot* frame = new frmPlot(parent,"Plot");
frame->ClearAndSetAxis(xA, typeAxisX, yA);
// Rows read
size_t numRows = GetNumberRows();
wxString lg,currLg;
if (legC !=-1) {
// 3 cols
std::vector<double> x,y;
@ -532,7 +567,7 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
if (GetRowSize(i) == 0) continue;
currLg= GetCellValue(i, legC);
if (lg != currLg && !lg.IsEmpty()) {
frame->AddSeries(lg, x, y);
if (x.size()>0) frame->AddSeries(lg, x, y,lbar);
lg = wxEmptyString;
}
if (lg.IsEmpty()) {
@ -550,8 +585,9 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
dt = parseDT(fmttype, xVal);
if (fmttype == -1) {
wxString temp = wxString::Format("The values of column X must be timestamp [row: %d,col: %d]",i+1, colsY[0]);
wxMessageBox(temp, "Plot");
return "";
rez = temp;
//wxMessageBox(temp, "Plot");
continue;
}
xv = (double)dt.GetTicks();
}
@ -562,7 +598,7 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
x.push_back(xv);
y.push_back(yv);
}
frame->AddSeries(lg, x, y);
frame->AddSeries(lg, x, y,lbar);
}
else {
@ -601,13 +637,13 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) {
y.push_back(yv);
}
frame->AddSeries(lg, x, y);
frame->AddSeries(lg, x, y,lbar);
y.clear();
first = false;
}
}
frame->Go();
return "plot draw";
return rez;
}
wxString ctlSQLResult::SummaryColumn()

View file

@ -10,10 +10,10 @@ enum {
ID_ALIGN_X_AXIS,
ID_ALIGN_Y_AXIS,
ID_TOGGLE_GRID,
ID_TOGGLE_SCROLLBARS,
ID_COPY_SCREEN,
ID_TOGGLE_INFO,
ID_SAVE_SCREENSHOT,
ID_TOGGLE_LISSAJOUX,
ID_TOGGLE_SHOW_SERIES,
ID_TOGGLE_SHOW_SIMBOL,
ID_TOGGLE_COSINE,
ID_BLACK_THEME
@ -73,13 +73,22 @@ EVT_MENU(mpID_FIT, frmPlot::OnFit)
EVT_MENU(ID_ALIGN_X_AXIS, frmPlot::OnAlignXAxis)
EVT_MENU(ID_ALIGN_Y_AXIS, frmPlot::OnAlignYAxis)
EVT_MENU(ID_TOGGLE_GRID, frmPlot::OnToggleGrid)
EVT_MENU(ID_TOGGLE_SCROLLBARS, frmPlot::OnCopy)
EVT_MENU(ID_COPY_SCREEN, frmPlot::OnCopy)
EVT_MENU(ID_TOGGLE_INFO, frmPlot::OnToggleInfoLayer)
EVT_MENU(ID_SAVE_SCREENSHOT, frmPlot::OnSaveScreenshot)
EVT_MENU(ID_BLACK_THEME, frmPlot::OnBlackTheme)
EVT_MENU(ID_TOGGLE_LISSAJOUX, frmPlot::OnToggleLissajoux)
EVT_MENU(ID_TOGGLE_SHOW_SERIES, frmPlot::OnToggleShowSeries)
EVT_MENU(ID_TOGGLE_SHOW_SIMBOL, frmPlot::OnToggleShowSimbol)
EVT_MENU(ID_TOGGLE_COSINE, frmPlot::OnToggleCosine)
EVT_MENU(mpID_CENTER, frmPlot::OnCenter)
EVT_MENU(mpID_ZOOM_IN, frmPlot::OnZoomIn)
EVT_MENU(mpID_ZOOM_INX, frmPlot::OnZoomInX)
EVT_MENU(mpID_ZOOM_INY, frmPlot::OnZoomInY)
EVT_MENU(mpID_ZOOM_OUTX, frmPlot::OnZoomOutX)
EVT_MENU(mpID_ZOOM_OUTY, frmPlot::OnZoomOutY)
EVT_MENU(mpID_ZOOM_OUT, frmPlot::OnZoomOut)
EVT_MENU(mpID_LOCKASPECT, frmPlot::OnLockAspect)
EVT_KEY_DOWN(frmPlot::OnKEY_DOWN)
EVT_CLOSE(frmPlot::OnClose)
wxEND_EVENT_TABLE()
@ -99,7 +108,7 @@ frmPlot::frmPlot(frmQuery* parent, const wxString& _title) : pgFrame(parent, _ti
file_menu->Append(ID_PRINT_PREVIEW, wxT("Print Pre&view..."));
file_menu->Append(ID_PRINT, wxT("&Print..."));
file_menu->Append(ID_SAVE_SCREENSHOT, wxT("Save screenshot"));
file_menu->Append(ID_TOGGLE_SCROLLBARS, wxT("Copy clipboard screenshot\tCtrl+C"));
file_menu->Append(ID_COPY_SCREEN, wxT("Copy clipboard screenshot\tCtrl+C"));
file_menu->AppendSeparator();
file_menu->Append(ID_ABOUT, wxT("&About..."));
@ -108,20 +117,28 @@ frmPlot::frmPlot(frmQuery* parent, const wxString& _title) : pgFrame(parent, _ti
view_menu->Append(mpID_FIT, wxT("&Fit bounding box"), wxT("Set plot view to show all items"));
view_menu->Append(mpID_ZOOM_IN, wxT("Zoom in"), wxT("Zoom in plot view."));
view_menu->Append(mpID_ZOOM_OUT, wxT("Zoom out"), wxT("Zoom out plot view."));
view_menu->AppendCheckItem(mpID_LOCKASPECT, _("Lock aspect"),_("Lock horizontal and vertical zoom aspect."));
view_menu->AppendSeparator();
view_menu->Append(mpID_ZOOM_INX, wxT("Zoom in X axis\tKP_Add"), wxT("Zoom in plot view X axis."));
view_menu->Append(mpID_ZOOM_OUTX, wxT("Zoom out X axis\tKP_Subtract"), wxT("Zoom out plot view X axis."));
view_menu->Append(mpID_ZOOM_INY, wxT("Zoom in Y axis\tCtrl+KP_Add"), wxT("Zoom in plot view Y axis."));
view_menu->Append(mpID_ZOOM_OUTY, wxT("Zoom out Y axis\tCtrl+KP_Subtract"), wxT("Zoom out plot view Y axis."));
view_menu->AppendSeparator();
view_menu->Append(ID_ALIGN_X_AXIS, wxT("Switch &X axis align"));
view_menu->Append(ID_ALIGN_Y_AXIS, wxT("Switch &Y axis align"));
view_menu->AppendCheckItem(ID_TOGGLE_GRID, wxT("Toggle grid/ticks"));
//view_menu->AppendCheckItem( ID_TOGGLE_SCROLLBARS, wxT("Show Scroll Bars"));
//view_menu->AppendCheckItem( ID_COPY_SCREEN, wxT("Show Scroll Bars"));
view_menu->AppendCheckItem(ID_TOGGLE_INFO, wxT("Show overlay info box"));
view_menu->Check(ID_TOGGLE_INFO, true);
view_menu->AppendCheckItem(ID_BLACK_THEME, wxT("Switch to black background theme"));
//show_menu->AppendCheckItem(ID_TOGGLE_LISSAJOUX, wxT("Lissajoux"));
show_menu->AppendCheckItem(ID_TOGGLE_SHOW_SERIES, wxT("Show name series"));
show_menu->AppendCheckItem(ID_TOGGLE_SHOW_SIMBOL, wxT("Show Simbol"));
//show_menu->AppendCheckItem(ID_TOGGLE_COSINE, wxT("Cosine"));
// Start with all plots visible
//show_menu->Check(ID_TOGGLE_LISSAJOUX, true);
show_menu->Check(ID_TOGGLE_SHOW_SERIES, false);
show_menu->Check(ID_TOGGLE_SHOW_SIMBOL, true);
//show_menu->Check(ID_TOGGLE_COSINE, true);
@ -135,9 +152,10 @@ frmPlot::frmPlot(frmQuery* parent, const wxString& _title) : pgFrame(parent, _ti
mpLayer* l;
m_plot = new mpWindow(this, -1, wxPoint(0, 0), wxSize(100, 100), wxSUNKEN_BORDER);
m_plot->SetMargins(30, 100, 50, 100);
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
m_plot->Bind(wxEVT_KEY_DOWN, &frmPlot::OnKEY_DOWN, this);
topsizer->Add(m_plot, 1, wxEXPAND);
// topsizer->Add(m_log, 0, wxEXPAND);
@ -184,23 +202,24 @@ void frmPlot::ClearAndSetAxis(wxString XtextAxis, unsigned int X_labelType, wxSt
yaxis->SetFont(graphFont);
xaxis->SetDrawOutsideMargins(false);
yaxis->SetDrawOutsideMargins(false);
m_plot->AddLayer(xaxis);
m_plot->AddLayer(yaxis);
m_plot->AddLayer(nfo = new mpInfoCoords(wxRect(80, 20, 10, 10), wxTRANSPARENT_BRUSH)); //&hatch));
nfo->SetVisible(true);
m_plot->AddLayer(xaxis); // 0
m_plot->AddLayer(yaxis); // 1
m_plot->AddLayer(nfo = new mpInfoCoords(wxRect(80, 80, 10, 10), wxTRANSPARENT_BRUSH)); //&hatch));
nfo->SetVisible(true); // 2
//wxBrush hatch2(wxColour(163,208,212), wxSOLID);
mpInfoLegend* leg;
m_plot->AddLayer(leg = new mpInfoLegend(wxRect(20, 20, 40, 40), wxTRANSPARENT_BRUSH)); //&hatch2));
leg->SetVisible(true);
leg->SetVisible(true); // 3
leg->SetDrawOutsideMargins(false);
indexColor = 0;
//m_plot->Fit();
}
void frmPlot::AddSeries(const wxString legend, const std::vector<double>& x, const std::vector<double>& y)
void frmPlot::AddSeries(const wxString legend, const std::vector<double>& x, const std::vector<double>& y, const std::vector<wxString>& l)
{
mpFXYVector* vectorLayer = new mpFXYVector(legend);
vectorLayer->SetData(x, y);
if (l.size()>0) vectorLayer->SetLegendBar(l);
vectorLayer->SetContinuity(true);
size_t n;
wxColourDesc cc;
@ -212,17 +231,71 @@ void frmPlot::AddSeries(const wxString legend, const std::vector<double>& x, con
//= new wxColour(cc.name);
}
if (indexColor >= WXSIZEOF(colors)) cc.name = L"#000000";
wxPen vectorpen(wxColour(cc.name), 2, wxPENSTYLE_SOLID);
vectorLayer->SetPen(vectorpen);
vectorLayer->SetDrawOutsideMargins(false);
vectorLayer->ShowName(false);
vectorLayer->ShowSimbol(true);
if (vectorLayer->IsLegendBar()) {
wxPen vectorpen(wxColour(cc.name), 1, wxPENSTYLE_SOLID);
wxBrush br(wxColour(cc.name));
vectorLayer->SetPen(vectorpen);
vectorLayer->ShowName(false);
vectorLayer->SetBrush(br);
vectorLayer->SetContinuity(false);
}
else
{
wxPen vectorpen(wxColour(cc.name), 2, wxPENSTYLE_SOLID);
vectorLayer->SetPen(vectorpen);
vectorLayer->ShowName(false);
}
m_plot->AddLayer(vectorLayer);
//m_plot->Fit();
}
void frmPlot::OnKEY_DOWN(wxKeyEvent& event) {
//void OnScrollThumbTrack(wxScrollWinEvent & event);
bool modctrl;
if ((event.GetModifiers() & wxMOD_CONTROL) == wxMOD_CONTROL) {
modctrl = true;
}
else modctrl = false;
int go = 0;
int orient = wxHORIZONTAL;
if (event.GetKeyCode() == WXK_DOWN) {
go =-( m_plot->GetScrY() - m_plot->GetMarginTop() - m_plot->GetMarginBottom());
orient = wxVERTICAL;
}
if (event.GetKeyCode() == WXK_UP) {
go = (m_plot->GetScrY() - m_plot->GetMarginTop() - m_plot->GetMarginBottom());
orient = wxVERTICAL;
}
if (event.GetKeyCode() == WXK_LEFT) {
go = -(m_plot->GetScrX()-m_plot->GetMarginRight() - m_plot->GetMarginLeft());
}
if (event.GetKeyCode() == WXK_RIGHT) {
go = m_plot->GetScrX()-m_plot->GetMarginRight() - m_plot->GetMarginLeft();
}
if ((go != 0)) {
wxScrollWinEvent evt(wxEVT_NULL, go ,orient);
double npos;
if (orient == wxHORIZONTAL) {
npos = m_plot->GetPosX() + (double)go / m_plot->GetScaleX();
//m_plot->OnScrollThumbTrack(evt);
m_plot->SetPosX(npos);
}
else {
npos = m_plot->GetPosY() + (double)go / m_plot->GetScaleY();
//m_plot->OnScrollThumbTrack(evt);
m_plot->SetPosY(npos);
}
event.Skip(false);
return;
}
event.Skip(true);
}
void frmPlot::OnFit(wxCommandEvent& WXUNUSED(event))
{
m_plot->Fit();
@ -379,9 +452,18 @@ void frmPlot::OnSaveScreenshot(wxCommandEvent& event)
event.Skip();
}
void frmPlot::OnToggleLissajoux(wxCommandEvent& event)
void frmPlot::OnToggleShowSeries(wxCommandEvent& event)
{
m_plot->SetLayerVisible(wxT("Lissajoux"), event.IsChecked());
bool v = event.IsChecked();
for (unsigned int p = 4; p < m_plot->CountAllLayers(); p++) {
mpFXYVector* ly = dynamic_cast<mpFXYVector*>(m_plot->GetLayer(p));
if (ly == NULL) continue;
if ((ly->GetLayerType() == mpLAYER_PLOT) && (ly->IsVisible())) {
ly->ShowName(v);
}
}
//m_plot->SetLayerVisible(wxT("Lissajoux"), event.IsChecked());
m_plot->UpdateAll();
}
void frmPlot::OnToggleShowSimbol(wxCommandEvent& event)

View file

@ -2172,7 +2172,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event)
xmenu->Append(MNU_COPY, _("&Copy"), _("Copy selected cells to clipboard."));
xmenu->Append(MNU_PASTE, _("&Paste"), _("Paste data from the clipboard."));
xmenu->Append(MNU_DELETE, _("&Delete"), _("Delete selected rows."));
xmenu->Append(MNU_AUTOCOLSPLOT, _("Draw plot LXY or XYYY..."), _("Draw plot LXY or XYYY..."));
xmenu->Append(MNU_AUTOCOLSPLOT, _("Draw plot LY(bar) or LXY or XYYY..."), _("Draw plot LY(bar) LXY or XYYY..."));
xmenu->Append(MNU_SUMMARY_COL, _("Summary"), _("Summary selected cells."));
xmenu->Append(MNU_CHECK_COLUMN_DATE, _("Check the sequence of dates"), _("Check the sequence of dates"));
xmenu->Append(MNU_COPY_INSERT, _("Copy Insert format"), _("Copy Insert format."));

View file

@ -58,7 +58,7 @@
#define mpSCROLL_NUM_PIXELS_PER_LINE 10
// See doxygen comments.
double mpWindow::zoomIncrementalFactor = 1.5;
double mpWindow::zoomIncrementalFactor = 1.2;
//-----------------------------------------------------------------------------
// mpLayer
@ -180,13 +180,15 @@ void mpInfoCoords::UpdateInfo(mpWindow &w, wxEvent &event) {
int mouseY = ((wxMouseEvent &)event).GetY();
double xx=w.p2x(mouseX);
double yy=w.p2y(mouseY);
double tx,ty;
double tx=0,ty=0;
double dd;
wxCoord sx,sy;
wxString namel;
int size_vec;
for (unsigned int p = 0; p < w.CountAllLayers(); p++) {
mpFXYVector *ly = reinterpret_cast<mpFXYVector*>(w.GetLayer(p));
mpFXYVector *ly = dynamic_cast<mpFXYVector*>(w.GetLayer(p));
if (ly == NULL) continue;
if ((ly->GetLayerType() == mpLAYER_PLOT) && (ly->IsVisible())) {
tx=xx;ty=yy;
double d=ly->GetDistance(tx,ty);
@ -195,7 +197,9 @@ void mpInfoCoords::UpdateInfo(mpWindow &w, wxEvent &event) {
dd=sqrt((double)(sx-mouseX)*(double)(sx-mouseX)+(double)(sy-mouseY)*(double)(sy-mouseY));
if (dd<4)
{
namel=ly->GetName();
size_vec = ly->GetSize();
namel.Printf("%s\nNumber points: %d",ly->GetName(),size_vec);
size_vec = ly->GetSize();
mouseX=1;
break;
}
@ -213,6 +217,7 @@ void mpInfoCoords::UpdateInfo(mpWindow &w, wxEvent &event) {
wxString s = xaxis->GetLabelTextValue(x);
wxString xname = xaxis->GetName();
wxString yname = yaxis->GetName();
toolTipContent.Printf(_("%s\n%s = %s\n%s = %f"), namel,xname,s,yname, ty);
wxTipWindow** ptr = NULL;
wxRect rectBounds(sx, sy, 5, 5);
@ -550,17 +555,46 @@ void mpFXY::UpdateViewBoundary(wxCoord xnew, wxCoord ynew) {
minDrawY = (minDrawY < ynew) ? minDrawY : ynew;
// drawnPoints++;
}
void drawInRectText(wxDC &dc, wxString text,wxRect out,int align) {
wxCoord tx, ty;
dc.GetMultiLineTextExtent(text, &tx, &ty);
wxRect in(0,0,tx,ty);
int angle = 0;
//if ((ix2 - ix) < ty) continue;
if (out.width < tx) {
angle = 90;
in.SetWidth(ty);
in.SetHeight(tx);
in = in.CenterIn(out);
in.y = in.y + tx;
if (in.y > (out.y+out.height)) in.y = out.y + out.height;
if (align == wxALIGN_TOP) {
in.y = out.y + tx+15;
}
}
else
{
in = in.CenterIn(out);
if (align == wxALIGN_TOP) {
in.y = out.y + ty;
}
}
dc.DrawRotatedText(text, in.x, in.y, angle);
}
void mpFXY::Plot(wxDC &dc, mpWindow &w) {
if (m_visible) {
mpFXYVector *v= dynamic_cast<mpFXYVector*>(this);
bool isBar = false;
if (v != NULL) isBar = v->IsLegendBar();
int wsimb = m_pen.GetWidth();
if (IsSelect()) {
if (IsSelect() && !isBar) {
wxPen pensel(m_pen);
pensel.SetWidth(wsimb * 2);
dc.SetPen(pensel);
}
else {
dc.SetPen(m_pen);
}
dc.SetBrush(m_brush);
@ -569,10 +603,10 @@ void mpFXY::Plot(wxDC &dc, mpWindow &w) {
// positioning
Rewind();
GetNextXY(x, y);
maxDrawX = x;
minDrawX = x;
maxDrawY = y;
minDrawY = y;
maxDrawX = 0;
minDrawX = 10000000000;
maxDrawY = 0;
minDrawY = 10000000000;
// drawnPoints = 0;
Rewind();
@ -588,7 +622,41 @@ void mpFXY::Plot(wxDC &dc, mpWindow &w) {
if (!m_continuous) {
// for some reason DrawPoint does not use the current pen,
// so we use DrawLine for fat pens
if (m_pen.GetWidth() <= 1) {
if (isBar) {
double widthbar = 0.9;
int ix2,iy2;
iy2 = w.y2p(0);
dc.SetFont(m_font);
if (iy2 > maxYpx) iy2 = maxYpx;
bool viewY = false;
while (GetNextXY(x, y)) {
ix = w.x2p(x- widthbar/2);
ix2 = w.x2p(x + widthbar / 2);
iy = w.y2p(y);
viewY = false;
if (iy < minYpx) { iy = minYpx; viewY = true; }
if (ix2 > endPx) ix2 = endPx;
if (ix < startPx) ix = startPx;
if (ix2 < startPx|| ix>endPx) continue;
if (m_drawOutsideMargins || ((ix >= startPx) && (ix <= endPx) &&
(iy >= minYpx) && (iy <= maxYpx))) {
dc.DrawRectangle(ix, iy, ix2 - ix, iy2 - iy);
UpdateViewBoundary(ix, iy);
wxCoord tx, ty;
wxString s = v->GetLegendBar();
wxRect rectBig(ix,iy, ix2 - ix, iy2 - iy);
wxRect rectSmall(0, 0, tx, ty);
drawInRectText(dc,s,rectBig,wxALIGN_CENTER);
if (viewY) {
s.Printf("%f",y);
drawInRectText(dc, s, rectBig, wxALIGN_TOP);
}
};
}
} else if (m_pen.GetWidth() <= 1) {
while (GetNextXY(x, y)) {
ix = w.x2p(x);
iy = w.y2p(y);
@ -923,11 +991,7 @@ void mpScaleX::Plot(wxDC &dc, mpWindow &w) {
// double n = floor( (w.GetPosX() - (double)extend / w.GetScaleX()) / step )
// * step ;
double n0 =
floor(
(w.GetPosX() /* - (double)(extend - w.GetMarginLeft() - w.GetMarginRight())/ w.GetScaleX() */) /
step) *
step;
double n0 =floor((w.GetPosX() /* - (double)(extend - w.GetMarginLeft() - w.GetMarginRight())/ w.GetScaleX() */) /step) * step;
double n = 0;
#ifdef MATHPLOT_DO_LOGGING
wxLogMessage(wxT("mpScaleX::Plot: dig: %f , step: %f, end: %f, n: %f"), dig,
@ -1325,6 +1389,10 @@ EVT_LEFT_UP(mpWindow::OnMouseLeftRelease)
EVT_MENU(mpID_CENTER, mpWindow::OnCenter)
EVT_MENU(mpID_FIT, mpWindow::OnFit)
EVT_MENU(mpID_ZOOM_IN, mpWindow::OnZoomIn)
EVT_MENU(mpID_ZOOM_INX, mpWindow::OnZoomInX)
EVT_MENU(mpID_ZOOM_INX, mpWindow::OnZoomInY)
EVT_MENU(mpID_ZOOM_OUTX, mpWindow::OnZoomOutX)
EVT_MENU(mpID_ZOOM_OUTX, mpWindow::OnZoomOutY)
EVT_MENU(mpID_ZOOM_OUT, mpWindow::OnZoomOut)
EVT_MENU(mpID_LOCKASPECT, mpWindow::OnLockAspect)
EVT_MENU(mpID_HELP_MOUSE, mpWindow::OnMouseHelp)
@ -1777,6 +1845,18 @@ void mpWindow::ZoomOut(const wxPoint &centerPoint) {
#endif
UpdateAll();
}
void mpWindow::OnZoomInX(wxCommandEvent& WXUNUSED(event)) {
ZoomInX();
}
void mpWindow::OnZoomInY(wxCommandEvent& WXUNUSED(event)) {
ZoomInY();
}
void mpWindow::OnZoomOutX(wxCommandEvent& WXUNUSED(event)) {
ZoomOutX();
}
void mpWindow::OnZoomOutY(wxCommandEvent& WXUNUSED(event)) {
ZoomOutY();
}
void mpWindow::ZoomInX() {
m_scaleX = m_scaleX * zoomIncrementalFactor;
@ -2566,6 +2646,7 @@ bool mpFXYVector::GetNextXY(double &x, double &y) {
return FALSE;
else {
x = m_xs[m_index];
if (m_leg.size() > 0) m_current_leg = m_leg[m_index];
y = m_ys[m_index++];
return m_index <= m_xs.size();
}
@ -2574,6 +2655,10 @@ bool mpFXYVector::GetNextXY(double &x, double &y) {
void mpFXYVector::Clear() {
m_xs.clear();
m_ys.clear();
m_leg.clear();
}
int mpFXYVector::GetSize() {
return m_xs.size();
}
double mpFXYVector::GetDistance(double &x,double &y) {
std::vector<double>::const_iterator itX;
@ -2593,7 +2678,15 @@ double mpFXYVector::GetDistance(double &x,double &y) {
return minD;
}
void mpFXYVector::SetLegendBar(const std::vector<wxString>& leg) {
if (leg.size() != m_ys.size()) {
wxLogError(
_("wxMathPlot error: X and Y vector are not of the same length!"));
return;
}
m_leg = leg;
}
void mpFXYVector::SetData(const std::vector<double> &xs,
const std::vector<double> &ys) {
// Check if the data vectora are of the same size

View file

@ -13,7 +13,7 @@ public:
frmPlot(frmQuery* parent, const wxString& _title);
~frmPlot();
void Go();
void AddSeries(const wxString legend, const std::vector<double>& x, const std::vector<double>& y);
void AddSeries(const wxString legend, const std::vector<double>& x, const std::vector<double>& y,const std::vector<wxString>& l);
void ClearAndSetAxis(wxString XtextAxis, unsigned int X_labelType, wxString YtextAxis);
void OnAbout(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
@ -26,10 +26,20 @@ public:
void OnCopy(wxCommandEvent& event);
void OnToggleInfoLayer(wxCommandEvent& event);
void OnSaveScreenshot(wxCommandEvent& event);
void OnToggleLissajoux(wxCommandEvent& event);
void OnToggleShowSeries(wxCommandEvent& event);
void OnToggleShowSimbol(wxCommandEvent& event);
void OnToggleCosine(wxCommandEvent& event);
void OnBlackTheme(wxCommandEvent& event);
void OnCenter(wxCommandEvent& event) { m_plot->OnCenter(event); };
void OnZoomIn(wxCommandEvent& event) { m_plot->OnZoomIn(event); };
void OnZoomInX(wxCommandEvent& event) { m_plot->OnZoomInX(event); };
void OnZoomInY(wxCommandEvent& event) { m_plot->OnZoomInY(event); };
void OnZoomOutX(wxCommandEvent& event) { m_plot->OnZoomOutX(event); };
void OnZoomOutY(wxCommandEvent& event) { m_plot->OnZoomOutY(event); };
void OnZoomOut(wxCommandEvent& event) { m_plot->OnZoomOut(event); };
void OnLockAspect(wxCommandEvent& event) { m_plot->OnLockAspect(event); };
void OnKEY_DOWN(wxKeyEvent& event);
mpWindow* m_plot;

View file

@ -122,6 +122,10 @@ enum {
mpID_FIT = 2000, //!< Fit view to match bounding box of all layers
mpID_ZOOM_IN, //!< Zoom into view at clickposition / window center
mpID_ZOOM_OUT, //!< Zoom out
mpID_ZOOM_INX,
mpID_ZOOM_INY,
mpID_ZOOM_OUTX,
mpID_ZOOM_OUTY,
mpID_CENTER, //!< Center view on click position
mpID_LOCKASPECT, //!< Lock x/y scaling aspect
mpID_HELP_MOUSE //!< Shows information about the mouse commands
@ -662,6 +666,14 @@ public:
*/
virtual bool GetNextXY(double &x, double &y) = 0;
/** Get legend value for N.
Override this function in your implementation.
@param x Returns X value
@param y Returns Y value
*/
virtual wxString GetLegendBar() = 0;
/** Layer plot handler.
This implementation will plot the locus in the visible area and
put a label according to the alignment specified.
@ -1315,6 +1327,18 @@ public:
@return reference to axis colour used in theme */
const wxColour &GetAxesColour() { return m_axColour; };
void OnCenter(wxCommandEvent& event); //!< Context menu handler
void OnFit(wxCommandEvent& event); //!< Context menu handler
void OnZoomIn(wxCommandEvent& event); //!< Context menu handler
void OnZoomOut(wxCommandEvent& event); //!< Context menu handler
void OnZoomInX(wxCommandEvent& WXUNUSED(event));
void OnZoomInY(wxCommandEvent& WXUNUSED(event));
void OnZoomOutX(wxCommandEvent& WXUNUSED(event));
void OnZoomOutY(wxCommandEvent& WXUNUSED(event));
void OnScrollThumbTrack(
wxScrollWinEvent& event); //!< Scroll thumb on scroll bar moving
void OnLockAspect(wxCommandEvent& event); //!< Context menu handler
protected:
void OnPaint(
wxPaintEvent &event); //!< Paint handler, will plot all attached layers
@ -1328,11 +1352,6 @@ protected:
//when the user drags with the
//right button or just "clicks"
//for the menu
void OnCenter(wxCommandEvent &event); //!< Context menu handler
void OnFit(wxCommandEvent &event); //!< Context menu handler
void OnZoomIn(wxCommandEvent &event); //!< Context menu handler
void OnZoomOut(wxCommandEvent &event); //!< Context menu handler
void OnLockAspect(wxCommandEvent &event); //!< Context menu handler
void OnMouseHelp(wxCommandEvent &event); //!< Context menu handler
void OnMouseWheel(wxMouseEvent &event); //!< Mouse handler for the wheel
void OnMouseMove(
@ -1341,8 +1360,6 @@ protected:
OnMouseLeftDown(wxMouseEvent &event); //!< Mouse left click (for rect zoom)
void
OnMouseLeftRelease(wxMouseEvent &event); //!< Mouse left click (for rect zoom)
void OnScrollThumbTrack(
wxScrollWinEvent &event); //!< Scroll thumb on scroll bar moving
void OnScrollPageUp(wxScrollWinEvent &event); //!< Scroll page up
void OnScrollPageDown(wxScrollWinEvent &event); //!< Scroll page down
void OnScrollLineUp(wxScrollWinEvent &event); //!< Scroll line up
@ -1451,17 +1468,24 @@ public:
* @sa Clear
*/
void SetData(const std::vector<double> &xs, const std::vector<double> &ys);
void SetLegendBar(const std::vector<wxString>& leg);
bool IsLegendBar() { return m_leg.size() > 0; }
wxString GetLegendBar() {
return m_current_leg
;
}
/** Clears all the data, leaving the layer empty.
* @sa SetData
*/
void Clear();
double GetDistance(double &x,double &y);
int GetSize();
protected:
/** The internal copy of the set of data to draw.
*/
std::vector<double> m_xs, m_ys;
std::vector<wxString> m_leg;
wxString m_current_leg;
/** The internal counter for the "GetNextXY" interface
*/
size_t m_index;

Binary file not shown.