/// <summary>
        /// Initializes a new instance of the <see cref="PieChart"/> class.
        /// </summary>
        /// <exception cref="Exception">Default colors are not valid</exception>
        public PieChart()
        {
            InitializeComponent();

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeCore();
            SizeChanged += OnSizeChanged;

            _seriesObserver = new CollectionDeepObserver <ISeries>(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                MainThread.BeginInvokeOnMainThread(() => core.Update());
            },
                (object sender, PropertyChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                MainThread.BeginInvokeOnMainThread(() => core.Update());
            });

            Series = new ObservableCollection <ISeries>();

            canvas.SkCanvasView.EnableTouchEvents = true;
            canvas.SkCanvasView.Touch            += OnSkCanvasTouched;

            if (core == null)
            {
                throw new Exception("Core not found!");
            }
            core.Measuring      += OnCoreMeasuring;
            core.UpdateStarted  += OnCoreUpdateStarted;
            core.UpdateFinished += OnCoreUpdateFinished;
        }
Example #2
0
    /// <summary>
    /// Initializes a new instance of the <see cref="PieChart"/> class.
    /// </summary>
    /// <exception cref="Exception">Default colors are not valid</exception>
    public PieChart()
    {
        InitializeComponent();

        // workaround to detect mouse events.
        // Avalonia do not seem to detect events if background is not set.
        Background = new SolidColorBrush(Colors.Transparent);

        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }

        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        {
            throw new Exception("Default colors are not valid");
        }
        initializer.ApplyStyleToChart(this);

        InitializeCore();

        AttachedToVisualTree += OnAttachedToVisualTree;

        _seriesObserver = new CollectionDeepObserver <ISeries>(
            (object?sender, NotifyCollectionChangedEventArgs e) =>
        {
            if (_core is null || (sender is IStopNPC stop && !stop.IsNotifyingChanges))
            {
                return;
            }
            _core.Update();
        },
            (object?sender, PropertyChangedEventArgs e) =>
        {
            if (_core is null || (sender is IStopNPC stop && !stop.IsNotifyingChanges))
            {
                return;
            }
            _core.Update();
        });

        Series        = new ObservableCollection <ISeries>();
        PointerLeave += Chart_PointerLeave;

        PointerMoved           += Chart_PointerMoved;
        PointerPressed         += Chart_PointerPressed;
        DetachedFromVisualTree += PieChart_DetachedFromVisualTree;
    }
Example #3
0
        public CartesianChart()
        {
            InitializeComponent();

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetStylesBuilder <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ConstructChart(this);

            InitializeCore();
            SizeChanged       += OnSizeChanged;
            mouseMoveThrottler = new ActionThrottler(MouseMoveThrottlerUnlocked, TimeSpan.FromMilliseconds(10));

            seriesObserver = new CollectionDeepObserver <ISeries>(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                MainThread.BeginInvokeOnMainThread(core.Update);
            },
                (object sender, PropertyChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                MainThread.BeginInvokeOnMainThread(core.Update);
            },
                true);

            XAxes = new List <IAxis>()
            {
                new Axis()
            };
            YAxes = new List <IAxis>()
            {
                new Axis()
            };
            Series = new ObservableCollection <ISeries>();
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="DrawMarginFrame"/> class.
    /// </summary>
    public DrawMarginFrame()
    {
        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }
        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        foreach (var rule in initializer.DrawMarginFrameBuilder)
        {
            rule(this);
        }
    }
Example #5
0
    /// <summary>
    /// Initializes a new instance of the <see cref="CartesianChart"/> class.
    /// </summary>
    /// <exception cref="Exception">Default colors are not valid</exception>
    public CartesianChart()
    {
        InitializeComponent();

        // workaround to detect mouse events.
        // Avalonia do not seem to detect pointer events if background is not set.
        ((IChartView)this).BackColor = LvcColor.FromArgb(0, 0, 0, 0);

        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }

        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        {
            throw new Exception("Default colors are not valid");
        }
        initializer.ApplyStyleToChart(this);

        InitializeCore();

        AttachedToVisualTree += CartesianChart_AttachedToVisualTree;

        _seriesObserver   = new CollectionDeepObserver <ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _xObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _yObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _sectionsObserver = new CollectionDeepObserver <Section <SkiaSharpDrawingContext> >(
            OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);

        XAxes = new List <ICartesianAxis>()
        {
            LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
        };
        YAxes = new List <ICartesianAxis>()
        {
            LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
        };
        Series = new ObservableCollection <ISeries>();

        PointerPressed += CartesianChart_PointerPressed;
        PointerMoved   += CartesianChart_PointerMoved;
        // .. special case in avalonia for pointer released... he handle our own pointer capture.
        PointerWheelChanged += CartesianChart_PointerWheelChanged;
        PointerLeave        += CartesianChart_PointerLeave;

        DetachedFromVisualTree += CartesianChart_DetachedFromVisualTree;
    }
Example #6
0
    /// <summary>
    /// Initializes a new instance of the <see cref="CartesianChart"/> class.
    /// </summary>
    /// <exception cref="Exception">Default colors are not valid</exception>
    public CartesianChart()
    {
        InitializeComponent();

        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }

        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        {
            throw new Exception("Default colors are not valid");
        }
        initializer.ApplyStyleToChart(this);

        InitializeCore();
        SizeChanged += OnSizeChanged;

        _seriesObserver   = new CollectionDeepObserver <ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _xObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _yObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
        _sectionsObserver = new CollectionDeepObserver <Section <SkiaSharpDrawingContext> >(
            OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);

        XAxes = new List <ICartesianAxis>()
        {
            LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
        };
        YAxes = new List <ICartesianAxis>()
        {
            LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
        };
        Series = new ObservableCollection <ISeries>();

        canvas.SkCanvasView.EnableTouchEvents = true;
        canvas.SkCanvasView.Touch            += OnSkCanvasTouched;

        if (core is null)
        {
            throw new Exception("Core not found!");
        }
        core.Measuring      += OnCoreMeasuring;
        core.UpdateStarted  += OnCoreUpdateStarted;
        core.UpdateFinished += OnCoreUpdateFinished;
    }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PieChart"/> class.
        /// </summary>
        /// <exception cref="Exception">Default colors are not valid</exception>
        public PieChart()
        {
            InitializeComponent();

            // workaround to detect mouse events.
            // Avalonia do not seem to detect events if background is not set.
            Background = new SolidColorBrush(Colors.Transparent);

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeCore();

            _seriesObserver = new CollectionDeepObserver <ISeries>(
                (object?sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                _ = Dispatcher.UIThread.InvokeAsync(() => core.Update(), DispatcherPriority.Background);
            },
                (object?sender, PropertyChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                _ = Dispatcher.UIThread.InvokeAsync(() => core.Update(), DispatcherPriority.Background);
            });

            Series        = new ObservableCollection <ISeries>();
            PointerLeave += CartesianChart_PointerLeave;

            PointerMoved += CartesianChart_PointerMoved;
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PolarChart"/> class.
        /// </summary>
        /// <exception cref="Exception">Default colors are not valid</exception>
        public PolarChart()
        {
            InitializeComponent();

            // workaround to detect mouse events.
            // Avalonia do not seem to detect pointer events if background is not set.
            ((IChartView)this).BackColor = LvcColor.FromArgb(0, 0, 0, 0);

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeCore();

            AttachedToVisualTree += OnAttachedToVisualTree;

            _seriesObserver = new CollectionDeepObserver <ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            _angleObserver  = new CollectionDeepObserver <IPolarAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            _radiusObserver = new CollectionDeepObserver <IPolarAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);

            AngleAxes = new List <IPolarAxis>()
            {
                LiveCharts.CurrentSettings.PolarAxisProvider()
            };
            RadiusAxes = new List <IPolarAxis>()
            {
                LiveCharts.CurrentSettings.PolarAxisProvider()
            };
            Series = new ObservableCollection <ISeries>();

            PointerWheelChanged += PolarChart_PointerWheelChanged;
            PointerPressed      += PolarChart_PointerPressed;
            PointerMoved        += PolarChart_PointerMoved;

            PointerLeave           += PolarChart_PointerLeave;
            DetachedFromVisualTree += PolarChart_DetachedFromVisualTree;
        }
    // Moved to css, probably remove?
    //private Font _tooltipFont = new(new FontFamily("Trebuchet MS"), 11, FontStyle.Regular);
    //private Color _tooltipBackColor = Color.FromArgb(255, 250, 250, 250);
    //private Font _legendFont = new(new FontFamily("Trebuchet MS"), 11, FontStyle.Regular);
    //private Color _legendBackColor = Color.FromArgb(255, 255, 255, 255);
    //private Color _legendTextColor = Color.FromArgb(255, 35, 35, 35);
    //private Color _tooltipTextColor;

    /// <summary>
    /// Called when the control is initialized.
    /// </summary>
    /// <exception cref="Exception"></exception>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }

        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        {
            throw new Exception("Default colors are not valid");
        }
        initializer.ApplyStyleToChart(this);
    }
Example #10
0
        public TestCartesianChartView()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            Core = new CartesianChart <SkiaSharpDrawingContext>(
                this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas);
        }
Example #11
0
        public PieChart()
        {
            InitializeComponent();

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetStylesBuilder <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ConstructChart(this);

            InitializeCore();

            mouseMoveThrottler = new ActionThrottler(MouseMoveThrottlerUnlocked, TimeSpan.FromMilliseconds(10));

            seriesObserver = new CollectionDeepObserver <ISeries>(
                (object?sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                Dispatcher.UIThread.InvokeAsync(core.Update, DispatcherPriority.Background);
            },
                (object?sender, PropertyChangedEventArgs e) =>
            {
                if (core == null)
                {
                    return;
                }
                Dispatcher.UIThread.InvokeAsync(core.Update, DispatcherPriority.Background);
            });

            Series = new ObservableCollection <ISeries>();
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Chart"/> class.
        /// </summary>
        /// <exception cref="Exception">Default colors are not valid</exception>
        protected Chart()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            SizeChanged += OnSizeChanged;
            MouseMove   += OnMouseMove;
            MouseLeave  += OnMouseLeave;
        }
Example #13
0
        public Chart()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetStylesBuilder <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ConstructChart(this);

            SizeChanged                 += OnSizeChanged;
            MouseMove                   += OnMouseMove;
            mouseMoveThrottler           = new ActionThrottler(TimeSpan.FromMilliseconds(10));
            mouseMoveThrottler.Unlocked += MouseMoveThrottlerUnlocked;
        }
Example #14
0
    /// <summary>
    /// Initializes a new instance of the <see cref="SKPolarChart"/> class.
    /// </summary>
    public SKPolarChart()
    {
        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }

        var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
        var initializer   = stylesBuilder.GetVisualsInitializer();

        if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        {
            throw new Exception("Default colors are not valid");
        }
        initializer.ApplyStyleToChart(this);

        Core                 = new PolarChart <SkiaSharpDrawingContext>(this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas);
        Core.Measuring      += OnCoreMeasuring;
        Core.UpdateStarted  += OnCoreUpdateStarted;
        Core.UpdateFinished += OnCoreUpdateFinished;
    }
Example #15
0
        public MainWindow()
        {
            InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif

            DataContext = new MainWindowViewModel();
            LoadContent("Home");

            LiveCharts.Configure(settings =>
                                 settings.
                                 AddDefaultMappers()
                                 .AddSkiaSharp()
                                 .AddLightTheme()

                                 // .., your custom settings here
                                 // .HasMap<Foo>( ... )

                                 );
        }
