Recent

Author Topic: Making node appear in front of lines  (Read 5103 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Making node appear in front of lines
« on: July 26, 2018, 08:44:31 am »
I have a straightforward chart. It has a few TLineSeries, drawn by \addplot. The I have a \node, to place some text on the chart. I cannot find a way of making the node aooear in front of (on top of) the lines. How can I do this?

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: Making node appear in front of lines
« Reply #1 on: July 26, 2018, 09:11:59 am »
Just an additional piece of info. The lines have pointers, and the node appears in front of the line between the pointers but behind the actual pointers.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Making node appear in front of lines
« Reply #2 on: July 26, 2018, 10:49:12 am »
What do you mean as "Node"? - there is no word "node" within TAChart, and a "AddPlot" does not exist either.

Please upload a little demo showing the issue? Only lpi, lpr, pas and lfm files packed to a common zip, no compiler-generated files, please.

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: Making node appear in front of lines
« Reply #3 on: July 26, 2018, 11:06:17 am »
Sorry!
My question relates to Latex/PGFPlots. I'm writing a Lazarus program that displays a chart using TAChart, then can write a file containing the LATEX/PGFPlots code for the same file for inclusion in a Latex document.

Actually the \node PGFPlots command can do a lot of different things, but in this context is displays some text at given graph coordinate points. It will be my ignorance, but doing this within TAChart seems to involve some complexity. A nice-to-have would be a builtin facility in TAChart to do this. Maybe someone has written such a thing already?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Making node appear in front of lines
« Reply #4 on: July 26, 2018, 11:44:20 am »
You can draw any user-provided text in the OnAfterDraw event of the chart using code like this:

Code: Pascal  [Select][+][-]
  1. uses
  2.   TAGeometry, TAChartUtils;
  3.  
  4. procedure TForm1.Chart1AfterDraw(ASender: TChart; ADrawer: IChartDrawer);
  5. // This example assumes that the extent of the chart has been set to XMin = -1, XMax = 1, YMin = -1, YMax = 1.
  6. var
  7.   imgPt: TPoint;
  8. begin
  9.   imgPt := Chart1.GraphToImage(DoublePoint(-0.9, 0.8));
  10.   ADrawer.TextOut.Text('Left-custified at x=-0.9/y=0.8').Pos(imgPt).Done;
  11.  
  12.   imgPt := Chart1.GraphToImage(DoublePoint(-0.8, 0.0));
  13.   ADrawer.Textout.TextFormat(tfHTML).Text('<b>bold</b>, <i>italic</i>, <u>underlined</u>').Pos(imgPt).Done;
  14. end;

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Making node appear in front of lines
« Reply #5 on: July 26, 2018, 12:26:01 pm »
Sorry!
My question relates to Latex/PGFPlots. I'm writing a Lazarus program that displays a chart using TAChart, then can write a file containing the LATEX/PGFPlots code for the same file for inclusion in a Latex document.
The most general way to do this would be to add a Latex drawer to TAChart. This means you'd have to write a class, say TALaTeXDrawer as "class(TBasicDrawer, IChartDrawer)" and implement the methods of IChartDrawer:
Code: Pascal  [Select][+][-]
  1.   IChartDrawer = interface
  2.     ['{6D8E5591-6788-4D2D-9FE6-596D5157C3C3}']
  3.     procedure AddToFontOrientation(ADelta: Integer);
  4.     procedure ClippingStart(const AClipRect: TRect);
  5.     procedure ClippingStart;
  6.     procedure ClippingStop;
  7.     procedure DrawingBegin(const ABoundingBox: TRect);
  8.     procedure DrawingEnd;
  9.     procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
  10.     procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
  11.     procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
  12.     procedure FillRect(AX1, AY1, AX2, AY2: Integer);
  13.     function GetBrushColor: TChartColor;
  14.     function GetFontAngle: Double;       // in radians
  15.     function GetFontColor: TFPColor;
  16.     function GetFontName: String;
  17.     function GetFontSize: Integer;
  18.     function GetFontStyle: TChartFontStyles;
  19.     procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
  20.     procedure Line(AX1, AY1, AX2, AY2: Integer);
  21.     procedure Line(const AP1, AP2: TPoint);
  22.     procedure LineTo(AX, AY: Integer);
  23.     procedure LineTo(const AP: TPoint);
  24.     procedure MoveTo(AX, AY: Integer);
  25.     procedure MoveTo(const AP: TPoint);
  26.     procedure Polygon(
  27.       const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
  28.     procedure Polyline(
  29.       const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
  30.     procedure PrepareSimplePen(AColor: TChartColor);
  31.     procedure PutImage(AX, AY: Integer; AImage: TFPCustomImage);
  32.     procedure PutPixel(AX, AY: Integer; AColor: TChartColor);
  33.     procedure RadialPie(
  34.       AX1, AY1, AX2, AY2: Integer;
  35.       AStartAngle16Deg, AAngleLength16Deg: Integer);
  36.     procedure Rectangle(const ARect: TRect);
  37.     procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
  38.     procedure ResetFont;
  39.     function Scale(ADistance: Integer): Integer;
  40.     procedure SetAntialiasingMode(AValue: TChartAntialiasingMode);
  41.     procedure SetBrushColor(AColor: TChartColor);
  42.     procedure SetBrush(ABrush: TFPCustomBrush);
  43.     procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
  44.     procedure SetFont(AValue: TFPCustomFont);
  45.     procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
  46.     procedure SetMonochromeColor(AColor: TChartColor);
  47.     procedure SetPen(APen: TFPCustomPen);
  48.     procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
  49.     function GetRightToLeft: Boolean;
  50.     procedure SetRightToLeft(AValue: Boolean);
  51.     procedure SetTransparency(ATransparency: TChartTransparency);
  52.     procedure SetXor(AXor: Boolean);
  53.     function TextExtent(const AText: String;
  54.       ATextFormat: TChartTextFormat = tfNormal): TPoint;
  55.     function TextExtent(AText: TStrings;
  56.       ATextFormat: TChartTextFormat = tfNormal): TPoint;
  57.     function TextOut: TChartTextOut;
  58.  
  59.     property Brush: TFPCustomBrush write SetBrush;
  60.     property BrushColor: TChartColor read GetBrushColor write SetBrushColor;
  61.     property Font: TFPCustomFont write SetFont;
  62.     property Pen: TFPCustomPen write SetPen;
  63.     property DoChartColorToFPColor: TChartColorToFPColorFunc
  64.       write SetDoChartColorToFPColorFunc;
  65.     property DoGetFontOrientation: TGetFontOrientationFunc
  66.       write SetGetFontOrientationFunc;
  67.   end;

See TSVGDrawer (in TADrawerSVG) as an example.

If you have something ready in this direction I'd be happy to add it to the official distribution.

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: Making node appear in front of lines
« Reply #6 on: August 18, 2018, 09:27:46 am »
Thanks for the suggestions. I think writing a Latex drawer is rather beyond my skills and experience with Lazarus/TAGraph.

 

TinyPortal © 2005-2018