Example #1
0
        private void SetStartPosition(List <GroupChartItem> groupCenters)
        {
            GroupChartItem item    = null;
            var            entries = groupCenters.OrderByDescending(x => x.Position);

            if (StartPositionEnd == false)
            {
                item             = entries.LastOrDefault();
                StartPositionEnd = null;
            }
            else if (StartPositionEnd == true)
            {
                item             = entries.FirstOrDefault();
                StartPositionEnd = null;
            }
            else if (!string.IsNullOrEmpty(SelectedTag) && entries.Any(x => x.Label == SelectedLabel))
            {
                item = entries.FirstOrDefault(x => x.Tag == SelectedTag);
            }

            if (item == null)
            {
                item = entries.ElementAtOrDefault(entries.Count() / 2);
            }

            var firstItemsPosition = entries.LastOrDefault().Position;

            var position = item.Position - firstItemsPosition;

            ShowSwipeNotifications(position);

            SnapToClosestBar(position, item);
        }
Example #2
0
        private void SnapToClosestBar(double position, GroupChartItem selectedItem)
        {
            var selectedValues = new SelectedChartValueItemArgs
            {
                ChartValueItems = new List <ChartValueItemParam>(),
                TouchedPoint    = TouchedPoint
            };

            foreach (var chartEntry in ChartEntries.Where(x => x.IsVisible))
            {
                var chartEntryItem = chartEntry.Items.FirstOrDefault(i => i.Tag.ToString() == selectedItem.Tag.ToString());

                if (chartEntryItem == null)
                {
                    continue;
                }

                selectedValues.ChartValueItems.Add(new ChartValueItemParam(chartEntryItem, null, chartEntry));
            }

            // Invoke command with selected items
            SelectedValuesCommand?.Execute(selectedValues);

            Device.BeginInvokeOnMainThread(async() =>
            {
                isSnapping = true;

                ScrollComponent.Scrolled -= ScrollComponent_Scrolled;

                SelectedLabel = selectedItem.Label;

                lastScrollPosition = position;

                await ScrollComponent.ScrollToAsync(lastScrollPosition, 0, false);

                ShowSwipeNotifications(lastScrollPosition);

                ScrollComponent.Scrolled += ScrollComponent_Scrolled;

                isSnapping = false;
            });
        }