Example #16
0
        public ViewModel()
        {
            // in this case we have an array of the Dog class
            // we need to compare the Age property of every dog in our array
            // you normally should configure every intance you require to use only when your application starts.

            // by default LiveCharts already knows how to map the types:
            // short, int, long, float, double, decimal, short?, int?, long?, float?, double?, decimal?,
            // WeightedPoint, WeightedPointF, ObservablePoint, ObservablePointF, OversableValue and ObservableValueF
            // for more info see:
            // https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/LiveChartsCore/LiveChartsSettings.cs#L122
            LiveCharts.Configure(config =>

                                 // The HasMap<T>() method helps us to define a map from a type T to a point in our chart
                                 config
                                 .HasMap <Dog>((dog, point) =>
            {
                // in this lambda function we take an intance of the Dog class (see dog parameter)
                // and the point in the chart for that instance (see point parameter)
                // LiveCharts will call this method for every instance of our Dog class,
                // now we need to populate the point coordinates from our Dog intance to our point

                // in this case we will use the Age property as our primary value (normally the Y coordinate)
                point.PrimaryValue = (float)dog.Age;

                // then the secondary value (normally the X coordinate)
                // will be the index of the given dog class in our array
                point.SecondaryValue = point.Context.Index;
            })

                                 // lets also set a mapper for the DogAverageAge class
                                 .HasMap <DogAverageAge>((dogAverageAge, point) =>
            {
                // in this case we are ignoring the point paramenter
                // every coordinate will be provided by our dogAverageAge instance
                point.PrimaryValue   = (float)dogAverageAge.Y;
                point.SecondaryValue = (float)dogAverageAge.X;
            })
                                 );
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoMap"/> class.
        /// </summary>
        public GeoMap()
        {
            InitializeComponent();
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }
            _core = new GeoMap <SkiaSharpDrawingContext>(this);

            canvas.SkCanvasView.EnableTouchEvents = true;
            canvas.SkCanvasView.Touch            += OnSkCanvasTouched;

            SizeChanged += GeoMap_SizeChanged;

            _shapesObserver = new CollectionDeepObserver <IMapElement>(
                (object?sender, NotifyCollectionChangedEventArgs e) => _core?.Update(),
                (object?sender, PropertyChangedEventArgs e) => _core?.Update(),
                true);
            SetValue(ShapesProperty, Enumerable.Empty <IMapElement>());
            SetValue(ActiveMapProperty, Maps.GetWorldMap());
            SetValue(SyncContextProperty, new object());
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CartesianChart"/> class.
        /// </summary>
        public PieChart()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeComponent();

            _seriesObserver = new CollectionDeepObserver <ISeries>(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (_core == null || (sender is IStopNPC stop && !stop.IsNotifyingChanges))
                {
                    return;
                }
                _core.Update();
            },
                (object sender, PropertyChangedEventArgs e) =>
            {
                if (_core == null || (sender is IStopNPC stop && !stop.IsNotifyingChanges))
                {
                    return;
                }
                _core.Update();
            });

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoMap"/> class.
        /// </summary>
        public GeoMap()
        {
            InitializeComponent();
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }
            _core           = new GeoMap <SkiaSharpDrawingContext>(this);
            _shapesObserver = new CollectionDeepObserver <IMapElement>(
                (object?sender, NotifyCollectionChangedEventArgs e) => _core?.Update(),
                (object?sender, PropertyChangedEventArgs e) => _core?.Update(),
                true);

            PointerWheelChanged += OnPointerWheelChanged;
            PointerPressed      += OnPointerPressed;
            PointerMoved        += OnPointerMoved;
            PointerLeave        += OnPointerLeave;

            //Shapes = Enumerable.Empty<MapShape<SkiaSharpDrawingContext>>();
            ActiveMap   = Maps.GetWorldMap();
            SyncContext = new object();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartesianChart"/> class.
        /// </summary>
        /// <exception cref="Exception">Default colors are not valid</exception>
        public CartesianChart()
        {
            InitializeComponent();

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeCore();
            SizeChanged += OnSizeChanged;

            seriesObserver = new CollectionDeepObserver <ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            xObserver      = new CollectionDeepObserver <IAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            yObserver      = new CollectionDeepObserver <IAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);

            XAxes = new List <IAxis>()
            {
                new Axis()
            };
            YAxes = new List <IAxis>()
            {
                new Axis()
            };
            Series = new ObservableCollection <ISeries>();

            canvas.SkCanvasView.EnableTouchEvents = true;
            canvas.SkCanvasView.Touch            += OnSkCanvasTouched;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartesianChart"/> class.
        /// </summary>
        public CartesianChart()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetVisualsInitializer();

            if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ApplyStyleToChart(this);

            InitializeComponent();

            _seriesObserver   = new CollectionDeepObserver <ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            _xObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            _yObserver        = new CollectionDeepObserver <ICartesianAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
            _sectionsObserver = new CollectionDeepObserver <Section <SkiaSharpDrawingContext> >(
                OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;

            SetValue(XAxesProperty, new ObservableCollection <ICartesianAxis>()
            {
                LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
            });
            SetValue(YAxesProperty, new ObservableCollection <ICartesianAxis>()
            {
                LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetDefaultCartesianAxis()
            });
            SetValue(SeriesProperty, new ObservableCollection <ISeries>());
            SetValue(SectionsProperty, new ObservableCollection <Section <SkiaSharpDrawingContext> >());
        }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoMap"/> class.
        /// </summary>
        public GeoMap()
        {
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            MouseDown  += OnMouseDown;
            MouseMove  += OnMouseMove;
            MouseUp    += OnMouseUp;
            MouseLeave += OnMouseLeave;
            MouseWheel += OnMouseWheel;

            SizeChanged += GeoMap_SizeChanged;

            _shapesObserver = new CollectionDeepObserver <IMapElement>(
                (object?sender, NotifyCollectionChangedEventArgs e) => _core?.Update(),
                (object?sender, PropertyChangedEventArgs e) => _core?.Update(),
                true);
            SetCurrentValue(ShapesProperty, Enumerable.Empty <MapShape <SkiaSharpDrawingContext> >());
            SetCurrentValue(ActiveMapProperty, Maps.GetWorldMap <SkiaSharpDrawingContext>());
            SetCurrentValue(SyncContextProperty, new object());
        }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoMap"/> class.
        /// </summary>
        public GeoMap()
        {
            InitializeComponent();
            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }
            _core           = new GeoMap <SkiaSharpDrawingContext>(this);
            _shapesObserver = new CollectionDeepObserver <IMapElement>(
                (object?sender, NotifyCollectionChangedEventArgs e) => _core?.Update(),
                (object?sender, PropertyChangedEventArgs e) => _core?.Update(),
                true);

            var c = Controls[0].Controls[0];

            c.MouseDown  += OnMouseDown;
            c.MouseMove  += OnMouseMove;
            c.MouseUp    += OnMouseUp;
            c.MouseLeave += OnMouseLeave;
            c.MouseWheel += OnMouseWheel;

            Resize += GeoMap_Resize;
        }
