Commit 7df1cfa6 authored by twanvl's avatar twanvl

Fixed #24: nullptr error in graph code

parent 921a36de
...@@ -284,12 +284,24 @@ bool Graph1D::findItem(const RealPoint& pos, const RealRect& rect, bool tight, v ...@@ -284,12 +284,24 @@ bool Graph1D::findItem(const RealPoint& pos, const RealRect& rect, bool tight, v
} }
} }
void Graph1D::setData(const GraphDataP& d) {
if (d->axes.size() <= axis) {
Graph::setData(GraphDataP()); // invalid
} else {
Graph::setData(d);
}
}
// ----------------------------------------------------------------------------- : Graph2D // ----------------------------------------------------------------------------- : Graph2D
void Graph2D::setData(const GraphDataP& d) { void Graph2D::setData(const GraphDataP& d) {
if (d->axes.size() <= max(axis1,axis2)) {
Graph::setData(GraphDataP()); // invalid
} else {
Graph::setData(d); Graph::setData(d);
if (data->axes.size() <= max(axis1,axis2)) return;
d->crossAxis(axis1,axis2,values); d->crossAxis(axis1,axis2,values);
}
} }
// ----------------------------------------------------------------------------- : Bar Graph // ----------------------------------------------------------------------------- : Bar Graph
...@@ -620,6 +632,7 @@ bool ScatterGraph::findItem(const RealPoint& pos, const RealRect& rect, bool tig ...@@ -620,6 +632,7 @@ bool ScatterGraph::findItem(const RealPoint& pos, const RealRect& rect, bool tig
void ScatterGraph::setData(const GraphDataP& d) { void ScatterGraph::setData(const GraphDataP& d) {
Graph2D::setData(d); Graph2D::setData(d);
if (!data) return;
if (values.empty()) return; if (values.empty()) return;
// find maximum // find maximum
max_value = 0; max_value = 0;
...@@ -656,13 +669,17 @@ void ScatterGraph::setData(const GraphDataP& d) { ...@@ -656,13 +669,17 @@ void ScatterGraph::setData(const GraphDataP& d) {
void ScatterGraphPlus::setData(const GraphDataP& d) { void ScatterGraphPlus::setData(const GraphDataP& d) {
ScatterGraph::setData(d); ScatterGraph::setData(d);
if (data->axes.size() <= max(max(axis1,axis2),axis3)) return; if (!data || data->axes.size() <= max(max(axis1,axis2),axis3)) {
d->crossAxis(axis1,axis2,axis3,values3D); data = GraphDataP(); // invalid
return;
}
data->crossAxis(axis1,axis2,axis3,values3D);
} }
// ----------------------------------------------------------------------------- : Scatter Pie graph // ----------------------------------------------------------------------------- : Scatter Pie graph
void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer layer) const { void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer layer) const {
if (!data) return;
if (data->axes.size() <= max(max(axis1,axis2),axis3)) return; if (data->axes.size() <= max(max(axis1,axis2),axis3)) return;
if (layer == LAYER_SELECTION) { if (layer == LAYER_SELECTION) {
ScatterGraph::draw(dc, current, layer); ScatterGraph::draw(dc, current, layer);
...@@ -711,6 +728,7 @@ void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer ...@@ -711,6 +728,7 @@ void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer
void GraphStats::setData(const GraphDataP& d) { void GraphStats::setData(const GraphDataP& d) {
Graph1D::setData(d); Graph1D::setData(d);
if (!data) return;
// update values // update values
GraphAxis& axis = axis_data(); GraphAxis& axis = axis_data();
values.clear(); values.clear();
...@@ -822,6 +840,7 @@ int GraphLegend::findItem(const RealPoint& pos, const RealRect& rect, bool tight ...@@ -822,6 +840,7 @@ int GraphLegend::findItem(const RealPoint& pos, const RealRect& rect, bool tight
// ----------------------------------------------------------------------------- : Graph label axis // ----------------------------------------------------------------------------- : Graph label axis
void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const { void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const {
if (!data) return;
RealRect rect = dc.getInternalRect(); RealRect rect = dc.getInternalRect();
GraphAxis& axis = axis_data(); GraphAxis& axis = axis_data();
int count = int(axis.groups.size()); int count = int(axis.groups.size());
...@@ -901,6 +920,7 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -901,6 +920,7 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const {
} }
} }
int GraphLabelAxis::findItem(const RealPoint& pos, const RealRect& rect, bool tight) const { int GraphLabelAxis::findItem(const RealPoint& pos, const RealRect& rect, bool tight) const {
if (!data) return -1;
GraphAxis& axis = axis_data(); GraphAxis& axis = axis_data();
int col; int col;
if (direction == HORIZONTAL) { if (direction == HORIZONTAL) {
......
...@@ -160,6 +160,7 @@ class Graph1D : public Graph { ...@@ -160,6 +160,7 @@ class Graph1D : public Graph {
inline Graph1D(size_t axis) : axis(axis) {} inline Graph1D(size_t axis) : axis(axis) {}
virtual void draw(RotatedDC& dc, const vector<int>& current, DrawLayer layer) const; virtual void draw(RotatedDC& dc, const vector<int>& current, DrawLayer layer) const;
virtual bool findItem(const RealPoint& pos, const RealRect& rect, bool tight, vector<int>& out) const; virtual bool findItem(const RealPoint& pos, const RealRect& rect, bool tight, vector<int>& out) const;
virtual void setData(const GraphDataP& d);
protected: protected:
size_t axis; size_t axis;
/// Find an item, return the position along the axis, or -1 if not found /// Find an item, return the position along the axis, or -1 if not found
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment