Beispiel #1
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DimensionalBounds"/> class.
    /// </summary>
    /// <param name="useInitial"></param>
    internal DimensionalBounds(bool useInitial)
    {
        PrimaryBounds          = new Bounds();
        SecondaryBounds        = new Bounds();
        TertiaryBounds         = new Bounds();
        VisiblePrimaryBounds   = new Bounds();
        VisibleSecondaryBounds = new Bounds();
        VisibleTertiaryBounds  = new Bounds();

        if (!useInitial)
        {
            return;
        }

        VisiblePrimaryBounds.AppendValue(0);
        VisiblePrimaryBounds.AppendValue(10);
        PrimaryBounds.AppendValue(0);
        PrimaryBounds.AppendValue(10);

        VisibleSecondaryBounds.AppendValue(0);
        VisibleSecondaryBounds.AppendValue(10);
        SecondaryBounds.AppendValue(0);
        SecondaryBounds.AppendValue(10);

        VisibleTertiaryBounds.AppendValue(1);
        TertiaryBounds.AppendValue(1);

        IsEmpty = true;
    }
Beispiel #2
0
        /// <summary>
        /// Returns a geoJson map into a heat map.
        /// </summary>
        /// <param name="geoJson">The geoJson.</param>
        /// <param name="values">The values.</param>
        /// <param name="heatMap">The heat map.</param>
        /// <param name="heatStops">The heat stops.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="fill">The fill.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="projector">The projector.</param>
        /// <returns></returns>
        public static IEnumerable<PathShape> AsHeatMapShapes(
            this GeoJsonFile geoJson,
            Dictionary<string, double> values,
            LvcColor[] heatMap, List<Tuple<double, LvcColor>> heatStops,
            LvcColor stroke,
            LvcColor fill,
            float thickness,
            MapProjector projector)
        {
            var paths = new List<PathShape>();

            var weightBounds = new Bounds();
            foreach (var value in values)
            {
                weightBounds.AppendValue(value.Value);
            }

            var d = new double[0][][][];

            foreach (var feature in geoJson.Features ?? new GeoJsonFeature[0])
            {
                var name = feature.Properties is not null ? feature.Properties["shortName"] : "";
                LvcColor? baseColor = values.TryGetValue(name, out var weight)
                    ? HeatFunctions.InterpolateColor((float)weight, weightBounds, heatMap, heatStops)
                    : null;

                foreach (var geometry in feature.Geometry?.Coordinates ?? d)
                {
                    foreach (var segment in geometry)
                    {
                        var path = new PathShape
                        {
                            StrokeColor = stroke,
                            FillColor = baseColor ?? fill,
                            StrokeThickness = thickness,
                            IsClosed = true
                        };
                        var isFirst = true;
                        foreach (var point in segment)
                        {
                            var p = projector.ToMap(point);

                            if (isFirst)
                            {
                                isFirst = false;
                                path.AddCommand(new MoveToPathCommand { X = p[0], Y = p[1] });
                                continue;
                            }

                            path.AddCommand(new LineSegment { X = p[0], Y = p[1] });
                        }
                        paths.Add(path);
                    }
                }
            }

            return paths;
        }
Beispiel #3
0
        protected override void Measure()
        {
            if (series == null)
            {
                chartView.CoreCanvas.ForEachGeometry((geometry, drawable) =>
                {
                    if (measuredDrawables.Contains(geometry))
                    {
                        return;                                       // then the geometry was measured
                    }
                    // at this point,the geometry is not required in the UI
                    geometry.RemoveOnCompleted = true;
                });
                return;
            }

            measuredDrawables = new HashSet <IDrawable <TDrawingContext> >();
            seriesContext     = new SeriesContext <TDrawingContext>(series);

            if (legend != null)
            {
                legend.Draw(this);
            }

            ValueBounds   = new Bounds();
            IndexBounds   = new Bounds();
            PushoutBounds = new Bounds();
            foreach (var series in series)
            {
                if (series.SeriesId == -1)
                {
                    series.SeriesId = nextSeries++;
                }
                LiveCharts.CurrentSettings.ResolveSeriesDefaults(series);

                var seriesBounds = series.GetBounds(this);

                ValueBounds.AppendValue(seriesBounds.PrimaryBounds.max);
                ValueBounds.AppendValue(seriesBounds.PrimaryBounds.min);
                IndexBounds.AppendValue(seriesBounds.SecondaryBounds.max);
                IndexBounds.AppendValue(seriesBounds.SecondaryBounds.min);
                PushoutBounds.AppendValue(seriesBounds.TertiaryBounds.max);
                PushoutBounds.AppendValue(seriesBounds.TertiaryBounds.min);
            }

            if (viewDrawMargin == null)
            {
                var m = viewDrawMargin ?? new Margin();
                SetDrawMargin(controlSize, m);
                SetDrawMargin(controlSize, m);
            }

            // invalid dimensions, probably the chart is too small
            // or it is initializing in the UI and has no dimensions yet
            if (drawMarginSize.Width <= 0 || drawMarginSize.Height <= 0)
            {
                return;
            }

            foreach (var series in series)
            {
                series.Measure(this);
            }

            chartView.CoreCanvas.ForEachGeometry((geometry, drawable) =>
            {
                if (measuredDrawables.Contains(geometry))
                {
                    return;                                       // then the geometry was measured
                }
                // at this point,the geometry is not required in the UI
                geometry.RemoveOnCompleted = true;
            });

            Canvas.Invalidate();
        }