[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/gnuplot/gnuplot-old/origin/term/js/gnuplot_mouse.js [Back]  [Original]

/*
 * $Id: gnuplot_mouse.js,v 1.28 2017-02-17 21:27:53 sfeam Exp $
 */
    gnuplot.mouse_version = " 17 February 2017";

// Mousing code for use with gnuplot's 'canvas' terminal driver.
// The functions defined here assume that the javascript plot produced by
// gnuplot initializes the plot boundary and scaling parameters.

    gnuplot.mousex = 0;
    gnuplot.mousey = 0;
    gnuplot.plotx = 0;
    gnuplot.ploty = 0;
    gnuplot.scaled_x = 0;
    gnuplot.scaled_y = 0;

// These will be initialized by the gnuplot canvas-drawing function
    gnuplot.plot_xmin = 0;
    gnuplot.plot_xmax = 0;
    gnuplot.plot_ybot = 0;
    gnuplot.plot_ytop = 0;
    gnuplot.plot_width  = 0
    gnuplot.plot_height = 0
    gnuplot.plot_term_ymax = 0;
    gnuplot.plot_axis_xmin = 0;
    gnuplot.plot_axis_xmax = 0;
    gnuplot.plot_axis_width  = 0;
    gnuplot.plot_axis_height = 0;
    gnuplot.plot_axis_ymin = 0;
    gnuplot.plot_axis_ymax = 0;
    gnuplot.plot_axis_x2min = "none";
    gnuplot.plot_axis_y2min = "none";
    gnuplot.plot_logaxis_x = 0;
    gnuplot.plot_logaxis_y = 0;
    gnuplot.grid_lines = true;
    gnuplot.zoom_text = false;
    gnuplot.display_is_uptodate = false;

// These are the equivalent parameters while zooming
    gnuplot.zoom_axis_xmin = 0;
    gnuplot.zoom_axis_xmax = 0;
    gnuplot.zoom_axis_ymin = 0;
    gnuplot.zoom_axis_ymax = 0;
    gnuplot.zoom_axis_x2min = 0;
    gnuplot.zoom_axis_x2max = 0;
    gnuplot.zoom_axis_y2min = 0;
    gnuplot.zoom_axis_y2max = 0;
    gnuplot.zoom_axis_width = 0;
    gnuplot.zoom_axis_height = 0;
    gnuplot.zoom_temp_xmin = 0;
    gnuplot.zoom_temp_ymin = 0;
    gnuplot.zoom_temp_x2min = 0;
    gnuplot.zoom_temp_y2min = 0;
    gnuplot.zoom_in_progress = false;

    gnuplot.full_canvas_image = null;
    gnuplot.axisdate = new Date();

gnuplot.init = function ()
{
  if (document.getElementById("gnuplot_canvas"))
      document.getElementById("gnuplot_canvas").onmousemove = gnuplot.mouse_update;
  if (document.getElementById("gnuplot_canvas"))
      document.getElementById("gnuplot_canvas").onmouseup = gnuplot.zoom_in;
  if (document.getElementById("gnuplot_canvas"))
      document.getElementById("gnuplot_canvas").onmousedown = gnuplot.saveclick;
  if (document.getElementById("gnuplot_canvas"))
      document.getElementById("gnuplot_canvas").onkeydown = gnuplot.do_hotkey;
  if (document.getElementById("gnuplot_grid_icon"))
      document.getElementById("gnuplot_grid_icon").onmouseup = gnuplot.toggle_grid;
  if (document.getElementById("gnuplot_textzoom_icon"))
      document.getElementById("gnuplot_textzoom_icon").onmouseup = gnuplot.toggle_zoom_text;
  if (document.getElementById("gnuplot_rezoom_icon"))
      document.getElementById("gnuplot_rezoom_icon").onmouseup = gnuplot.rezoom;
  if (document.getElementById("gnuplot_unzoom_icon"))
      document.getElementById("gnuplot_unzoom_icon").onmouseup = gnuplot.unzoom;
  gnuplot.mouse_update();
}

gnuplot.getMouseCoordsWithinTarget = function(event)
{
	var coords = { x: 0, y: 0};

	if(!event) // then we're in a non-DOM (probably IE) browser
	{
		event = window.event;
		if (event) {
			coords.x = event.offsetX;
			coords.y = event.offsetY;
		}
	}
	else		// we assume DOM modeled javascript
	{
		var Element = event.target ;
		var CalculatedTotalOffsetLeft = 0;
		var CalculatedTotalOffsetTop = 0 ;

		while (Element.offsetParent)
 		{
 			CalculatedTotalOffsetLeft += Element.offsetLeft ;     
			CalculatedTotalOffsetTop += Element.offsetTop ;
 			Element = Element.offsetParent ;
 		}

		coords.x = event.pageX - CalculatedTotalOffsetLeft ;
		coords.y = event.pageY - CalculatedTotalOffsetTop ;
	}

	gnuplot.mousex = coords.x;
	gnuplot.mousey = coords.y;
}


gnuplot.mouse_update = function(e)
{
  gnuplot.getMouseCoordsWithinTarget(e);

  gnuplot.plotx = gnuplot.mousex - gnuplot.plot_xmin;
  gnuplot.ploty = -(gnuplot.mousey - gnuplot.plot_ybot);

  // Limit tracking to the interior of the plot
  if (gnuplot.plotx < 0 || gnuplot.ploty < 0){
      if (gnuplot.hypertext_list != "undefined" && gnuplot.hypertext_list.length > 0) {
	  gnuplot.check_hypertext();
      } 
      return;
  }
  if (gnuplot.mousex > gnuplot.plot_xmax || gnuplot.mousey < gnuplot.plot_ytop){
      if (gnuplot.hypertext_list != "undefined" && gnuplot.hypertext_list.length > 0) {
	  gnuplot.check_hypertext();
      } 
      return;
  }

  var axis_xmin = (gnuplot.zoomed) ? gnuplot.zoom_axis_xmin : gnuplot.plot_axis_xmin;
  var axis_xmax = (gnuplot.zoomed) ? gnuplot.zoom_axis_xmax : gnuplot.plot_axis_xmax;
  var axis_ymin = (gnuplot.zoomed) ? gnuplot.zoom_axis_ymin : gnuplot.plot_axis_ymin;
  var axis_ymax = (gnuplot.zoomed) ? gnuplot.zoom_axis_ymax : gnuplot.plot_axis_ymax;

    if (gnuplot.plot_logaxis_x != 0) {
	x = Math.log(axis_xmax) - Math.log(axis_xmin);
	x = x * (gnuplot.plotx / (gnuplot.plot_xmax-gnuplot.plot_xmin)) + Math.log(axis_xmin);
	x = Math.exp(x);
    } else {
	x =  axis_xmin + (gnuplot.plotx / (gnuplot.plot_xmax-gnuplot.plot_xmin)) * (axis_xmax - axis_xmin);
    }

    if (gnuplot.plot_logaxis_y != 0) {
	y = Math.log(axis_ymax) - Math.log(axis_ymin);
	y = y * (-gnuplot.ploty / (gnuplot.plot_ytop-gnuplot.plot_ybot)) + Math.log(axis_ymin);
	y = Math.exp(y);
    } else {
	y =  axis_ymin - (gnuplot.ploty / (gnuplot.plot_ytop-gnuplot.plot_ybot)) * (axis_ymax - axis_ymin);
    }

    if (gnuplot.plot_axis_x2min != "none") {
	gnuplot.axis_x2min = (gnuplot.zoomed) ? gnuplot.zoom_axis_x2min : gnuplot.plot_axis_x2min;
	gnuplot.axis_x2max = (gnuplot.zoomed) ? gnuplot.zoom_axis_x2max : gnuplot.plot_axis_x2max;
	if (gnuplot.x2_mapping != undefined)
	    x2 = gnuplot.x2_mapping(x);
	else
	    x2 =  gnuplot.axis_x2min + (gnuplot.plotx / (gnuplot.plot_xmax-gnuplot.plot_xmin)) * (gnuplot.axis_x2max - gnuplot.axis_x2min);
	if (document.getElementById(gnuplot.active_plot_name + "_x2"))
	    document.getElementById(gnuplot.active_plot_name + "_x2").innerHTML = x2.toPrecision(4);
    }
    if (gnuplot.plot_axis_y2min != "none") {
	gnuplot.axis_y2min = (gnuplot.zoomed) ? gnuplot.zoom_axis_y2min : gnuplot.plot_axis_y2min;
	gnuplot.axis_y2max = (gnuplot.zoomed) ? gnuplot.zoom_axis_y2max : gnuplot.plot_axis_y2max;
	if (gnuplot.y2_mapping != undefined)
	    y2 = gnuplot.y2_mapping(y);
	else
	    y2 = gnuplot.axis_y2min - (gnuplot.ploty / (gnuplot.plot_ytop-gnuplot.plot_ybot)) * (gnuplot.axis_y2max - gnuplot.axis_y2min);
	if (document.getElementById(gnuplot.active_plot_name + "_y2"))
	    document.getElementById(gnuplot.active_plot_name + "_y2").innerHTML = y2.toPrecision(4);
    }
  
  var label_x, label_y;
  if (gnuplot.polar_mode) {
    var polar = gnuplot.convert_to_polar(x,y);
    label_x = "ang= " + polar.ang.toPrecision(4);
    label_y = "R= " + polar.r.toPrecision(4);
  } else {
    if (typeof(gnuplot.plot_timeaxis_x) == "string" && gnuplot.plot_timeaxis_x != "")
      label_x = gnuplot.datafmt(x);
    else
      label_x = x.toPrecision(4);
    if (typeof(gnuplot.plot_timeaxis_y) == "string" && gnuplot.plot_timeaxis_y != "")
      label_y = gnuplot.datafmt(y);
    else
      label_y = y.toPrecision(4);
  }

  if (document.getElementById(gnuplot.active_plot_name + "_x"))
      document.getElementById(gnuplot.active_plot_name + "_x").innerHTML = label_x;
  if (document.getElementById(gnuplot.active_plot_name + "_y"))
      document.getElementById(gnuplot.active_plot_name + "_y").innerHTML = label_y;

  // Echo the zoom box interactively
  if (gnuplot.zoom_in_progress) {
    // Clear previous box before drawing a new one
    if (gnuplot.full_canvas_image == null) {
      gnuplot.full_canvas_image = ctx.getImageData(0,0,canvas.width,canvas.height);
    } else {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.putImageData(gnuplot.full_canvas_image,0,0);
    }
    ctx.strokeStyle="rgba(128,128,128,0.60)";
    var x0 = gnuplot.plot_xmin + gnuplot.zoom_temp_plotx;
    var y0 = gnuplot.plot_ybot - gnuplot.zoom_temp_ploty;
    var w = gnuplot.plotx - gnuplot.zoom_temp_plotx;
    var h = -(gnuplot.ploty - gnuplot.zoom_temp_ploty);
    if (w

Web Proxy Viewer  |  New URL  |  Original Page