Skip to content

Commit

Permalink
Scatter plot matrix not showing time periods of grouped variables #1796
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Jan 9, 2019
1 parent c6b36c3 commit e861d5e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 48 deletions.
26 changes: 17 additions & 9 deletions Explore/ScatterPlotMatView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ void ScatterPlotMatFrame::SetupPanelForNumVariables(int num_vars)

} else {
for (int row=0; row<num_vars; ++row) {
wxString row_nm(var_man.GetName(row));
wxString row_nm;
row_nm = var_man.GetName(row);
int row_tm(var_man.GetTime(row));

if (data_map[row_nm].size() == 1)
Expand All @@ -523,7 +524,7 @@ void ScatterPlotMatFrame::SetupPanelForNumVariables(int num_vars)
}
wxString col_nm(var_man.GetName(col));
int col_tm = 0;
if (!var_man.IsTimeVariant(col)) {
if (var_man.IsTimeVariant(col)) {
col_tm = var_man.GetTime(col);
}
const vector<bool>& X_undef = data_undef_map[col_nm][col_tm];
Expand Down Expand Up @@ -590,10 +591,10 @@ void ScatterPlotMatFrame::SetupPanelForNumVariables(int num_vars)
continue;
}
wxString col_nm(var_man.GetName(col));
int col_tm(var_man.GetTime(col));

if (data_map[row_nm].size() == 1)
col_tm = 0;
int col_tm = 0;
if (var_man.IsTimeVariant(col)) {
col_tm = var_man.GetTime(col);
}

wxString col_title(var_man.GetNameWithTime(col));

Expand Down Expand Up @@ -744,9 +745,16 @@ void ScatterPlotMatFrame::UpdateDataMapFromVarMan()
TableInterface* table_int = project->GetTableInt();
for (set<wxString>::iterator i=to_add.begin(); i!=to_add.end(); ++i) {
wxString nm = (*i);
wxString group_name = nm;
int c_id = table_int->FindColId(nm);
if (c_id < 0) {
continue;
// possible time grouped variable
int pos = nm.Find(" (");
int pos1 = nm.Find(")");
if (pos == wxNOT_FOUND && pos1 == wxNOT_FOUND) return;
group_name = nm.SubString(0, pos-1);
c_id = table_int->FindColId(group_name);
if (c_id <0) continue;
}
int tms = table_int->GetColTimeSteps(c_id);
vec_vec_dbl_type dat(tms);
Expand All @@ -757,8 +765,8 @@ void ScatterPlotMatFrame::UpdateDataMapFromVarMan()
table_int->GetColUndefined(c_id, t, dat_undef[t]);
}

data_map[nm] = dat;
data_undef_map[nm] = dat_undef;
data_map[group_name] = dat;
data_undef_map[group_name] = dat_undef;
}
}

Expand Down
96 changes: 66 additions & 30 deletions Explore/VarsChooserDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#include "VarsChooserDlg.h"

VarsChooserFrame::VarsChooserFrame(GdaVarTools::Manager& var_man,
Project* project_,
bool allow_duplicates_,
bool specify_times_,
const wxString& help_html_,
const wxString& help_title_,
const wxString& title,
const wxPoint& pos,
const wxSize& size)
Project* project_,
bool allow_duplicates_,
bool specify_times_,
const wxString& help_html_,
const wxString& help_title_,
const wxString& title,
const wxPoint& pos,
const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size, wxDEFAULT_FRAME_STYLE),
VarsChooserObservable(var_man), project(project_),
allow_duplicates(allow_duplicates_), specify_times(specify_times_),
Expand All @@ -53,34 +53,33 @@ vars_list(0), include_list(0)
wxStaticText* include_list_text = new wxStaticText(panel, wxID_ANY, _("Include"));

vars_list = new wxListBox(panel, XRCID("ID_VARS_LIST"), wxDefaultPosition,
wxSize(-1, 150), 0, 0, wxLB_SINGLE);

wxSize(-1, 150), 0, 0, wxLB_SINGLE);
include_list = new wxListBox(panel, XRCID("ID_INCLUDE_LIST"),
wxDefaultPosition, wxSize(-1, 150),
0, 0, wxLB_SINGLE);
wxDefaultPosition, wxSize(-1, 150),
0, 0, wxLB_SINGLE);

Connect(XRCID("ID_VARS_LIST"), wxEVT_LISTBOX_DCLICK,
wxCommandEventHandler(VarsChooserFrame::OnVarsListDClick));
Connect(XRCID("ID_INCLUDE_LIST"), wxEVT_LISTBOX_DCLICK,
wxCommandEventHandler(VarsChooserFrame::OnIncludeListDClick));

