예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void readChartElements(org.w3c.dom.Element root) throws org.maltparser.core.exception.MaltChainedException
        public virtual void readChartElements(Element root)
        {
            NodeList chartElem = root.getElementsByTagName("chartelement");

            for (int i = 0; i < chartElem.Length; i++)
            {
                ChartElement chartElement = new ChartElement();
                chartElement.read((Element)chartElem.item(i), this);
                chartElements[((Element)chartElem.item(i)).getAttribute("item")] = chartElement;
            }
        }
예제 #2
0
        public void ConstructorSeparatesPartsOfTheName()
        {
            Document     doc     = new Document();
            var          slide   = new SlideElement(doc);
            ChartElement element = ChartElement.Create(@"TEST_1[""column 1"", 4, 6][2, 4, ""row 1""] FORMAT{""##,#"", ""de-DE""} FIXED LEGEND_FROM{1} SORT{2, ASC} FORMULA{""[column 2] - [column 1]""}", null, slide);

            Assert.AreEqual(@"TEST_1[""column 1"", 4, 6][2, 4, ""row 1""] FORMAT{""##,#"", ""de-DE""} FIXED LEGEND_FROM{1} SORT{2, ASC} FORMULA{""[column 2] - [column 1]""}", element.FullName);
            Assert.AreEqual("TEST_1", element.Name);
            Assert.AreEqual(@"""column 1"", 4, 6", element.DataDescriptor.ColumnIndexesString);
            Assert.AreEqual(@"2, 4, ""row 1""", element.DataDescriptor.RowIndexesString);
            Assert.AreEqual(@"FORMAT{""##,#"", ""de-DE""} FIXED LEGEND_FROM{1} SORT{2, ASC} FORMULA{""[column 2] - [column 1]""}", element.CommandString);
        }
예제 #3
0
        public virtual void DiscoverShapes()
        {
            var shapes = Slide.Descendants <DocumentFormat.OpenXml.Presentation.Shape>().Where(s => s.ElementName().ToUpper().StartsWith("DATA:"));

            Shapes.AddRange(shapes.Select(s => ShapeElement.Create(s.ElementName().Substring(5).Trim(), s, this)).Where(s => s != null));
            var graphicFrames = Slide.Descendants <DocumentFormat.OpenXml.Presentation.GraphicFrame>().Where(s => s.ElementName().ToUpper().StartsWith("DATA:"));

            foreach (var item in graphicFrames)
            {
                string name = item.ElementName().Substring(5).Trim();
                if (item.Graphic.GraphicData.FirstElement <Table>() != null)
                {
                    TableElement table = TableElement.Create(name, item, this);
                    if (table != null)
                    {
                        Shapes.Add(table);
                    }
                }
                else if (item.Graphic.GraphicData.FirstElement <ChartReference>() != null)
                {
                    ChartElement chart = ChartElement.Create(name, item, this);
                    if (chart != null)
                    {
                        Shapes.Add(chart);
                    }
                }
            }
            var paragraphs = Slide.Descendants <Paragraph>();

            foreach (var item in paragraphs)
            {
                if (!item.Ancestors <Table>().Any())
                {
                    if (textTagRegex.Match(item.InnerText).Success)
                    {
                        foreach (Match match in textTagRegex.Matches(item.InnerText))
                        {
                            McKinsey.PowerPointGenerator.Elements.TextElement text = McKinsey.PowerPointGenerator.Elements.TextElement.Create(match.Groups["tag"].Value, item, this);
                            if (text != null)
                            {
                                Shapes.Add(text);
                            }
                        }
                    }
                }
            }
            foreach (ShapeElementBase item in Shapes)
            {
                item.Slide = this;
            }
        }
예제 #4
0
        public void PreprocessSwitchCommandsSetsDefaultValuesWhenNoSwitchCommandsExist()
        {
            Document     doc      = new Document();
            var          slide    = new SlideElement(doc);
            ChartElement element  = ChartElement.Create("TEST", null, slide);
            var          commands = new List <Command>()
            {
                new FormatCommand(), new FormulaCommand(), new NoContentCommand()
            };
            var result = element.PreprocessSwitchCommands(commands);

            Assert.AreEqual(3, result.Count());
            Assert.IsFalse(element.IsWaterfall);
            Assert.IsFalse(element.IsFixed);
            Assert.IsFalse(element.IsPaged);
        }
