Ejemplo n.º 1
0
 private void AddStartCode()
 {
     Bars.Clear();
     foreach (var bar in BarViewModel.CreateRange(new[] { 1, 0, 1, 0 }, new[] { 1d, 1d, 1d, 1d }, DefaultBarHeight))
     {
         Bars.Add(bar);
     }
 }
Ejemplo n.º 2
0
        private void InitializeIsoGrid()
        {
            // May need to come up with a better fix for this, as this isn't the best fix for our memory leak
            Resources.UnloadUnusedAssets();    // Needed to unload unused materials (which are assets); in our case these are the isoGrid materials

            foreach (var bar in Bars)
            {
                Destroy(bar.VisualData.Bound.gameObject);
            }
            Bars.Clear();
        }
Ejemplo n.º 3
0
        public IBarGraphViewModel UpdateWith(int[] percentages)
        {
            Bars.Clear();

            if (percentages.Length < 2)
            {
                Visible = false;
                return(this);
            }

            AddBarsAndMakeVisible(percentages);

            return(this);
        }
Ejemplo n.º 4
0
 public void move_off()
 {
     Window_Move_Array = new List <int> {
         0, 0, 0, -18, -18, -18, -18, -18, -18, -18, -18
     };
     Header_Move_Array = new List <int> {
         0, 0, 0, -18, -18, -18, -18, -18, -18, -18, -18
     };
     Face_Move_Array = new List <int> {
         0, 0, 0, 12, 12, 12, 12, 12, 12, 12, 12
     };
     Arrows.Clear();
     Bars.Clear();
     Stat_Gains.Clear();
 }
Ejemplo n.º 5
0
 private void UpdateBars()
 {
     Transactions.Clear();
     Bars.Clear();
     for (int month = 1; month < 13; month++)
     {
         Core.Instance.GetSpendings(SelectedYear, month).ForEach((s) =>
         {
             if (s.Category == SelectedCategory.category)
             {
                 Bars.Add(new BudgetBar(s));
             }
         });
     }
 }
Ejemplo n.º 6
0
        private void GenerateBars(string code)
        {
            if (!code.StartsWith("*"))
            {
                code = '*' + code;
            }
            if (!code.EndsWith("*"))
            {
                code += '*';
            }

            Bars.Clear();
            foreach (var item in code.Select(x => Encoding[x]))
            {
                foreach (char e in item.Encoding)
                {
                    Bars.Add(new BarViewModel(e == '1' ? BarType.Solid : BarType.Clear, 1, DefaultBarHeight));
                }
                Bars.Add(new BarViewModel(BarType.Clear, 1, DefaultBarHeight));
            }
        }
