Exemplo n.º 1
0
        private static Axis GetDefaultAxisObject(AxisKind axisKind, Series series, ISeriesInfo seriesInfo, Type userSpecifiedAxisType, Style style)
        {
            // Determine the axis type.

            Type axisType = userSpecifiedAxisType ?? seriesInfo?.AxisTypes[(int)axisKind];

            var builder = seriesInfo?.SeriesBuilder ?? SeriesBuilderStore.OfType(series.GetType());

            if (axisType == builder.DefaultAxisTypes[(int)axisKind])
            {
                axisType = null;
            }

            // Create an axis instance.

            Axis axis;

            if (axisType != null)
            {
                axis          = (Axis)axisType.GetConstructor(new Type[0]).Invoke(new object[0]);
                axis.Position = axisKind.GetDefaultPosition();
            }
            else
            {
                axis = builder.GetDefaultAxisObject(axisKind);
            }

            if (axisKind == AxisKind.Az && series is CandleStickAndVolumeSeries candlev)
            {
                var key = "Volume Axis_" + Guid.NewGuid().ToString();
                axis.Key = key;
                candlev.VolumeAxisKey = axis.Key;
            }

            if (axis != null)
            {
                var title = seriesInfo?.AxisTitles[(int)axisKind];
                if (!string.IsNullOrEmpty(title))
                {
                    axis.Title = title;
                }

                if (axis is CategoryAxis ca && seriesInfo?.CategoryNames != null)
                {
                    foreach (var n in seriesInfo.CategoryNames)
                    {
                        ca.Labels.Add(n);
                    }
                }

                style.ApplyStyleTo(axis);
            }

            return(axis);
        }
Exemplo n.º 2
0
        public static PlotModel Create(PlotModel model, IList <ISeriesInfo> siList, Style style)
        {
            var defaultColorsSave = model.DefaultColors;
            var defaultFontSave   = model.DefaultFont;

            style.ApplyStyleTo(model);

            if (ReferenceEquals(model.DefaultFont, defaultFontSave) && !string.IsNullOrEmpty(style.DefaultFont))
            {
                model.DefaultFont = style.DefaultFont;
            }

            var updated = false;

            model.Updating += (object sender, EventArgs e) =>
            {
                if (updated)
                {
                    return;
                }

                updated = true;

                style.ApplyEventHook(model, EventType.BeforeAxesFixup);

                if (siList == null || siList.Count == 0)
                {
                    AxisInitializer.EnsureAxes((PlotModel)sender, null, style);
                }
                else
                {
                    foreach (var si in siList)
                    {
                        AxisInitializer.EnsureAxes((PlotModel)sender, si, style);
                    }
                }

                if (style.ColorScheme != null && ReferenceEquals(model.DefaultColors, defaultColorsSave))
                {
                    style.ApplyColorScheme(model);
                }

                style.ApplyEventHook(model, EventType.BeforeRendering);
            };

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a SeriesInfo object based on the cmdlet parameters.
        /// </summary>
        /// <returns>A SeriesInfo object.</returns>
        public virtual SeriesInfo <SeriesT> CreateSeriesInfo(Style style)
        {
            int count = (new int[] { _e1.Count, _e2.Count, _e3.Count, _e4.Count, _e5.Count, _e6.Count, _e7.Count, _e8.Count }).Max();

            if (count == 0)
            {
                var s = Create();
                style.ApplyStyleTo(s);
                _info.Series = new[] { s };
                return(_info);
            }

            // Validate data lengths.

            ValidateInputData();

            // Create a set of series.

            var seriesSet = new Dictionary <object, SeriesT>();

            for (var i = 0; i < count; ++i)
            {
                object g = DefaultGroupName;
                if (i < _groups.Count)
                {
                    g = _groups[i];
                }

                SeriesT s;
                if (!seriesSet.TryGetValue(g, out s))
                {
                    s = Create();
                    if (g.ToString() != DefaultGroupName)
                    {
                        s.Title = g.ToString();
                    }
                    seriesSet.Add(g, s);
                }

                AddDataPointToSeries(
                    s,
                    i < _e1.Count ? _e1[i] : GetNaN <E1>(),
                    i < _e2.Count ? _e2[i] : GetNaN <E2>(),
                    i < _e3.Count ? _e3[i] : GetNaN <E3>(),
                    i < _e4.Count ? _e4[i] : GetNaN <E4>(),
                    i < _e5.Count ? _e5[i] : GetNaN <E5>(),
                    i < _e6.Count ? _e6[i] : GetNaN <E6>(),
                    i < _e7.Count ? _e7[i] : GetNaN <E7>(),
                    i < _e8.Count ? _e8[i] : GetNaN <E8>()
                    );
            }

            Postprocess(seriesSet);

            var keys = seriesSet.Keys.ToArray();

            Array.Sort(keys);
            _info.Series = keys.Select(k => seriesSet[k]).ToArray();

            _info.CategoryNames = GetCategoryNames();

            foreach (var s in _info.Series)
            {
                style.ApplyStyleTo(s);
            }

            return(_info);
        }