Exemplo n.º 1
0
        private void FillNodes(TShapeProperties ShapeProps, TreeNode Node)
        {
            Node.Tag = ShapeProps; //In this simple demo we will use the tag property to store the Shape properties. This is not indented for 'real' use.


            for (int i = 1; i <= ShapeProps.ChildrenCount; i++)
            {
                TShapeProperties ChildProps = ShapeProps.Children(i);
                string           ShapeName  = ChildProps.ShapeName;
                if (ShapeName == null)
                {
                    ShapeName = "Object " + i.ToString();
                }
                TreeNode Child = new TreeNode(ShapeName);
                FillNodes(ChildProps, Child);
                Node.Nodes.Add(Child);
            }
        }
Exemplo n.º 2
0
        internal static string GetGeoText(TShapeProperties ShProp)
        {
            if (ShProp.ShapeOptions == null)
            {
                return(string.Empty);
            }

            string UnicodeText = ShProp.ShapeOptions.AsUnicodeString(TShapeOption.gtextUNICODE, null);

            if (UnicodeText != null)
            {
                return(UnicodeText);
            }

            string RTFText = ShProp.ShapeOptions.AsUnicodeString(TShapeOption.gtextRTF, null);

            if (RTFText != null)
            {
                return(RTFText);
            }

            return(String.Empty);
        }
Exemplo n.º 3
0
 internal static Pen GetPen(TShapeProperties ShProp, ExcelFile Workbook, TShadowInfo ShadowInfo)
 {
     return(DrawShape.GetPen(ShProp, Workbook, ShadowInfo));
 }
Exemplo n.º 4
0
 internal static Brush GetBrush(RectangleF Coords, TShapeProperties ShProp, ExcelFile Workbook, TShadowInfo ShadowInfo, float Zoom100)
 {
     return(DrawShape.GetBrush(Coords, ShProp, Workbook, ShadowInfo, Zoom100));
 }