Ejemplo n.º 7
0
        protected override void CalcData()
        {
            Bars.Clear();
            NeedDraw = false;
            if (Option == null || Option.Series == null || Option.SeriesCount == 0)
            {
                return;
            }

            DrawOrigin = new Point(Option.Grid.Left, Height - Option.Grid.Bottom);
            DrawSize   = new Size(Width - Option.Grid.Left - Option.Grid.Right,
                                  Height - Option.Grid.Top - Option.Grid.Bottom);

            if (DrawSize.Width <= 0 || DrawSize.Height <= 0)
            {
                return;
            }
            if (Option.XAxis.Data.Count == 0)
            {
                return;
            }

            NeedDraw     = true;
            DrawBarWidth = DrawSize.Width * 1.0f / Option.XAxis.Data.Count;

            double min = double.MaxValue;
            double max = double.MinValue;

            foreach (var series in Option.Series)
            {
                if (series.Data.Count > 0)
                {
                    min = Math.Min(min, series.Data.Min());
                    max = Math.Max(max, series.Data.Max());
                }
            }

            if (min > 0 && max > 0 && !Option.YAxis.Scale)
            {
                min = 0;
            }
            if (min < 0 && max < 0 && !Option.YAxis.Scale)
            {
                max = 0;
            }
            if (!Option.YAxis.MaxAuto)
            {
                max = Option.YAxis.Max;
            }
            if (!Option.YAxis.MinAuto)
            {
                min = Option.YAxis.Min;
            }

            if ((max - min).IsZero() && min.IsZero())
            {
                max = 100;
                min = 0;
            }
            else
            {
                if (max > 0)
                {
                    min = 0;
                }
                else
                {
                    max = 0;
                }
            }

            CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
                            out int start, out int end, out double interval, out int decimalCount);

            YAxisStart        = start;
            YAxisEnd          = end;
            YAxisInterval     = interval;
            YAxisDecimalCount = decimalCount;

            float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1);
            float x2 = x1 * 2;

            for (int i = 0; i < Option.SeriesCount; i++)
            {
                float barX   = DrawOrigin.X;
                var   series = Option.Series[i];
                Bars.TryAdd(i, new List <BarInfo>());
                for (int j = 0; j < series.Data.Count; j++)
                {
                    Color color = ChartStyle.GetColor(i);
                    if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                    {
                        color = series.Colors[j];
                    }

                    float xx = barX + x1 * (i + 1) + x2 * i + x1;
                    float ww = Math.Min(x2, series.MaxWidth);
                    xx -= ww / 2.0f;

                    if (YAxisStart >= 0)
                    {
                        float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                        Bars[i].Add(new BarInfo()
                        {
                            Rect  = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
                            Color = color
                        });
                    }
                    else if (YAxisEnd <= 0)
                    {
                        float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                        Bars[i].Add(new BarInfo()
                        {
                            Rect  = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
                            Color = color
                        });
                    }
                    else
                    {
                        float lowH          = 0;
                        float highH         = 0;
                        float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                        float lowV          = 0;
                        float highV         = 0;
                        for (int k = YAxisStart; k <= YAxisEnd; k++)
                        {
                            if (k < 0)
                            {
                                lowH += DrawBarHeight;
                            }
                            if (k > 0)
                            {
                                highH += DrawBarHeight;
                            }
                            if (k < 0)
                            {
                                lowV += (float)YAxisInterval;
                            }
                            if (k > 0)
                            {
                                highV += (float)YAxisInterval;
                            }
                        }

                        // lowH.ConsoleWriteLine();
                        // highH.ConsoleWriteLine();

                        if (series.Data[j] >= 0)
                        {
                            float h = Math.Abs((float)(highH * series.Data[j] / highV));
                            Bars[i].Add(new BarInfo()
                            {
                                Rect  = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
                                Color = color
                            });
                        }
                        else
                        {
                            float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                            Bars[i].Add(new BarInfo()
                            {
                                Rect  = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
                                Color = color
                            });
                        }
                    }

                    barX += DrawBarWidth;
                }
            }

            if (Option.ToolTip != null)
            {
                for (int i = 0; i < Option.XAxis.Data.Count; i++)
                {
                    string str = Option.XAxis.Data[i];
                    foreach (var series in Option.Series)
                    {
                        str += '\n';
                        str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat);
                    }

                    Bars[0][i].Tips = str;
                }
            }
        }
