protected void ShowSliderValuesPosition(SKCanvas canvas, SKRect frame) { if (!IsSliderVisible) { return; } var valueItems = ChartEntries.GetChartValueItemFromX(TouchedPoint.X, frame, MaxItems); if (valueItems?.Any() != true) { return; } int index = 0; foreach (var item in valueItems) { canvas.DrawSliderCircle(item.ChartValueItem.Point.X, item.ChartValueItem.Point.Y, item.Color, this.SliderPointSize); string text = Math.Round(double.Parse(item.ChartValueItem.Value.ToString()), 0, MidpointRounding.AwayFromZero).ToString() + " " + this.VerticalUnit; canvas.DrawSliderValue( text, frame.GetInsideXValue(TouchedPoint.X), frame.Top, SliderDetailTextSize, SKColors.White, item.Color, SliderDetailPadding, SliderDetailMargin, MaxValue + " " + this.VerticalUnit, valueItems.Count, index, SliderDetailOrientation, frame, item.Parent?.UseDashedEffect == true); index++; } }
protected void ShowExactSliderValuesPosition(SKCanvas canvas, SKRect frame) { if (!IsSliderVisible) { return; } var valueItems = ChartEntries.GetChartValueItemFromX(TouchedPoint.X, frame, MaxItems); if (valueItems?.Any() != true) { return; } int index = 0; foreach (var item in valueItems) { var chartEntry = item.ChartValueItem; var nextChartEntry = item.NextChartValueItem; float y, points; if (nextChartEntry != null) { // Difference in value var diffVal = nextChartEntry.Value - chartEntry.Value; // Difference in Y position var diffY = nextChartEntry.Point.Y - chartEntry.Point.Y; // Difference in X position var diffX = nextChartEntry.Point.X - chartEntry.Point.X; var yValue = diffVal / diffY; var xValue = diffVal / diffX; // Current X position over first item var x = TouchedPoint.X - chartEntry.Point.X; points = x * xValue; y = (points / yValue) + chartEntry.Point.Y; } else { y = chartEntry.Point.Y; points = chartEntry.Value; } canvas.DrawSliderCircle(frame.GetInsideXValue(TouchedPoint.X), y, item.Color, SliderPointSize); float currentVal = 0; if (nextChartEntry != null) { try { currentVal = chartEntry.Value + (int)Math.Round(decimal.Parse(points.ToString()), 0, MidpointRounding.AwayFromZero); } catch (Exception ex) { ex.Print(); } if (TouchedPoint.X == chartEntry.Point.X) { currentVal = chartEntry.Value; } else if (TouchedPoint.X == nextChartEntry?.Point.X) { currentVal = nextChartEntry.Value; } } else { currentVal = chartEntry.Value; } string text = currentVal.ToString() + " " + this.VerticalUnit; canvas.DrawSliderValue( text, frame.GetInsideXValue(TouchedPoint.X), frame.Top, SliderDetailTextSize, SKColors.White, item.Color, SliderDetailPadding, SliderDetailMargin, MaxValue + " " + VerticalUnit, valueItems.Count, index, SliderDetailOrientation, frame, item.Parent?.UseDashedEffect == true); index++; } }
private void DrawBars(SKCanvas canvas, SKRect frame, SKRect chart) { var itemWidth = (MaxItems >= 12 ? chart.GetItemWidth(MaxItems) : chart.GetItemWidth(12)) / 2; var count = ChartEntries.Count(x => x.IsVisible); // Regular bar width var barWidth = (itemWidth / count) - 10; // Selected bar width var selectedValueItems = ChartEntries.GetChartValueItemFromX(chart.GetInsideXValue(TouchedPoint.X), chart, MaxItems, false); var selectedTags = selectedValueItems?.Select(x => x.ChartValueItem.Tag); int index = 0; foreach (var item in ChartEntries.Where(x => x.IsVisible)) { foreach (var valueItem in item.Items.Where(x => selectedTags?.Contains(x.Tag) != true)) { // Draw not selected bars // canvas.DrawBar( valueItem.Point.X, valueItem.Point.Y, chart.Bottom, barWidth, BarMargin, count, index, IsSliderVisible ? item.Color.ToSKColor().AsTransparency() : item.Color.ToSKColor(), item.UseDashedEffect); } index++; } if (!IsSliderVisible) { return; } count = selectedValueItems?.Count() ?? 1; barWidth = (itemWidth / selectedValueItems?.Count() ?? 1) + 10; index = 0; foreach (var item in ChartEntries.Where(x => x.IsVisible)) { var valueItems = item.Items.Where(x => selectedTags?.Contains(x.Tag) == true); if (valueItems?.Any() != true) { continue; } foreach (var valueItem in valueItems) { canvas.DrawBar( valueItem.Point.X, valueItem.Point.Y, chart.Bottom, barWidth, BarMargin, count, index, item.Color.ToSKColor(), item.UseDashedEffect); string text = Math.Round(double.Parse(valueItem.Value.ToString()), 0, MidpointRounding.AwayFromZero).ToString() + " " + this.VerticalUnit; canvas.DrawSliderValue( text, frame.GetInsideXValue(valueItem.Point.X), frame.Top, SliderDetailTextSize, SKColors.White, item.Color.ToSKColor(), SliderDetailPadding, SliderDetailMargin, MaxValue + " " + this.VerticalUnit, selectedValueItems.Count, index, SliderDetailOrientation, frame, item.UseDashedEffect); } index++; } float hintX = selectedValueItems?.FirstOrDefault()?.ChartValueItem?.Point.X ?? 0; float hintY = selectedValueItems?.OrderByDescending(x => x.ChartValueItem.Point.Y)?.FirstOrDefault()?.ChartValueItem?.Point.Y ?? 0; if (hintX != 0 && hintY != 0) { DrawDragHintGraphic( canvas, hintX, hintY + ((frame.Bottom - hintY) / 2), (barWidth * count), frame); } }