public PlotLine(DataChart <T> source, string symbol, string expression) { this.Symbol = symbol; // Set the expression and create the corresponding plot line SetExpression(source, expression); }
/// <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; } } }
public PlotLine(DataChart source, string symbol, string expression) { this.Symbol = symbol; // Get a color for the plot line Color = source.PlotLineColors.Dequeue(); source.PlotLineColors.Enqueue(Color); // Add the color to the end of the list so that it can be re-used if needed // Set the expression and create the corresponding plot line SetExpression(source, expression); }
public LinePlotContainer(DataChart source, PlotLine line) : base(source) { Plot = new LinePlot(); Plot.DataSource = line.Data; Plot.AbscissaData = source.XAxis; Plot.OrdinateData = line.Expression; this.Expression = line.Expression; plotInterface = Plot; PlotYAxis = new Axis(); source.Plot.Add(Plot, XAxisPosition.Bottom, YAxisPosition.Left, 0, null, PlotYAxis); }
public PointPlotContainer(DataChart <T> source, PlotLine line) : base(source) { Plot = new NPlot.PointPlot(); Plot.DataSource = line.Data; Plot.AbscissaData = source.XAxis; Plot.OrdinateData = line.Expression; Plot.Marker.Type = Marker.MarkerType.Circle; this.Expression = line.Expression; plotInterface = Plot; PlotYAxis = new Axis(); source.Plot.Add(Plot, XAxisPosition.Bottom, YAxisPosition.Left, 0, null, PlotYAxis); }
/// <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 source, string expression) { this.Expression = expression; if (!string.IsNullOrEmpty(expression)) { // Attempt to generate the data table for the given expression this.GetValue = source.getExpressionEvaluator(expression); Generate(source); } if (ExpressionChanged != null) { ExpressionChanged(this); } }
/// <summary> /// Generates the data to use in the plot line /// </summary> /// <param name="source"></param> public void Generate(DataChart <T> source) { this.Data = new DataTable(); Data.Columns.Add(source.XAxis, source.getExpressionType(source.XAxis, source.XAxisGetValue)); Data.Columns.Add(Expression, source.getExpressionType(Expression, GetValue)); List <string> symbols = source.GetSymbolList(Symbol); foreach (var s in symbols) { List <StockDataSet <T> > sources; if (!source.DataSets.TryGetValue(s, out sources)) { return; } // Create a table of each data point in the specified range for (int i = 0; i < sources.Count; i++) { if (sources[i].Start >= source.Start) { sources[i].Load(source.Session); for (int j = 0; j < sources[i].Count; j++) { if (sources[i].Time(j) <= source.End) { // Add the point to the table Data.Rows.Add(source.XAxisGetValue(sources[i], j), GetValue(sources[i], j)); } else { break; } } } } } // Update the line plot data if (Plot != null) { Plot.SetData(Data); } }
/// <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; } }
public override void Remove(DataChart source) { source.Plot.Remove(Plot, false); }
/// <summary> /// Creates an appropriate type of /// </summary> /// <returns>The created plot line</returns> protected static PlotContainer DefaultCreator(DataChart source, PlotLine line) { return(source.XAxis.Equals("Time") ? (PlotContainer) new LinePlotContainer(source, line) : new PointPlotContainer(source, line)); }
public abstract void Remove(DataChart source);
public PlotContainer(DataChart chart) { this.Chart = chart; }
/// <summary> /// Generates the data to use in the plot line /// </summary> /// <param name="source"></param> public void Generate(DataChart source) { DataMutex.WaitOne(); List <string> symbols = source.GetSymbolList(Symbol); this.Data = new DataTable(); foreach (var s in symbols) { List <StockDataInterface> sources; if (!source.getDataList(s, out sources) || (GetValue == null)) { break; } // Load the sources first (need to load to the end before accessing the data since loading later sources could backfill data) */ for (int i = 0; i < sources.Count; i++) { sources[i].Load(source.Session); } // Ensure columns are added for the data types if (Data.Columns.Count < 2) { Data.Columns.Add(source.XAxis, source.XAxisGetValue(sources[0], 0).GetType()); Data.Columns.Add(Expression, GetValue(sources[0], 0).GetType()); } // Create a table of each data point in the specified range for (int i = 0; i < sources.Count; i++) { string symbol; DateTime start; TimeSpan interval; sources[i].GetInfo(out symbol, out start, out interval); if (start >= source.Start) { // Add the data set to the table for (int j = 0; j < sources[i].GetCount(); j++) { if (start.AddSeconds(interval.TotalSeconds * j) <= source.End) { // Add the point to the table Data.Rows.Add(source.XAxisGetValue(sources[i], j), GetValue(sources[i], j)); } else { break; } } } } } // Update the line plot data CreatePlotLine(source); if (Plot != null) { Plot.SetData(Data); } DataMutex.ReleaseMutex(); }