Example #24
0
    /// <summary>
    /// Initialices a new instance of the <see cref="HeatLandSeries"/> class.
    /// </summary>
    public HeatLandSeries()
    {
        HeatMap = new[]
        {
            LvcColor.FromArgb(255, 179, 229, 252),  // cold (min value)
            LvcColor.FromArgb(255, 2, 136, 209)     // hot (max value)
        };

        if (!LiveCharts.IsConfigured)
        {
            LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
        }
        IntitializeSeries(LiveCharts.CurrentSettings.GetProvider <SkiaSharpDrawingContext>().GetSolidColorPaint());

        // ToDo: Themeit!

        //var stylesBuilder = LiveCharts.CurrentSettings.GetTheme<TDrawingContext>();
        //var initializer = stylesBuilder.GetVisualsInitializer();
        //if (stylesBuilder.CurrentColors is null || stylesBuilder.CurrentColors.Length == 0)
        //    throw new Exception("Default colors are not valid");

        //initializer.ApplyStyleToSeries(this);
    }
Example #25
0
    public ViewModel()
    {
        // Ideally you should call this when your application starts
        // If you need help to decide where to add this code
        // please see the installation guide in this docs.

        // in this case we have an array of the City class
        // we need to compare the Population property of every city in our array

        LiveCharts.Configure(config =>
                             config
                             .HasMap <City>((city, point) =>
        {
            // in this lambda function we take an instance of the City class (see city parameter)
            // and the point in the chart for that instance (see point parameter)
            // LiveCharts will call this method for every instance of our City class array,
            // now we need to populate the point coordinates from our City instance to our point

            // in this case we will use the Population property as our primary value (normally the Y coordinate)
            point.PrimaryValue = (float)city.Population;

            // then the secondary value (normally the X coordinate)
            // will be the index of the given dog class in our array
            point.SecondaryValue = point.Context.Index;
        })

                             // lets also set a mapper for the CityDensity class
                             .HasMap <CityDensity>((cityDensity, point) =>
        {
            // in this case we will use the Population property in the Y axis (primary)
            // and the LandArea property in the X axis (secondary)
            point.PrimaryValue   = (float)cityDensity.Population;
            point.SecondaryValue = (float)cityDensity.LandArea;
        })
                             );
    }
