diff --git a/src/gui/control/graph.cpp b/src/gui/control/graph.cpp index 56756e30..5542784a 100644 --- a/src/gui/control/graph.cpp +++ b/src/gui/control/graph.cpp @@ -85,9 +85,10 @@ GraphData::GraphData(const GraphDataPre& d) { // find groups on each axis size_t i = 0; - FOR_EACH(a, axes) { + for (auto const& a : axes) { map counts; // note: default constructor for UInt() does initialize to 0 FOR_EACH_CONST(e, d.elements) { + assert(e->values.size() == axes.size()); counts[e->values[i]] += 1; } if (a->numeric) { diff --git a/src/gui/control/graph.hpp b/src/gui/control/graph.hpp index 6f69712b..adca76a5 100644 --- a/src/gui/control/graph.hpp +++ b/src/gui/control/graph.hpp @@ -28,7 +28,9 @@ DECLARE_LOCAL_EVENT_TYPE(EVENT_GRAPH_SELECT, ) // ----------------------------------------------------------------------------- : Graph data /// A group in a table or graph -/** A group is rendered as a single bar or pie slice */ +/** This corresponds to a specific value on an axis. For example "red" would be a GraphGroup for the "color" GraphAxis + * A group is rendered as a single bar or pie slice. + */ class GraphGroup : public IntrusivePtrBase { public: GraphGroup(const String& name, UInt size, const Color& color = *wxBLACK) @@ -62,17 +64,17 @@ public: , order(order) {} - String name; ///< Name/label of this axis - AutoColor auto_color; ///< Automatically assign colors to the groups on this axis - vector groups; ///< Groups along this axis - bool numeric; ///< Numeric axis? - double bin_size; ///< Group numeric values into bins of this size - UInt max; ///< Maximum size of the groups - UInt total; ///< Sum of the size of all groups - double mean_value; ///< Mean value, only for numeric axes - double max_value; ///< Maximal value, only for numeric axes - const map* colors; ///< Colors for each choice (optional) - const vector* order; ///< Order of the items (optional) + String name; ///< Name/label of this axis + AutoColor auto_color; ///< Automatically assign colors to the groups on this axis + vector groups; ///< Groups along this axis + bool numeric; ///< Numeric axis? + double bin_size; ///< Group numeric values into bins of this size + UInt max; ///< Maximum size of the groups + UInt total; ///< Sum of the size of all groups + double mean_value; ///< Mean value, only for numeric axes + double max_value; ///< Maximal value, only for numeric axes + const map* colors; ///< Colors for each choice (optional) + const vector* order; ///< Order of the items (optional) /// Add a graph group void addGroup(const String& name, UInt size); @@ -88,6 +90,8 @@ public: }; /// Data to be displayed in a graph, not processed yet +/** Requires: for (e : elements) e.values.size() == axes.size() + */ class GraphDataPre { public: vector axes; diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index 99ec4df3..5978463b 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -477,7 +477,7 @@ void StatsPanel::showCategory(const GraphType* prefer_layout) { // find values for each card for (size_t i = 0 ; i < set->cards.size() ; ++i) { Context& ctx = set->getContext(set->cards[i]); - GraphElementP e(new GraphElement(i)); + GraphElementP e = make_intrusive(i); bool show = true; FOR_EACH(dim, dims) { try { @@ -490,9 +490,12 @@ void StatsPanel::showCategory(const GraphType* prefer_layout) { } } catch (ScriptError const& e) { handle_error(ScriptError(e.what() + _("\n in script for statistics dimension '") + dim->name + _("'"))); + show = false; + break; } } if (show) { + assert(e->values.size() == dims.size()); d.elements.push_back(e); } }