EDGE Online Grapher

$v) { if ($query != '') { $query .= '&'; } $query .= urlencode($k); $query .= '='; $query .= urlencode($v); } return $query; } // Create an html link to the given relation. function link_rel($rel) { global $forceiphone; echo '', htmlspecialchars($rel), ''; } // Build the URL to the currently graphed relation, including the window. function url_current() { global $forceiphone; global $reln, $xmin, $xmax, $ymin, $ymax, $undefined, $axes, $slices, $nmin, $nmax, $ncurrent; $url_parameters = array('reln'=>$reln, 'xmin'=>$xmin, 'xmax'=>$xmax, 'ymin'=>$ymin, 'ymax'=>$ymax); if ($undefined) { $url_parameters['undefined'] = 1; } if ($axes) { $url_parameters['axes'] = 1; } if ($slices) { $url_parameters['nmin'] = $nmin; $url_parameters['nmax'] = $nmax; $url_parameters['ncurrent'] = $ncurrent; } if ($forceiphone != false) { $url_parameters['forceiphone'] = $forceiphone; } return $_SERVER['SCRIPT_URL'] . '?' . my_http_build_query($url_parameters); } // --------------------------------------------------------------------------- // REQUEST PARSING // --------------------------------------------------------------------------- $reln = ''; $undefined = 0; $axes = 0; $xmin = ''; $xmax = ''; $ymin = ''; $ymax = ''; // Request may come from form (post) or direct URL (get), so use $_REQUEST. if (isset($_REQUEST['reln'])) { $reln = strtolower($_REQUEST['reln']); } if (!isset($_REQUEST['clear_x']) and isset($_REQUEST['xmin'])) { $xmin = $_REQUEST['xmin']; $xmax = $_REQUEST['xmax']; $ymin = $_REQUEST['ymin']; $ymax = $_REQUEST['ymax']; if (isset($_REQUEST['undefined'])) { $undefined = 1; } if (isset($_REQUEST['axes'])) { $axes = 1; } } // Default window, if none is provided. if ($xmin == '') $xmin = XMIN_DEFAULT; if ($xmax == '' || $xmin >= $xmax) $xmax = XMAX_DEFAULT; if ($ymin == '') $ymin = YMIN_DEFAULT; if ($ymax == '' || $ymin >= $ymax) $ymax = YMAX_DEFAULT; if (isset($_REQUEST['point_x'])) { // Center on the mouse pointer position. $x1 = $_REQUEST['point_x'] - 1; $y1 = $_REQUEST['point_y'] - 1; $dx = $xmax - $xmin; $dy = $ymax - $ymin; $divx = ($xmax - $xmin) / ((VIEWER_WIDTH -1) * 1.0) ; $divy = ($ymax - $ymin) / ((VIEWER_HEIGHT -1) * 1.0); $x1 = ($x1 * $divx) + $xmin; $y1 = $ymax - ($y1 * $divy); $xmin = $x1 - ($dx / 2.0); $xmax = $xmin + $dx; $ymin = $y1 - ($dy / 2.0); $ymax = $ymin + $dy; } if (isset($_REQUEST['zoomplus_x'])) { $dex = (($xmax - $xmin) / 2.0 ) * (1.0 - (1.0 / ZOOM_FACTOR)); $dey = (($ymax - $ymin) / 2.0 ) * (1.0 - (1.0 / ZOOM_FACTOR)); $xmin = $xmin + $dex; $xmax = $xmax - $dex; $ymin = $ymin + $dey; $ymax = $ymax - $dey; } if (isset($_REQUEST['zoomminus_x'])) { $dex = (($xmax - $xmin) / 2.0 ) * (1.0 - (1.0 / (1.0 / ZOOM_FACTOR))); $dey = (($ymax - $ymin) / 2.0 ) * (1.0 - (1.0 / (1.0 / ZOOM_FACTOR))); $xmin = $xmin + $dex; $xmax = $xmax - $dex; $ymin = $ymin + $dey; $ymax = $ymax - $dey; } if (isset($_REQUEST['left_x'])) { $dex = ($xmax - $xmin) / 4.0; $xmin = $xmin - $dex; $xmax = $xmax - $dex; } if (isset($_REQUEST['right_x'])) { $dex = ($xmax - $xmin) / 4.0; $xmin = $xmin + $dex; $xmax = $xmax + $dex; } if (isset($_REQUEST['up_x'])) { $dey = ($ymax - $ymin) / 4.0; $ymin = $ymin + $dey; $ymax = $ymax + $dey; } if (isset($_REQUEST['down_x'])) { $dey = ($ymax - $ymin) / 4.0; $ymin = $ymin - $dey; $ymax = $ymax - $dey; } // --------------------------------------------------------------------------- // GRAPH GENERATION // --------------------------------------------------------------------------- // Check for a valid relation. Add 'y=' or 'x=' if needed. if ($reln != '') { if ((strstr($reln, '=') == false) && (strstr($reln, '<') == false) && (strstr($reln, '>') == false)) { // Not a relation! if (strstr($reln, 'y') == false) { // No 'y' -> Just add 'y=' in front of the expression. $reln = 'y=' . $reln; } elseif (strstr($reln, 'x') == false) { // 'y' but no 'x' -> Just add 'x=' in front of the expression. $reln = 'x=' . $reln; } } } // Check syntax. $slices = false; if (preg_match("/\bn\b/i", $reln)) { $slices = true; $image = generate_tile(preg_replace("/\bn\b/i", '0', $reln), 1/PIXELS_PER_UNIT, 1/PIXELS_PER_UNIT, 0, 0, 0, 0); $nmin = 0; $nmax = 8; $ncurrent = -1; if (isset($_REQUEST['nmin'])) { $nmin = $_REQUEST['nmin']; } if (isset($_REQUEST['nmax'])) { $nmax = $_REQUEST['nmax']; } if (isset($_REQUEST['ncurrent'])) { $ncurrent = $_REQUEST['ncurrent']; } } else { $image = generate_tile($reln, 1/PIXELS_PER_UNIT, 1/PIXELS_PER_UNIT, 0, 0, 0, 0); } $is_relation_valid = ($image != ''); // Definitions: // - viewer: graphic area where graph appears on web page; fixed size and position on page. // - block: collection of tiles, with enough tiles to cover the viewer; it will move relative to the viewer. // - tile: one image containing a subset of the graph; it is fixed within the submap. // Number of tiles needed to fill the viewer with tiles. $number_tiles_x = ceil(VIEWER_WIDTH / TILE_WIDTH ) + 1; $number_tiles_y = ceil(VIEWER_HEIGHT / TILE_HEIGHT) + 1; // Scale of the graph. $scalex = ($xmax - $xmin) / (VIEWER_WIDTH - 1); $scaley = ($ymax - $ymin) / (VIEWER_HEIGHT - 1); // Index of the top-left tile. $left_indexx = floor(($xmin / $scalex + (floor(TILE_WIDTH / 2) + 0.5)) / TILE_WIDTH); $top_indexy = floor(($ymax / $scaley + (floor(TILE_HEIGHT / 2) + 0.5)) / TILE_HEIGHT); // Coordinates of middle of top-left pixel in block. $block_left_x = ($left_indexx * TILE_WIDTH - floor(TILE_WIDTH / 2)) * $scalex; $block_top_y = (($top_indexy + 1) * TILE_HEIGHT - floor(TILE_HEIGHT / 2) - 1) * $scaley; // Initial position of block, so that given window range is what appears in viewer. $block_left = round(($block_left_x - $xmin) / $scalex); $block_top = round(($ymax - $block_top_y) / $scaley); // --------------------------------------------------------------------------- // MAIN PAGE // --------------------------------------------------------------------------- ?>
'; } ?>
Relation to be graphed:      (e.g., )
Window x: /> ... />
  y: /> ... />
 

 

checked style="font-size:8px;" />Find undefined regions   checked />Draw axes on top of graph
  ' . TOOLTIPTXT . ''; } else if ($reln != "") { echo SYNTAX_ERROR; } ?>
     
align="center" valign="middle">
'; // Tiles are fixed in a grid inside the viewer. for ($row = 0; $row < $number_tiles_y; $row++) { $top = $row * TILE_HEIGHT; for ($column = 0; $column < $number_tiles_x; $column++) { $left = $column * TILE_WIDTH; echo ''; } } echo '
'; // End of block. ?>
'; } } ?>
     
  Link to this page
n= decrease n 0 1 2 3 4 5 6 7 8 increase n
', UNDEFINED_TEXT; } } ?>

 

Please enter a valid relation in the field above.

Examples:

Limitations in this demo:

  • Implicit multiplication isn’t supported:
    eg. use 2*x not 2x
  • The only supported library functions are:
    • abs(x)
    • ln(x)
    • sqrt(x)
    • sin(x)
    • cos(x)
    • asin(x)
    • acos(x)
    • tan(x)
    • atan(x)