예제 #1
0
        protected override void measure()
        {
            base.measure();
            simplifiedSize = 0;
            int n       = xPercentage.Length;
            int nl      = lines.Count;
            int step    = (int)Math.Max(1, Math.Round(n / 140f));
            int maxSize = n / step;

            simplifiedY = new int[nl][];

            for (int i = 0; i < nl; i++)
            {
                simplifiedY[i] = new int[maxSize];
            }

            int[] max = new int[nl];

            for (int i = 0; i < n; i++)
            {
                for (int k = 0; k < nl; k++)
                {
                    ChartData.Line line = lines[k];
                    if (line.y[i] > max[k])
                    {
                        max[k] = line.y[i];
                    }
                }
                if (i % step == 0)
                {
                    for (int k = 0; k < nl; k++)
                    {
                        simplifiedY[k][simplifiedSize] = max[k];
                        max[k] = 0;
                    }
                    simplifiedSize++;
                    if (simplifiedSize >= maxSize)
                    {
                        break;
                    }
                }
            }
        }
예제 #2
0
        public ChartData(JsonObject jsonObject)
        {
            JsonArray columns = jsonObject.GetNamedArray("columns");

            int n = columns.Count;

            for (uint i = 0; i < columns.Count; i++)
            {
                JsonArray a = columns.GetArrayAt(i);
                if (a.GetStringAt(0).Equals("x"))
                {
                    int len = a.Count - 1;
                    x = new long[len];
                    for (uint j = 0; j < len; j++)
                    {
                        x[j] = (long)a.GetNumberAt(j + 1);
                    }
                }
                else
                {
                    Line l = new Line();
                    lines.Add(l);
                    int len = a.Count - 1;
                    l.id = a.GetStringAt(0);
                    l.y  = new int[len];
                    for (uint j = 0; j < len; j++)
                    {
                        l.y[j] = (int)a.GetNumberAt(j + 1);
                        if (l.y[j] > l.maxValue)
                        {
                            l.maxValue = l.y[j];
                        }
                        if (l.y[j] < l.minValue)
                        {
                            l.minValue = l.y[j];
                        }
                    }
                }

                if (x.Length > 1)
                {
                    timeStep = x[1] - x[0];
                }
                else
                {
                    timeStep = 86400000L;
                }
                measure();
            }

            JsonObject colors = jsonObject.GetNamedObject("colors");
            JsonObject names  = jsonObject.GetNamedObject("names");

            Regex colorPattern = new Regex("(.*)(#.*)", RegexOptions.Compiled);

            for (int i = 0; i < lines.Count; i++)
            {
                ChartData.Line line = lines[i];

                if (colors != null)
                {
                    var matcher = colorPattern.Match(colors.GetNamedString(line.id));
                    if (matcher.Success)
                    {
                        String key = matcher.Groups[1].Value;
                        if (key != null)
                        {
                            line.colorKey = "statisticChartLine_" + matcher.Groups[1].Value;
                        }

                        line.color = matcher.Groups[2].Value.ToColor();
                        //line.colorDark = ColorUtils.blendARGB(Color.WHITE, line.color, 0.85f);
                    }
                }

                if (names != null)
                {
                    line.name = names.GetNamedString(line.id);
                }
            }
        }