Ejemplo n.º 8
0
        protected override void CalcData()
        {
            Bars.Clear();
            NeedDraw = false;
            if (Option == null || Option.Series == null || Option.SeriesCount == 0)
            {
                return;
            }
            if (DrawSize.Width <= 0 || DrawSize.Height <= 0)
            {
                return;
            }
            if (Option.Series.Count == 0)
            {
                return;
            }

            NeedDraw     = true;
            DrawBarWidth = DrawSize.Width * 1.0f / Option.Series.Count;

            double min = double.MaxValue;
            double max = double.MinValue;

            foreach (var series in Option.Series)
            {
                min = Math.Min(min, series.Data.Min());
                max = Math.Max(max, series.Data.Max());
            }

            if (min > 0 && max > 0 && !Option.YAxis.Scale)
            {
                min = 0;
            }

            if (min < 0 && max < 0 && !Option.YAxis.Scale)
            {
                max = 0;
            }

            if (!Option.YAxis.MaxAuto)
            {
                max = Option.YAxis.Max;
            }
            if (!Option.YAxis.MinAuto)
            {
                min = Option.YAxis.Min;
            }

            if ((max - min).IsZero())
            {
                if (min.IsZero())
                {
                    max = 100;
                    min = 0;
                }
                else if (max > 0)
                {
                    max = max * 2;
                    min = 0;
                }
                else
                {
                    max = 0;
                    min = min * 2;
                }
            }

            CalcDegreeScale(min, max, Option.YAxis.SplitNumber,
                            out int start, out int end, out double interval, out int decimalCount);

            YAxisStart        = start;
            YAxisEnd          = end;
            YAxisInterval     = interval;
            YAxisDecimalCount = decimalCount;
            float barX = DrawOrigin.X;

            if (Option.AutoSizeBars)
            {
                //每个柱子等宽
                float x1 = DrawSize.Width * 1.0f / DataCount / 4;
                float x2 = x1 * 2;

                if (Option.AutoSizeBarsCompact)
                {
                    //紧凑
                    for (int i = 0; i < Option.SeriesCount; i++)
                    {
                        var series = Option.Series[i];
                        Bars.TryAdd(i, new List <BarInfo>());
                        float sx = barX + x1 * ((series.Data.Count * 4 - (series.Data.Count * 2 + (series.Data.Count - 1) * Option.AutoSizeBarsCompactValue)) / 2.0f) + x1;

                        for (int j = 0; j < series.Data.Count; j++)
                        {
                            Color color = ChartStyle.GetColor(i);
                            if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                            {
                                color = series.Colors[j];
                            }

                            float ww = Math.Min(x2, series.MaxWidth);
                            float xx = sx - ww / 2.0f;

                            if (YAxisStart >= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
                                    Color = color
                                });
                            }
                            else if (YAxisEnd <= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
                                    Color = color
                                });
                            }
                            else
                            {
                                float lowH          = 0;
                                float highH         = 0;
                                float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                                float lowV          = 0;
                                float highV         = 0;
                                for (int k = YAxisStart; k <= YAxisEnd; k++)
                                {
                                    if (k < 0)
                                    {
                                        lowH += DrawBarHeight;
                                    }
                                    if (k > 0)
                                    {
                                        highH += DrawBarHeight;
                                    }
                                    if (k < 0)
                                    {
                                        lowV += (float)YAxisInterval;
                                    }
                                    if (k > 0)
                                    {
                                        highV += (float)YAxisInterval;
                                    }
                                }

                                if (series.Data[j] >= 0)
                                {
                                    float h = Math.Abs((float)(highH * series.Data[j] / highV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
                                        Color = color
                                    });
                                }
                                else
                                {
                                    float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
                                        Color = color
                                    });
                                }
                            }

                            sx += x2 + x1 * Option.AutoSizeBarsCompactValue;
                        }

                        barX += x2 * 2 * series.Data.Count;
                    }
                }
                else
                {
                    //宽松
                    for (int i = 0; i < Option.SeriesCount; i++)
                    {
                        var series = Option.Series[i];
                        Bars.TryAdd(i, new List <BarInfo>());

                        for (int j = 0; j < series.Data.Count; j++)
                        {
                            Color color = ChartStyle.GetColor(i);
                            if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                            {
                                color = series.Colors[j];
                            }

                            float xx = barX + DrawSize.Width * 1.0f / DataCount / 2;
                            float ww = Math.Min(x2, series.MaxWidth);
                            xx -= ww / 2.0f;

                            if (YAxisStart >= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
                                    Color = color
                                });
                            }
                            else if (YAxisEnd <= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
                                    Color = color
                                });
                            }
                            else
                            {
                                float lowH          = 0;
                                float highH         = 0;
                                float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                                float lowV          = 0;
                                float highV         = 0;
                                for (int k = YAxisStart; k <= YAxisEnd; k++)
                                {
                                    if (k < 0)
                                    {
                                        lowH += DrawBarHeight;
                                    }
                                    if (k > 0)
                                    {
                                        highH += DrawBarHeight;
                                    }
                                    if (k < 0)
                                    {
                                        lowV += (float)YAxisInterval;
                                    }
                                    if (k > 0)
                                    {
                                        highV += (float)YAxisInterval;
                                    }
                                }

                                if (series.Data[j] >= 0)
                                {
                                    float h = Math.Abs((float)(highH * series.Data[j] / highV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
                                        Color = color
                                    });
                                }
                                else
                                {
                                    float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
                                        Color = color
                                    });
                                }
                            }

                            barX += DrawSize.Width * 1.0f / DataCount;
                        }
                    }
                }
            }
            else
            {
                //每个序列等宽
                if (Option.AutoSizeBarsCompact)
                {
                    //紧凑

                    float CompactWidth = DrawBarWidth / 4.0f * Option.AutoSizeBarsCompactValue;

                    for (int i = 0; i < Option.SeriesCount; i++)
                    {
                        var   series = Option.Series[i];
                        float x1     = DrawBarWidth / series.Data.Count / 4.0f;
                        float x2     = x1 * 2;
                        float ww     = Math.Min(x2, series.MaxWidth);

                        float sx = barX + (DrawBarWidth - ww * series.Data.Count - (series.Data.Count - 1) * CompactWidth) / 2.0f;

                        Bars.TryAdd(i, new List <BarInfo>());
                        for (int j = 0; j < series.Data.Count; j++)
                        {
                            Color color = ChartStyle.GetColor(i);
                            if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                            {
                                color = series.Colors[j];
                            }

                            float xx = sx;

                            if (YAxisStart >= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
                                    Color = color
                                });
                            }
                            else if (YAxisEnd <= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
                                    Color = color
                                });
                            }
                            else
                            {
                                float lowH          = 0;
                                float highH         = 0;
                                float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                                float lowV          = 0;
                                float highV         = 0;
                                for (int k = YAxisStart; k <= YAxisEnd; k++)
                                {
                                    if (k < 0)
                                    {
                                        lowH += DrawBarHeight;
                                    }
                                    if (k > 0)
                                    {
                                        highH += DrawBarHeight;
                                    }
                                    if (k < 0)
                                    {
                                        lowV += (float)YAxisInterval;
                                    }
                                    if (k > 0)
                                    {
                                        highV += (float)YAxisInterval;
                                    }
                                }

                                if (series.Data[j] >= 0)
                                {
                                    float h = Math.Abs((float)(highH * series.Data[j] / highV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
                                        Color = color
                                    });
                                }
                                else
                                {
                                    float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
                                        Color = color
                                    });
                                }
                            }

                            sx += ww + CompactWidth;
                        }

                        barX += DrawBarWidth;
                    }
                }
                else
                {
                    //宽松
                    for (int i = 0; i < Option.SeriesCount; i++)
                    {
                        var   series = Option.Series[i];
                        float x1;
                        if (Option.FixedSeriesCount > 0)
                        {
                            x1 = DrawBarWidth / (Option.FixedSeriesCount * 2 + Option.FixedSeriesCount + 1);
                        }
                        else
                        {
                            x1 = DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1);
                        }

                        float x2 = x1 * 2;

                        Bars.TryAdd(i, new List <BarInfo>());
                        for (int j = 0; j < series.Data.Count; j++)
                        {
                            Color color = ChartStyle.GetColor(i);
                            if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                            {
                                color = series.Colors[j];
                            }

                            float xx;
                            if (Option.FixedSeriesCount > 0)
                            {
                                xx = barX + DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1) * ((j + 1) * 3 - 1);
                            }
                            else
                            {
                                xx = barX + x1 * ((j + 1) * 3 - 1);
                            }

                            float ww = Math.Min(x2, series.MaxWidth);
                            xx -= ww / 2.0f;

                            if (YAxisStart >= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
                                    Color = color
                                });
                            }
                            else if (YAxisEnd <= 0)
                            {
                                float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                                Bars[i].Add(new BarInfo()
                                {
                                    Rect  = new RectangleF(xx, Option.Grid.Top + 1, ww, h - 1),
                                    Color = color
                                });
                            }
                            else
                            {
                                float lowH          = 0;
                                float highH         = 0;
                                float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                                float lowV          = 0;
                                float highV         = 0;
                                for (int k = YAxisStart; k <= YAxisEnd; k++)
                                {
                                    if (k < 0)
                                    {
                                        lowH += DrawBarHeight;
                                    }
                                    if (k > 0)
                                    {
                                        highH += DrawBarHeight;
                                    }
                                    if (k < 0)
                                    {
                                        lowV += (float)YAxisInterval;
                                    }
                                    if (k > 0)
                                    {
                                        highV += (float)YAxisInterval;
                                    }
                                }

                                if (series.Data[j] >= 0)
                                {
                                    float h = Math.Abs((float)(highH * series.Data[j] / highV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
                                        Color = color
                                    });
                                }
                                else
                                {
                                    float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                                    Bars[i].Add(new BarInfo()
                                    {
                                        Rect  = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
                                        Color = color
                                    });
                                }
                            }
                        }

                        barX += DrawBarWidth;
                    }
                }
            }

            if (Option.ToolTip != null)
            {
                for (int i = 0; i < Option.Series.Count; i++)
                {
                    var    series = Option.Series[i];
                    string str    = Option.Series[i].Name;
                    for (int j = 0; j < series.Data.Count; j++)
                    {
                        str += '\n';
                        if (series.BarName.Count > 0 && j < series.BarName.Count)
                        {
                            str += series.BarName[j] + " : ";
                        }

                        str += series.Data[j].ToString(Option.ToolTip.ValueFormat);
                    }

                    Bars[i][0].Tips = str;
                }
            }
        }