wxButton* include_btn = new wxButton(panel, XRCID("ID_INCLUDE_BTN"), ">",
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxButton* remove_btn = new wxButton(panel, XRCID("ID_REMOVE_BTN"), "<",
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxButton* up_btn = new wxButton(panel, XRCID("ID_UP_BTN"), _("Up"),
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxButton* down_btn = new wxButton(panel, XRCID("ID_DOWN_BTN"), _("Down"),
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxButton* help_btn = 0;
if (!help_html.IsEmpty()) {
help_btn = new wxButton(panel, XRCID("ID_HELP_BTN"), _("Help"),
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
}
//wxButton* close_btn = new wxButton(panel, XRCID("ID_CLOSE_BTN"), "Cancel",
// wxDefaultPosition, wxDefaultSize,
Expand Down Expand Up @@ -235,7 +234,7 @@ void VarsChooserFrame::OnHelpBtn(wxCommandEvent& ev)
{
LOG_MSG("In VarsChooserFrame::OnHelpBtn");
WebViewHelpWin* win = new WebViewHelpWin(project, help_html, NULL, wxID_ANY,
help_title);
help_title);
}

void VarsChooserFrame::OnCloseBtn(wxCommandEvent& ev)
Expand Down Expand Up @@ -265,18 +264,38 @@ void VarsChooserFrame::UpdateLists()

std::set<wxString> vm_names;
include_list->Clear();
wxString str_name;
for (size_t i=0, sz=var_man.GetVarsCount(); i<sz; ++i) {
include_list->Append(var_man.GetName(i));
vm_names.insert(var_man.GetName(i));
if (var_man.IsTimeVariant(i)) {
str_name = var_man.GetNameWithTime(i);
} else {
str_name = var_man.GetName(i);
}
include_list->Append(str_name);
vm_names.insert(str_name);
}

vars_list->Clear();
std::vector<wxString> names;
table_int->FillNumericNameList(names);
int steps = table_int->GetTimeSteps();
for (size_t i=0, sz=names.size(); i<sz; ++i) {
if (vm_names.find(names[i]) == vm_names.end()) {
vars_list->Append(names[i]);
}
int idx = table_int->FindColId(names[i]);
if (table_int->IsColTimeVariant(idx)) {
for (size_t j=0; j<steps; ++j) {
str_name = names[i];
str_name << " (" << table_int->GetTimeString(j) << ")";
if (vm_names.find(str_name) == vm_names.end()) {
vars_list->Append(str_name);
}
}
} else {
str_name = table_int->GetColName(idx);
if (vm_names.find(names[i]) == vm_names.end()) {
vars_list->Append(names[i]);
}
}

}
if (vars_list->GetCount() > 0) vars_list->SetFirstItem(0);

Expand All @@ -287,10 +306,27 @@ void VarsChooserFrame::IncludeFromVarsListSel(int sel)
if (!vars_list || !include_list || vars_list->GetCount() == 0) return;
if (sel == wxNOT_FOUND) return;
wxString name = vars_list->GetString(sel);
wxString group_name = name;
int time = project->GetTimeState()->GetCurrTime();
TableInterface* table_int = project->GetTableInt();
int time_steps = table_int->GetTimeSteps();
int col_id = table_int->FindColId(name);
if (col_id < 0 ) return;
if (col_id < 0 ) {
// possible time grouped variable
int pos = name.Find(" (");
int pos1 = name.Find(")");
if (pos == wxNOT_FOUND && pos1 == wxNOT_FOUND) return;
group_name = name.SubString(0, pos-1);
col_id = table_int->FindColId(group_name);
if (col_id <0) return;
wxString group_time = name.SubString(pos+2, pos1-1);
for (size_t i=0; i<time_steps; ++i) {
if (group_time == table_int->GetTimeString(i)) {
time = i;
break;
}
}
}
std::vector<double> min_vals;
std::vector<double> max_vals;
table_int->GetMinMaxVals(col_id, min_vals, max_vals);
Expand All @@ -304,7 +340,7 @@ void VarsChooserFrame::IncludeFromVarsListSel(int sel)
return;
}

var_man.AppendVar(name, min_vals, max_vals, time);
var_man.AppendVar(group_name, min_vals, max_vals, time);
include_list->Append(name);
vars_list->Delete(sel);
if (vars_list->GetCount() > 0) {
Expand Down
16 changes: 8 additions & 8 deletions Explore/VarsChooserDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class VarsChooserFrame : public wxFrame, public VarsChooserObservable
{
public:
VarsChooserFrame(GdaVarTools::Manager& var_man,
Project* project,
bool allow_duplicates = false,
bool specify_times = false,
const wxString& help_html = wxEmptyString,
const wxString& help_title = wxEmptyString,
const wxString& title = "Variables Add/Remove",
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize(-1, 170));
Project* project,
bool allow_duplicates = false,
bool specify_times = false,
const wxString& help_html = wxEmptyString,
const wxString& help_title = wxEmptyString,
const wxString& title = "Variables Add/Remove",
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize(-1, 170));
virtual ~VarsChooserFrame();

void OnVarsListDClick(wxCommandEvent& ev);
Expand Down
2 changes: 1 addition & 1 deletion VarTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ wxString Manager::GetNameWithTime(int var)
if (var < 0 || var >= vars.size()) return "";
wxString s(vars[var].name);
if (!vars[var].is_time_variant) return s;
s << " (" << GetStrForTmId(vars[var].time) << ")";
s << " (" << GetStrForTmId(vars[var].time) << ")";
return s;
}

Expand Down

0 comments on commit e861d5e

Please sign in to comment.