How do I remove dots from interactive guideline (but keep the tooltip)? - nvd3.js

The interactive guideline adds circles that move along each series as you mouse over the graph. However, if there are points in the graph that are undefined that dot just moves along the line the top of the graph. I want to remove these dots, preferably just when values are undefined, but if that's not possible then just remove them altogether. I tried just excluding the values that would be undefined in the time series, but that's also ugly, as the tooltip then shows the value in the series which is closest to your current position; I need it not to show a number if there isn't actually a value at that position.

Related

How to identify the hexagons which overlap with a given geofence?

The H3 API reference introduced polyfill, the idea of which is "a point-in-poly operation on every hexagon in a k-ring defined around the given geofence". The questions are:
I don't understand what's the meaning of "k-ring defined around a geofence", is this a "ring" and it center is actually the total geofence?
If the judgement is based on the hexagons' center location, and do an "point in polygon" operation, it's possible that the geofence and a hexagon overlaps, but the hexagon's center is out of the geofence and I can't get it's index using polyfill. So, is there any ways that I can get the 2 kinds of hexagons separately which are totally inside a geofence and the hexagons which are partly overlaps with the geofence?
You can actually ignore the k-ring part of this - it's an implementation detail, and in fact that detail has changed in the latest version of the library. The basic idea in both implementations is that we collect a "test" set of cells that covers the entire polygon, and then do a point-in-poly check based on the center of each cell.
It sounds like what you need are ways to get all fully-contained cells and all intersecting cells. There's an existing feature request for this functionality, and while we'd like to add this we don't have any support for other polyfill modes in the library at present.
It's not too hard to roll this yourself, but it may be slow for large sets. You'd need to have a polygon intersection check for a cell and the polygon - a naive implementation would simply check if any two segments intersect (O(polygonVertices), since the count of cell vertices is effectively constant).
Run polyfill to get the starting set. This includes fully contained and some, but not necessarily all, partially contained cells.
For each cell in the starting set, check if it intersects the polygon
If it does not intersect, it is fully contained, add to the set of contained cells
If it does intersect, add to the set of partially contained cells and also to a temporary queue of "border" cells.
If it is contiguous with the polygon, it's fully contained. Add it to the set of contained cells, and also to the border cell queue.
Now identify partially-contained cells that were not in the initial polyfill set. While cells remain in the border queue, pop the first cell and use kRing(cell, 1) to get its neighbors. For each neighbor:
If the neighbor is in the initial polyfill set, ignore.
If the neighbor does not intersect the polygon, ignore.
If the neighbor intersects the polygon, add to the set of partially contained cells and push onto the border queue.
When the border queue is empty, your two sets (contained and partially contained) are complete.

get exact coordinates of animating element with d3.js

In this jsbin, I am trying to position the horizontal line to the smaller circle in the animating group but the jsbin is using getBoundingClientRect and some arbitrary values to get there.
I wanted to use this value:
d3.select('.circle-guide').attr('cx')
But it always returns the same value and does not take the transform into account.
How can I get the coordinates of a n animating element?

How to add randon transparent dots over CGPath or NSBezierPath

