src/runtimes/netf/Azos.WinForms/Controls/ChartKit/Temporal/SeriesView.cs
/// <summary>
/// Builds elements that render the data by adding drawable elements to the chart.
/// Returns how many samples could fit
/// </summary>
Builds elements that render the data by adding drawable elements to the chart.
Returns how many samples could fit
Builds elements that render the data by adding drawable elements to the chart . Returns how many samples could fit
public sealed override int BuildElements(TimeSeriesChart chart, PlotPane pane, TimeSeries series, int maxSampleWidth)
    {
        var cdata = series as TSeries;
        if (cdata==null) throw new WFormsException("{0} requires {1} source".Args(GetType().FullName, typeof(TSeries).FullName));
        var drawData = GetDataPerScroll(chart, cdata);
        if (!drawData.Any()) return 0;
        var x = chart.VRulerPosition == VRulerPosition.Left ? chart.VRulerWidth + 1 : 1;
        if (pane.Zoom != 1.0f)
          x = (int)(x/pane.Zoom);
        var xcutof = chart.VRulerPosition == VRulerPosition.Right ? pane.Width - 1 - chart.VRulerWidth : pane.Width;
        var fitSamples = 0;
        var canFitSamples = (int)(pane.Width / ((maxSampleWidth+1) * pane.Zoom)) + 2;
        float minScale;
        float maxScale;
        CalcMinMaxScale(series, drawData.Take(canFitSamples), out minScale, out maxScale);
        if (pane.Zoom!=1.0f)
        {
          switch (this.VScaleZoomAlignment)
          {
             case VScaleZoomAlign.Bottom:
              {
                maxScale = maxScale / pane.Zoom;
                break;
              }
             case VScaleZoomAlign.Top:
              {
                minScale = minScale / pane.Zoom;
                break;
              }
             default: 
              {
                var range = maxScale - minScale;
                var originalMid = minScale + (range  / 2f);
                range = range / pane.Zoom;
                minScale = originalMid - (range / 2f);
                maxScale = originalMid + (range / 2f);
                break;
              }
          }
        }
        m_MinScale = minScale;
        m_MaxScale = maxScale;
        pane.SetMinMaxScale(minScale, maxScale, false);
        var elm = MakeSeriesElement(chart, pane, drawData, x, minScale, maxScale, maxSampleWidth, out fitSamples);
        if (elm!=null)
        {
          elm.Visible = true;
        }
        else
        {
          foreach(var candle in drawData)
          {
            elm = MakeSampleElement(chart, pane, candle, x, minScale, maxScale);
            var edx = elm.DisplayRegion.Left;
            var edw = elm.DisplayRegion.Width;
            if (edx + edw + 1 >= xcutof)
            {
              elm.Dispose();
              break;
            }
            elm.Visible = true;
            x += maxSampleWidth;
            x++;
            fitSamples++;
          }
        }
        if (ShowYLevels)
        {
          foreach(var level in series.YLevels.OrderedValues)
          {
             if (!level.Visible) continue;
             elm = MakeYLevelElement(chart, pane, level, minScale, maxScale);
             elm.Visible = true;
          }
        }
        return fitSamples;
      }
public sealed override int BuildElements ( TimeSeriesChart chart , PlotPane pane , TimeSeries series , int maxSampleWidth ) { var cdata = series as TSeries ; if ( cdata == null ) throw new WFormsException ( " " . Args ( GetType ( ) . FullName , typeof ( TSeries ) . FullName ) ) ; var drawData = GetDataPerScroll ( chart , cdata ) ; if ( ! drawData . Any ( ) ) return 0 ; var x = chart . VRulerPosition == VRulerPosition . Left ? chart . VRulerWidth + 1 : 1 ; if ( pane . Zoom != 1.0f ) x = ( int ) ( x / pane . Zoom ) ; var xcutof = chart . VRulerPosition == VRulerPosition . Right ? pane . Width - 1 - chart . VRulerWidth : pane . Width ; var fitSamples = 0 ; var canFitSamples = ( int ) ( pane . Width / ( ( maxSampleWidth + 1 ) * pane . Zoom ) ) + 2 ; float minScale ; float maxScale ; CalcMinMaxScale ( series , drawData . Take ( canFitSamples ) , out minScale , out maxScale ) ; if ( pane . Zoom != 1.0f ) { switch ( this . VScaleZoomAlignment ) { case VScaleZoomAlign . Bottom : { maxScale = maxScale / pane . Zoom ; break ; } case VScaleZoomAlign . Top : { minScale = minScale / pane . Zoom ; break ; } default : { var range = maxScale - minScale ; var originalMid = minScale + ( range / 2f ) ; range = range / pane . Zoom ; minScale = originalMid - ( range / 2f ) ; maxScale = originalMid + ( range / 2f ) ; break ; } } } m_MinScale = minScale ; m_MaxScale = maxScale ; pane . SetMinMaxScale ( minScale , maxScale , false ) ; var elm = MakeSeriesElement ( chart , pane , drawData , x , minScale , maxScale , maxSampleWidth , out fitSamples ) ; if ( elm != null ) { elm . Visible = true ; } else { foreach ( var candle in drawData ) { elm = MakeSampleElement ( chart , pane , candle , x , minScale , maxScale ) ; var edx = elm . DisplayRegion . Left ; var edw = elm . DisplayRegion . Width ; if ( edx + edw + 1 >= xcutof ) { elm . Dispose ( ) ; break ; } elm . Visible = true ; x += maxSampleWidth ; x ++ ; fitSamples ++ ; } } if ( ShowYLevels ) { foreach ( var level in series . YLevels . OrderedValues ) { if ( ! level . Visible ) continue ; elm = MakeYLevelElement ( chart , pane , level , minScale , maxScale ) ; elm . Visible = true ; } } return fitSamples ; }
Builds elements that render the data by adding drawable elements to the chart.
Builds elements that render the data by adding drawable elements to the chart .
//nothing to draw //safe margin //adjust scale for zoom //case VScaleZoomAlign.Mid: //switch //1. Try to build whole view from 1 Element //2. Make elements per sample //Build level elements
chart
TimeSeriesChart
pane
PlotPane
series
TimeSeries
maxSampleWidth
int