Esempio n. 1
0
        public void TestGraph()
        {
            var option = new GraphOption {
                xDelta = 20, yDelta = 0.5, yRatio = 0.5, SampleCount = 500
            };
            var graphPlotter = new GraphPlotter(option);

            graphPlotter.Plot(Math.Tanh, new Interv(5, 102));
            graphPlotter.Plot(x => Math.Cos(x) + 1, new Interv(10, 90), 3);
            var graph          = graphPlotter.GetGraphBlock();
            var blockReference = new BlockReference(Point3d.Origin, graph);
            var first          = Interaction.GetPoint("\nSpecify extent point 1");

            Interaction.InsertScalingEntity(blockReference, first, "\nSpecify extent point 2");
        }
Esempio n. 2
0
        public ObjectId GetGraphBlock()
        {
            if (this.XRange == null || this.YRange == null)
            {
                throw new Exception("Plot undefined.");
            }

            var entIds = new List <ObjectId>();

            // Ranges cannot be less than epsilon.
            if (this.XRange.Length < Consts.Epsilon)
            {
                this.XRange = new Interv(this.XRange.Start - Consts.Epsilon, this.XRange.End + Consts.Epsilon);
            }
            if (this.YRange.Length < Consts.Epsilon)
            {
                this.YRange = new Interv(this.YRange.Start - Consts.Epsilon, this.YRange.End + Consts.Epsilon);
            }

            // Stops
            double[] xStops = GraphPlotter.GetDivStops(this.Option.xDelta, this.XRange, this.Option.xRedundanceFactor);
            double[] yStops = GraphPlotter.GetDivStops(this.Option.yDelta, this.YRange, this.Option.yRedundanceFactor);

            // Grid lines
            var gridLines = new List <ObjectId>();

            foreach (var xStop in xStops)
            {
                gridLines.Add(Draw.Line(new Point3d(xStop, this.RealRatio * yStops.First(), 0), new Point3d(xStop, this.RealRatio * yStops.Last(), 0)));
            }
            foreach (var yStop in yStops)
            {
                gridLines.Add(Draw.Line(new Point3d(xStops.First(), this.RealRatio * yStop, 0), new Point3d(xStops.Last(), this.RealRatio * yStop, 0)));
            }
            gridLines.QForEach <Entity>(line => line.ColorIndex = this.Option.GridColor);
            entIds.AddRange(gridLines);

            // Labels
            var    labels    = new List <ObjectId>();
            double txtHeight = this.XRange.Length / 50;

            foreach (var xStop in xStops)
            {
                labels.Add(Draw.MText(xStop.ToString("0.###"), txtHeight, new Point3d(xStop, this.RealRatio * yStops.First() - 2 * txtHeight, 0), 0, true));
            }
            foreach (var yStop in yStops)
            {
                labels.Add(Draw.MText(yStop.ToString("0.###"), txtHeight, new Point3d(xStops.First() - 2 * txtHeight, this.RealRatio * yStop, 0), 0, true));
            }
            labels.QForEach <Entity>(mt => mt.ColorIndex = this.Option.LabelColor);
            entIds.AddRange(labels);

            // Curves
            foreach (var curve in this.Curves)
            {
                var plineId = Draw.Pline(curve.Item1.OrderBy(point => point.X).Select(point => new Point3d(point.X, this.RealRatio * point.Y, 0)));
                int color1  = curve.Item2 == -1 ? this.Option.CurveColor : curve.Item2;
                plineId.QOpenForWrite <Entity>(pline => pline.ColorIndex = color1);
                entIds.Add(plineId);
            }

            // Returns a block.
            var result = Draw.Block(entIds, "tjGraph" + LogManager.GetTimeBasedName(), entIds.GetCenter());

            entIds.QForEach(entity => entity.Erase());
            entIds.Clear();
            return(result);
        }