kineticjs line points array contentes - line

what are the interpretation values in the"" points assignment. all I want is a "plane jane" line where I can manipulate the length and width. Any help will greatly appreciated.
var line = new Kinetic.Line({
x: 100,
y: 50,
points: [73, 70, 340, 23, 450, 60, 500, 20],
stroke: 'red',
tension: 1
});

The points array is a series of x,y coordinates:
// [73, 70, 340, 23, 450, 60, 500, 20],
{x:73,y:70},
{x:340,y:23},
{x:450,y:60},
{x:500,y:20}
This is your "plain jane" line:
// draw a black line from 25,25 to 100,50 and width of 5
var line = new Kinetic.Line({
points:[25,25, 100,50],
y:100,
stroke: 'black',
strokeWidth: 5
});

Related

Sorting Pandas dataframe by multiple conditions

I have a large dataframe (thousands of rows by hundreds of columns), a short excerpt is as the following:
data = {'Step':['', '', '', 'First', 'First', 'Second', 'Third', 'Second', 'First', 'Second', 'First', 'First', 'Second', 'Second'],
'Stuff':['tot', 'white', 'random', 7583, 3563, 824, 521, 7658, 2045, 33, 9823, 5, 8090, 51],
'Mark':['marking', '', '', 1, 5, 5, 5, 1, 27, 27, 1, 6, 1, 9],
'A':['item_a', 100, 'st1', 142, 2, 2, 2, 100, 150, 105, 118, 118, 162, 156],
'B':['skill', 66, 'abc', 160, 2, 130, 140, 169, 1, 2, 130, 140, 144, 127],
'C':['item', 50, 'st1', 2000, 2, 65, 2001, 1999, 1, 2, 2000, 4, 2205, 2222],
'D':['item_c', 100, 'st1', 433, 430, 150, 170, 130, 1, 2, 300, 4, 291, 606],
'E':['test', 90, 'st1', 111, 130, 5, 10, 160, 1, 2, 232, 4, 144, 113],
'F':['done', 80, 'abc', 765, 755, 5, 10, 160, 1, 2, 733, 4, 666, 500],
'G':['nd', 90, 'mag', 500, 420, 5, 10, 160, 1, 2, 300, 4, 469, 500],
'H':['prt', 100, 'st1', 999, 200, 5, 10, 160, 1, 2, 477, 4, 620, 7],
'Name':['NS', '', '', "Pat", "Lucy", "Lucy", "Lucy", "Nick", "Kirk", "Kirk", "Joe", "Nico", "Nico", "Bryan"],
'Value':[ -1, 0, 0, 0, 3, 6, 5, 0, 7, 7, 0, 6, 0, 1]}
df = pd.DataFrame(data)
I need to sort this dataframe according to the following conditions that have to be satisfied all together:
In the "Name" column, names that are the same are to remain grouped (e.g. there are 3
records of "Lucy" next to each other, and they cannot be moved apart)
For each group of names, the appearance order has to remain the one
given by the "Step" column (e.g. the first appearance of "Lucy" is
related to the value "First" in the "Step" column, the second to
"Second" and so on)
All the remaining names that in the "Value" column have a value = 0,
have to be moved below the others (e.g. "Pat" can be moved after the
others, but not "Nico" because there are two records of "Nico" and
the other one has a value = 6)
The first three rows cannot be moved
What I have done is to concatenate different sub-dataframes:
df_groupnames=df[df.duplicated(subset=['Name'], keep=False)]
df_nogroup = df[~df.duplicated(subset=['Name'], keep=False)]
df_nogroup_high = df_nogroup[df_nogroup["Value"] > 0 ]
df_nogroup_null = df_nogroup[df_nogroup["Value"] == 0]
# Let's concatenate these dataframes to get the sorted one
df_sorted = pd.concat([df_groupnames, df_nogroup_high, df_nogroup_null])
It works, but I wonder if there's a smarter, simpler way, and maybe faster, to obtain the same.
Thank you for your attention.

ChartJS 2 tooltip title is undefined

I am looking to add the word "Ages " to my tooltip title, to represent age groups as per in the chart.
Basically, title should be "Ages 11-20", for example. However, I get "Ages undefined"?
Anyone know why I am getting this issue?
Code (fiddle below):
var ageRangedata = {type: 'bar',
data:{datasets: [
{ data : [0,1,5,2,1,0,0, 0, 0, 0], backgroundColor: 'rgba(255, 209, 240, 0.6)', borderColor: 'rgba(255, 209, 240, 1)', borderWidth: 2, label: 'Female' },
{ data : [1,0,1,1,6,1,0, 1, 0, 0], backgroundColor: 'rgba(81, 187, 245, 0.6)', borderColor: 'rgba(81, 187, 245, 1)', borderWidth: 2, label: 'Male' }],
labels:['0-10','11-20','21-30','31-40','41-50','51-60','61-70', '71-80', '81-90', '90-']},
options: {maintainAspectRatio: false,responsive: true, tooltips: { callbacks: { title: function(tooltipItem, data) { return 'Ages ' + data.labels[tooltipItem.Index]; }}},legend: { display: false }}};
var ageR = document.getElementById("ageRange").getContext("2d");
var chart_ageR = new Chart(ageR, ageRangedata);
Extra points (side question, ignore if you want) to anyone who know what using afterLabel sends the text to just below the label instead of after it (as it sounds like it should be doing)"?
https://jsfiddle.net/unc76c7s/
Try it like this:
return 'Ages ' + tooltipItem[0].xLabel;
In any case your error is quite explicit. You could do a console.log of your tooltipItem in your callback to see if you're using it correctly.
Hope this helps.

how tf.contrib.layers.bucketized_column works?

I am trying to figure out how to use
age = tf.contrib.layers.real_valued_column("age")
age_buckets = tf.contrib.layers.bucketized_column(age, boundaries=[18, 25, 30, 35, 40, 45, 50, 55, 60, 65])
addressed in https://www.tensorflow.org/tutorials/wide.
One example usage defined as a comment in: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/feature_column.py
Copying from that file:
age_column = real_valued_column("age")
bucketized_age_column = bucketized_column(
source_column=age_column,
boundaries=[18, 25, 30, 35, 40, 45, 50, 55, 60, 65])
first_layer = input_from_feature_columns(...,
feature_columns=[..., bucketized_age_column])
second_layer = fully_connected(first_layer, ...)
# For linear models
predicitions, _, _ = weighted_sum_from_feature_columns(...,
feature_columns=[..., bucketized_age_column])

YAML root node !Null but size is 0

I'm new to YAML and trying to get an example up and running. I have the Sprites_list YAML file from http://www.gamedev.net/page/resources/_/technical/apis-and-tools/yaml-basics-and-parsing-with-yaml-cpp-r3508 and the root/base node is always NOT Null but the size is Always 0, the type is Scalar, and trying to access a node throws a YAML::BadSubscript exception. Line 118 in impl.h of Yaml 0.5.3. Why does the root node have a 0 size and why isn't accessing a node possible?
YAML::Node root_node_ = YAML::Load( file );
if( root_node_.IsNull() )
{
// Never entered
}
int sz = root_node_.size(); // Always 0
YAML::Node a_node = root_node_[ "Sprites_List" ]; // Exception
Edit-->
Full file contents ( pasted into a file called sprites.yml )
Sprites_List: [Player, Monster, Gem]
Player:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [run, idle, jump, die]
run:
Offset: {x: 0, y: 0}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
idle:
Offset: {x: 0, y: 32}
Size: {w: 32, h: 32}
Frame_Durations: [80, 120, 80, 30, 30, 130] #Notice the different durations!
jump:
Offset: {x: 0, y: 64}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 120, 80, 80, 0] #Can I say 0 mean no skipping?
die:
Offset: {x: 0, y: 192} #192? Yup, it is the last row in that sheet.
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80] #this one has only 5 frames.
Monster: #lol that lam nam
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [hover, die]
hover:
Offset: {x: 0, y: 128}
Size: {w: 32, h: 32}
Frame_Durations: [120, 80, 120, 80]
die:
Offset: {x: 0, y: 160}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80]
Gem:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [shine]
shine:
Offset: {x: 0, y: 96}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
In class declaration -
YAML::Node root_node_;
In class definition -
CConfigFile( std::string const & file ) :
root_node_ ( YAML::Load( file ) )
The file path is the full absolute path and it's escaped with \\ for each \.
YAML::Load loads a YAML string, not a file. To load a file, you need to use YAML::LoadFile.

add more options in records per page dropdown using datatable jquery

I've been using the datatable jquery (http://datatables.net/ ) plugin.
Everything is working fine, but now I want to be able to select more than the default options of records per page, by default I can choose 10 , 25 , 50 , 100. I want to add 15 and 30 to this list.
How can I do that, I searched on internet but could't find any answer.
Thanks
Use pageLength and lengthMenu for setting the default view, like this:
$('#example').DataTable({
"pageLength": 15,
"lengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
});
old api
$('#example').dataTable({
"iDisplayLength": 15,
"aLengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
});
Second array will hold the values for that will be displayed in the drop down menu
Read more: DataTables example - Page length options