private void InterpolationSeries_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { return; } var data = this.Chart.ConvertPointToData(e.MouseDevice.GetPosition(this.Chart)); if (data.FirstValue == null || data.SecondValue == null || (double)data.SecondValue > this.SelectedVertex.SafeMax || (double)data.SecondValue < this.SelectedVertex.SafeMin) { return; } var mousePoint = new ScatterDataPoint { XValue = (double)data.FirstValue, YValue = (double)data.SecondValue }; if (this.capturedPoint != null) { var newPoint = new ScatterDataPoint { XValue = this.capturedPoint.XValue, YValue = mousePoint.YValue }; ((sender as ScatterLineSeries).DataContext as ObservableCollection <ScatterDataPoint>).Replace(this.capturedPoint, newPoint); this.capturedPoint = newPoint; } }
protected override void InitializeBinding(DataPointBindingEntry binding) { ScatterDataPoint dataPoint = binding.DataPoint as ScatterDataPoint; if (this.xValueBinding != null) { object xValue = this.xValueBinding.GetValue(binding.DataItem); double doubleValue; if (NumericConverter.TryConvertToDouble(xValue, out doubleValue)) { dataPoint.XValue = doubleValue; } } if (this.yValueBinding != null) { object yValue = this.yValueBinding.GetValue(binding.DataItem); double doubleValue; if (NumericConverter.TryConvertToDouble(yValue, out doubleValue)) { dataPoint.YValue = doubleValue; } } base.InitializeBinding(binding); }
private void InterpolationSeries_MouseDown(object sender, MouseButtonEventArgs e) { var series = sender as ScatterLineSeries; series.CaptureMouse(); var points = series.DataContext as ObservableCollection <ScatterDataPoint>; var mousePosition = e.MouseDevice.GetPosition(this.Chart); var data = this.Chart.ConvertPointToData(mousePosition); if (data.FirstValue == null || data.SecondValue == null) { return; } var nearestPoint = points.MinBy(p => Utils.Distance(p, new ScatterDataPoint { XValue = (double)data.FirstValue, YValue = (double)data.SecondValue })); var nearestPointPosition = this.Chart.ConvertDataToPoint(new DataTuple(nearestPoint.XValue, nearestPoint.YValue)); this.capturedPoint = Utils.Distance(mousePosition, nearestPointPosition) < 10 ? nearestPoint : null; }
private void InterpolationSeries_MouseRightDown(object sender, MouseButtonEventArgs e) { var series = sender as ScatterLineSeries; var points = series.DataContext as ObservableCollection <ScatterDataPoint>; var mousePosition = e.MouseDevice.GetPosition(this.Chart); var closestPointDistance = Utils.Distance(this.Chart.GetPointOnChart(points[0]), mousePosition); ScatterDataPoint closestScatterPoint = null; foreach (var scatterDataPoint in points) { var linePoint = this.Chart.GetPointOnChart(scatterDataPoint); closestPointDistance = Math.Min(closestPointDistance, Utils.Distance(linePoint, mousePosition)); if (!(closestPointDistance < Tolerance)) { continue; } closestScatterPoint = scatterDataPoint; break; } if (!(closestPointDistance < Tolerance)) { return; } points.Remove(closestScatterPoint); }
protected override void ProcessSize(DataPoint point, Size size) { ScatterDataPoint scatterPoint = point as ScatterDataPoint; scatterPoint.XValue = size.Width; scatterPoint.YValue = size.Height; }
protected override void ProcessPoint(DataPoint dataPoint, Point point) { ScatterDataPoint scatterPoint = dataPoint as ScatterDataPoint; scatterPoint.XValue = point.X; scatterPoint.YValue = point.Y; }
private void InterpolationSeries_MouseUp(object sender, MouseButtonEventArgs e) { var series = sender as ScatterLineSeries; series.ReleaseMouseCapture(); this.capturedPoint = null; }
public static double Distance(ScatterDataPoint p1, ScatterDataPoint p2) { if (p1.YValue != null && p2.YValue != null) { return(Math.Sqrt(Math.Pow(p1.XValue - p2.XValue, 2) + Math.Pow((double)p1.YValue - (double)p2.YValue, 2))); } return(0); }
//private Font font = new Font("Segoe Script", 12, FontStyle.Regular); private void controler_TextNeeded(object sender, TextNeededEventArgs e) { e.Element.BackColor = ColorTranslator.FromHtml("#ffffff"); //e.Element.ForeColor = ColorTranslator.FromHtml("#bb2525"); e.Element.BorderColor = ColorTranslator.FromHtml("#000000"); e.Element.Padding = new Padding(10); //e.Element.Font = font; //e.Element.NumberOfColors = 1; e.Element.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid; ScatterDataPoint dataPoint = e.Points[3].DataPoint as ScatterDataPoint; e.Text = $@"<html><color='gray'>HRS:{dataPoint.XValue} Consumption:{dataPoint.YValue.Value:F}"; }
protected override void ProcessNullableDoubleArray(DataPoint point, double?[] values) { ScatterDataPoint scatterPoint = point as ScatterDataPoint; if (values.Length > 0 && values[0].HasValue) { scatterPoint.XValue = values[0].Value; } if (values.Length > 1 && values[1].HasValue) { scatterPoint.YValue = values[1].Value; } }
protected override void ProcessDoubleArray(DataPoint point, double[] values) { ScatterDataPoint scatterPoint = point as ScatterDataPoint; if (values.Length > 0) { scatterPoint.XValue = values[0]; } if (values.Length > 1) { scatterPoint.YValue = values[1]; } }
public string GetParentPlotDataPoint(ScatterDataPoint datapoint) { string plot = "none"; foreach (KeyValuePair <string, ScatterPlot> scatterPlot in scatterPlotList) { selected = scatterPlot.Value.PosessesDataPoint(datapoint); if (selected) { plot = scatterPlot.Key; } } return(plot); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { ScatterDataPoint dataPoint = (ScatterDataPoint)item; var series = container as ScatterPointSeries; var chart = series.GetVisualParent <RadCartesianChart>(); if (dataPoint.YValue > 105) { return(chart.Resources["ellipseTemplate"] as DataTemplate); } else { return(chart.Resources["rectangleTemplate"] as DataTemplate); } }
/// <summary> /// Parser for ScatterPlot data. Takes in a string array from GetLinesFromTextResource, /// converts it to an array of ScatterDataPoints, and returns it /// </summary> public static ScatterDataPoint[] ParseScatterPlotData(string[] data, int trial) { string[] xCoordsStrings = data[0].Split(','); string[] yCoordsStrings = data[1].Split(','); string[] zCoordsStrings = data[2].Split(','); ScatterDataPoint[] parsedData = new ScatterDataPoint[xCoordsStrings.Length]; for (int idx = 0; idx < xCoordsStrings.Length; idx++) { parsedData[idx] = new ScatterDataPoint(new ThreeTuple <float>((float)Math.Round(float.Parse(xCoordsStrings[idx]), 2), (float)Math.Round(float.Parse(yCoordsStrings[idx]), 2), (float)Math.Round(float.Parse(zCoordsStrings[idx]), 2)), trial); } return(parsedData); }
private void InterpolationSeries_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var series = sender as ScatterLineSeries; var points = series.DataContext as ObservableCollection <ScatterDataPoint>; var mousePosition = e.MouseDevice.GetPosition(this.Chart); var data = this.Chart.ConvertPointToData(mousePosition); var mousePoint = new ScatterDataPoint { XValue = (double)data.FirstValue, YValue = (double)data.SecondValue }; var nextPoint = points.First(point => point.XValue > mousePoint.XValue); var index = points.IndexOf(nextPoint); points.Insert(index, mousePoint); }
private void InitializeScatter() { this.radChartView1.AreaType = ChartAreaType.Cartesian; this.radChartView2.AreaType = ChartAreaType.Cartesian; this.radChartView1.ShowGrid = true; this.radChartView2.ShowGrid = true; ScatterSeries scatter = new ScatterSeries(); scatter.LegendTitle = "Area/Price ratio New York"; scatter.ShowLabels = true; scatter.DrawLinesToLabels = this.radCheckBox1.Checked; scatter.SyncLinesToLabelsColor = this.radCheckBox3.Checked; ScatterSeries scatter2 = new ScatterSeries(); scatter2.LegendTitle = "Area/Price ratio Los Angeles"; scatter2.ShowLabels = true; scatter2.DrawLinesToLabels = this.radCheckBox1.Checked; scatter2.SyncLinesToLabelsColor = this.radCheckBox3.Checked; ScatterSeries smartScatter = new ScatterSeries(); smartScatter.LegendTitle = "Area/Price ratio New York"; smartScatter.ShowLabels = true; smartScatter.DrawLinesToLabels = this.radCheckBox1.Checked; smartScatter.SyncLinesToLabelsColor = this.radCheckBox3.Checked; ScatterSeries smartScatter2 = new ScatterSeries(); smartScatter2.LegendTitle = "Area/Price ratio Los Angeles"; smartScatter2.ShowLabels = true; smartScatter2.DrawLinesToLabels = this.radCheckBox1.Checked; smartScatter2.SyncLinesToLabelsColor = this.radCheckBox3.Checked; List <KeyValuePair <double, double> > points = this.data.GetScatterData(); for (int i = 0; i < points.Count / 2; i++) { ScatterDataPoint point = new ScatterDataPoint(points[i].Key, points[i].Value); point.Label = string.Format("{0:F2}", point.XValue / point.YValue); scatter.DataPoints.Add(point); point = new ScatterDataPoint(points[i].Key, points[i].Value); point.Label = string.Format("{0:F2}", point.XValue / point.YValue); smartScatter.DataPoints.Add(point); } for (int i = points.Count / 2; i < points.Count; i++) { ScatterDataPoint point = new ScatterDataPoint(points[i].Key, points[i].Value); point.Label = string.Format("{0:F2}", point.XValue / point.YValue); scatter2.DataPoints.Add(point); point = new ScatterDataPoint(points[i].Key, points[i].Value); point.Label = string.Format("{0:F2}", point.XValue / point.YValue); smartScatter2.DataPoints.Add(point); } this.radChartView1.Series.Add(scatter); this.radChartView1.Series.Add(scatter2); this.radChartView2.Series.Add(smartScatter); this.radChartView2.Series.Add(smartScatter2); ((LinearAxis)scatter.VerticalAxis).Maximum = 110; ((LinearAxis)scatter.VerticalAxis).DesiredTickCount = 12; ((LinearAxis)scatter.VerticalAxis).Title = "Price(USD/per sq.ft.)"; ((LinearAxis)scatter.HorizontalAxis).Maximum = 110; ((LinearAxis)scatter.HorizontalAxis).DesiredTickCount = 12; ((LinearAxis)scatter.HorizontalAxis).Title = "Property area (sq.ft.)"; ((LinearAxis)smartScatter.VerticalAxis).Maximum = 110; ((LinearAxis)smartScatter.VerticalAxis).DesiredTickCount = 12; ((LinearAxis)smartScatter.VerticalAxis).Title = "Price(USD/per sq.ft.)"; ((LinearAxis)smartScatter.HorizontalAxis).Maximum = 110; ((LinearAxis)smartScatter.HorizontalAxis).DesiredTickCount = 12; ((LinearAxis)smartScatter.HorizontalAxis).Title = "Property area (sq.ft.)"; }
/// <summary> /// Print text to the panel /// </summary> public void ShowData(ScatterDataPoint dataPoint) { dataPointPlot.text = PlotManager.Instance.GetParentPlotDataPoint(dataPoint); dataPointValue.text = dataPoint.Value.ToString(); dataPointPosition.text = dataPoint.Coords.ToString(); }
public void MedsAddSeries(List<MedData> listdata) { stackTitle.Visibility = Windows.UI.Xaml.Visibility.Collapsed; string sPrevDrugname = ""; string sPrevDrugStr = ""; this.chart.HorizontalAxis =new LinearAxis(); this.chart.VerticalAxis = new LinearAxis(); this.chart.VerticalAxis.ShowLabels = false; this.chart.HorizontalAxis.ShowLabels = false; ChartSeriesLabelDefinition csld = new ChartSeriesLabelDefinition(); csld.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right; csld.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; csld.Template = CreateScatterDataLabelTemplate(); int i = 0; int iTotalDays = 0; ScatterPointSeries sls = null; bool bSwitch = false; foreach (MedData md in listdata) { if (md.Drugname.Trim() != sPrevDrugname) { sls = new ScatterPointSeries(); sls.Name = md.Drugname.Trim() + "_"+md.Strength.Trim(); sls.XValueBinding = new PropertyNameDataPointBinding("XValue"); sls.YValueBinding = new PropertyNameDataPointBinding("YValue"); sls.ShowLabels = true; sls.LabelDefinitions.Add(csld); sPrevDrugname = md.Drugname.Trim() ; sPrevDrugStr = md.Strength; bSwitch = true; i = i + 20; iTotalDays = 0; } for (int b = 0; b < md.Days; b++) { ScatterDataPoint sdp = new ScatterDataPoint(); sdp.XValue = b + iTotalDays; sdp.YValue = i; if (b == 1 ) { sdp.Label = md.Drugname + " " + md.Strength; } //only paint if there is data. if (!string.IsNullOrEmpty(md.Strength)) { sls.DataPoints.Add(sdp); } } iTotalDays = iTotalDays + md.Days; if (bSwitch) { this.chart.Series.Add(sls); bSwitch = false; } SolidColorBrush br = chart.Palette.GetBrush(chart.Series.Count - 1, PaletteVisualPart.Stroke) as SolidColorBrush; sls.PointTemplate = CreateScatterDataTemplate(br.Color.ToString(), 1); } int z = this.chart.Series.Count(); z--; while( z >= 0) { ChartLegend leg = new ChartLegend(); leg.ChartControl = this.chart; SolidColorBrush scb = new SolidColorBrush(); scb.Color = Windows.UI.Colors.Black; leg.BrushColor = scb; leg.HideRect = true; string[] smed = this.chart.Series[z].Name.Split('_'); leg.Text = smed[0]; leg.SeriesName = this.chart.Series[z].Name; leg.StackPanelParent = this.legend; leg.ChartTitleParent = this.stackTitle; this.legend.Children.Add(leg); z--; } }
public static Point GetPointOnChart(this RadCartesianChart chart, ScatterDataPoint scatterPoint) { return(chart.ConvertDataToPoint(new DataTuple(scatterPoint.XValue, scatterPoint.YValue))); }