Repository navigation
Expand file tree
/
Copy pathstatistics.cpp
More file actions
136 lines (121 loc) · 4.02 KB
/
Copy pathstatistics.cpp
File metadata and controls
136 lines (121 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/statistics.hpp>
#include <data/field.hpp>
#include <data/field/choice.hpp>
extern ScriptValueP script_primary_choice;
// ----------------------------------------------------------------------------- : Statistics dimension
StatsDimension::StatsDimension()
: automatic (false)
, position_hint(0)
, numeric (false)
, bin_size (0)
, show_empty (false)
, split_list (false)
{}
StatsDimension::StatsDimension(const Field& field)
: automatic (true)
, name (field.name)
, description (field.description)
, position_hint(field.position_hint)
, icon_filename(field.icon_filename)
, numeric (false)
, show_empty (false)
, split_list (false)
{
// choice field?
const ChoiceField* choice_field = dynamic_cast<const ChoiceField*>(&field);
if (choice_field) {
colors = choice_field->choice_colors;
/*int count = choice_field->choices->lastId();
for (int i = 0 ; i < count ; ++i) {
groups.push_back(choice_field->choices->choiceName(i));
}*/
// only top level choices
for(const auto& g : choice_field->choices->choices) {
groups.push_back(g->name);
}
// initialize script: primary_choice(card.{field_name})
Script& s = script.getMutableScript();
s.addInstruction(I_PUSH_CONST, script_primary_choice);
s.addInstruction(I_GET_VAR, SCRIPT_VAR_card);
s.addInstruction(I_MEMBER_C, field.name);
s.addInstruction(I_CALL, 1);
s.addInstruction(I_NOP, SCRIPT_VAR_input);
} else {
// initialize script, card.{field_name}
Script& s = script.getMutableScript();
s.addInstruction(I_GET_VAR, SCRIPT_VAR_card);
s.addInstruction(I_MEMBER_C, field.name);
}
}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
if (!automatic) {
REFLECT(name);
REFLECT(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT(script);
REFLECT(numeric);
REFLECT(bin_size);
REFLECT(show_empty);
REFLECT(split_list);
REFLECT(colors);
REFLECT(groups);
}
}
// ----------------------------------------------------------------------------- : Statistics category
StatsCategory::StatsCategory()
: automatic(false)
, position_hint(0)
, type(GRAPH_TYPE_BAR)
{}
StatsCategory::StatsCategory(const StatsDimensionP& dim)
: automatic(true)
, name (dim->name)
, description (dim->description)
, position_hint(dim->position_hint)
, icon_filename(dim->icon_filename)
, dimensions(1, dim)
, type(GRAPH_TYPE_BAR)
{}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
if (!automatic) {
REFLECT(name);
REFLECT(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT(type);
REFLECT_N("dimensions", dimension_names);
}
}
void StatsCategory::find_dimensions(const vector<StatsDimensionP>& available) {
if (!dimensions.empty()) return;
for(const auto& n : dimension_names) {
StatsDimensionP dim;
for(const auto& d : available) {
if (d->name == n) {
dim = d;
break;
}
}
if (!dim) {
handle_error(_ERROR_1_("dimension not found",n));
} else {
dimensions.push_back(dim);
}
}
}
// ----------------------------------------------------------------------------- : GraphType (from graph_type.hpp)
IMPLEMENT_REFLECTION_ENUM(GraphType) {
VALUE_N("bar", GRAPH_TYPE_BAR);
VALUE_N("pie", GRAPH_TYPE_PIE);
VALUE_N("stack", GRAPH_TYPE_STACK);
VALUE_N("scatter", GRAPH_TYPE_SCATTER);
VALUE_N("scatter pie", GRAPH_TYPE_SCATTER_PIE);
}