How do you obtain all the ILLinePLots contained in the ILPlotCube in ILNumerics? - ilnumerics

If I use this expression Scene.Find().Find(), it gets me the first line object contained in the plotcube. In otherwise I can loop through the objects contained in the plotcube and find each lineplot?

do you mean ... ?
foreach (var lineplot in scene.Find<ILLinePlot>()) {
// do with lineplot here
}

Related

Using Math::Polygon to determine if point is inside a polygon. Not working

I am trying to determine if a certain point is inside of a polygon. Trying to use Math::Polygon. I have the boundary of the polygon in a mySQL table as one record per point for the polygon:
example:
1,38.33208,-75.51919
2,38.33286,-75.52265
etc.
38,38.33208,-75.51919
No matter what I do, the routine will not show the point inside the polygon despite the fact that the point would be truly inside the polygon.
Here's the relevant code
use Math::Polygon;
my #poly = ();
$sqlc = "SELECT segment,lat,lon FROM boundary WHERE xxxxxxx ";
my $stcc = $dbh->prepare(qq{$sqlc});
$stcc->execute();
while(($seg,$slat,$slon) = $stcc->fetchrow_array())
{
$poly[$seg] = ([$slat,$slon]);
}
my $bound = Math::Polygon->new(points => #poly);
my #this_loc = ([$lat2,$lon2]);
if($bound->contains( $this_loc ))
{
# never reaches this point.
}
No matter what, I can't get the ->contains() routine to ever return true.
Any thoughts would be appreciated. Thanks.
There seems to be (at least) two errors:
my $bound = Math::Polygon->new(points => #poly);
the constructor takes a reference to an array, not an array. So it should be:
my $bound = Math::Polygon->new(points => \#poly);
Second, $bound->contains( ) takes a reference to a point array, so it should be:
if($bound->contains( \#this_loc )) { ... }

How do I add EventTriggers to Multiple instantiated prefabs from a list?

I have a prefab which I am spawning a dynamic amount of.
I want to attach an event trigger to each one of them, on pointerclick, to call a method accepting an int as parameter.
I have the following code which partly works, however the event added to each prefab uses the same parameter, even though they are given as beign different.
foreach (EasterEgg EE in AllEasterEggs.List)
{
Transform x = Instantiate(EasterEggPrefab);
...
EventTrigger.Entry Entry = new EventTrigger.Entry();
Entry.eventID = EventTriggerType.PointerClick;
Entry.callback.AddListener((eventData) => { EasterEggClicked(EE.ID); });
x.GetChild(1).GetComponent<EventTrigger>().triggers.Add(Entry);
}
EE.Id on the first item will be 0, then it will be 1, then 2 etc. I have debugged to ensure that when it is adding the listener that EE.Id is the correct number, and this is true. The trigger is being added correctly.
However when I trigger the trigger (how to say that?), the parameter beign passed is always the parameter of the last item in that list. For example, if AllEasterEggs.List contains 5 elements, all elements will have a trigger on pointer click calling EasterEggClicked(4), whereas they should be EasterEggClicked(0) thru EasterEggClicked(4).
As a request, this is the answer:
Instead of passing EE object to anonimous delegate, just store value of EE.ID before and pass this:
foreach (EasterEgg EE in AllEasterEggs.List)
{
Transform x = Instantiate(EasterEggPrefab);
...
EventTrigger.Entry Entry = new EventTrigger.Entry();
Entry.eventID = EventTriggerType.PointerClick;
int ID = EE.ID;
Entry.callback.AddListener((eventData) => { EasterEggClicked(ID); });
x.GetChild(1).GetComponent<EventTrigger>().triggers.Add(Entry);
}

Specman list pseudo-method to pop/push from/to specific index

I am looking for a way to implement a new List pseud-method that would
push/pop from a certain location in the list (not necessarily from index 0).
is there a way to add list pseudo-methods?
Implementing list pseudo-methods can be dont using macros.
Here is an example fpr how to implement the desired pop from index pseudo method:
define <my_n_pop'exp> "<list'exp>[ ].[ ]pop_index[ ]\(<num'exp>\)" as {
evaluate typeof_item(<list'exp>) {
if(<list'exp>.size()> <num'exp>) {
value = <list'exp>[<num'exp>];
<list'exp>.delete(<num'exp>);
}else {
error("error : This list is has the size of ",<list'exp>.size(),"and you requested item",<num'exp>);
};
};
};
The usage from within the code will look something like this:
i=l.pop_index(2); // pop the item with index 2. All greater indices will decrease by 1.

nvd3 stacked area chart looks glitchy how to fix?

My stacked area chart looks like this:
The data I used has the same number of values and is just like in the example. THe data I used is at : http://pastebin.com/D07hja76
The code I use is also almost similar appart from the selector:
var colors = d3.scale.category20();
keyColor = function(d, i) {return colors(d.key)};
nv.addGraph(function() {
chart = nv.models.stackedAreaChart()
.useInteractiveGuideline(true)
.x(function(d) { return d.t })
.y(function(d) { return d.v })
.color(keyColor)
.transitionDuration(300)
chart.xAxis
.tickFormat(function(d) { return d3.time.format('%x')(new Date(d)) });
chart.yAxis
.tickFormat(d3.format(',.0f'));
d3.select('#browserBreakdown')
.datum(browserchartdata)
.transition().duration(500)
.call(chart)
.each('start', function() {
setTimeout(function() {
d3.selectAll('#browserBreakdown *').each(function() {
if(this.__transition__)
this.__transition__.duration = 1;
})
}, 0)
})
nv.utils.windowResize(chart.update);
return chart;
});
How can I get the chart to look right?
The NVD3 chart doesn't sort your data points into a left-to-right order along your x axis, so you're getting the strange criss-crossing shape.
I assume there is some way to tell NVD3 to sort the data, but they have next to no documentation and I couldn't figure it out quickly. Instead, you can use this function to sort the data before you add it to the chart:
data.forEach(function(d,i){
d.values = d.values.sort(
function(a,b){
return +a.t -b.t;
}
);
});
How this works:
data is the array of objects from the JSON file (you would use browserchartdata);
the Javascript Array.forEach(function(){}) method calls the passed-in function for each element of the array, and passes that function the element of the array and its index;
the Javascript Array.sort() method creates a sorted version of an array using the passed-in function to determine how two elements (a and b) compare;
the sort function I created uses the .t variable (which you're using for the x-axis) from each element in your array to determine whether a is bigger than b (and therefore should go after it in the sorted array);
I call this sort function on the values array of each data line, and then write-over the unsorted values array, so that the objects in data all end up with their values sorted from smallest to largest according to t.
I tried it with your data on NVD3's "live code" site, and it looks fine.

concatenating jQuery objects

Below is the prototype of what I am trying to do.
var entry_set = $;
// start to loop data
for([])
{
// create HTML element to represent that data
$('<div></div>')
.data([])
.addClass([])
.on([])
.insertAfter(entry_set);
}
// modify DOM only once all the entries are consolidated to a single jQuery object
entry_set.appendTo('.entries');
The comments say it all. In short - the idea is to modify document DOM only once when inserting data. I would usually go HTML string approach (simply concatenating the same structure using a string), but I am interested whether anything similar to this might work as well.
You could create an empty DOM element and .append() to that
var entry_set = $("<div>"); //empty dom element
// start to loop data
var i = 4;
while(i--) {
// create HTML element to represent that data
var item = $('<div>', {
text: "test " + i
});
entry_set.append(item);
}
// modify DOM only once all the entries are consolidated to a single jQuery object
$("body").append(entry_set.children());​
working demo at: http://jsfiddle.net/F2J6g/1/
EDIT
You can also start with an empty collection and use .add()
var entry_set = $(); //empty collection
// start to loop data
var i = 4;
while(i--) {
// create HTML element to represent that data
var item = $('<div>', {
text: "test " + i
});
entry_set = entry_set.add(item);
}
// modify DOM only once all the entries are consolidated to a single jQuery object
$("body").append(entry_set);
http://jsfiddle.net/F2J6g/2/
#Guy, I don't think you will get the desired HTML output. try using "wrap".
Sample Syntax:
$('.OuterDiv').wrap('<div class="abc" />');
Unfortunately, because those objects aren't actually attached to any heirarchy, calling insertAfter doesn't actually mean anything. What you'll need to do is put them inside a containing div, maybe something like this:
var entry_set = $('<div>');
// start to loop data
for([])
{
// create HTML element to represent that data
$('<div></div>')
.data([])
.addClass([])
.on([])
.appendTo(entry_set);
}
// modify DOM only once all the entries are consolidated to a single jQuery object
entry_set.appendTo('.entries');
I haven't tested that, but I think it should work.