Ejemplo n.º 9
0
        protected override void CalcData(UIOption option)
        {
            Bars.Clear();
            NeedDraw = false;
            UIBarOption o = (UIBarOption)option;

            if (o == null || o.Series == null || o.SeriesCount == 0)
            {
                return;
            }

            DrawOrigin = new Point(BarOption.Grid.Left, Height - BarOption.Grid.Bottom);
            DrawSize   = new Size(Width - BarOption.Grid.Left - BarOption.Grid.Right,
                                  Height - BarOption.Grid.Top - BarOption.Grid.Bottom);

            if (DrawSize.Width <= 0 || DrawSize.Height <= 0)
            {
                return;
            }
            if (o.XAxis.Data.Count == 0)
            {
                return;
            }

            NeedDraw     = true;
            DrawBarWidth = DrawSize.Width * 1.0f / o.XAxis.Data.Count;

            double min = double.MaxValue;
            double max = double.MinValue;

            foreach (var series in o.Series)
            {
                min = Math.Min(min, series.Data.Min());
                max = Math.Max(max, series.Data.Max());
            }

            if (min > 0 && max > 0 && !o.YAxis.Scale)
            {
                min = 0;
            }

            if (min < 0 && max < 0 && !o.YAxis.Scale)
            {
                max = 0;
            }

            if (!o.YAxis.MaxAuto)
            {
                max = o.YAxis.Max;
            }
            if (!o.YAxis.MinAuto)
            {
                min = o.YAxis.Min;
            }

            if ((max - min).IsZero())
            {
                max = 100;
                min = 0;
            }

            UIChartHelper.CalcDegreeScale(min, max, o.YAxis.SplitNumber,
                                          out int start, out int end, out double interval);

            YAxisStart    = start;
            YAxisEnd      = end;
            YAxisInterval = interval;

            float x1 = DrawBarWidth / ((o.SeriesCount * 2) + o.SeriesCount + 1);
            float x2 = x1 * 2;

            for (int i = 0; i < o.SeriesCount; i++)
            {
                float barX   = DrawOrigin.X;
                var   series = o.Series[i];
                Bars.TryAdd(i, new List <BarInfo>());

                for (int j = 0; j < series.Data.Count; j++)
                {
                    if (YAxisStart >= 0)
                    {
                        float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));

                        Bars[i].Add(new BarInfo()
                        {
                            Rect = new RectangleF(
                                barX + x1 * (i + 1) + x2 * i,
                                DrawOrigin.Y - h,
                                x2, h)
                        });
                    }
                    else if (YAxisEnd <= 0)
                    {
                        float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
                        Bars[i].Add(new BarInfo()
                        {
                            Rect = new RectangleF(
                                barX + x1 * (i + 1) + x2 * i,
                                BarOption.Grid.Top + 1,
                                x2, h - 1)
                        });
                    }
                    else
                    {
                        float lowH          = 0;
                        float highH         = 0;
                        float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
                        float lowV          = 0;
                        float highV         = 0;
                        for (int k = YAxisStart; k <= YAxisEnd; k++)
                        {
                            if (k < 0)
                            {
                                lowH += DrawBarHeight;
                            }
                            if (k > 0)
                            {
                                highH += DrawBarHeight;
                            }
                            if (k < 0)
                            {
                                lowV += (float)YAxisInterval;
                            }
                            if (k > 0)
                            {
                                highV += (float)YAxisInterval;
                            }
                        }

                        lowH.ConsoleWriteLine();
                        highH.ConsoleWriteLine();

                        if (series.Data[j] >= 0)
                        {
                            float h = Math.Abs((float)(highH * series.Data[j] / highV));
                            Bars[i].Add(new BarInfo()
                            {
                                Rect = new RectangleF(
                                    barX + x1 * (i + 1) + x2 * i,
                                    DrawOrigin.Y - lowH - h,
                                    x2, h)
                            });
                        }
                        else
                        {
                            float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
                            Bars[i].Add(new BarInfo()
                            {
                                Rect = new RectangleF(
                                    barX + x1 * (i + 1) + x2 * i,
                                    DrawOrigin.Y - lowH + 1,
                                    x2, h - 1)
                            });
                        }
                    }

                    barX += DrawBarWidth;
                }
            }

            if (BarOption.ToolTip != null)
            {
                for (int i = 0; i < BarOption.XAxis.Data.Count; i++)
                {
                    string str = BarOption.XAxis.Data[i];
                    foreach (var series in BarOption.Series)
                    {
                        str += '\n';
                        str += series.Name + " : " + series.Data[i].ToString(BarOption.ToolTip.ValueFormat);
                    }

                    Bars[0][i].Tips = str;
                }
            }
        }
