Ejemplo n.º 1
0
        // values[0] - Point CurrentMousePosition
        // values[1] - double VolumeHistogramHeight
        // values[2] - CandleExtremums visibleCandlesExtremums
        // values[3] - double VolumeHistogramTopMargin
        // values[4] - double VolumeHistogramBottomMargin
        // values[5] - CultureInfo candleChartCulture
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length < 5 || (values[0]).GetType() != typeof(Point) || (values[1]).GetType() != typeof(double) || (values[2]).GetType() != typeof(CandleExtremums) ||
                (values[3]).GetType() != typeof(double) || (values[4]).GetType() != typeof(double))
            {
                return(0.0);
            }

            Point           currentMousePosition        = (Point)values[0];
            double          volumeHistogramHeight       = (double)values[1];
            CandleExtremums visibleCandlesExtremums     = (CandleExtremums)values[2];
            double          volumeHistogramTopMargin    = (double)values[3];
            double          volumeHistogramBottomMargin = (double)values[4];

            CultureInfo candleChartCulture = (CultureInfo)values[5];
            string      decimalSeparator   = candleChartCulture.NumberFormat.NumberDecimalSeparator;

            char[] decimalSeparatorArray = decimalSeparator.ToCharArray();

            double volume = (((visibleCandlesExtremums.VolumeHigh - (currentMousePosition.Y - volumeHistogramTopMargin) / (volumeHistogramHeight - volumeHistogramTopMargin - volumeHistogramBottomMargin) * visibleCandlesExtremums.VolumeHigh)));

            return(MyNumberFormatting.VolumeToLimitedLengthString(volume, candleChartCulture, decimalSeparator, decimalSeparatorArray));
        }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------------------------------------------------------------------------
        protected override void OnRender(DrawingContext drawingContext)
        {
            //if (VisibleCandlesExtremums.VolumeHigh == long.MinValue) return;

            double textHeight      = (new FormattedText("1,23", Culture, FlowDirection.LeftToRight, currentTypeFace, TickLabelFontSize, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip)).Height;
            double halfTextHeight  = textHeight / 2.0;
            double chartPanelWidth = ActualWidth - PriceAxisWidth;
            double tickLabelX      = chartPanelWidth + TICK_LINE_WIDTH + TICK_LEFT_MARGIN;
            double tickLineEndX    = chartPanelWidth + TICK_LINE_WIDTH;
            double chartHeight     = ActualHeight - ChartBottomMargin - ChartTopMargin;

            if (chartHeight <= 0)
            {
                return;
            }

            double stepInVolumeUnits        = VisibleCandlesExtremums.VolumeHigh * ((textHeight + GapBetweenTickLabels) / chartHeight);
            double stepInVolumeUnits_HPlace = MyWpfMath.HighestDecimalPlace(stepInVolumeUnits, out _);

            stepInVolumeUnits = Math.Ceiling(stepInVolumeUnits / stepInVolumeUnits_HPlace) * stepInVolumeUnits_HPlace;
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            double chartHeight_candlesLHRange_Ratio = chartHeight / VisibleCandlesExtremums.VolumeHigh;

            string decimalSeparator = Culture.NumberFormat.NumberDecimalSeparator;

            char[] decimalSeparatorArray = decimalSeparator.ToCharArray();

            void DrawVolumeTick(double volume)
            {
                string        s = MyNumberFormatting.VolumeToLimitedLengthString(volume, Culture, decimalSeparator, decimalSeparatorArray);
                FormattedText priceTickFormattedText = new FormattedText(s, Culture, FlowDirection.LeftToRight, currentTypeFace, TickLabelFontSize, TickColor, VisualTreeHelper.GetDpi(this).PixelsPerDip);
                double        y = ChartTopMargin + (VisibleCandlesExtremums.VolumeHigh - volume) * chartHeight_candlesLHRange_Ratio;

                drawingContext.DrawText(priceTickFormattedText, new Point(tickLabelX, y - halfTextHeight));
                drawingContext.DrawLine(tickPen, new Point(chartPanelWidth, y), new Point(tickLineEndX, y));

                if (IsGridlinesEnabled && GridlinesPen != null)
                {
                    drawingContext.DrawLine(GridlinesPen, new Point(0, y), new Point(chartPanelWidth, y));
                }
            }

            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            double theMostRoundVolume = MyWpfMath.HighestDecimalPlace(VisibleCandlesExtremums.VolumeHigh, out _);

            DrawVolumeTick(theMostRoundVolume);

            double maxVolumeThreshold = (VisibleCandlesExtremums.VolumeHigh + (ChartTopMargin - halfTextHeight) / chartHeight_candlesLHRange_Ratio);
            double minVolumeThreshold = (VisibleCandlesExtremums.VolumeHigh + (ChartTopMargin - ActualHeight + halfTextHeight) / chartHeight_candlesLHRange_Ratio);

            int    step_i = 1;
            double next_tick;

            while ((next_tick = theMostRoundVolume + step_i * stepInVolumeUnits) < maxVolumeThreshold)
            {
                DrawVolumeTick(next_tick);
                step_i++;
            }

            step_i = 1;
            while ((next_tick = theMostRoundVolume - step_i * stepInVolumeUnits) > minVolumeThreshold)
            {
                DrawVolumeTick(next_tick);
                step_i++;
            }
        }