// XXX: this code assumes that the model is sorted public void FocusNext() { if (!has_focus || focused_plots.Count == 0) { return; } // get the focused value for the first plot LinePlot focus_plot = (LinePlot)focused_plots[0]; TreeModel model; TreeIter focus_iter; if (!focus_plot.GetFocused(out model, out focus_iter)) { return; } if (x_axis == null || y_axis == null) { return; } int focus_x, focus_y; GetPlotPoint(focus_plot, focus_iter, out focus_x, out focus_y); // scour the rest of the plots, searching for values // with a small delta to min_x int min_delta = Int32.MaxValue; ArrayList min_delta_plots = new ArrayList(); ArrayList min_delta_iters = new ArrayList(); foreach (LinePlot plot in plots) { TreeIter iter; if (!plot.Model.GetIterFirst(out iter)) { break; } TreeModel plot_model; TreePath plot_focus_path = null; TreeIter plot_focus_iter = TreeIter.Zero; if (plot.HasFocus && plot.GetFocused(out plot_model, out plot_focus_iter)) { plot_focus_path = plot.Model.GetPath(plot_focus_iter); } do { TreePath path = plot.Model.GetPath(iter); int x, y; if (!GetPlotPoint(plot, iter, out x, out y)) { continue; } // ensure that we always pick points // after the previously focused point, // if this plot had focus if (plot_focus_path != null && path.Compare(plot_focus_path) != 1) { continue; } // continue walking until p_x >= x if (x < focus_x) { continue; } // now, we're at the point right of the // last focused point, so find the // minimal x delta int delta = x - focus_x; if (delta > min_delta) { continue; } if (delta < min_delta) { min_delta_plots.Clear(); min_delta_iters.Clear(); } min_delta = delta; min_delta_plots.Add(plot); min_delta_iters.Add(iter); break; } while (plot.Model.IterNext(ref iter)); } // we must be at the end if (min_delta_plots.Count == 0) { FocusFirst(); return; } FocusIters(min_delta_plots, min_delta_iters); }
public void FocusPrev() { if (!has_focus || focused_plots.Count == 0) { return; } // get the focused value for the first plot LinePlot focus_plot = (LinePlot)focused_plots[0]; TreeModel model; TreeIter focus_iter; if (!focus_plot.GetFocused(out model, out focus_iter)) { return; } if (x_axis == null || y_axis == null) { return; } int focus_x, focus_y; GetPlotPoint(focus_plot, focus_iter, out focus_x, out focus_y); // scour the rest of the plots, searching for values // with a small (negative) delta to min_x int min_delta = Int32.MaxValue; ArrayList min_delta_plots = new ArrayList(); ArrayList min_delta_iters = new ArrayList(); foreach (LinePlot plot in plots) { TreeIter iter; if (!plot.Model.GetIterFirst(out iter)) { break; } TreeModel plot_model; TreePath plot_focus_path = null; TreeIter plot_focus_iter = TreeIter.Zero; if (plot.HasFocus && plot.GetFocused(out plot_model, out plot_focus_iter)) { plot_focus_path = model.GetPath(plot_focus_iter); } TreeIter prev_iter = TreeIter.Zero; do { TreePath path = plot.Model.GetPath(iter); int x, y; if (!GetPlotPoint(plot, iter, out x, out y)) { continue; } // stop when we hit the currently // focused point, if we had focus if (plot_focus_path != null) { if (path.Compare(plot_focus_path) == 0) { break; } } else if (x >= focus_x) { // or stop when we've hit // focus_x, or the nearest // point to it break; } prev_iter = iter; } while (plot.Model.IterNext(ref iter)); // point must have been the first one if (prev_iter.Equals(TreeIter.Zero)) { continue; } // now, we're at the point right before the // last focused point, so find the minimal x // delta int prev_x, prev_y; GetPlotPoint(plot, prev_iter, out prev_x, out prev_y); int delta = focus_x - prev_x; if (delta > min_delta) { continue; } if (delta < min_delta) { min_delta_plots.Clear(); min_delta_iters.Clear(); } min_delta = delta; min_delta_plots.Add(plot); min_delta_iters.Add(prev_iter); } if (min_delta_plots.Count == 0) { FocusLast(); return; } FocusIters(min_delta_plots, min_delta_iters); }
public void Draw(Cairo.Context cr) { if (Allocation.Width == 0 && Allocation.Height == 0) { return; } if (x_axis == null || y_axis == null) { return; } int selection_x = -1; if (has_selection && selected_plots.Count > 0) { // get the x of the first focused point, and // then draw a line from top to bottom // connecting all focused points LinePlot first_plot = (LinePlot)selected_plots[0]; TreeIter iter; TreeModel model; first_plot.GetSelected(out model, out iter); int x, y; GetPlotPoint(first_plot, iter, out x, out y); style.DrawLinkedSelectionLine(cr, x, Allocation.Y, x, Allocation.Y + Allocation.Height); selection_x = x; } if (has_focus && focused_plots.Count > 0) { // get the x of the first focused point, and // then draw a line from top to bottom // connecting all focused points LinePlot first_plot = (LinePlot)focused_plots[0]; TreeIter iter; TreeModel model; first_plot.GetFocused(out model, out iter); int x, y; GetPlotPoint(first_plot, iter, out x, out y); if (x != selection_x) { style.DrawLinkedFocusLine(cr, x, Allocation.Y, x, Allocation.Y + Allocation.Height); } } foreach (LinePlot plot in plots) { plot.SizeAllocate(Allocation); plot.SetAxes(axes); plot.Draw(cr); } }