/// <summary>
    /// Gets the bounds.
    /// </summary>
    /// <param name="chart">The chart.</param>
    /// <param name="secondaryAxis">The secondary axis.</param>
    /// <param name="primaryAxis">The primary axis.</param>
    /// <returns></returns>
    public override SeriesBounds GetBounds(
        CartesianChart <TDrawingContext> chart, ICartesianAxis secondaryAxis, ICartesianAxis primaryAxis)
    {
        var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis);

        if (baseSeriesBounds.HasData)
        {
            return(baseSeriesBounds);
        }
        var baseBounds = baseSeriesBounds.Bounds;

        var tickPrimary   = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds);
        var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds);

        var ts = tickSecondary.Value * DataPadding.X;
        var tp = tickPrimary.Value * DataPadding.Y;

        return
            (new SeriesBounds(
                 new DimensionalBounds
        {
            SecondaryBounds = new Bounds
            {
                Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth,
                Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth,
                PaddingMax = ts,
                PaddingMin = ts
            },
            PrimaryBounds = new Bounds
            {
                Max = baseBounds.PrimaryBounds.Max + tp,
                Min = baseBounds.PrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min : 0,
                PaddingMax = tp,
                PaddingMin = baseBounds.PrimaryBounds.Min < 0 ? tp : 0,
            },
            VisibleSecondaryBounds = new Bounds
            {
                Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts,
                Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts
            },
            VisiblePrimaryBounds = new Bounds
            {
                Max = baseBounds.VisiblePrimaryBounds.Max + tp,
                Min = baseBounds.VisiblePrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0
            },
            MinDeltaPrimary = baseBounds.MinDeltaPrimary,
            MinDeltaSecondary = baseBounds.MinDeltaSecondary
        },
                 false));
    }
Exemplo n.º 2
0
        public MeasureHelper(
            Scaler scaler,
            CartesianChart <TDrawingContext> cartesianChart,
            IBarSeries <TDrawingContext> barSeries,
            ICartesianAxis axis,
            float p)
        {
            this.p = p;

            uw       = scaler.MeasureInPixels(axis.UnitWidth);
            actualUw = uw;

            var gp = (float)barSeries.GroupPadding;

            if (uw - gp < 1)
            {
                gp -= uw - gp;
            }

            uw -= gp;
            uwm = 0.5f * uw;

            var pos   = cartesianChart.SeriesContext.GetColumnPostion(barSeries);
            var count = cartesianChart.SeriesContext.GetColumnSeriesCount();

            cp = 0f;

            if (!barSeries.IgnoresBarPosition && count > 1)
            {
                uw /= count;
                uwm = 0.5f * uw;
                cp  = (pos - count / 2f) * uw + uwm;
            }

            if (uw > barSeries.MaxBarWidth)
            {
                uw  = (float)barSeries.MaxBarWidth;
                uwm = uw * 0.5f;
            }

            if (uw < 1)
            {
                uw  = 1;
                uwm = 0.5f;
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc cref="CartesianSeries{TModel, TVisual, TLabel, TDrawingContext}.GetBounds(CartesianChart{TDrawingContext}, ICartesianAxis, ICartesianAxis)"/>
        public override SeriesBounds GetBounds(
            CartesianChart <TDrawingContext> chart, ICartesianAxis secondaryAxis, ICartesianAxis primaryAxis)
        {
            var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis);

            if (baseSeriesBounds.HasData)
            {
                return(baseSeriesBounds);
            }
            var baseBounds = baseSeriesBounds.Bounds;

            var tickPrimary   = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds);
            var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds);

            var ts = tickSecondary.Value * DataPadding.X;
            var tp = tickPrimary.Value * DataPadding.Y;

            if (baseBounds.VisibleSecondaryBounds.Delta == 0)
            {
                var ms = baseBounds.VisibleSecondaryBounds.Min == 0 ? 1 : baseBounds.VisibleSecondaryBounds.Min;
                ts = 0.1 * ms * DataPadding.X;
            }

            if (baseBounds.VisiblePrimaryBounds.Delta == 0)
            {
                var mp = baseBounds.VisiblePrimaryBounds.Min == 0 ? 1 : baseBounds.VisiblePrimaryBounds.Min;
                tp = 0.1 * mp * DataPadding.Y;
            }

            return
                (new SeriesBounds(
                     new DimensionalBounds
            {
                PrimaryBounds = new Bounds
                {
                    Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth,
                    Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth,
                    PaddingMax = ts,
                    PaddingMin = ts
                },
                SecondaryBounds = new Bounds
                {
                    Max = baseBounds.PrimaryBounds.Max,
                    Min = baseBounds.PrimaryBounds.Min,
                    PaddingMax = tp,
                    PaddingMin = tp
                },
                VisiblePrimaryBounds = new Bounds
                {
                    Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth,
                    Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth
                },
                VisibleSecondaryBounds = new Bounds
                {
                    Max = baseBounds.VisiblePrimaryBounds.Max,
                    Min = baseBounds.VisiblePrimaryBounds.Min
                },
                MinDeltaPrimary = baseBounds.MinDeltaPrimary,
                MinDeltaSecondary = baseBounds.MinDeltaSecondary
            },
                     false));
        }
