Jump to content

PHP Graphing -- !($faint-hearted); how to determine overlaps and overcome them


thepip3r

Recommended Posts

so i'm writing a wrote a page that displays a graph:

 

http://www.zigsdigs.com/trigeo/graphDisplay.php

 

all you'll see is the default values, not actual data because no form was submitted.  BUT, here you can kind of see my problem.  i'm writing the actual number values on top of the graph points.  but sometimes, the lines overwrite the word or the points are too close on the chart that they overlap each other.  i'm not asking for code... just an idea on how to go about fixing this issue?

 

i was thinking about possibly trying to figure out a calculation for overlap using point-to-point slope  with some calc to see if a point would lie on a line, x,y coord with strlen to see the total space taken up by a text image, etc. 

 

can anyone describe a better way ?? TIA!

One thing you can do is check the slope of the next line you are going to draw. If the next line is going to go upwards, place the text underneath the dot. Inversely, if it is going to go downwards, place the text above the dot. (If the slope is zero you probably want to put it on the opposite side than the previous one.) Also, since it is a graph, the previous line is always going to be on the left side so you might also want to offset the number to the right slightly.

 

As for them being too close together; there should always be a static horizontal distance between them all shouldn't there?

yes and there is... but it is not so static as it is based off of a calculation of the number of points to be placed on the graph... maybe i should include some "minimum distance" or something along that order.

 

ty for the very simplistic logic on how to orient the texts.  greatly appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.