mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Fixed #24: nullptr error in graph code
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1453 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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) {
|
||||||
Graph::setData(d);
|
if (d->axes.size() <= max(axis1,axis2)) {
|
||||||
if (data->axes.size() <= max(axis1,axis2)) return;
|
Graph::setData(GraphDataP()); // invalid
|
||||||
d->crossAxis(axis1,axis2,values);
|
} else {
|
||||||
|
Graph::setData(d);
|
||||||
|
d->crossAxis(axis1,axis2,values);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Bar Graph
|
// ----------------------------------------------------------------------------- : Bar Graph
|
||||||
@@ -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) {
|
|||||||
|
|
||||||
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
|
|||||||
|
|
||||||
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
|
|||||||
// ----------------------------------------------------------------------------- : 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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 {
|
|||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user