Skip to content

Commit

Permalink
Added an automatic mode for plots that switch according to the x-vect…
Browse files Browse the repository at this point in the history
…or type.

For ravel #56.
  • Loading branch information
highperformancecoder committed Jun 24, 2020
1 parent c243294 commit bea8084
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ecolab
2 changes: 1 addition & 1 deletion gui-tk/plots.tcl
Expand Up @@ -44,7 +44,7 @@ proc deiconifyPltWindowOptions {} {

frame .pltWindowOptions.plotType
label .pltWindowOptions.plotType.label -text "Plot type"
ttk::combobox .pltWindowOptions.plotType.val -width 20 -state readonly -textvariable plotWindowOptions(plotType) -value {line bar}
ttk::combobox .pltWindowOptions.plotType.val -width 20 -state readonly -textvariable plotWindowOptions(plotType) -value {line bar automatic}
pack .pltWindowOptions.plotType.label .pltWindowOptions.plotType.val -side left


Expand Down
20 changes: 16 additions & 4 deletions model/plotWidget.cc
Expand Up @@ -198,6 +198,15 @@ namespace minsky
cairo_set_line_width(cairo,1);
double gw=w-2*portSpace, gh=h-portSpace;;
if (!title.empty()) gh=h-portSpace-titleHeight; // take into account room for the title
//TODO Urgh - fix up the const_casts here. Maybe pass plotType as parameter to draw
auto& pt=const_cast<Plot*>(static_cast<const Plot*>(this))->plotType;
switch (plotType)
{
case line: pt=Plot::line; break;
case bar: pt=Plot::bar; break;
default: break;
}

Plot::draw(cairo,gw,gh);
cairo_restore(cairo);
if (mouseFocus)
Expand Down Expand Up @@ -467,7 +476,7 @@ namespace minsky
// work out a reference to the x data
vector<double> xdefault;
double* x;
if (pen<xvars.size() && xvars[pen]->idx()>=0)
if (pen<xvars.size() && xvars[pen])
{
if (xvars[pen]->hypercube().xvectors[0].size()!=d[0])
throw error("x vector not same length as y vectors");
Expand All @@ -489,7 +498,8 @@ namespace minsky
xticks.emplace_back(i, str(xv[i]));
xdefault.push_back(i);
}
plotType=bar;
if (plotType==automatic)
Plot::plotType=Plot::bar;
break;
case Dimension::value:
if (xIsSecsSinceEpoch && xv.dimension.units=="year")
Expand All @@ -499,7 +509,8 @@ namespace minsky
else
for (auto& i: xv)
xdefault.push_back(any_cast<double>(i));
plotType=line;
if (plotType==automatic)
Plot::plotType=Plot::line;
break;
case Dimension::time:
{
Expand All @@ -511,7 +522,8 @@ namespace minsky
xdefault.push_back(tv);
}
}
plotType=line;
if (plotType==automatic)
Plot::plotType=Plot::line;
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion model/plotWidget.h
Expand Up @@ -74,7 +74,11 @@ namespace minsky


std::string title;


/// automatic means choose line or bar depending on the x-vector type.
enum PlotType {line, bar, automatic};
PlotType plotType=automatic;

PlotWidget();

// pick the Item width method, not ecolab::Plot's
Expand Down
5 changes: 3 additions & 2 deletions schema/schema3.h
Expand Up @@ -112,7 +112,7 @@ namespace schema3
Optional<float> iconScale; // for handling legacy schemas
// Plot specific fields
Optional<bool> logx, logy, ypercent;
Optional<Plot::PlotType> plotType;
Optional<minsky::PlotWidget::PlotType> plotType;
Optional<std::string> xlabel, ylabel, y1label;
Optional<int> nxTicks, nyTicks;
Optional<double> xtickAngle, exp_threshold;
Expand Down Expand Up @@ -173,7 +173,8 @@ namespace schema3
ravelState(it.ravelState), lockGroup(it.lockGroup), dimensions(it.dimensions),
axis(it.axis), arg(it.arg), data(it.data), assetClasses(it.assetClasses),
iconScale(it.iconScale), logx(it.logx), logy(it.logy), ypercent(it.ypercent),
plotType(it.plotType), xlabel(it.xlabel), ylabel(it.ylabel), y1label(it.y1label),
plotType(minsky::PlotWidget::PlotType(it.plotType? int(*it.plotType): 0)),
xlabel(it.xlabel), ylabel(it.ylabel), y1label(it.y1label),
nxTicks(it.nxTicks), nyTicks(it.nyTicks), xtickAngle(it.xtickAngle),
exp_threshold(it.exp_threshold), legend(it.legend), bookmarks(it.bookmarks),
tensorData(convertTensorDataFromSchema2(it.tensorData)), palette(it.palette)
Expand Down

0 comments on commit bea8084

Please sign in to comment.