Ejemplo n.º 1
0
        protected void UpdateDataLeft(IRenderContext rc, PlotModel model)
        {
            _features   = null;
            _grid_lines = new List <List <ScreenPoint> >();

            double left = _bound.Left;

            //render label
            FeatureTextIntersector feature_text_intersector = new FeatureTextIntersector();

            foreach (double major_label_value in _points)
            {
                string  text      = FormatString(major_label_value);
                OxySize text_size = rc.MeasureText(text);
                double  x         = left - MajorTickSize - AxisTickToLabelDistance - text_size.Width;
                double  y         = this.Transform(major_label_value);
                if (double.IsNaN(y) || y < _bound.Top || y > _bound.Bottom)
                {
                    continue;
                }

                double y_center = y - text_size.Height / 2;
                feature_text_intersector.Add(new FeatureText(text, new ScreenPoint(x, y_center), text_size, new ScreenPoint(left, y)));
            }

            _features = feature_text_intersector.DiscaredIntersection();
            double text_width = 0;

            if (_features != null)
            {
                foreach (FeatureText feature in _features)
                {
                    List <ScreenPoint> major_line = new List <ScreenPoint>();
                    ScreenPoint        source     = feature.SourcePosition;
                    ScreenPoint        left_sp    = new ScreenPoint(source.X - MajorTickSize, source.Y);

                    major_line.Add(source);
                    major_line.Add(left_sp);
                    _grid_lines.Add(major_line);

                    if (text_width < feature.Size.Width)
                    {
                        text_width = feature.Size.Width;
                    }
                }
            }

            if (!string.IsNullOrEmpty(Title))
            {
                OxySize title_size = rc.MeasureText(Title, label_font);
                double  title_x    = _label_bond.Left + AxisTitleDistance;
                double  title_y    = _bound.Top + _bound.Height / 2;
                _title_position = new ScreenPoint(title_x, title_y);
            }
        }
Ejemplo n.º 2
0
        public override void Render(OxyPlot.IRenderContext rc, PlotModel model1, AxisLayer axisLayer, int pass)
        {
            PlotModel model = this.PlotModel;

            if (Theme != null)
            {
                OxyColor color = Convertor.ConvertColorToOxyColor(Theme.GetThemeColor());
                TicklineColor = color;
                TextColor     = color;
                TitleColor    = color;
            }
            //base.Render(rc, model, axisLayer, pass);
            IList <IList <ScreenPoint> > points      = new List <IList <ScreenPoint> >();
            FeatureTextIntersector       intersector = new FeatureTextIntersector(FeatureTextIntersector.SortStyle.Horizontal, 3);

            for (int i = 0; i < this.Labels.Count; i++)
            {
                string  label     = this.Labels[i];
                OxySize text_size = rc.MeasureText(label, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);

                double x = Transform(i);
                if (x < model.PlotArea.Left || x > model.PlotArea.Right)
                {
                    continue;
                }

                double y  = model.PlotArea.Bottom;
                double y2 = y + 5;

                IList <ScreenPoint> sps = new List <ScreenPoint>();
                sps.Add(new ScreenPoint(x, y));
                sps.Add(new ScreenPoint(x, model.PlotArea.Top));

                points.Add(sps);
                intersector.Add(new FeatureText(label, new ScreenPoint(x, y2), text_size));

                // rc.DrawText(new ScreenPoint(x, y + 7), label, TextColor, this.ActualFont, this.ActualFontSize, this.ActualFontWeight, this.Angle, HorizontalAlignment.Left, VerticalAlignment.Middle);
            }

            List <FeatureText> fearures = intersector.DiscaredIntersection();

            if (fearures != null)
            {
                foreach (FeatureText ft in fearures)
                {
                    rc.DrawText(ft.Position, ft.Text, this.TextColor, this.ActualFont, this.ActualFontSize, this.ActualFontWeight, this.Angle, HorizontalAlignment.Center);
                }
            }

            foreach (IList <ScreenPoint> line in points)
            {
                rc.DrawLine(line, this.ExtraGridlineColor, 1, LineStyle.Dash.GetDashArray());
            }
        }
