numeric statistics dimensions; minor tweaks of graph

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@150 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-12-22 22:47:48 +00:00
parent 69e4edff95
commit d5db3f46ff
12 changed files with 92 additions and 37 deletions
+2
View File
@@ -126,6 +126,8 @@ void DataEditor::createTabIndex() {
}
void DataEditor::onInit() {
createTabIndex();
current_viewer = nullptr;
current_editor = nullptr;
}
// ----------------------------------------------------------------------------- : Clipboard & Formatting
+34 -7
View File
@@ -42,9 +42,36 @@ GraphData::GraphData(const GraphDataPre& d)
counts[e->values[i]] += 1;
}
// TODO: allow some ordering in the groups, and allow colors to be passed
FOR_EACH(c, counts) {
a->groups.push_back(GraphGroup(c.first, c.second));
a->max = max(a->max, c.second);
if (a->numeric) {
// TODO: start at something other than 0?
// TODO: support fractions?
size_t left = counts.size();
int i = 0;
while (left) {
String is = String() << i++;
map<String,UInt>::const_iterator it = counts.find(is);
if (it == counts.end()) {
// not found, add a 0 bar
a->groups.push_back(GraphGroup(is, 0));
} else {
a->groups.push_back(GraphGroup(is, it->second));
a->max = max(a->max, it->second);
left--;
}
if (i > 100) {
// prevent infinite loops if there are non-numeric entries
// drop empty tail
while (a->groups.size() > 1 && a->groups.back().size == 0) {
a->groups.pop_back();
}
break;
}
}
} else {
FOR_EACH(c, counts) {
a->groups.push_back(GraphGroup(c.first, c.second));
a->max = max(a->max, c.second);
}
}
// find some nice colors for the groups
if (a->auto_color) {
@@ -106,7 +133,7 @@ bool Graph1D::findItem(const RealPoint& pos, const RealRect& rect, vector<int>&
void BarGraph::draw(RotatedDC& dc, int current) const {
if (!data) return;
// Rectangle for bars
RealRect rect = dc.getInternalRect().move(15, 5, -20, -20);
RealRect rect = dc.getInternalRect().move(23, 8, -30, -28);
// Bar sizes
GraphAxis& axis = axis_data();
int count = int(axis.groups.size());
@@ -151,10 +178,10 @@ void BarGraph::draw(RotatedDC& dc, int current) const {
FOR_EACH_CONST(g, axis.groups) {
// draw bar
dc.SetBrush(g.color);
dc.DrawRectangle(RealRect(x + space / 2, rect.bottom() + 1, width, -step_height * g.size - 1.999));
dc.DrawRectangle(RealRect(x + space / 2, rect.bottom() + 1, width, (int)(rect.bottom() - step_height * g.size) - rect.bottom() - 1));
// draw label, aligned bottom center
RealSize text_size = dc.GetTextExtent(g.name);
dc.SetClippingRegion(RealRect(x + 2, rect.bottom(), width_space - 4, text_size.height));
dc.SetClippingRegion(RealRect(x + 2, rect.bottom() + 3, width_space - 4, text_size.height));
dc.DrawText(g.name, align_in_rect(ALIGN_TOP_CENTER, text_size, RealRect(x, rect.bottom() + 3, width_space, 0)));
dc.DestroyClippingRegion();
x += width_space;
@@ -163,7 +190,7 @@ void BarGraph::draw(RotatedDC& dc, int current) const {
int BarGraph::findItem(const RealPoint& pos, const RealRect& rect1) const {
if (!data) return -1;
// Rectangle for bars
RealRect rect = rect1.move(15, 5, -20, -20);
RealRect rect = rect1.move(23, 8, -30, -28);
// Bar sizes
GraphAxis& axis = axis_data();
int count = int(axis.groups.size());
+3 -1
View File
@@ -36,15 +36,17 @@ class GraphGroup {
/** The sum of groups.sum = sum of all elements in the data */
class GraphAxis {
public:
GraphAxis(const String& name, bool auto_color = true)
GraphAxis(const String& name, bool auto_color = true, bool numeric = false)
: name(name)
, auto_color(auto_color)
, max(0)
, numeric(numeric)
{}
String name; ///< Name/label of this axis
bool auto_color; ///< Automatically assign colors to the groups on this axis
vector<GraphGroup> groups; ///< Groups along this axis
bool numeric; ///< Numeric axis?
UInt max; ///< Maximum size of the groups
};
+3 -2
View File
@@ -54,9 +54,10 @@ void PackageList::showData(const String& pattern) {
PackageP package = ::packages.openAny(f);
// open image
InputStreamP stream = package->openIconFile();
Image img;
Bitmap bmp;
if (stream) {
bmp = Bitmap(Image(*stream));
if (stream && img.LoadFile(*stream)) {
bmp = Bitmap(img);
}
// add to list
packages.push_back(PackageData(package, bmp));
+1 -1
View File
@@ -114,7 +114,7 @@ void StatsPanel::onCommand(int id) {
StatsCategory& cat = categories->getSelection();
GraphDataPre d;
FOR_EACH(dim, cat.dimensions) {
d.axes.push_back(new_shared1<GraphAxis>(dim->name));
d.axes.push_back(new_shared3<GraphAxis>(dim->name, true, dim->numeric));
}
FOR_EACH(card, set->cards) {
Context& ctx = set->getContext(card);