Exemplo n.º 5
0
        internal static void DrawPlainText(IFlxGraphics Canvas, ExcelFile Workbook, TShapeProperties ShProp, RectangleF Coords, TShadowInfo ShadowInfo, TClippingStyle Clipping, float Zoom100)
        {
            string Text = GetGeoText(ShProp);

            if (Text == null)
            {
                return;
            }
            Text = Text.Replace("\n", String.Empty);
            string[] Lines = Text.Split('\r');
            if (Lines == null || Lines.Length <= 0)
            {
                return;
            }
            int LinesLength = Lines[Lines.Length - 1].Length == 0? Lines.Length - 1: Lines.Length;               //Last line is an empty enter.

            if (LinesLength <= 0)
            {
                return;
            }

            using (Font TextFont = GetGeoFont(ShProp))
            {
                using (Pen pe = GetPen(ShProp, Workbook, ShadowInfo))
                {
                    Canvas.SaveTransform();
                    try
                    {
                        float   LineGap = Canvas.FontLinespacing(TextFont);
                        SizeF[] Sizes   = new SizeF[LinesLength];
                        Sizes[0]         = Canvas.MeasureStringEmptyHasHeight(Lines[0], TextFont);
                        Sizes[0].Height -= LineGap; //Linespacing is not included here.

                        SizeF sz = Sizes[0];
                        for (int i = 1; i < LinesLength; i++)
                        {
                            Sizes[i] = Canvas.MeasureStringEmptyHasHeight(Lines[i], TextFont);
                            if (Sizes[i].Width > sz.Width)
                            {
                                sz.Width = Sizes[i].Width;
                            }
                            sz.Height += Sizes[i].Height;
                        }

                        if (sz.Width <= 0 || sz.Height <= 0 || Coords.Width <= 0 || Coords.Height <= 0)
                        {
                            return;
                        }
                        float rx = Coords.Width / sz.Width;
                        float ry = Coords.Height / sz.Height;
                        Canvas.Scale(rx, ry);

                        using (Brush br = GetBrush(new RectangleF(Coords.Left / rx, Coords.Top / ry, sz.Width, sz.Height), ShProp, Workbook, ShadowInfo, Zoom100)) //Mast be selected AFTER scaling, so gradients work.
                        {
                            float y = LineGap;
                            for (int i = 0; i < LinesLength; i++)
                            {
                                y += Sizes[i].Height;
                                float x = (sz.Width - Sizes[i].Width) / 2f;
                                Canvas.DrawString(Lines[i], TextFont, pe, br, Coords.Left / rx + x, Coords.Top / ry + y);
                            }
                        }
                    }
                    finally
                    {
                        Canvas.ResetTransform();
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void AddChart(ExcelFile xls)
        {
            //This code is adapted from APIMate.
            //Objects
            TShapeProperties ChartOptions1 = new TShapeProperties();

            ChartOptions1.Anchor    = new TClientAnchor(TFlxAnchorType.MoveAndResize, 1, 215, 1, 608, 30, 228, 17, 736);
            ChartOptions1.ShapeName = "Lines of code";
            ChartOptions1.Print     = true;
            ChartOptions1.Visible   = true;
            ChartOptions1.ShapeOptions.SetValue(TShapeOption.fLockText, true);
            ChartOptions1.ShapeOptions.SetValue(TShapeOption.LockRotation, true);
            ChartOptions1.ShapeOptions.SetValue(TShapeOption.fAutoTextMargin, true);
            ChartOptions1.ShapeOptions.SetValue(TShapeOption.fillColor, 134217806);
            ChartOptions1.ShapeOptions.SetValue(TShapeOption.wzName, "Lines of code");
            ExcelChart Chart1 = xls.AddChart(ChartOptions1, TChartType.Area, new ChartStyle(102), false);

            TDataLabel Title = new TDataLabel();

            Title.PositionZeroBased = null;
            ChartFillOptions  TextFillOptions  = new ChartFillOptions(new TShapeFill(new TSolidFill(TDrawingColor.FromRgb(0x80, 0x80, 0x80)), true, TFormattingType.Subtle, TDrawingColor.FromRgb(0x00, 0x00, 0x00, new TColorTransform(TColorTransformType.Alpha, 0)), false));
            TChartTextOptions LabelTextOptions = new TChartTextOptions(new TFlxChartFont("Calibri Light", 320, TExcelColor.FromArgb(0x80, 0x80, 0x80), TFlxFontStyles.Bold, TFlxUnderline.None, TFontScheme.Major), THFlxAlignment.center, TVFlxAlignment.center, TBackgroundMode.Transparent, TextFillOptions);

            Title.TextOptions = LabelTextOptions;
            TDataLabelOptions LabelOptions = new TDataLabelOptions();

            Title.LabelOptions = LabelOptions;
            ChartLineOptions ChartLineOptions = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle));
            ChartFillOptions ChartFillOptions = new ChartFillOptions(new TShapeFill(new TNoFill(), false, TFormattingType.Subtle, null, false));

            Title.Frame = new TChartFrameOptions(ChartLineOptions, ChartFillOptions, false);

            TRTFRun[] Runs;
            Runs = new TRTFRun[1];
            Runs[0].FirstChar = 0;
            TFlxFont fnt;

            fnt               = xls.GetDefaultFont;
            fnt.Name          = "Calibri Light";
            fnt.Size20        = 320;
            fnt.Color         = TExcelColor.FromArgb(0x80, 0x80, 0x80);
            fnt.Style         = TFlxFontStyles.Bold;
            fnt.Family        = 0;
            fnt.CharSet       = 1;
            fnt.Scheme        = TFontScheme.Major;
            Runs[0].FontIndex = xls.AddFont(fnt);
            TRichString LabelValue1 = new TRichString("FlexCel: Lines of code over time", Runs, xls);

            Title.LabelValues = new Object[] { LabelValue1 };

            Chart1.SetTitle(Title);

            Chart1.Background = new TChartFrameOptions(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85)), 9525, TDrawingColor.FromTheme(TThemeColor.Light1), false);

            TChartFrameOptions PlotAreaFrame;

            ChartLineOptions = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle));
            ChartFillOptions = new ChartFillOptions(new TShapeFill(new TPatternFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85)), TDrawingColor.FromTheme(TThemeColor.Light1), TDrawingPattern.ltDnDiag), true, TFormattingType.Subtle, null, false));
            PlotAreaFrame    = new TChartFrameOptions(ChartLineOptions, ChartFillOptions, false);
            TChartPlotAreaPosition PlotAreaPos = new TChartPlotAreaPosition(true, TChartRelativeRectangle.Automatic, TChartLayoutTarget.Inner, true);

            Chart1.PlotArea = new TChartPlotArea(PlotAreaFrame, PlotAreaPos, false);

            Chart1.SetChartOptions(1, new TAreaChartOptions(false, TStackedMode.Stacked, null));

            int    LastYear = 0;
            double shade    = 1;

            for (int i = 2; i < 190; i++)
            {
                ChartSeries Series = new ChartSeries(
                    "=" + new TCellAddress("Data", 1, i, true, true).CellRef,
                    "=" + new TCellAddress("Data", 2, i, true, true).CellRef + ":" + new TCellAddress("Data", 189, i, true, true).CellRef,
                    "=Data!$A$2:$A$189");

                //We will display every year in a single color. Each month gets its own shade.
                int xf   = -1;
                int Year = FlxDateTime.FromOADate(((double)xls.GetCellValue(2, 1, i, ref xf)), false).Year;
                if (LastYear != Year)
                {
                    shade = 1;
                }
                else if (shade > 0.3)
                {
                    shade -= 0.05;
                }
                LastYear = Year;
                TDrawingColor SeriesColor = TDrawingColor.FromTheme(TThemeColor.Accent1 + Year % 6,
                                                                    new TColorTransform(TColorTransformType.Shade, shade));

                ChartSeriesFillOptions SeriesFill = new ChartSeriesFillOptions(new TShapeFill(new TSolidFill(SeriesColor), true, TFormattingType.Subtle, null, false), null, false, false);
                ChartSeriesLineOptions SeriesLine = new ChartSeriesLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle), false);
                Series.Options.Add(new ChartSeriesOptions(-1, SeriesFill, SeriesLine, null, null, null, true));

                Chart1.AddSeries(Series);
            }

            Chart1.PlotEmptyCells = TPlotEmptyCells.Zero;
            Chart1.ShowDataInHiddenRowsAndCols = false;

            TFlxChartFont    AxisFont = new TFlxChartFont("Calibri", 180, TExcelColor.FromArgb(0x59, 0x59, 0x59), TFlxFontStyles.None, TFlxUnderline.None, TFontScheme.Minor);
            TAxisLineOptions AxisLine = new TAxisLineOptions();

            AxisLine.MainAxis = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle));
            AxisLine.DoNotDrawLabelsIfNotDrawingAxis = false;
            TAxisTickOptions  AxisTicks        = new TAxisTickOptions(TTickType.Outside, TTickType.None, TAxisLabelPosition.NextToAxis, TBackgroundMode.Transparent, TDrawingColor.FromRgb(0x59, 0x59, 0x59), 0);
            TAxisRangeOptions AxisRangeOptions = new TAxisRangeOptions(12, 1, false, false, false);
            TBaseAxis         CatAxis          = new TCategoryAxis(0, 0, 12, TDateUnits.Days, 12, TDateUnits.Days, TDateUnits.Months, 0, TCategoryAxisOptions.AutoMin | TCategoryAxisOptions.AutoMax | TCategoryAxisOptions.DateAxis | TCategoryAxisOptions.AutoCrossDate | TCategoryAxisOptions.AutoDate, AxisFont, "yyyy\\-mm\\-dd;@", true, AxisLine, AxisTicks, AxisRangeOptions, null, TChartAxisPos.Bottom, 1);

            AxisFont                = new TFlxChartFont("Calibri", 180, TExcelColor.FromArgb(0x59, 0x59, 0x59), TFlxFontStyles.None, TFlxUnderline.None, TFontScheme.Minor);
            AxisLine                = new TAxisLineOptions();
            AxisLine.MainAxis       = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle));
            AxisLine.MajorGridLines = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle));
            AxisLine.DoNotDrawLabelsIfNotDrawingAxis = false;
            AxisTicks            = new TAxisTickOptions(TTickType.None, TTickType.None, TAxisLabelPosition.NextToAxis, TBackgroundMode.Transparent, TDrawingColor.FromRgb(0x59, 0x59, 0x59), 0);
            CatAxis.NumberFormat = "yyyy-mm";
            CatAxis.NumberFormatLinkedToSource = false;

            TBaseAxis ValAxis = new TValueAxis(0, 0, 0, 0, 0, TValueAxisOptions.AutoMin | TValueAxisOptions.AutoMax | TValueAxisOptions.AutoMajor | TValueAxisOptions.AutoMinor | TValueAxisOptions.AutoCross, AxisFont, "General", true, AxisLine, AxisTicks, null, TChartAxisPos.Left);

            Chart1.SetChartAxis(new TChartAxis(0, CatAxis, ValAxis));
        }