Wanted to know how can I add transparent dots or lines over CGPath or NSBezierPath.
Here are more details about the problem.
I've a solid line say width = 30(drawn using NSBezierPath or CGPath) , now I wanted to draw transparent dots over it or transparent lines(thickness=2 or something smaller than 30).
You can enumerate the elements of an NSBezierPath or CGPath, and do something for each one.
For NSBezierPath, use elementCount, elementAtIndex:associatedPoints:, and a for loop. The elementAtIndex:associatedPoints: requires a C array of up to three NSPoints.
For CGPath, use CGPathApply. This takes a pointer to a C function that you have written. One of the two arguments to the function is a structure that contains the same information returned by elementAtIndex:associatedPoints:, except that it will create the array of points for you.
The element types are mostly the same between them:
A moveto or lineto carries one point.
You might wonder why a lineto doesn't have two points. The point associated with the element is the destination point—the to in lineto—that is the new current point immediately afterward. The other point, the one you're coming from, is implicit; in cases where you want to use it, you will simply have to remember the last current point.
A (cubic) curveto uses all three points.
As with lineto, the source point is implicit, being simply the last current point. The last point in the array is the destination anchor point; the two other points are the control points.
Core Graphics has quadratic curveto elements, which only have two points.
A cubic curveto has two control points and one anchor point; a quadratic one has only one control point and one anchor point.
NSBezierPath does not have quadratic curveto elements. All curveto elements in an NSBezierPath are cubic.
A closepath has no points. It returns to the point of the last moveto.
Either way, for each element, draw whatever anchor-point indicator you want. You could, for example, draw a blue circle at the destination point, and not draw anything for a closepath (since you already drew that when you encountered the matching moveto). For curveto elements, you might also want to draw an indicator for each of the two control points.
Use -bezierPathByFlatteningPath.
Once you have flattened copy of the receiver, compute its length.
Then, iterate through the flattened copy, which is basically an array of points. Keep track of the distance between successive points, so that you can see where you are exactly on the curve.
For example, if you want to draw multiple copies of an object, you have to find on which segment of the flattened copy the object will reside. Once you have found the segment, linear interpolate between the two ends of that segment to find the exact spot.
If this is what you want to achieve, I can elaborate a little and post the category I wrote that does this.

Is Point inside a polygon?

Given a list of points that represent the polygon in 2D, how can I determine if the point is inside the polygon.
Please note that the polygon can be either concave or convex. You can also make any assumptions about the order of the points.
The best approach to doing this is to draw a line in any direction from your point, and count the number of times that you cross the boundary of the object. If you hit the boundary an even number of times, you are outside the object, if an odd, you are inside. It is usually easiest to go along one of the axis to make this determination.
Essentially, you just have to find a way to determine if you cross a point. Use the slope of a line equation(m=(y1-y2)/(x1-x2), y=m*x(x-x1)+y1, and see if you cross within the boundaries that the point is valid. Given this equation for the line between the points, determine where your line crosses this line, and figure out if it is within the range of the line.
Incidentally, the same method works for any arbitrary dimension, just determining if you hit the face becomes more difficult.
To show a couple of examples, I've drawn a simple illustration, showing both what happens inside and outside, even with a weird shape.
Incidentally, if you hit a corner, it counts for the number of times you make a transition from inside to outside.
Select a point outside of the polygon. Draw a line between your´s and the point outside. If the line intersects the polygon an odd number of times, its inside, otherwise its outside. Zero intersections are also outside. However, this only workes for non overlapping polygons
It's a known problem with many solutions, just google it.
And read this :
http://en.wikipedia.org/wiki/Point_in_polygon
Take an arbitrary line from your point, to any point definitely outside your polygon (i.e. outside of the bounds). Check how many times that line intersects with one of the edges of your polygon. If the value is odd, the point is inside.
When checking, be careful of lines that go through a vertex, where your test may indicate two edge crossings.

Algorithm for finding empty areas

does anybody know of a good algorithm for this task:
a multi polygon contains the reserved areas
find an empty position for the given polygon which is closest to its original position but does not intersect the reserved areas
I have implemented some very basic algorithm which does the job but far from optimally.
Thank You!
Edit:
my solution basically does the following:
move given polygon in all possible directions dx and dy
check wether the new intersection is less than the previous intersection
if so, use new position and make sure that you don't move your polygon back and forth at the same position
repeat these steps a maximum of N times
Example: it is intended for placing text which should not overlap with each other.
One method that immediately pops into my mind is to shoot a ray (i.e. measure a line segment) from the original position to every vertex of the polygon. Do a comparison on those distances, and then based on those comparisons, narrow it down to the minimally far away line segment of the polygon. Compute the perpendicular intersection of that line with the origin, and you'll get the minimally far away point. If the vertex comparisons don't lead you down the right path, just shoot off lines in random directions, and just stop when you're happy with the result. It doesn't sound like you require optimality.
Let's look at the original problem: making sure that one piece of text doesn't overlap another. Presumably this is for labelling a map. The way I do it is this: draw the text invisibly, checking for overlap (by using a specialised graphics context that instead of drawing a pixel, checks whether a pixel is already there) then try another position along the line on which the text is to be placed - usually a street. I try the middle of the line first, then successive positions further and further left and right of the middle. If that fails I try again with a condensed (narrower) font.

Resources