Example #26
0
        public Chart()
        {
            motionCanvas = new MotionCanvas();
            SuspendLayout();
            motionCanvas.Anchor          = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            motionCanvas.FramesPerSecond = 90D;
            motionCanvas.Location        = new Point(0, 0);
            motionCanvas.Name            = "motionCanvas";
            motionCanvas.Size            = new Size(150, 150);
            motionCanvas.TabIndex        = 0;
            motionCanvas.Resize         += OnResized;
            motionCanvas.MouseMove      += OnMouseMove;
            AutoScaleDimensions          = new SizeF(7F, 15F);
            AutoScaleMode = AutoScaleMode.Font;
            Controls.Add(motionCanvas);
            Name = "CartesianChart";
            ResumeLayout(false);

            if (!LiveCharts.IsConfigured)
            {
                LiveCharts.Configure(LiveChartsSkiaSharp.DefaultPlatformBuilder);
            }

            var stylesBuilder = LiveCharts.CurrentSettings.GetStylesBuilder <SkiaSharpDrawingContext>();
            var initializer   = stylesBuilder.GetInitializer();

            if (stylesBuilder.CurrentColors == null || stylesBuilder.CurrentColors.Length == 0)
            {
                throw new Exception("Default colors are not valid");
            }
            initializer.ConstructChart(this);

            InitializeCore();
            mouseMoveThrottler           = new ActionThrottler(TimeSpan.FromMilliseconds(10));
            mouseMoveThrottler.Unlocked += MouseMoveThrottlerUnlocked;
        }
Example #27
0
 public MainWindowVM(IDialogService dialogService)
 {
     LiveCharts.Configure(a => a.HasMap <DataModel>((b, c) => { c.PrimaryValue = (float)b.Value; c.SecondaryValue = b.Second; }));
     _dialogService = dialogService;
     Compute.Execute(null);
 }