예제 #5
0
        public void PreprocessSwitchCommandsGetAllCommandsIfTheyExist()
        {
            Document     doc      = new Document();
            var          slide    = new SlideElement(doc);
            ChartElement element  = ChartElement.Create("TEST", null, slide);
            var          commands = new List <Command>()
            {
                new FormatCommand(), new FormulaCommand(), new NoContentCommand(), new FixedCommand(), new WaterfallCommand(), new PageCommand()
            };
            var result = element.PreprocessSwitchCommands(commands);

            Assert.AreEqual(5, result.Count());
            Assert.IsTrue(element.IsWaterfall);
            Assert.IsTrue(element.IsFixed);
            Assert.IsTrue(element.IsPaged);
        }
예제 #6
0
 protected virtual void ProcessChartType(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
 {
     if (area.Area3DStyle.Enable3D)
     {
         ProcessChartType3D(selection, graph, common, area, seriesToDraw);
         return;
     }
     if (ShiftedSerName.Length == 0)
     {
         indexedSeries = area.IndexedSeries((string[])area.GetSeriesFromChartType(Name).ToArray(typeof(string)));
     }
     else
     {
         indexedSeries = ChartElement.IndexedSeries(common.DataManager.Series[ShiftedSerName]);
     }
     foreach (Series item in common.DataManager.Series)
     {
         bool flag = false;
         if (ShiftedSerName.Length > 0)
         {
             if (ShiftedSerName != item.Name)
             {
                 continue;
             }
             flag = true;
         }
         if (string.Compare(item.ChartTypeName, Name, ignoreCase: true, CultureInfo.CurrentCulture) != 0 || item.ChartArea != area.Name || !item.IsVisible() || (seriesToDraw != null && seriesToDraw.Name != item.Name))
         {
             continue;
         }
         hAxis = area.GetAxis(AxisName.X, item.XAxisType, item.XSubAxisName);
         vAxis = area.GetAxis(AxisName.Y, item.YAxisType, item.YSubAxisName);
         double viewMaximum  = hAxis.GetViewMaximum();
         double viewMinimum  = hAxis.GetViewMinimum();
         double viewMaximum2 = vAxis.GetViewMaximum();
         double viewMinimum2 = vAxis.GetViewMinimum();
         if (!selection)
         {
             common.EventsManager.OnBackPaint(item, new ChartPaintEventArgs(graph, common, area.PlotAreaPosition));
         }
         int num  = 0;
         int num2 = 1;
         foreach (DataPoint point in item.Points)
         {
             point.positionRel = new PointF(float.NaN, float.NaN);
             double yValue = indexedSeries ? ((double)num2) : point.XValue;
             yValue = hAxis.GetLogValue(yValue);
             if (yValue > viewMaximum || yValue < viewMinimum)
             {
                 num2++;
                 continue;
             }
             double yValue2 = GetYValue(common, area, item, point, num2 - 1, yValueIndex);
             yValue2 = vAxis.GetLogValue(yValue2);
             if (yValue2 > viewMaximum2 || yValue2 < viewMinimum2)
             {
                 num2++;
                 continue;
             }
             bool flag2 = false;
             if (!ShouldDrawMarkerOnViewEdgeX())
             {
                 if (yValue == viewMaximum && ShiftedX >= 0.0)
                 {
                     flag2 = true;
                 }
                 if (yValue == viewMinimum && ShiftedX <= 0.0)
                 {
                     flag2 = true;
                 }
             }
             int         markerSize  = point.MarkerSize;
             string      markerImage = point.MarkerImage;
             MarkerStyle markerStyle = point.MarkerStyle;
             PointF      empty       = PointF.Empty;
             empty.Y = (float)vAxis.GetLinearPosition(yValue2);
             if (indexedSeries)
             {
                 empty.X = (float)hAxis.GetPosition(num2);
             }
             else
             {
                 empty.X = (float)hAxis.GetPosition(point.XValue);
             }
             empty.X          += (float)ShiftedX;
             point.positionRel = new PointF(empty.X, empty.Y);
             SizeF markerSize2 = GetMarkerSize(graph, common, area, point, markerSize, markerImage);
             if (flag2)
             {
                 num2++;
                 continue;
             }
             if (alwaysDrawMarkers || markerStyle != 0 || markerImage.Length > 0)
             {
                 if (common.ProcessModePaint)
                 {
                     if (num == 0)
                     {
                         graph.StartHotRegion(point);
                         graph.StartAnimation();
                         DrawPointMarker(graph, point.series, point, empty, (markerStyle == MarkerStyle.None) ? MarkerStyle.Circle : markerStyle, (int)markerSize2.Height, (point.MarkerColor == Color.Empty) ? point.Color : point.MarkerColor, (point.MarkerBorderColor == Color.Empty) ? point.BorderColor : point.MarkerBorderColor, GetMarkerBorderSize(point), markerImage, point.MarkerImageTransparentColor, (point.series != null) ? point.series.ShadowOffset : 0, (point.series != null) ? point.series.ShadowColor : Color.Empty, new RectangleF(empty.X, empty.Y, markerSize2.Width, markerSize2.Height));
                         graph.StopAnimation();
                         graph.EndHotRegion();
                     }
                     if (common.ProcessModeRegions)
                     {
                         SetHotRegions(common, graph, point, markerSize2, point.series.Name, num2 - 1, markerStyle, empty);
                     }
                 }
                 num++;
                 if (item.MarkerStep == num)
                 {
                     num = 0;
                 }
             }
             graph.StartHotRegion(point, labelRegion: true);
             graph.StartAnimation();
             DrawLabels(area, graph, common, empty, (int)markerSize2.Height, point, item, num2 - 1);
             graph.StopAnimation();
             graph.EndHotRegion();
             num2++;
         }
         if (!selection)
         {
             common.EventsManager.OnPaint(item, new ChartPaintEventArgs(graph, common, area.PlotAreaPosition));
         }
         if (flag)
         {
             break;
         }
     }
 }
        public override double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
        {
            if (this.totalPerPoint == null)
            {
                int num = 0;
                foreach (Series item in common.DataManager.Series)
                {
                    if (string.Compare(item.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) == 0 && item.ChartArea == area.Name && item.IsVisible())
                    {
                        num++;
                    }
                }
                Series[] array = new Series[num];
                int      num2  = 0;
                foreach (Series item2 in common.DataManager.Series)
                {
                    if (string.Compare(item2.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) == 0 && item2.ChartArea == area.Name && item2.IsVisible())
                    {
                        array[num2++] = item2;
                    }
                }
                common.DataManipulator.CheckXValuesAlignment(array);
                this.totalPerPoint = new double[series.Points.Count];
                for (int i = 0; i < series.Points.Count; i++)
                {
                    this.totalPerPoint[i] = 0.0;
                    Series[] array2 = array;
                    foreach (Series series4 in array2)
                    {
                        this.totalPerPoint[i] += Math.Abs(series4.Points[i].YValues[0]);
                    }
                }
            }
            if (!area.Area3DStyle.Enable3D)
            {
                if (this.totalPerPoint[pointIndex] == 0.0)
                {
                    int num4 = 0;
                    foreach (Series item3 in common.DataManager.Series)
                    {
                        if (string.Compare(item3.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) == 0 && item3.ChartArea == area.Name && item3.IsVisible())
                        {
                            num4++;
                        }
                    }
                    return(100.0 / (double)num4);
                }
                return(point.YValues[0] / this.totalPerPoint[pointIndex] * 100.0);
            }
            double num5 = double.NaN;

            if (yValueIndex == -1)
            {
                Axis   axis = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
                double num6 = axis.Crossing;
                num5 = this.GetYValue(common, area, series, point, pointIndex, 0);
                if (area.Area3DStyle.Enable3D && num5 < 0.0)
                {
                    num5 = 0.0 - num5;
                }
                if (num5 >= 0.0)
                {
                    if (!double.IsNaN(base.prevPosY))
                    {
                        num6 = base.prevPosY;
                    }
                }
                else if (!double.IsNaN(base.prevNegY))
                {
                    num6 = base.prevNegY;
                }
                return(num5 - num6);
            }
            base.prevPosY      = double.NaN;
            base.prevNegY      = double.NaN;
            base.prevPositionX = double.NaN;
            foreach (Series item4 in common.DataManager.Series)
            {
                if (string.Compare(series.ChartArea, item4.ChartArea, true, CultureInfo.CurrentCulture) == 0 && string.Compare(series.ChartTypeName, item4.ChartTypeName, true, CultureInfo.CurrentCulture) == 0 && series.IsVisible())
                {
                    num5 = item4.Points[pointIndex].YValues[0] / this.totalPerPoint[pointIndex] * 100.0;
                    if (!double.IsNaN(num5) && area.Area3DStyle.Enable3D && num5 < 0.0)
                    {
                        num5 = 0.0 - num5;
                    }
                    if (num5 >= 0.0 && !double.IsNaN(base.prevPosY))
                    {
                        num5 += base.prevPosY;
                    }
                    if (num5 < 0.0 && !double.IsNaN(base.prevNegY))
                    {
                        num5 += base.prevNegY;
                    }
                    if (string.Compare(series.Name, item4.Name, StringComparison.Ordinal) == 0)
                    {
                        break;
                    }
                    if (num5 >= 0.0)
                    {
                        base.prevPosY = num5;
                    }
                    else
                    {
                        base.prevNegY = num5;
                    }
                    base.prevPositionX = item4.Points[pointIndex].XValue;
                    if (base.prevPositionX == 0.0 && ChartElement.IndexedSeries(series))
                    {
                        base.prevPositionX = (double)(pointIndex + 1);
                    }
                }
            }
            if (num5 > 100.0)
            {
                return(100.0);
            }
            return(num5);
        }
예제 #8
0
        public override double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
        {
            double num = double.NaN;

            if (!area.Area3DStyle.Enable3D)
            {
                return(point.YValues[0]);
            }
            if (yValueIndex == -1)
            {
                Axis   axis     = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
                double crossing = axis.Crossing;
                num = this.GetYValue(common, area, series, point, pointIndex, 0);
                if (area.Area3DStyle.Enable3D && num < 0.0)
                {
                    num = 0.0 - num;
                }
                if (num >= 0.0)
                {
                    if (!double.IsNaN(this.prevPosY))
                    {
                        crossing = this.prevPosY;
                    }
                }
                else if (!double.IsNaN(this.prevNegY))
                {
                    crossing = this.prevNegY;
                }
                return(num - crossing);
            }
            this.prevPosY      = double.NaN;
            this.prevNegY      = double.NaN;
            this.prevPositionX = double.NaN;
            foreach (Series item in common.DataManager.Series)
            {
                if (string.Compare(series.ChartArea, item.ChartArea, StringComparison.Ordinal) == 0 && string.Compare(series.ChartTypeName, item.ChartTypeName, StringComparison.OrdinalIgnoreCase) == 0 && item.IsVisible())
                {
                    num = item.Points[pointIndex].YValues[0];
                    if (area.Area3DStyle.Enable3D && num < 0.0)
                    {
                        num = 0.0 - num;
                    }
                    if (!double.IsNaN(num))
                    {
                        if (num >= 0.0 && !double.IsNaN(this.prevPosY))
                        {
                            num += this.prevPosY;
                        }
                        if (num < 0.0 && !double.IsNaN(this.prevNegY))
                        {
                            num += this.prevNegY;
                        }
                    }
                    if (string.Compare(series.Name, item.Name, StringComparison.Ordinal) != 0)
                    {
                        if (num >= 0.0)
                        {
                            this.prevPosY = num;
                        }
                        if (num < 0.0)
                        {
                            this.prevNegY = num;
                        }
                        this.prevPositionX = item.Points[pointIndex].XValue;
                        if (this.prevPositionX == 0.0 && ChartElement.IndexedSeries(series))
                        {
                            this.prevPositionX = (double)(pointIndex + 1);
                        }
                        continue;
                    }
                    return(num);
                }
            }
            return(num);
        }
예제 #9
0
        private void RecursePaintPanel(Graphics g,
                                       decimal xMult,
                                       decimal yMult,
                                       bool print,
                                       Rdl.Render.Element elmt,
                                       Point destOffset,
                                       decimal top, decimal left)
        {
            decimal mult = 1;

            int t = (int)((top + elmt.Top) * yMult) + destOffset.Y;
            int l = (int)((left + elmt.Left) * xMult) + destOffset.X;
            int w = (int)(elmt.Width * xMult);
            int h = (int)(elmt.Height * yMult);

            Rectangle clipRect = new Rectangle(l, t, w, h);

            if (elmt is Rdl.Render.TextElement ||
                elmt is Rdl.Render.ImageElement ||
                elmt is Rdl.Render.Container ||
                elmt is Rdl.Render.ChartElement)
            {
                if (elmt.Style != null && elmt.Style.BackgroundColor != null)
                {
                    g.FillRectangle(new SolidBrush(Rdl.Engine.Style.W32Color(elmt.Style.BackgroundColor)),
                                    clipRect);
                }

                if (elmt.Style != null && elmt.Style.BorderWidth != null)
                {
                    Rdl.Render.Drawing.DrawBorder(g, new System.Drawing.Rectangle(l, t, w, h),
                                                  elmt.Style.BorderWidth, elmt.Style.BorderStyle, elmt.Style.BorderColor, xMult, yMult);
                }
            }

            if (elmt.Style != null)
            {
                l += (int)(elmt.Style.PaddingLeft.points * xMult);
                t += (int)(elmt.Style.PaddingTop.points * yMult);
                w -= (int)((elmt.Style.PaddingLeft.points + elmt.Style.PaddingRight.points) * xMult);
                h -= (int)((elmt.Style.PaddingTop.points + elmt.Style.PaddingBottom.points) * yMult);
            }

            if (elmt is TextElement)
            {
                TextElement te    = elmt as TextElement;
                TextStyle   ts    = te.Style as TextStyle;
                int         width = (int)(elmt.Width * mult);

                if (te.IsToggle && !print)
                {
                    if (te.ToggleState == TextElement.ToggleStateEnum.open)
                    {
                        g.DrawImage(Properties.Resources.minus, new Point(l, t));
                    }
                    else
                    {
                        g.DrawImage(Properties.Resources.plus, new Point(l, t));
                    }

                    l     += Properties.Resources.minus.Width;
                    width -= Properties.Resources.minus.Width;
                }

                StringFormat sf = new StringFormat();
                Rdl.Engine.Style.TextAlignEnum align = ts.TextAlign;
                if (align == Rdl.Engine.Style.TextAlignEnum.General)
                {
                    decimal d;
                    if (decimal.TryParse(te.Text, out d))
                    {
                        align = Rdl.Engine.Style.TextAlignEnum.Right;
                    }
                    else
                    {
                        align = Rdl.Engine.Style.TextAlignEnum.Left;
                    }
                }
                switch (align)
                {
                case Rdl.Engine.Style.TextAlignEnum.General:
                case Rdl.Engine.Style.TextAlignEnum.Left:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case Rdl.Engine.Style.TextAlignEnum.Center:
                    sf.Alignment = StringAlignment.Center;
                    break;

                case Rdl.Engine.Style.TextAlignEnum.Right:
                    sf.Alignment = StringAlignment.Far;
                    break;
                }

                g.DrawString(te.Text,
                             _fonts[te.StyleIndex],
                             new SolidBrush(Rdl.Engine.Style.W32Color(te.Style.Color)),
                             new Rectangle(l, t, w, h),
                             sf
                             );
            }


            if (elmt._imageIndex >= 0)
            {
                g.DrawImage(_report.ImageList[elmt._imageIndex].GetSizedImage(w, h),
                            new Rectangle(l, t, w, h));
            }

            if (elmt is ChartElement)
            {
                ChartElement cc = elmt as ChartElement;
                g.DrawImage(cc.RenderChart(w, h, xMult, yMult), new Rectangle(l, t, w, h));
            }

            if (elmt is Rdl.Render.Container)
            {
                foreach (Element child in ((Rdl.Render.Container)elmt).Children)
                {
                    RecursePaintPanel(g, xMult, yMult, print, child, destOffset, top + elmt.Top, left + elmt.Left);
                }
            }
        }
        /// <summary>
        /// Handle visibility of FlexChart elements if TrackBar scrolled by user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void ShowElement(ChartElement ele)
        {
            switch (ele)
            {
            case ChartElement.ChartArea: _flexChart.Visible = true;
                break;

            case ChartElement.PlotArea:
                _flexChart.PlotStyle.FillColor   = Color.FromArgb(100, Color.LightGreen);
                _flexChart.PlotStyle.StrokeColor = Color.DarkGreen;
                break;

            case ChartElement.Header:
                _flexChart.Header.Content = "FlexChart Header";
                break;

            case ChartElement.Footer:
                _flexChart.Footer.Content = "FlexChart Footer";
                break;

            case ChartElement.AxisX:
                _flexChart.AxisX.AxisLine = true;
                _flexChart.AxisX.Labels   = true;
                _flexChart.AxisX.Title    = "X-Axis Title";
                break;

            case ChartElement.AxisY:
                _flexChart.AxisY.AxisLine = true;
                _flexChart.AxisY.Labels   = true;
                _flexChart.AxisY.Title    = "Y-Axis Title";
                break;

            case ChartElement.Legend:
                _flexChart.Legend.Position = Position.Right;
                break;

            case ChartElement.Series:
                _flexChart.Series[0].Visibility         = SeriesVisibility.Visible;
                _flexChart.Series[0].DataLabel.Position = LabelPosition.None;
                _flexChart.Series[1].Visibility         = SeriesVisibility.Visible;
                _flexChart.Series[1].DataLabel.Position = LabelPosition.None;
                break;

            case ChartElement.SeriesSymbol:
                _flexChart.Series[0].DataLabel.Position = LabelPosition.Center;
                break;

            case ChartElement.DataLabel:
                _flexChart.Series[1].DataLabel.Position = LabelPosition.Top;
                break;

            case ChartElement.None:
            default:
                _flexChart.Visible               = false;
                _flexChart.Header.Content        = string.Empty;
                _flexChart.Footer.Content        = string.Empty;
                _flexChart.PlotStyle.FillColor   = Color.Transparent;
                _flexChart.PlotStyle.StrokeColor = Color.Transparent;
                _flexChart.AxisX.AxisLine        = false;
                _flexChart.AxisX.Labels          = false;
                _flexChart.AxisX.Title           = string.Empty;
                _flexChart.AxisY.AxisLine        = false;
                _flexChart.AxisY.Labels          = false;
                _flexChart.AxisY.Title           = string.Empty;
                _flexChart.Series[0].Visibility  = SeriesVisibility.Hidden;
                _flexChart.Series[1].Visibility  = SeriesVisibility.Hidden;
                _flexChart.Legend.Position       = Position.None;
                break;
            }
        }
예제 #11
0
파일: Charts.cs 프로젝트: tgnemecek/sos
 //adiciona novos pontos à estrutura de dados
 public void AddPoint(ChartElement newPoint)
 {
     pointsList.Add(newPoint);
 }
예제 #12
0
        public void Process(ShapeElementBase shape)
        {
            element      = shape as ChartElement;
            fullData     = element.Data.Clone();
            element.Data = fullData.GetFragmentByIndexes(element.RowIndexes, element.ColumnIndexes);
            element.ProcessCommands(element.Data);
            if (element.Data == null)
            {
                return;
            }

            //get chart reference
            A.GraphicData  graphicData    = element.ChartFrame.Graphic.GraphicData;
            ChartReference chartReference = graphicData.FirstElement <ChartReference>();

            if (chartReference == null)
            {
                return;
            }

            //various chart structure elements
            ChartPart chartPart = element.Slide.Slide.SlidePart.GetPartById(chartReference.Id.Value) as ChartPart;
            Chart     chart     = chartPart.ChartSpace.FirstElement <Chart>();

            //get external data and update it
            DataElement dataToInsert = element.Data.Clone();

            foreach (var item in element.ChildShapes)
            {
                var childDataElement = fullData.GetFragmentByIndexes(item.RowIndexes, item.ColumnIndexes);
                element.ProcessCommands(childDataElement);
                dataToInsert.MergeWith(childDataElement);
            }
            ExternalData        externalData   = chartPart.ChartSpace.FirstElement <ExternalData>();
            EmbeddedPackagePart xlsPackagePart = chartPart.GetPartById(externalData.Id.Value) as EmbeddedPackagePart;
            Stream sourceStream = xlsPackagePart.GetStream();
            Stream outputStream = new MemoryStream();

            dataToInsert.TrimHiddenRowsAndColumns();
            List <ChartSeriesElement> newSeries = SpreadsheetProcessor.InsertData(dataToInsert, sourceStream, outputStream);

            outputStream.Seek(0, SeekOrigin.Begin);
            xlsPackagePart.FeedData(outputStream);


            ChartType        type      = ChartType.None;
            Tuple <int, int> dataRange = null;
            var charts = chart.PlotArea.Elements().ToList();

            OpenXmlElement mainChart  = null;
            int            chartIndex = 0;

            for (; chartIndex < charts.Count; chartIndex++)
            {
                GetChartTypeAndDataRange(ref type, ref dataRange, charts[chartIndex]);
                if (type != ChartType.None)
                {
                    mainChart = charts[chartIndex];
                    chartIndex++;
                    break;
                }
            }


            int seriesIndex = 0;

            foreach (ErrorBarCommand errorBarCommand in element.CommandsOf <ErrorBarCommand>())
            {
                ChartSeriesElement chartSeriesMinus = newSeries.FirstOrDefault(s => s.ColumnIndex == errorBarCommand.MinusIndex && !s.ColumnIndex.IsCore);
                ChartSeriesElement chartSeriesPlus  = null;
                if (errorBarCommand.PlusIndex != null)
                {
                    chartSeriesPlus = newSeries.FirstOrDefault(s => s.ColumnIndex == errorBarCommand.PlusIndex && !s.ColumnIndex.IsCore);
                }
                if (seriesIndex < newSeries.Count)
                {
                    newSeries[seriesIndex].MinusErrorBar = chartSeriesMinus;
                    newSeries[seriesIndex].PlusErrorBar  = chartSeriesPlus;
                }
                seriesIndex++;
            }
            foreach (ErrorBarCommand errorBarCommand in element.CommandsOf <ErrorBarCommand>())
            {
                ChartSeriesElement chartSeriesMinus = newSeries.FirstOrDefault(s => s.ColumnIndex == errorBarCommand.MinusIndex && !s.ColumnIndex.IsCore);
                ChartSeriesElement chartSeriesPlus  = null;
                if (errorBarCommand.PlusIndex != null)
                {
                    chartSeriesPlus = newSeries.FirstOrDefault(s => s.ColumnIndex == errorBarCommand.PlusIndex && !s.ColumnIndex.IsCore);
                }
                if (chartSeriesMinus != null)
                {
                    newSeries.Remove(chartSeriesMinus);
                }
                if (chartSeriesPlus != null)
                {
                    newSeries.Remove(chartSeriesPlus);
                }
            }
            seriesIndex = 0;
            if (element.CommandsOf <YCommand>().Count > 0)
            {
                List <ChartSeriesElement> newSeriesWithoutY = new List <ChartSeriesElement>(newSeries);
                foreach (YCommand yCommand in element.CommandsOf <YCommand>())
                {
                    ChartSeriesElement yChartSeries = newSeries.FirstOrDefault(s => s.ColumnIndex == yCommand.Index);  //  && !s.ColumnIndex.IsCore
                    if (yChartSeries != null)
                    {
                        newSeriesWithoutY.Remove(yChartSeries);
                    }
                }
                foreach (YCommand yCommand in element.CommandsOf <YCommand>())
                {
                    ChartSeriesElement yChartSeries = newSeries.FirstOrDefault(s => s.ColumnIndex == yCommand.Index); // && !s.ColumnIndex.IsCore
                    for (int i = seriesIndex; i < newSeriesWithoutY.Count; i++)
                    {
                        newSeriesWithoutY[i].YValues = yChartSeries;
                    }
                    //if (seriesIndex < newSeries.Count)
                    //{
                    //    newSeries[seriesIndex].YValues = yChartSeries;
                    //}
                    seriesIndex++;
                }
                newSeries = new List <ChartSeriesElement>(newSeriesWithoutY);
            }


            switch (type)
            {
            case ChartType.Waterfall:
            case ChartType.Bar:
                ReplaceBarChart(newSeries, mainChart as BarChart, element, element.IsWaterfall);
                break;

            case ChartType.Scatter:
                ReplaceScatterChart(newSeries, mainChart as ScatterChart, element);
                break;

            case ChartType.Line:
                ReplaceLineChart(newSeries, mainChart as LineChart, element);
                break;
            }
            int childShapeIndex = 0;

            for (; chartIndex < charts.Count; chartIndex++)
            {
                var childChart = charts[chartIndex];
                if (element.ChildShapes.Count > childShapeIndex)
                {
                    GetChartTypeAndDataRange(ref type, ref dataRange, childChart);
                    if (type != ChartType.None)
                    {
                        ProcessChildShapes(element, element.ChildShapes[childShapeIndex], type, childChart, newSeries);
                        childShapeIndex++;
                    }
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Ejecuta un algoritmo determinado, dado por un ChartElementCollection.
        /// </summary>
        /// <param name="instructionCollection">El conjunto de instrucciones a ejecutar.</param>
        public void ExecuteAlgorithm(ChartElementCollection instructionCollection)
        {
            ChartElement current = null;

            try
            {
                ChartElement first = instructionCollection.First; // Obtiene el elemento "Begin" si existe.

                if (first == null || first.Connections == null)
                {
                    throw new Exception("Invalid algorithm to execute.");                                         // Si no existe el "Begin", el algoritmo no es valido.
                }
                foreach (var connection in first.Connections)
                {
                    if (connection.To != null)
                    {
                        current = connection.To.ChartElement;                   // Obtiene la primera instruccion a ejecutar.
                    }
                }
                while (!(current is EndChartElement) && !shouldStop)
                {
                    if (current == null)
                    {
                        throw new InvalidOperationException("Unconnected chart element. Check your chart connections.");
                    }

                    if (current is ConditionalChartElement)
                    {
                        ConditionalChartElement conditionalChart = (ConditionalChartElement)current;
                        if (conditionalChart.Condition == "")
                        {
                            throw new InvalidOperationException("Invalid conditional chart.");
                        }
                        string preExpression    = ParseSensorData(conditionalChart.Condition).ToLower();
                        string evaluationResult = Evaluator.Evaluate(preExpression);
                        bool   found            = false;
                        foreach (var connection in current.Connections)
                        {
                            if (evaluationResult.Equals(connection.Label))
                            {
                                if (connection.To != null)
                                {
                                    current = connection.To.ChartElement;
                                    found   = true;
                                }
                                else
                                {
                                    throw new Exception("Invalid connection");
                                }
                                break;
                            }
                        }
                        if (!found)
                        {
                            throw new InvalidOperationException("Invalid conditional expression.");
                        }
                    }
                    else
                    {
                        if (current is CommandChartElement)
                        {
                            ExecuteCommand((CommandChartElement)current);
                        }

                        else if (current is ActivityChartElement)
                        {
                            string activityName = ((ActivityChartElement)current).ActivityName;
                            if (ActivityList.ContainsKey(activityName))
                            {
                                ExecuteAlgorithm(ActivityList[activityName]);
                            }
                            else
                            {
                                throw new InvalidOperationException("Invalid activity.");
                            }
                        }

                        else if (current is AssignationChartElement)
                        {
                            AssignationChartElement assignChart = (AssignationChartElement)current;
                            if (assignChart.Name == "" || assignChart.Expression == "")
                            {
                                throw new InvalidOperationException("Invalid assignation chart element.");
                            }
                            string where = ParseSensorData(assignChart.Name);
                            string preExpression = ParseSensorData(((AssignationChartElement)current).Expression).ToLower();
                            string what          = Evaluator.Evaluate(preExpression);

                            Evaluator.Assign(where, what);
                        }

                        foreach (var connection in current.Connections)
                        {
                            if (connection.To != null)
                            {
                                current = connection.To.ChartElement;
                            }
                            else
                            {
                                throw new InvalidOperationException("Unconnected chart element. Check your chart connections.");
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (!(exception is ThreadAbortException))
                {
                    OnError(exception); // Lanza el evento Error con el mensaje incluido.
                    if (current != null)
                    {
                        current.BackColor = Color.Red; // Cambia el color del chartElement actual para permitir al usuario conocer la fuente del error.
                    }
                    Thread.CurrentThread.Abort();      // Termina la ejecucion del hilo actual.
                }
            }
        }