Ejemplo n.º 3
0
        public void Render(IRenderContext rc, PlotModel model)
        {
            if (Theme != null)
            {
                OxyColor color = Convertor.ConvertColorToOxyColor(Theme.GetThemeColor(ThemeMode));
                TicklineColor = color;
                TextColor     = color;
                TitleColor    = color;
            }
            ///base.Render(rc, model, axisLayer, pass);
            /// //绘制线标值和线条
            IList <IList <ScreenPoint> > points      = new List <IList <ScreenPoint> >();
            FeatureTextIntersector       intersector = new FeatureTextIntersector(FeatureTextIntersector.SortStyle.Horizontal, 3);

            for (int i = 0; i < this.Labels.Count; i++)
            {
                string  label     = this.Labels[i];
                OxySize text_size = rc.MeasureText(label, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);

                double x = Transform(i);
                if (x < model.PlotArea.Left || x > model.PlotArea.Right)
                {
                    continue;
                }

                double y  = model.PlotArea.Bottom;
                double y2 = y + 5;

                IList <ScreenPoint> sps = new List <ScreenPoint>();
                sps.Add(new ScreenPoint(x, y));
                sps.Add(new ScreenPoint(x, model.PlotArea.Top));

                points.Add(sps);
                intersector.Add(new FeatureText(label, new ScreenPoint(x, y2), text_size, new ScreenPoint(x, y)));

                // rc.DrawText(new ScreenPoint(x, y + 7), label, TextColor, this.ActualFont, this.ActualFontSize, this.ActualFontWeight, this.Angle, HorizontalAlignment.Left, VerticalAlignment.Middle);
            }

            List <FeatureText> fearures = intersector.DiscaredIntersection();

            if (fearures != null)
            {
                foreach (FeatureText ft in fearures)
                {
                    rc.DrawText(ft.Position, ft.Text, this.TextColor, this.ActualFont, this.ActualFontSize, this.ActualFontWeight, this.Angle, HorizontalAlignment.Center);
                }
            }

            foreach (IList <ScreenPoint> line in points)
            {
                rc.DrawLine(line, this.ExtraGridlineColor, 1, LineStyle.Dash.GetDashArray());
            }
            if (model.Series.Count == 0)
            {
                return;
            }


            var      field = rc.GetType().GetField("g", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object   o     = field.GetValue(rc);
            Graphics g     = (Graphics)o;

            foreach (string element in Font_Elements)
            {
                Dictionary <int, SeqData> datas;
                if (_element_value_mapping.TryGetValue(element, out datas))
                {
                    PointF offset;
                    if (!_element_offsets.TryGetValue(element, out offset))
                    {
                        offset = new PointF(0, 0);
                    }

                    switch (element)
                    {
                    case ElementNames.Wind:
                        offset = new PointF(-15, 15);
                        DrawSymbol(g, datas, element, 1, 30F, HorizontalAlignment.Left, VerticalAlignment.Bottom, (int)offset.X, (int)offset.Y);
                        break;

                    default:
                        DrawSymbol(g, datas, element, 2);
                        break;
                    }
                }
            }
            foreach (string element in Value_Elements)
            {
                Dictionary <int, SeqData> current_points;
                bool visible = true;
                if (_element_visible_mapping.ContainsKey(element))
                {
                    visible = _element_visible_mapping[element];
                }

                if (visible && _element_value_mapping.TryGetValue(element, out current_points))
                {
                    PointF offset;
                    if (!_element_offsets.TryGetValue(element, out offset))
                    {
                        offset = new PointF(0, 0);
                    }
                    double y = model.Height - 50;
                    y += offset.Y;
                    ITheme theme;
                    if (!_thems.TryGetValue(element, out theme))
                    {
                        theme = new Model.Themes.ColorTheme();
                    }
                    OxyColor color = Helper.ConvertColorToOxyColor(theme.GetThemeColor(ThemeMode));
                    foreach (KeyValuePair <int, SeqData> item in current_points)
                    {
                        double x = Transform(item.Key);
                        x += offset.X;

                        string data = item.Value.Y;
                        rc.DrawText(new ScreenPoint(x, y), data, color);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Render(IRenderContext rc, PlotModel model1, AxisLayer axisLayer, int pass)
        {
#if DEBUG_MAP
            Console.WriteLine("render timecategoryaxis " + this.Name);
#endif
            PlotModel model           = this.PlotModel;
            OxyColor  live_color      = OxyColors.Red;
            OxyColor  forecast_color  = OxyColors.Red;
            OxyColor  separator_color = OxyColors.Red;
            OxyColor  grid_color      = OxyColors.Red;
            //OxyColor line_color = OxyColors.Red;
            if (Theme != null)
            {
                AxisStyle style = Theme.GetStyle(ThemeMode) as AxisStyle;
                TitleColor      = Helper.ConvertColorToOxyColor(style.TitleColor);
                TextColor       = Helper.ConvertColorToOxyColor(style.LabelColor);
                TicklineColor   = Helper.ConvertColorToOxyColor(style.LineColor);
                live_color      = Helper.ConvertColorToOxyColor(style.LiveColor);
                forecast_color  = Helper.ConvertColorToOxyColor(style.ForecastColor);
                separator_color = Helper.ConvertColorToOxyColor(style.SepatorColor);
                grid_color      = Helper.ConvertColorToOxyColor(style.GridColor);
            }

            //找到所有的y轴
            if (TimeLines != null)
            {
                //绘制线标值和线条
                FeatureTextIntersector intersector = new FeatureTextIntersector(FeatureTextIntersector.SortStyle.Horizontal, 3);
                for (int i = 0; i < TimeLines.Count; i++)
                {
                    string  label = TimeLines[i].Time.ToString("dd-HH");
                    OxySize size  = rc.MeasureText(label);
                    double  x     = TransformX(TimeLines[i].Index);
                    if (x < model.PlotArea.Left || x > model.PlotArea.Right)
                    {
                        continue;
                    }

                    double y  = model.PlotArea.Bottom;
                    double y2 = y + 5;

                    //if (TimeLines[i].TimeStyle == TimeStyle.Seperator)
                    //    continue;

                    intersector.Add(new FeatureText(label, new ScreenPoint(x, y + 7), size, new ScreenPoint(x, y)));
                }
                List <FeatureText> features = intersector.DiscaredIntersection(this.Angle);
                if (features != null)
                {
                    foreach (FeatureText feature in features)
                    {
                        rc.DrawText(feature.Position, feature.Text, TextColor, this.ActualFont, this.ActualFontSize, 200, this.Angle, HorizontalAlignment.Left, VerticalAlignment.Middle);
                    }
                }
                //绘制纵线
                foreach (Axis axis in model.Axes)
                {
                    if (axis.Position == AxisPosition.Left || axis.Position == AxisPosition.Right)
                    {
                        if (axis is IAxis)
                        {
                            IAxis y_axis = axis as IAxis;
                            if (!y_axis.AxisVisible)
                            {
                                continue;
                            }
                            foreach (TimeLine line in TimeLines)
                            {
                                OxyColor  color     = OxyColors.Red;
                                double    thickness = 1;
                                LineStyle style     = LineStyle.Solid;
                                switch (line.TimeStyle)
                                {
                                case TimeStyle.Forecast:
                                    color = forecast_color;
                                    style = LineStyle.Dash;
                                    break;

                                case TimeStyle.Live:
                                    color = live_color;
                                    break;

                                case TimeStyle.Seperator:
                                    color     = separator_color;
                                    style     = LineStyle.Dash;
                                    thickness = 2;
                                    break;
                                }

                                IList <ScreenPoint> sps = new List <ScreenPoint>();
                                double x   = TransformX(line.Index);
                                double top = y_axis.Bound.Top;
                                sps.Add(new ScreenPoint(x, top));
                                sps.Add(new ScreenPoint(x, y_axis.Bound.Bottom));

                                rc.DrawClippedLine(y_axis.Bound, sps, 2, color, thickness, style.GetDashArray(), LineJoin.Round, false);
                            }
                        }
                    }
                }
            }
        }