⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart.cs

📁 一种.net实现ajax方法的类库
💻 CS
📖 第 1 页 / 共 2 页
字号:
                this.recordToPoints[r] = c;
            }
            else
            {
                if( ! recordToPoints.ContainsKey(r) ) return;
                Circle c = recordToPoints[r] as Circle;
                Dictionary<string, string> newAttributes = new Dictionary<string, string>();
                if (xRequiresBinding || c.X != x)
                    c.X = x;
                if (yRequiresBinding || c.Y != y)
                    c.Y = y;
                if (sizeRequiresBinding || c.R != size)
                    c.R = size;
                if (colorRequiresBinding || c.Fill != colorString)
                    c.Fill = colorString;
            }
        }

        private void setupGradients()
        {
            Gradient gr = root.CreateWidget<Gradient>();
            gr.Stops = string.Format("0% {0} 100% {1}", colorStart.ToHtmlColor(), colorEnd.ToHtmlColor());
            gr.GradientId = "colorSeriesGradient";
            gr.Type = GradientType.linearGradient;
            gr.Direction = new Vector(0, 1, 0);
            Add(gr);

            gr = root.CreateWidget<Gradient>();
            gr.Stops = "0% #ccd 100% #ffe";
            gr.GradientId = "backgroundGradient";
            gr.Type = GradientType.linearGradient;
            gr.Direction = new Vector(1, 1, 0);
            Add(gr);
        }

        private Text colorKeyLabel, 
            sizeKeyLabel, 
            xKeyLabel, 
            yKeyLabel,
            colorMinLabel, 
            colorMaxLabel, 
            sizeMinLabel,
            sizeMaxLabel;
        private Group xLabelsGroup, yLabelsGroup;
        private void addLegend()
        {
            if (!rendered)
            {
                Group legendValues = root.CreateWidget<Group>();
                legendValues.id = "legendValues";
                legendValues.Scale(1, -1);
                Rect r = new Rect("colorKey", 1020, 100, 50, 200, "url(#colorSeriesGradient)");
                if (OnColorReceiveDropHandler != null)
                {
                    r.OnReceiveDrop += OnColorReceiveDropHandler;
                }

                Path p = root.CreateWidget<Path>();
                p.Fill = "Black";
                p.D = "m1036,500 l12,0 l20,200 l-50,0z";
                g.Add(p);
                if (OnSizeReceiveDropHandler != null)
                {
                    p.OnReceiveDrop += OnSizeReceiveDropHandler;
                }

                colorMinLabel = legendValues.DrawText(1045, -80, colormin.ToString(), "middle", fontSize);
                colorMaxLabel = legendValues.DrawText(1045, -320, colormax.ToString(), "middle", fontSize);
                sizeMinLabel = legendValues.DrawText(1045, -480, sizemin.ToString(), "middle", fontSize);
                sizeMaxLabel = legendValues.DrawText(1045, -710, sizemax.ToString(), "middle", fontSize);
                g.Add(r, legendValues);
                Group legendLabels = root.CreateWidget<Group>();
                legendLabels.id = "legendLabels";
                legendLabels.Scale(1, -1);
                legendLabels.Rotate(-90);
                colorKeyLabel = legendLabels.DrawText(100, 1100, colorSeries, "start", fontSize);
                sizeKeyLabel = legendLabels.DrawText(500, 1100, sizeSeries, "start", fontSize);
                g.Add(legendLabels);
            }
            else
            {
                if (colormin.ToString() != colorMinLabel.InnerText)
                {
                    colorKeyLabel.InnerText = colorSeries;
                    colorMinLabel.InnerText = colormin.ToString();
                    colorMaxLabel.InnerText = colormax.ToString();
                }
                if (sizemin.ToString() != sizeMinLabel.InnerText)
                {
                    sizeKeyLabel.InnerText = sizeSeries;
                    sizeMinLabel.InnerText = sizemin.ToString();
                    sizeMaxLabel.InnerText = sizemax.ToString();
                }
            }
        }

        private float prepareValue(float min, float delta, float current, float newMax)
        {
            return ((current - min) / delta) * newMax;
        }

        private float screenToData(float value, float delta, float min )
        {
            return value / 1000 * delta + min;
        }

        Vector colorStart = new Vector(100, 50, 0);
        Vector colorEnd = new Vector(255,150,255);

        private string colorFromRange(float min, float max, float delta, float current)
        {
            Vector colorStart = new Vector(100, 50, 0);
            Vector colorEnd = new Vector(255, 150, 255);
            Vector colorRange = colorEnd - colorStart;
            Vector newColor = (colorRange * ((current - min) / delta)) + colorStart;
            return newColor.ToHtmlColor();
        }

        private void findMinMax(string column, out float min, out float max, out float delta)
        {
            Type t = DataSource[0][column].GetType();
            min = max = coerceValue(DataSource[0][column]);

            foreach (T r in dataSource)
            {
                float x = coerceValue(r[column]);
                if( x < min ) min = x;
                else if (x > max ) max = x;
            }

            delta = max - min;

            min = (float)Math.Floor(min);
            min = (float)Math.Ceiling(min);
            
            if (delta < 10 || t.IsEnum)
            {
                min -= 1;
                max += 1;
            }
            else if( t == typeof(DateTime) )
            {
                min *= 0.9999f;
                max *= 1.0001f;
            }
            else
            {
                min -= min % 5;
                max += 5 - min % 5;
            }
            delta = max - min;
        }

        private float coerceValue(object o)
        {
            if (o is DateTime)
            {
                DateTime d = (DateTime)o;
                return (float)d.Ticks;
            }

            else if (o is IConvertible)
            {
                return Convert.ToSingle(o);
            }

            /*if (o.GetType().IsEnum)
            {
                return (float)((int)o);
            }*/

            throw new System.ArgumentOutOfRangeException("o", o, "could not convert o to float.");
        }
        /*
        private object originalize(float f, Type t)
        {
            int num_quanta = 10;
            if (t.IsEnum)
            {
                f = (float)Math.Round(f);
                
            }
            else if (t.IsSubclassOf(typeof(Record)))
            {

            }
        }*/

        List<string> xlabels, ylabels;
        
        private void buildLabels(float min, float max, float delta, List<string> labels, Type t)
        {
            int numTicks = 10;
            if (delta < numTicks)
                numTicks = (int)delta;
            if (t == typeof(DateTime))
            {
                numTicks = 5;
                bool inDays = true;
                DateTime minDate = new DateTime((long)min);
                DateTime maxDate = new DateTime((long)max);
                TimeSpan ts = new TimeSpan((long)delta);
                if( ts.Days < 1 )
                {
                    inDays = false;
                }
                float space = delta / numTicks;

                for (int i = 0; i < numTicks; i++)
                {
                    TimeSpan currTimeSpan = new TimeSpan((long)space*i);
                    DateTime currDate = minDate + currTimeSpan;
                    if( inDays )
                        labels.Add(currDate.ToShortDateString());
                    else
                        labels.Add(currDate.ToShortTimeString());
                }
            }
            else if (t.IsEnum)
            {
                //enums are buffered by 1 on each side.
                labels.Add(string.Empty);
                labels.AddRange(Enum.GetNames(t));
                labels.Add(string.Empty);
            }
            else
            {
                float space = delta / numTicks;
                for (int i = 0; i < numTicks; i++)
                {
                    labels.Add((min + (space * i)).ToString("N0"));
                }
            }
        }

        int fontSize = 25, headerSize = 35;
        private void setLabels()
        {
            xlabels = new List<string>();
            ylabels = new List<string>();

            buildLabels( xmin, xmax, xdelta, xlabels, xType);
            buildLabels( ymin, ymax, ydelta, ylabels, yType );

            if (!rendered || this.xKeyLabel.InnerText != XSeries)
            {
                if (rendered)
                {
                    xLabelsGroup.Remove();
                    xKeyLabel.InnerText = XSeries;
                }
                xLabelsGroup = root.CreateWidget<Group>();
                xLabelsGroup.Translate(0, (int)(-1.5 * fontSize));
                xLabelsGroup.Scale(1, -1);
                g.Add(xLabelsGroup);
                xKeyLabel = xLabelsGroup.DrawText(500, 30, xSeries, "middle", headerSize);
                int quanta_length = 1000 / xlabels.Count;
                for (int i = 0; i < xlabels.Count; i++)
                {
                    xLabelsGroup.DrawText(i * quanta_length, 0, xlabels[i], "middle", fontSize);
                }
            }

            if (!rendered || yKeyLabel.InnerText != YSeries)
            {
                if (rendered)
                {
                    yLabelsGroup.Remove();
                    yKeyLabel.InnerText = YSeries;
                }
                yLabelsGroup = root.CreateWidget<Group>();
                yLabelsGroup.Translate((int)(-1.2 * fontSize), 0);
                yLabelsGroup.Scale(1, -1);
                yLabelsGroup.Rotate(-90);
                g.Add(yLabelsGroup);
                yKeyLabel = yLabelsGroup.DrawText(500, -10, ySeries, "middle", headerSize);
                int quanta_length = 1000 / ylabels.Count;
                for (int i = 0; i < ylabels.Count; i++)
                {
                    yLabelsGroup.DrawText(i * quanta_length, 10, ylabels[i], "middle", fontSize);
                }
            }
        }

        #region IDataSourced Members

        IRecordList IDataSourced.DataSource
        {
            get
            {
                return dataSource as IRecordList;
            }
            set
            {
                dataSource = value as IRecordList<T>;
            }
        }

        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -