I am tring to test pie chart in highcharts with watir web driver. I have the issue of locate a tiny small piece of the pie.
#Get the pie
series1 = browser.element(:css => 'g.highcharts-tracker')
#Get the pieces
all_path_elements = series1.elements(:css => 'path')
#get the second to last
points = all_path_elements[-2..-2]
with range -1 to -1 it will able to get the last piece.
-2 to -2 still last piece.
-3 to -3 will get the third from last.
it will skip the second to last. i think because it is the smallest. but i am able to locate it with my mouse.
is there another way to locate the path elements? so maybe an alternative way can solve my issue.
i made a red dots where the piece gets skip.
http://i.stack.imgur.com/tDAaH.png
I figure out the solution myself. instead of hover on to each of the path elements. i did a fire event of the onmouseover of each path elements.
series1 = browser.element(:css => 'g.highcharts-tracker')
all_path_elements = series1.elements(:css => 'path')
points = all_path_elements[0..-1]
point = points.find do |p|
p.fire_event "onmouseover"
puts browser.elements(:css => 'g.highcharts-tooltip tspan')[3].text
end
Related
I have a question. I am trying to plot a live graph while continuously updating a CSV file continuously from a LIDAR sensor. However when I call animation.FuncAnimation(... the graph does not continuously update. If I rerun, I see the graph updated. When I view the CSV file, I see has been updating.
class SecondGraph:
def animate(i):
graph_data = open(NameofCSV,'r').read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 0:
x, y = line.split(' ')
xs.append(float(x))
ys.append(float(y))
ax1.clear()
ax1.plot(ys, xs)
ani = animation.FuncAnimation(fig, SecondGraph.animate, interval=10)
When someone has a chance, can someone guide me in the right direction here. I do not think I need to plot my full code, but if you need to see it. Let me know.
Disregard. I think I know the answer. The CSV does not update automatically, which may be the problem. I do not think there is anything wrong with my code that I posted.
I'm building a chess game that takes a start coordinate and end coordinate and builds a tree using BFS. I have two methods to find possible moves.
The #find_possible_positions_from_origin method logs every single possible square that chess piece can end up (for example a rook can end up either, north up to 7 spaces, south up to 7 spaces, left up to 7 spaces, and right up to 7 spaces. If the end coordinate ends up BEING one of these coordinates from #find_possible_positions_from_origin, it then runs another method directly under it #find_possible_incremental_moves that traverses every single one of these spaces by only 1 space at a time - the reason being so that it can check if each space is empty, and not just hop over another piece. It creates a "cell" on each of these spaces so that it can log the path to destination. Each cell remembers the path to it from the starting coordinate.
I'm having trouble getting the second variable #find_possible_incremental_moves run smoothly under the #find_possible_positions_from_origin method. A "cell" is supposed to be created at the destination coordinate of the board, so that I can have the path to it, and check if the path is occupied by any other pieces. But when I call the destination coordinate, I get nil.
Someone corrected me on a previous question that I shouldn't post my entire production code which makes sense, so I included the single #build_tree that I'm having trouble with I hope that's enough.
Here is my code that have for this section.
def build_tree
#start_coor = convert_input_to_coor(#start)
#destination_coor = convert_input_to_coor(#destination)
#selected_piece = #gameboard[#start_coor[0]][#start_coor[1]]
starting_cell = Cell.new(#start_coor[0], #start_coor[1])
queue = []
queue.unshift(starting_cell)
until queue.empty?
current = queue.shift
possible_positions = find_possible_positions_from_origin([current.x, current.y])
next if possible_positions.nil?
if possible_positions.include?(#destination_coor)
#selected_piece.possible_positions = find_possible_incremental_moves(([current.x, current.y]))
#selected_piece.possible_positions.each do |move|
next unless !#dummyboard.board[move[0]][move[1]].instance_of? Cell
linked_cell = Cell.new(move[0], move[1])
current.edges << linked_cell
linked_cell.path = current.path + linked_cell.path
#dummyboard.board[move[0]][move[1]] = linked_cell
queue.push(linked_cell)
end
end
end
starting_cell
end
im building a basic game in the style of the original pokemon games using the ruby gosu library. Ive managed to figure out how to move the originally loaded sprite about but i cant figure out how to clear that sprite and draw the new sprite e.g. back view in its place.
Ive been looking throught the documentation and came across the "insert" method, although im not sure if this is what i want. Any help?
im creating the var in the initialize method then drawing it later on like so:
def initialize
#character_image = Gosu::Image.new("media/images/char.png", :tileable => false)
end
def draw
#character_image.draw(#character_location_X, #character_location_Y, 1)
end
You need to make a class for your character, which needs an update and draw function. In the update function, when input such as WASD is received you can switch the image of the sprite. If you don't have a sprite sheet, you'll have to load multiple images and switch between them.
Here's some ruby pseudocode to help you:
#back_image = Gosu::Image.new("media/images/back.png")
#front_image = Gosu::Image.new("media/images/front.png")
#left_image = Gosu::Image.new("media/images/left.png")
#right_image = Gosu::Image.new("media/images/right.png")
current_image = front_image
This goes in your update function:
if up
current_image = back_image
elsif down
current_image = front_image
elsif right
current_image = right_image
elsif left
current_image = left_image
end
Then in your draw function all you need to do is
def draw
#current_image.draw(#character_location_X, #character_location_Y, 1)
end
This is a pretty basic way, but if you use a sprite sheet, you can create your own animation class that Gosu can use that allows you to select between certain ranges of frames of your character spritesheet.
I’m trying to animate a Mayavi pipeline volume:
src = mlab.pipeline.volume(mlab.pipeline.scalar_field(data),vmin=.1*np.max(data),vmax=.2*np.max(data))
that is combined in the pipeline by another dataset represented as a cut plane.
However, I can’t get the volume visualization to update - only the first frame shows up. The animation is stepping through the data correctly (I get different values of the np.max(data[t]) below) but nothing in the visualization changes.
My understanding is that mlab_source_set should re-render correctly, and there’s nothing on the web anywhere that describes this (as far as I can tell).
The animation looks like:
#mlab.show
#mlab.animate(delay=250,ui=True)
def anim(src,data,tax,fig):
"""Animate."""
t = 0
nt = len(tax)
while 1:
vmin = .1*np.max(data[t])
vmax = .2*np.max(data[t])
print 'animation t = ',tax[t],', max = ',np.max(data[t])
src.mlab_source.set(scalar = mlab.pipeline.scalar_field(data[t]), vmin=vmin,vmax=vmax)
t = mod(t+1,nt)
yield
Any thoughts?
i'm writing Ruby in Watir webdriver and i would like to test highcharts accuracy of data presented in comparison of a CSV file (which i already read). How can i read the highchart data from the website?
A highchart graph generated with many data dots as you mouseover the dot, a data will be shown in a box.
I cannot locate the element using watir webdriver as what i see from source that each dot are path tags.
I am thinking maybe automate the cursor to move to a x y location but not sure how to do that. Any helps? thank you
Assumptions
Since we only have an image of your chart, rather than the specific html, I will assume the graph is similar in design to the "Basic Line" highcharts demo. The below will hopefully work conceptually for your graph (ie the approach will probably work, but it will likely require some tweaks).
Get Path Elements
In the graph, there is a path element to draw each point, as well as a path element to draw the line.
<g class="highcharts-markers" visibility="visible" zIndex="0.1" transform="translate(62,55) scale(1 1)" clip-path="none">
<path fill="#2f7ed8" d="M 638.25 182.5 C 643.578 182.5 643.578 190.5 638.25 190.5 C 632.922 190.5 632.922 182.5 638.25 182.5 Z"></path>
The g and path elements are not directly supported by watir, so you will need to use the generic element type with a css or xpath locator.
#Get the first line (as there are 4 in the demo)
series1 = browser.element(:css => 'g.highcharts-markers')
#Get the data points (the last point is ignored since it is the line)
all_path_elements = series1.elements(:css => 'path')
points = all_path_elements[0..-2]
Simulate MouseOver
You can simulate mousing over an element using the hover method:
browser.element(:css => 'g.highcharts-markers path').hover
Read the Popup
The html of the popup looks like:
<g opacity="0" transform="translate(146,222)" visibility="hidden" style="cursor:default;padding:0;white-space:nowrap;" zIndex="8" class="highcharts-tooltip">
<text zIndex="1" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#333333;fill:#333333;" y="21" x="8">
<tspan x="8" style="font-size: 10px">Apr</tspan>
<tspan dy="16" x="8" style="fill:#8bbc21">Berlin</tspan>
<tspan dx="0">: </tspan>
<tspan dx="0" style="font-weight:bold">8.4°C</tspan>
</text>
We can get the text of the popup using either of the following:
#All text together
puts browser.element(:css => 'g.highcharts-tooltip').text
#=> "DecTokyo: 9.6°C"
#Each line of the popup
browser.elements(:css => 'g.highcharts-tooltip tspan').each{ |x| puts x.text }
#=> "Dec"
#=> "Tokyo"
#=> ":"
#=> "9.6°C"
Note that the text method only displays visible text, therefore you need to ensure that the popup is displayed before getting the text. Alternatively you could parse the html of the elements.
Search the Data Points
To find the value (ex temperature) for the specific date, we need to iterate over the path elements until we find one that matches the desired date. Using the points variable from before, let us get the value for July.
point = points.find do |p|
#Hover over a point
p.hover
#Get the month from the popup
month = browser.elements(:css => 'g.highcharts-tooltip tspan')[0].text
#Keep going until the month is "Jul"
month == 'Jul'
end
#Get the value of the point
point.hover
puts browser.elements(:css => 'g.highcharts-tooltip tspan')[3].text
#=> "25.2°C"
This value could then be compared to the spreadsheet of expected values.
Running Script
Putting all the points together, gives the final running example.
require 'watir'
browser = Watir::Browser.new :chrome
browser.goto 'http://www.highcharts.com/demo/'
series1 = browser.element(:css => 'g.highcharts-markers')
all_path_elements = series1.elements(:css => 'path')
points = all_path_elements[0..-2]
point = points.find do |p|
p.hover
month = browser.elements(:css => 'g.highcharts-tooltip tspan')[0].text
month == 'Jul'
end
point.hover
puts browser.elements(:css => 'g.highcharts-tooltip tspan')[3].text
#=> "25.2°C"