Exemplo n.º 4
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Scaler"/> class.
    /// </summary>
    /// <param name="drawMagrinLocation">The draw margin location.</param>
    /// <param name="drawMarginSize">Size of the draw margin.</param>
    /// <param name="axis">The axis.</param>
    /// <param name="usePreviousScale">Indicates if the scaler should be built based on the previous known data.</param>
    /// <param name="bounds">Indicates the bounds to use.</param>
    /// <exception cref="Exception">The axis is not ready to be scaled.</exception>
    public Scaler(
        LvcPoint drawMagrinLocation, LvcSize drawMarginSize, ICartesianAxis axis, bool usePreviousScale = false, Bounds?bounds = null)
    {
        if (axis.Orientation == AxisOrientation.Unknown)
        {
            throw new Exception("The axis is not ready to be scaled.");
        }

        _orientation = axis.Orientation;

        var actualBounds        = usePreviousScale ? axis.PreviousDataBounds : axis.DataBounds;
        var actualVisibleBounds = usePreviousScale ? axis.PreviousVisibleDataBounds : axis.VisibleDataBounds;
        var maxLimit            = usePreviousScale ? axis.PreviousMaxLimit : axis.MaxLimit;
        var minLimit            = usePreviousScale ? axis.PreviousMinLimit : axis.MinLimit;

        if (bounds != null)
        {
            actualBounds        = bounds;
            actualVisibleBounds = bounds;
        }

        if (actualBounds is null || actualVisibleBounds is null)
        {
            throw new Exception("bounds not found");
        }

        if (double.IsInfinity(actualBounds.Delta) || double.IsInfinity(actualVisibleBounds.Delta))
        {
            _maxVal   = 0;
            _minVal   = 0;
            _deltaVal = 0;

            if (axis.Orientation == AxisOrientation.X)
            {
                _minPx   = drawMagrinLocation.X;
                _maxPx   = drawMagrinLocation.X + drawMarginSize.Width;
                _deltaPx = _maxPx - _minPx;
            }
            else
            {
                _minPx   = drawMagrinLocation.Y;
                _maxPx   = drawMagrinLocation.Y + drawMarginSize.Height;
                _deltaPx = _maxPx - _minPx;
            }

            _m    = 0;
            _mInv = 0;

            return;
        }

        if (axis.Orientation == AxisOrientation.X)
        {
            _minPx   = drawMagrinLocation.X;
            _maxPx   = drawMagrinLocation.X + drawMarginSize.Width;
            _deltaPx = _maxPx - _minPx;

            _maxVal = axis.IsInverted ? actualBounds.Min : actualBounds.Max;
            _minVal = axis.IsInverted ? actualBounds.Max : actualBounds.Min;

            if (maxLimit is not null || minLimit is not null)
            {
                _maxVal = axis.IsInverted ? minLimit ?? _minVal : maxLimit ?? _maxVal;
                _minVal = axis.IsInverted ? maxLimit ?? _maxVal : minLimit ?? _minVal;
            }
            else
            {
                var visibleMax = axis.IsInverted ? actualVisibleBounds.Min : actualVisibleBounds.Max;
                var visibleMin = axis.IsInverted ? actualVisibleBounds.Max : actualVisibleBounds.Min;

                if (visibleMax != _maxVal || visibleMin != _minVal)
                {
                    _maxVal = visibleMax;
                    _minVal = visibleMin;
                }
            }

            _deltaVal = _maxVal - _minVal;
        }