Exemplo n.º 1
0
        private void CommitDrag(Point pt, bool finegrained)
        {
            if (d_draggingLine != null)
            {
                Point dpt  = d_dataLine[d_draggingData];
                Point axis = d_graph.Graph.PixelToAxis(pt);

                if (d_graph.Graph.SnapRulerToAxis)
                {
                    int factor = d_graph.Graph.SnapRulerToAxisFactor;

                    if (finegrained)
                    {
                        factor *= 2;
                    }

                    axis = d_graph.Graph.SnapToAxis(axis, factor);
                }

                if (!dpt.MarginallyEquals(axis))
                {
                    // Store new data
                    List <Point> data = new List <Point>(d_dataLine.Data);
                    data[d_draggingData] = axis;

                    // Then update the original data
                    UpdatePieces(data);
                }

                d_graph.Graph.Remove(d_draggingLine);
                d_draggingLine = null;
            }

            d_draggingData = -1;
        }
Exemplo n.º 2
0
        private void UpdateDragging(Point pt, bool finegrained)
        {
            // Check if we moved something
            Point dpt  = d_dataLine[d_draggingData];
            Point axis = d_graph.Graph.PixelToAxis(pt);

            if (d_graph.Graph.SnapRulerToAxis)
            {
                int factor = d_graph.Graph.SnapRulerToAxisFactor;

                if (finegrained)
                {
                    factor *= 2;
                }

                axis = d_graph.Graph.SnapToAxis(axis, factor);
            }

            if (dpt.MarginallyEquals(axis))
            {
                return;
            }

            if (d_draggingLine == null)
            {
                d_draggingLine = d_dataLine.Copy() as Plot.Renderers.Line;

                d_draggingLine.Color        = d_graph.Graph.ColorMap[1];
                d_draggingLine.LineStyle    = Plot.Renderers.LineStyle.Dotted;
                d_draggingLine.YLabel       = null;
                d_draggingLine.YLabelMarkup = null;

                d_graph.Graph.Add(d_draggingLine);
            }

            List <Point> data = new List <Point>(d_dataLine.Data);

            data[d_draggingData] = axis;

            Plot.Renderers.Bezier bezier = d_draggingLine as Plot.Renderers.Bezier;

            if (bezier != null)
            {
                // Do interpolation again on data
                Biorob.Math.Interpolation.PChip pchip = new Biorob.Math.Interpolation.PChip();
                bezier.PiecewisePolynomial = pchip.Interpolate(data);
            }
            else
            {
                d_draggingLine.Data = data;
            }
        }
Exemplo n.º 3
0
        private void UpdatePreview()
        {
            if (d_ignoreUpdatePreview)
            {
                return;
            }

            foreach (Plot.Renderers.Line line in d_previewLines)
            {
                d_graph.Graph.Remove(line);
            }

            d_previewLines.Clear();
            d_dataLine = null;

            d_iscubic = true;
            List <Biorob.Math.Functions.PiecewisePolynomial.Piece> pieces = new List <Biorob.Math.Functions.PiecewisePolynomial.Piece>();

            // Determine if we are going to draw cubics or just sampled
            foreach (Cdn.FunctionPolynomialPiece piece in d_function.Pieces)
            {
                if (piece.Coefficients.Length != 4)
                {
                    d_iscubic = false;
                }

                pieces.Add(new Biorob.Math.Functions.PiecewisePolynomial.Piece(new Biorob.Math.Range(piece.Begin, piece.End), piece.Coefficients));
            }

            Biorob.Math.Range period = DeterminePeriod(pieces);

            if (period != null)
            {
                d_period.Text = (period.Max - period.Min).ToString();
            }
            else
            {
                d_period.Text = "";
            }

            Biorob.Math.Functions.PiecewisePolynomial poly;
            poly = new Biorob.Math.Functions.PiecewisePolynomial(pieces);

            double msize = 8;
            int    lw    = 2;

            Plot.Renderers.MarkerStyle mtype = Plot.Renderers.MarkerStyle.FilledCircle;

            if (poly.Count == 0 && d_lastAddedData != null)
            {
                List <Point> data = new List <Point>();
                data.Add(d_lastAddedData);

                Plot.Renderers.Line line = new Plot.Renderers.Line {
                    Data = data, Color = d_graph.Graph.ColorMap[0], YLabel = "preview"
                };
                line.MarkerSize  = msize;
                line.MarkerStyle = mtype;
                line.LineWidth   = lw;

                d_graph.Graph.Add(line);
                d_previewLines.Add(line);

                d_dataLine = line;
            }
            else if (d_iscubic && poly.Count != 0)
            {
                // If it's cubic, then use the bezier line
                Plot.Renderers.Bezier bezier = new Plot.Renderers.Bezier {
                    PiecewisePolynomial = poly, Color = d_graph.Graph.ColorMap[0], YLabel = "preview"
                };

                bezier.Periodic    = period;
                bezier.MarkerSize  = msize;
                bezier.MarkerStyle = mtype;
                bezier.LineWidth   = lw;

                d_graph.Graph.Add(bezier);
                d_previewLines.Add(bezier);

                d_dataLine = bezier;
            }
            else if (poly.Count != 0)
            {
                // Otherwise use two lines, one with markers, the other sampled
                Plot.Renderers.Line line = new Plot.Renderers.Line {
                    YLabel = "preview"
                };
                line.Color     = d_graph.Graph.ColorMap[0];
                line.LineWidth = lw;

                if (pieces.Count > 0)
                {
                    line.GenerateData(new Biorob.Math.Range(pieces[0].Begin, pieces[pieces.Count - 1].End),
                                      1000,
                                      x => new Biorob.Math.Point(x, poly.Evaluate(x)));
                }

                d_graph.Graph.Add(line);

                Plot.Renderers.Line markers = new Plot.Renderers.Line();
                markers.Color       = line.Color;
                markers.MarkerSize  = msize;
                markers.MarkerStyle = mtype;

                List <Point> data = new List <Point>();

                foreach (Biorob.Math.Functions.PiecewisePolynomial.Piece piece in pieces)
                {
                    data.Add(new Point(piece.Begin, piece.Coefficients[piece.Coefficients.Length - 1]));
                }

                if (pieces.Count > 0)
                {
                    Biorob.Math.Functions.PiecewisePolynomial.Piece piece = pieces[pieces.Count - 1];
                    data.Add(new Point(piece.End, piece.Coefficients.Sum()));
                }

                d_graph.Graph.Add(markers);

                d_previewLines.Add(line);
                d_previewLines.Add(markers);

                d_dataLine = markers;
            }
        }