0

I am working on a UserControl which displays many line segments. This is done with a GraphicsPath.

When the user moves the mouse a hittest is done to check if it is over any of the line segments, the cursor is changed accordingly, the line can then be clicked.

As long as there are few segments (as in the left example) this works OK and makes sense.
But when there are more and more segments, the hittest becomes senseless and of course very slow (in the example there are 75, 750 and 2500 segments).

sample

What strategy could I use to avoid useless testing and simplify the path if it becomes "dense"?

The line segments are of unknown pattern, they may not be of obvious rectangular outline, but are always some kind of data chart as in the example image.

WarpEnterprises
  • 155
  • 1
  • 8
  • 1
    If the graph is extremely dense (as in, moving a single pixel could move it on or off the graph) then changing the cursor to indicate clickability isn't of much use in the first place. Nobody wants to inch the mouse in a pixel perfect fashion for a click. Do you need to identify *which* segment was clicked and if so, why? Could you come up with a simpler interface for that that is always invoked if the number of segments becomes large? – Jeroen Mostert Feb 22 '17 at 13:31
  • Did you consider using the MSChart control? Also: What do you mean by 'simplifying' the path?? – TaW Feb 22 '17 at 13:36
  • I don't need which segment is under the cursor. If the graph is dense it would be enough to check if the mouse is over a painted pixel. A "simplified" path in the right example would be the whole rectangle or the outline of all painted pixel. But as I wrote this is a simple example. Other cartcontrols are no option. – WarpEnterprises Feb 22 '17 at 14:35
  • Hm, you could grab a bitmap holding a copy of the pixels (DrawToBitmap) and use a GetPixel. This would probably be a lot faster to test if you hit and only then do the real hittest to find oput where you hit.. – TaW Feb 22 '17 at 14:38
  • My point is that you don't even need to check if you're over a pixel! If the graph is *that* dense, you may as well assume the user has just clicked on some part of the graph. In fact, there's no reason to bother with the hit testing at all unless you need to distinguish it from the user clicking on the background -- which even the *user* will not be able to do if it's that dense. Hence my suggestion for an alternate interface if you do not, in fact, need to know exactly what part of the graph they clicked on (or the user wouldn't be able to click precisely anyway). – Jeroen Mostert Feb 22 '17 at 15:23

0 Answers0