When I use gwt-visualization and GeoMap it happens that when I give a value to Vienna it works fine, but if I give a value to lower austria -> Vienna is not shown anymore on the map.
Heres the code I use to create the geomap:
private Options createOptions() {
Options options = Options.create();
options.setDataMode(DataMode.REGIONS);
options.setWidth(1000);
options.setHeight(650);
options.setRegion("AT");
return options;
}
private AbstractDataTable createTable2() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Bundesland");
data.addColumn(ColumnType.NUMBER, "Sessions");
data.addRows(9);
data.setValue(0, 0, "Niederösterreich");
data.setValue(0, 1, 200);
data.setValue(1, 0, "Salzburg");
data.setValue(1, 1,56);
data.setValue(2, 0, "Tirol");
data.setValue(2, 1, 11);
data.setValue(3, 0, "Oberösterreich");
data.setValue(3, 1, 11);
data.setValue(4, 0, "Burgenland");
data.setValue(4, 1, 55);
data.setValue(5, 0, "Vorarlberg");
data.setValue(5, 1, 567);
data.setValue(6, 0, "Kärnten");
data.setValue(6, 1, 11);
data.setValue(7, 0, "Steiermark");
data.setValue(7, 1, 99);
data.setValue(8, 0, "Wien");
data.setValue(8, 1, 1);
return data;
}
I think the reason why this is happen is becaus lower austria surround vienna. Is there a way to get this working?
It looks like GeoMaps does not include AT-9 in its map. In your luck, GeoCharts (the non-flash newer version of GeoMaps) does.
I don't use GWT, so I won't be able to tell you how to translate this in to GWT (apologies, maybe someone else can tack on the proper syntax). Here is the code:
function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Bundesland', 'Sessions'],
['AT-3', 200],
['AT-5', 56],
['AT-7', 11],
['AT-4', 11],
['AT-1', 55],
['AT-8', 567],
['AT-2', 11],
['AT-6', 99],
['AT-9', 1]
]);
var geochart = new google.visualization.GeoChart(
document.getElementById('visualization'));
geochart.draw(data, {region: 'AT', resolution: 'provinces', width: 556, height: 347});
}
In general, I suggest using the ISO-3166 codes for whichever country you map to make it render faster. Let me know if it works!
createOptions() should return an object class GeoMap.Options. That may be the problem.
private GeoMap.Options createOptions() {
GeoMap.Options options = GeoMap.Options.create();
options.setDataMode(DataMode.REGIONS);
options.setWidth(1000);
options.setHeight(650);
options.setRegion("AT");
return options;
}
Related
I'm trying to adapt a c++ to dart, and I ran into this situation with enum, assigning default values I think. follow the code
enum skills_t : uint8_t {
SKILL_FIST = 0,
SKILL_CLUB = 1,
SKILL_SWORD = 2,
SKILL_AXE = 3,
SKILL_DISTANCE = 4,
SKILL_SHIELD = 5,
SKILL_FISHING = 6,
SKILL_CRITICAL_HIT_CHANCE = 7,
SKILL_CRITICAL_HIT_DAMAGE = 8,
SKILL_LIFE_LEECH_CHANCE = 9,
SKILL_LIFE_LEECH_AMOUNT = 10,
SKILL_MANA_LEECH_CHANCE = 11,
SKILL_MANA_LEECH_AMOUNT = 12,
SKILL_MAGLEVEL = 13,
SKILL_LEVEL = 14,
SKILL_FIRST = SKILL_FIST,
SKILL_LAST = SKILL_MANA_LEECH_AMOUNT
};
}
uint32_t skillBase[SKILL_LAST + 1] = {50, 50, 50, 50, 30, 100, 20};
Is it possible to adapt this code to dart/flutter?
I would like to replicate the same operation in dart, it seems that he assigned these values to each enum in a range
Yes, it is possible to adapt this code to Dart/Flutter.
In Dart, you can use the enum keyword to define an enumeration. The syntax is similar to C++, but there is no need to specify a type like uint8_t.
Regarding the default values, you can initialize the enum members with a value like in C++.
Here is an example of how the C++ code could be adapted to Dart:
enum Skills {
FIST,
CLUB,
SWORD,
AXE,
DISTANCE,
SHIELD,
FISHING,
CRITICAL_HIT_CHANCE,
CRITICAL_HIT_DAMAGE,
LIFE_LEECH_CHANCE,
LIFE_LEECH_AMOUNT,
MANA_LEECH_CHANCE,
MANA_LEECH_AMOUNT,
MAGLEVEL,
LEVEL,
FIRST = FIST,
LAST = MANA_LEECH_AMOUNT,
}
final List<int> skillBase = [
50, 50, 50, 50, 30, 100, 20
];
You can also use a Map to assign the default values to each enum member.
enum Skills {
FIST,
CLUB,
SWORD,
AXE,
DISTANCE,
SHIELD,
FISHING,
CRITICAL_HIT_CHANCE,
CRITICAL_HIT_DAMAGE,
LIFE_LEECH_CHANCE,
LIFE_LEECH_AMOUNT,
MANA_LEECH_CHANCE,
MANA_LEECH_AMOUNT,
MAGLEVEL,
LEVEL,
FIRST = FIST,
LAST = MANA_LEECH_AMOUNT,
}
final Map<Skills, int> skillBase = {
Skills.FIST: 50,
Skills.CLUB: 50,
Skills.SWORD: 50,
Skills.AXE: 50,
Skills.DISTANCE: 30,
Skills.SHIELD: 100,
Skills.FISHING: 20,
// Add the rest of the skills
};
Both the above examples will work fine in dart/flutter.
I need to plot line segments (not continous) combined in one chart.
In order to create a plot I use the code from the VTK example but when I skip some values when filling vtkTable line goes down to zero value. And if creating another plot and skip some of the first elements the line goes up from zero. So I need to solve these issues.
I have figured out the solution myself. It appears very simple at last. The basic idea is to represent each line segment by its own plot and to use a separate table for each of the plots. One more improtant point all of the tables do not need to have the same step on the X-axis.
Here is the sample code:
vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
vtkSmartPointer<vtkTable> table1 = vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> xAxis1 = vtkSmartPointer<vtkFloatArray>::New();
xAxis1->SetName("X");
vtkSmartPointer<vtkFloatArray> yAxis1 = vtkSmartPointer<vtkFloatArray>::New();
yAxis1->SetName("");
table1->AddColumn(xAxis1);
table1->AddColumn(yAxis1);
table1->SetNumberOfRows(2);
table1->SetValue(0, 0, 1);
table1->SetValue(0, 1, 1);
table1->SetValue(1, 0, 2);
table1->SetValue(1, 1, 2);
vtkPlot* plot1 = chart->AddPlot(vtkChart::LINE);
plot1->SetInputData(table1, 0, 1);
plot1->SetColor(0, 0, 255, 255);
vtkSmartPointer<vtkTable> table2 = vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> xAxis2 = vtkSmartPointer<vtkFloatArray>::New();
xAxis2->SetName("X");
vtkSmartPointer<vtkFloatArray> yAxis2 = vtkSmartPointer<vtkFloatArray>::New();
yAxis2->SetName("");
table2->AddColumn(xAxis2);
table2->AddColumn(yAxis2);
table2->SetNumberOfRows(3);
table2->SetValue(0, 0, 4);
table2->SetValue(0, 1, 4);
table2->SetValue(1, 0, 5);
table2->SetValue(1, 1, 5);
table2->SetValue(2, 0, 6);
table2->SetValue(2, 1, 6);
vtkPlot* plot2 = chart->AddPlot(vtkChart::LINE);
plot2->SetInputData(table2, 0, 1);
plot2->SetColor(255, 0, 0, 255);
view->GetScene()->AddItem(chart);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
P.S. You can also specify several rows with the same x coordinate.
I'm testing a set of output styler classes which style data before outputting it to an output interface. The behavior of each styler is dependent on up to 5 different conditions (at the moment, but a sixth is on the way) with regard to the object being outputted: isKey, isDefault, isEmpty, isReadOnly, isAccessible
So one styler might output nothing if it has readonly data, while another might show "access denied".
At the moment I am testing along these lines, but the tests are exploding as more conditions are added.
{
// isKey, isDefault, isEmpty, isReadOnly, isAccessible
ValueOutputTester::TestConditions conditions = {0, 0, 0, 0, 0};
EXPECT_EQ(valueOutputTester(conditions), accessDeniedOutput);
}
{
ValueOutputTester::TestConditions conditions = {0, 0, 0, 0, 1};
EXPECT_EQ(valueOutputTester(conditions), normalOutput);
}
{
ValueOutputTester::TestConditions conditions = {0, 0, 0, 1, 0};
EXPECT_EQ(valueOutputTester(conditions), accessDeniedOutput);
}
{
ValueOutputTester::TestConditions conditions = {0, 0, 0, 1, 1};
EXPECT_EQ(valueOutputTester(conditions), accessDeniedOutput);
}
{
ValueOutputTester::TestConditions conditions = {0, 0, 1, 0, 0};
EXPECT_EQ(valueOutputTester(conditions), emptyOutput);
}
...
Can you recommend a better way of doing this?
You might write a test helper method that lets you specify condition patterns and that generates all combinations that match the pattern, e.g. assuming -1 means 'either 0 or 1':
TestPattern pattern = {-1, -1, 1, -1, -1};
ExpectForPattern(pattern, emptyOutput);
In an effort to reduce multiple functions (that were nearly identical) in my code, I decided to consolidate them all into one function which takes an additional parameter (a class with multiple parameters, actually), and then uses those values to imitate what the multiple functions would have done. Then, long story short, I put each of those class declarations into a vector, and now my program seems dysfunctional.
My multiple instances of a class:
FragmentCostParameters commonFCP = FragmentCostParameters(.05, 0);
FragmentCostParameters rareFCP = FragmentCostParameters(.05, 50);
FragmentCostParameters uniqueFCP = FragmentCostParameters(.05, 125);
FragmentCostParameters legendaryFCP = FragmentCostParameters(.02, 175);
FragmentCostParameters crystallineFCP = FragmentCostParameters(.02, 250);
FragmentCostParameters superEliteFCP = FragmentCostParameters(.02, 300);
Which get placed into a vector by:
vector<FragmentCostParameters> FCPs(6);
FCPs.push_back(FragmentCostParameters(.05, 0));
FCPs.push_back(FragmentCostParameters(.05, 50));
FCPs.push_back(FragmentCostParameters(.05, 125));
FCPs.push_back(FragmentCostParameters(.02, 175));
FCPs.push_back(FragmentCostParameters(.02, 250));
FCPs.push_back(FragmentCostParameters(.02, 300));
Additionally, that class is defined below:
class FragmentCostParameters {
public:
double multFactor;
double subtractFactor;
FragmentCostParameters(double _multFactor, double _subtractFactor){
multFactor = _multFactor;
subtractFactor = _subtractFactor;
}
FragmentCostParameters(){
multFactor = .05;
subtractFactor = 0;
}
};
Now, you'll notice that the default constructor for the FragmentCostParameters involves setting multFactor = .05 and subtractFactor = 0. However, it seems that no matter what I push back, each of the values in my vector become mutated into those values. At least, that's what VS 2011 tells me the values are equal to when I'm looking at them in a local scope in the following function (which is the only place they're used).
int FragmentCost(double skillLevel, int duration, FragmentCostParameters FCP){
return max((int)(ceil(FCP.multFactor*(skillLevel-FCP.subtractFactor))*ceil(duration/30.0)) , 0);
}
And the only place that FragmentCost is called is from this function below, which is supposed to pass different values .. but somewhere in the process, when I look at locals in FragmentCost, they're always the default values in the constructor for the class.
//given a skill level + duration, will return an array with the fragment usage
int* regularTotalFragCost(int skillLevel, int duration){
int fragments[7] = {0,0,0,0,0,0,0};
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[0]);
fragments[1]+= FragmentCost(skillLevel,duration, FCPs[0]);
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[1]);
fragments[2]+= FragmentCost(skillLevel,duration, FCPs[1]);
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[2]);
fragments[3]+= FragmentCost(skillLevel,duration, FCPs[2]);
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[3]);
fragments[4]+= FragmentCost(skillLevel,duration, FCPs[3]);
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[4]);
fragments[5]+= FragmentCost(skillLevel,duration, FCPs[4]);
fragments[0]+= FragmentCost(skillLevel,duration, FCPs[5]);
fragments[6]+= FragmentCost(skillLevel,duration, FCPs[5]);
return fragments;
}
For some reason I feel that I'm making a really stupid mistake somewhere, but for the life of me I can't seem to figure it out. I would appreciate any help and/or advice anyone could offer.
EDIT: Here's what the values for fragments[] in regularTotalFragCost are supposed to be if everything is working correctly, using a couple test values (skillLevel = 250 and duration = 30)
FCPs[0] : Fragments: 13, 13, 0, 0, 0, 0, 0,
FCPs[1] : Fragments: 17, 15, 2, 0, 0, 0, 0,
FCPs[2] : Fragments: 20, 14, 5, 1, 0, 0, 0,
FCPs[3] : Fragments: 29, 14, 9, 5, 1, 0, 0,
FCPs[4] : Fragments: 32, 13, 10, 7, 2, 0, 0,
FCPs[5] : Fragments: 32, 13, 10, 7, 2, 0, 0,
And here is what they are as of right now:
FCPs[0] : Fragments: 78, 13, 13, 13, 13, 13, 13,
FCPs[1] : Fragments: 78, 13, 13, 13, 13, 13, 13,
FCPs[2] : Fragments: 78, 13, 13, 13, 13, 13, 13,
FCPs[3] : Fragments: 78, 13, 13, 13, 13, 13, 13,
FCPs[4] : Fragments: 78, 13, 13, 13, 13, 13, 13,
FCPs[5] : Fragments: 78, 13, 13, 13, 13, 13, 13,
vector<FragmentCostParameters> FCPs(6);
creates a vector of 6 default-constructed values, numbered 0-5.
FCPs.push_back(FragmentCostParameters(.05, 0));
adds value at index 6
int fragments[7] is a local variable on the stack. Once that function returns, that memory is no longer valid. You are returning a pointer to that local variable and any access to that memory is undefined behavior.
Instead, return an std::array:
std::array<int, 7> fragments = {}; // value initialize
return fragments;
Hint: How big is your vector after you push_back your FCPs?
I'm currently working on a project in which I load a huge number of data points on a graph (something like 50,000, so I can zoom in as much as I want).
I wanted to test how the commands worked, so I thought I'd try out the code with 10 pieces of data, but unfortunately my curve refuses to show up on my graph.
QwtPlot *leftGraph;
leftGraph = new QwtPlot;
leftGraph->setCanvasBackground(Qt::white);
leftGraph->setMaximumHeight(200);
leftGraph->setAxisScale(0, 0.0, 20.0, 2.0);
leftGraph->setAxisScale(2, 0.0, 20.0, 2.0);
and
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setStyle(QwtPlotCurve::Lines);
curve->setCurveAttribute(QwtPlotCurve::Fitted, true);
const double x[] = {0, 1, 2, 4, 5, 8, 10, 13, 14, 19};
const double y[] = {17, 16.5, 8, 3, 5, 7.5, 9, 10, 12, 14};
curve->setSamples(x, y, 10);
curve->attach(leftGraph);
Any ideas? Many thanks.
Try calling leftGraph->replot() to make the curve appear.