Giter Site home page Giter Site logo

Comments (1)

planetarian avatar planetarian commented on June 15, 2024

Currently I am partially working around this by setting MinLimit = -(items.Count()/16.0), MaxLimit = items.Count() on the X Axis. This doesn't actually fix anything, but it at least sets the limits to be roughly similar to the post-pan limits by default, so that the movement on click isn't as jarring.

The secondary issue is that ChartPointPointerDown executes before it can even be determined whether the user is dragging or clicking, and there is no ChartPointPressed or ChartPointPointerUp or ChartPointClicked.
For that, I'm making use of everything I have at my disposal: ChartPointPointerDown to get the ChartPoint, and MouseDown and MouseUp to determine whether we're clicking or dragging.

        object? mouseDownObject;
        Point? mouseDownPos;
        ChartPoint? chartPoint;

        private void CartesianChart_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Store the clicked object and mouse position for comparison on MouseUp
            mouseDownObject = sender;
            mouseDownPos = e.GetPosition(this);
        }

        private void CartesianChart_ChartPointPointerDown(IChartView chart, ChartPoint point)
        {
            // Store the clicked point for use on MouseUp
            chartPoint = point;
        }

        private void CartesianChart_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (DataContext is not MyViewModel vm)
                return;

            // Ensure we're still acting on the same object
            if (sender != mouseDownObject)
            {
                mouseDownObject = null;
                return;
            }

            // If the new position isn't the same as the old one, we're dragging, not clicking
            Point pos = e.GetPosition(this);
            if (pos != mouseDownPos)
                return;
            
            // Get the series and point model and execute the appropriate point activation function for that series
            var series = (ColumnSeries<(string Key, double Value)>)((CartesianChart)sender).Series.First();
            var pointModel = ((string Key, double Value))chartPoint.Context.DataSource;
            vm.ActivatePoint(series, pointModel);
        }

from livecharts2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.