Example #28
0
        /// <summary>
        /// Adds the default resolvers.
        /// </summary>
        /// <param name="theme">The theme.</param>
        /// <returns></returns>
        public static Theme <SkiaSharpDrawingContext> AddDefaultLightResolvers(
            this Theme <SkiaSharpDrawingContext> theme)
        {
            return(theme
                   .WithSeriesDefaultsResolver(
                       (Color[] colors, IDrawableSeries <SkiaSharpDrawingContext> series, bool forceApply) =>
            {
                if (forceApply)
                {
                    if (!LiveCharts.IsConfigured)
                    {
                        LiveCharts.Configure(DefaultPlatformBuilder);
                    }
                    var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
                    var initializer = stylesBuilder.GetVisualsInitializer();

                    initializer.ApplyStyleToSeries(series);
                }

                var color = colors[series.SeriesId % colors.Length];
                if (series.Name == null)
                {
                    series.Name = $"Series {series.SeriesId + 1}";
                }

                if ((series.SeriesProperties & SeriesProperties.PieSeries) == SeriesProperties.PieSeries ||
                    (series.SeriesProperties & SeriesProperties.Bar) == SeriesProperties.Bar)
                {
                    if (series.Fill == DefaultPaintTask)
                    {
                        series.Fill = new SolidColorPaintTask(color.AsSKColor());
                    }
                    if (series.Stroke == DefaultPaintTask)
                    {
                        series.Stroke = new SolidColorPaintTask(color.AsSKColor(), 3);
                    }

                    return;
                }

                if (series.Fill == DefaultPaintTask)
                {
                    var mask = SeriesProperties.Line | SeriesProperties.Stacked;
                    var opacity = (series.SeriesProperties & mask) == mask ? 1 : 0.2;

                    series.Fill = new SolidColorPaintTask(color.AsSKColor((byte)(opacity * 255)));
                }
                if (series.Stroke == DefaultPaintTask)
                {
                    series.Stroke = new SolidColorPaintTask(color.AsSKColor(), 5);
                }

                if ((series.SeriesProperties & SeriesProperties.Line) == SeriesProperties.Line)
                {
                    var lineSeries = (ILineSeries <SkiaSharpDrawingContext>)series;

                    if (lineSeries.GeometryFill == DefaultPaintTask)
                    {
                        lineSeries.GeometryFill = new SolidColorPaintTask(color.AsSKColor());
                    }
                    if (lineSeries.GeometryStroke == DefaultPaintTask)
                    {
                        lineSeries.GeometryStroke =
                            new SolidColorPaintTask(color.AsSKColor(), lineSeries.Stroke?.StrokeThickness ?? 5);
                    }
                }
            })
                   .WithAxisDefaultsResolver(
                       (IAxis <SkiaSharpDrawingContext> axis, bool forceApply) =>
            {
                //if (forceApply)
                //{
                //    if (!LiveCharts.IsConfigured) LiveCharts.Configure(DefaultPlatformBuilder);
                //    var stylesBuilder = LiveCharts.CurrentSettings.GetTheme<SkiaSharpDrawingContext>();
                //    var initializer = stylesBuilder.GetVisualsInitializer();

                //    initializer.ApplyStyleToAxis(axis);
                //}

                if (axis.SeparatorsBrush == DefaultPaintTask)
                {
                    axis.SeparatorsBrush = axis.Orientation == AxisOrientation.X
                                ? null
                                : new SolidColorPaintTask(new SKColor(235, 235, 235));
                }

                if (axis.TextBrush == DefaultPaintTask)
                {
                    axis.TextBrush = new SolidColorPaintTask(new SKColor(90, 90, 90));
                }
            }));
        }
        /// <summary>
        /// Adds the default resolvers.
        /// </summary>
        /// <param name="theme">The theme.</param>
        /// <returns></returns>
        public static Theme <SkiaSharpDrawingContext> AddDefaultDarkResolvers(
            this Theme <SkiaSharpDrawingContext> theme)
        {
            return(theme
                   .WithSeriesDefaultsResolver(
                       (Color[] colors, IChartSeries <SkiaSharpDrawingContext> series, bool forceApply) =>
            {
                if (forceApply)
                {
                    if (!LiveCharts.IsConfigured)
                    {
                        LiveCharts.Configure(DefaultPlatformBuilder);
                    }
                    var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
                    var initializer = stylesBuilder.GetVisualsInitializer();

                    initializer.ApplyStyleToSeries(series);
                }

                if (series.DataLabelsPaint == DefaultPaintTask)
                {
                    series.DataLabelsPaint = new SolidColorPaintTask(new SKColor(230, 230, 230));
                }

                if ((series.SeriesProperties & SeriesProperties.GaugeFill) != 0)
                {
                    var gaugeSeries = (IPieSeries <SkiaSharpDrawingContext>)series;
                    if (gaugeSeries.Stroke == DefaultPaintTask)
                    {
                        gaugeSeries.Stroke = null;
                    }
                    if (gaugeSeries.Fill == DefaultPaintTask)
                    {
                        gaugeSeries.Fill = new SolidColorPaintTask(new SKColor(255, 255, 255, 15));
                    }
                    return;
                }

                var color = colors[series.SeriesId % colors.Length];
                if (series.Name == null)
                {
                    series.Name = $"Series {series.SeriesId + 1}";
                }

                if ((series.SeriesProperties & SeriesProperties.PieSeries) == SeriesProperties.PieSeries ||
                    (series.SeriesProperties & SeriesProperties.Bar) == SeriesProperties.Bar)
                {
                    var sf = (IStrokedAndFilled <SkiaSharpDrawingContext>)series;
                    if (sf.Fill == DefaultPaintTask)
                    {
                        sf.Fill = new SolidColorPaintTask(color.AsSKColor());
                    }
                    if (sf.Stroke == DefaultPaintTask)
                    {
                        sf.Stroke = new SolidColorPaintTask(color.AsSKColor(), 3);
                    }

                    return;
                }

                if (series is IStrokedAndFilled <SkiaSharpDrawingContext> strokedAndFilled)
                {
                    if (strokedAndFilled.Fill == DefaultPaintTask)
                    {
                        var opacity = 0.2;
                        var mask1 = SeriesProperties.Line | SeriesProperties.Stacked;
                        var mask2 = SeriesProperties.StepLine | SeriesProperties.Stacked;
                        if ((series.SeriesProperties & mask1) == mask1 || (series.SeriesProperties & mask2) == mask2)
                        {
                            opacity = 1;
                        }

                        strokedAndFilled.Fill = new SolidColorPaintTask(color.AsSKColor((byte)(opacity * 255)));
                    }
                    if (strokedAndFilled.Stroke == DefaultPaintTask)
                    {
                        strokedAndFilled.Stroke = new SolidColorPaintTask(color.AsSKColor(), 5);
                    }
                }

                if ((series.SeriesProperties & SeriesProperties.Line) == SeriesProperties.Line)
                {
                    var lineSeries = (ILineSeries <SkiaSharpDrawingContext>)series;

                    if (lineSeries.GeometryFill == DefaultPaintTask)
                    {
                        lineSeries.GeometryFill = new SolidColorPaintTask(color.AsSKColor());
                    }
                    if (lineSeries.GeometryStroke == DefaultPaintTask)
                    {
                        lineSeries.GeometryStroke =
                            new SolidColorPaintTask(color.AsSKColor(), lineSeries.Stroke?.StrokeThickness ?? 5);
                    }
                }

                if ((series.SeriesProperties & SeriesProperties.StepLine) == SeriesProperties.StepLine)
                {
                    var steplineSeries = (IStepLineSeries <SkiaSharpDrawingContext>)series;

                    if (steplineSeries.GeometryFill == DefaultPaintTask)
                    {
                        steplineSeries.GeometryFill = new SolidColorPaintTask(color.AsSKColor());
                    }
                    if (steplineSeries.GeometryStroke == DefaultPaintTask)
                    {
                        steplineSeries.GeometryStroke =
                            new SolidColorPaintTask(color.AsSKColor(), steplineSeries.Stroke?.StrokeThickness ?? 5);
                    }
                }

                if ((series.SeriesProperties & SeriesProperties.Financial) == SeriesProperties.Financial)
                {
                    var financialSeries = (IFinancialSeries <SkiaSharpDrawingContext>)series;

                    if (financialSeries.UpFill == DefaultPaintTask)
                    {
                        financialSeries.UpFill = new SolidColorPaintTask(new SKColor(139, 195, 74, 255));
                    }
                    if (financialSeries.UpStroke == DefaultPaintTask)
                    {
                        financialSeries.UpStroke = new SolidColorPaintTask(new SKColor(139, 195, 74, 255), 3);
                    }
                    if (financialSeries.DownFill == DefaultPaintTask)
                    {
                        financialSeries.DownFill = new SolidColorPaintTask(new SKColor(239, 83, 80, 255));
                    }
                    if (financialSeries.DownStroke == DefaultPaintTask)
                    {
                        financialSeries.DownStroke = new SolidColorPaintTask(new SKColor(239, 83, 80, 255), 3);
                    }
                }
            })
                   .WithAxisDefaultsResolver(
                       (IAxis <SkiaSharpDrawingContext> axis, bool forceApply) =>
            {
                if (forceApply)
                {
                    if (!LiveCharts.IsConfigured)
                    {
                        LiveCharts.Configure(DefaultPlatformBuilder);
                    }
                    var stylesBuilder = LiveCharts.CurrentSettings.GetTheme <SkiaSharpDrawingContext>();
                    var initializer = stylesBuilder.GetVisualsInitializer();

                    initializer.ApplyStyleToAxis(axis);
                }

                if (axis.SeparatorsPaint == DefaultPaintTask)
                {
                    axis.SeparatorsPaint = axis.Orientation == AxisOrientation.X
                                ? null
                                : new SolidColorPaintTask(new SKColor(90, 90, 90));
                }

                if (axis.LabelsPaint == DefaultPaintTask)
                {
                    axis.LabelsPaint = new SolidColorPaintTask(new SKColor(200, 200, 200));
                }

                if (axis.Padding == Padding.Default)
                {
                    axis.Padding = new Padding {
                        Bottom = 8, Left = 8, Right = 8, Top = 8
                    }
                }
                ;
            }));
        }