예제 #1
0
            /// <summary>
            /// Creates a plot line instance (if necessary)
            /// </summary>
            /// <param name="source">The data chart the line is a part of</param>
            private void CreatePlotLine(DataChart source)
            {
                // Ensure the data has been generated
                if (Data.Columns.Contains(Expression))
                {
                    // Remove any previous plot
                    if (Plot != null)
                    {
                        Plot.Remove(source);
                        Plot = null;
                    }

                    // Create a new plot
                    PlotLineCreator creator;
                    Type            expressionType = Data.Columns[Expression].DataType;
                    if (!LineCreators.TryGetValue(expressionType, out creator))
                    {
                        creator = DefaultCreator;
                    }
                    bool   preserveAxisPosition = (source.Plot.XAxis1 != null);
                    double worldMin             = preserveAxisPosition ? source.Plot.XAxis1.WorldMin : 0;
                    double worldMax             = preserveAxisPosition ? source.Plot.XAxis1.WorldMax : 0;
                    Plot = creator(source, this);
                    Plot.SetData(Data);
                    Plot.Color = Color;
                    if (preserveAxisPosition)
                    {
                        source.Plot.XAxis1.WorldMin = worldMin;
                        source.Plot.XAxis1.WorldMax = worldMax;
                    }
                }
            }
예제 #2
0
            /// <summary>
            /// Sets a new expression for the plot line
            /// </summary>
            /// <param name="source">The data source</param>
            /// <param name="expression">The new expression to set</param>
            public void SetExpression(DataChart <T> source, string expression)
            {
                System.Drawing.Color c;
                if (Plot != null)
                {
                    c = this.Color;
                    Plot.Remove(source);
                    Plot = null;
                }
                else
                {
                    c = source.PlotLineColors.Dequeue();
                    source.PlotLineColors.Enqueue(c);   // Add the color to the end of the list so that it can be re-used if needed
                }

                this.Expression = expression;
                this.GetValue   = getExpressionEvaluator(expression);
                Generate(source);

                PlotLineCreator creator;

                if (!LineCreators.TryGetValue(source.getExpressionType(Expression, GetValue), out creator))
                {
                    creator = DefaultCreator;
                }
                bool   preserveAxisPosition = (source.Plot.XAxis1 != null);
                double worldMin             = preserveAxisPosition ? source.Plot.XAxis1.WorldMin : 0;
                double worldMax             = preserveAxisPosition ? source.Plot.XAxis1.WorldMax : 0;

                Plot       = creator(source, this);
                this.Color = c;
                if (preserveAxisPosition)
                {
                    source.Plot.XAxis1.WorldMin = worldMin;
                    source.Plot.XAxis1.WorldMax = worldMax;
                }
            }