Ejemplo n.º 10
0
        protected override void CalcData()
        {
            Bars.Clear();
            NeedDraw = false;
            if (Option == null || Option.Series == null || Option.SeriesCount == 0)
            {
                return;
            }
            if (DrawSize.Width <= 0 || DrawSize.Height <= 0)
            {
                return;
            }
            if (Option.XAxis.Data.Count == 0)
            {
                return;
            }

            NeedDraw     = true;
            DrawBarWidth = DrawSize.Width * 1.0f / Option.XAxis.Data.Count;

            double min = double.MaxValue;
            double max = double.MinValue;

            foreach (var series in Option.Series)
            {
                if (series.Data.Count > 0)
                {
                    min = Math.Min(min, series.Data.Min());
                    max = Math.Max(max, series.Data.Max());
                }
            }

            if (min > 0 && max > 0 && !Option.YAxis.Scale)
            {
                min = 0;
            }
            if (min < 0 && max < 0 && !Option.YAxis.Scale)
            {
                max = 0;
            }
            if (!Option.YAxis.MaxAuto)
            {
                max = Option.YAxis.Max;
            }
            if (!Option.YAxis.MinAuto)
            {
                min = Option.YAxis.Min;
            }

            if (Option.YAxis.MaxAuto && Option.YAxis.MinAuto)
            {
                if (min > 0)
                {
                    min = 0;
                }
                if (max < 0)
                {
                    max = 0;
                }

                if (min.IsZero() && !max.IsZero())
                {
                    max = max * 1.2;
                }

                if (max.IsZero() && !min.IsZero())
                {
                    min = min * 1.2;
                }

                if (!max.IsZero() && !min.IsZero())
                {
                    max = max * 1.2;
                    min = min * 1.2;
                }
            }

            if ((max - min).IsZero())
            {
                if (min.IsZero())
                {
                    max = 100;
                    min = 0;
                }
                else if (max > 0)
                {
                    max = max * 2;
                    min = 0;
                }
                else
                {
                    max = 0;
                    min = min * 2;
                }
            }

            YScale.Max = max;
            YScale.Min = min;
            YScale.AxisChange();

            YAxisStart    = YScale.Min;
            YAxisEnd      = YScale.Max;
            YAxisInterval = YScale.Step;
            double[] YLabels = YScale.CalcLabels();
            float[]  labels  = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
            YAxisDecimalCount = YScale.Format.Replace("F", "").ToInt();

            float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1);
            float x2 = x1 * 2;

            for (int i = 0; i < Option.SeriesCount; i++)
            {
                float barX   = DrawOrigin.X;
                var   series = Option.Series[i];
                Bars.TryAdd(i, new List <BarInfo>());
                for (int j = 0; j < series.Data.Count; j++)
                {
                    Color color = ChartStyle.GetColor(i);
                    if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
                    {
                        color = series.Colors[j];
                    }

                    float xx = barX + x1 * (i + 1) + x2 * i + x1;
                    float ww = Math.Min(x2, series.MaxWidth);
                    xx -= ww / 2.0f;

                    float YZeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);
                    float VPos     = YScale.CalcYPixel(series.Data[j], DrawOrigin.Y, DrawSize.Height);

                    if (VPos <= YZeroPos)
                    {
                        Bars[i].Add(new BarInfo()
                        {
                            Rect  = new RectangleF(xx, VPos, ww, (YZeroPos - VPos)),
                            Value = series.Data[j],
                            Color = color,
                            Top   = true
                        });
                    }
                    else
                    {
                        Bars[i].Add(new BarInfo()
                        {
                            Rect  = new RectangleF(xx, YZeroPos, ww, (VPos - YZeroPos)),
                            Value = series.Data[j],
                            Color = color,
                            Top   = false
                        });
                    }

                    barX += DrawBarWidth;
                }
            }

            if (Option.ToolTip != null)
            {
                for (int i = 0; i < Option.XAxis.Data.Count; i++)
                {
                    string str = Option.XAxis.Data[i];
                    foreach (var series in Option.Series)
                    {
                        str += '\n';
                        str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat);
                    }

                    Bars[0][i].Tips = str;
                }
            }
        }