{"id":1670,"date":"2008-03-14T11:35:32","date_gmt":"2008-03-14T11:35:32","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2008\/03\/14\/finding-pixel-boundaries\/"},"modified":"2008-05-01T18:14:33","modified_gmt":"2008-05-01T18:14:33","slug":"finding-pixel-boundaries","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2008\/03\/14\/finding-pixel-boundaries\/","title":{"rendered":"Finding Pixel Boundaries"},"content":{"rendered":"

Important note<\/strong>: The AmiBroker 5.09.0 Beta<\/a> introduced the following new GFX functions:<\/p>\n

Status(“pxchartleft”) – returns x-coordinate of top-left corner of chart area
\nStatus(“pxcharttop”) – returns y-coordinate of top-left corner of chart area
\nStatus(“pxchartright”) – returns x-coordinate of bottom-right corner of chart area
\nStatus(“pxchartbottom”) – returns y-coordinate of bottom-right corner of chart area
\nStatus(“pxchartwidth”) – returns width chart area (right-left)
\nStatus(“pxchartheight”) – returns width chart area (bottom-top)<\/p>\n

Since this release appeared after this post was published these functions are not used in the examples below. This post has been left unchanged for educational purposes. For examples using the new functions please see the 5.09.0 Read Me<\/a> file.<\/p>\n

=====<\/p>\n

The first requirement when designing chart overlays and\/or control panels is to know the exact dimensions of your charting pane. These are expressed in pixels. The numerical values where the margins (the four edges of your charting pane) are located depends on the resolution of your monitor, the size of the chart pane, and the fonts used to label your axis. <\/p>\n

Currently the only way to obtain the values is, as far as I know, to determine the pane boundaries manually. The code below plots four lines that you can position using sliders in the Param window. When the lines fall exactly on the edges of your charting pane you can read the pixel value in the Param window and in the chart Title. See the image below and note how the blue lines hide the regular black chart frame:<\/p>\n

\"clip_image002\"<\/a><\/p>\n

Try changing the size of your charting pane, the overall AmiBroker window, and the font for the axis, to see how the pixel values change. Be aware that opening multiple chart panes and\/or windows will also change pixel values. Also, probably to ensure that the first bar shows, the left edge of your charting pane is located at the third pixel, while actual bars start plotting at the fifth pixel. This means that trying to overlay the Blue line to determine the left boundary will be offset to the left by two pixels. To use the code below copy it to a new Indicator formula window and click Apply. <\/p>\n

<\/span>function <\/span>gfxPlotHLine<\/span>( <\/span>YPixels<\/span>, <\/span>Color <\/span>)\r{\r    global <\/span>pxwidth<\/span>;\r    <\/span>GfxSelectPen<\/span>( <\/span>Color <\/span>) ;\r    <\/span>GfxMoveTo<\/span>( <\/span>0<\/span>, <\/span>YPixels <\/span>);\r    <\/span>GfxLineTo<\/span>( <\/span>pxwidth<\/span>, <\/span>YPixels <\/span>);\r}\r\rfunction <\/span>gfxPlotVLine<\/span>( <\/span>XPixels<\/span>, <\/span>Color <\/span>)\r{\r    global <\/span>pxheight<\/span>;\r    <\/span>GfxSelectPen<\/span>( <\/span>Color <\/span>) ;\r    <\/span>GfxMoveTo<\/span>( <\/span>XPixels<\/span>, <\/span>0 <\/span>);\r    <\/span>GfxLineTo<\/span>( <\/span>XPixels<\/span>, <\/span>pxheight <\/span>);\r}\r\r<\/span>GraphXSpace <\/span>= <\/span>0<\/span>;\r<\/span>SetChartOptions<\/span>( <\/span>2<\/span>, <\/span>chartHideQuoteMarker <\/span>);\r\r<\/span>pxwidth <\/span>= <\/span>Status<\/span>( <\/span>"pxwidth" <\/span>);\r<\/span>pxheight <\/span>= <\/span>Status<\/span>( <\/span>"pxheight" <\/span>);\r\r<\/span>BottomMargin <\/span>= <\/span>Param<\/span>( <\/span>"Bottom Margin"<\/span>, <\/span>14<\/span>, <\/span>0<\/span>, <\/span>100 <\/span>);\r<\/span>gfxPlotHLine<\/span>( <\/span>pxheight <\/span>- <\/span>BottomMargin<\/span>, <\/span>6 <\/span>);\r\r<\/span>RightMargin <\/span>= <\/span>Param<\/span>( <\/span>"Right Margin"<\/span>, <\/span>77<\/span>, <\/span>0<\/span>, <\/span>100 <\/span>);\r<\/span>gfxPlotVLine<\/span>( <\/span>pxwidth <\/span>- <\/span>RightMargin<\/span>, <\/span>6 <\/span>);\r\r<\/span>LeftMargin <\/span>= <\/span>Param<\/span>( <\/span>"Left margin"<\/span>, <\/span>3<\/span>, <\/span>0<\/span>, <\/span>100 <\/span>);\r<\/span>gfxPlotVLine<\/span>( <\/span>LeftMargin<\/span>, <\/span>6 <\/span>);\r\r<\/span>TopMargin <\/span>= <\/span>Param<\/span>( <\/span>"Top Margin"<\/span>, <\/span>5<\/span>, <\/span>0<\/span>, <\/span>100 <\/span>);\r<\/span>gfxPlotHLine<\/span>( <\/span>TopMargin<\/span>, <\/span>6 <\/span>);\r\r<\/span>Title<\/span>=<\/span>"\\n"<\/span>+\r<\/span>"   Pixel width: "<\/span>+<\/span>NumToStr<\/span>(<\/span>pxwidth<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"\\n"<\/span>+\r<\/span>"  Pixel height: "<\/span>+<\/span>NumToStr<\/span>(<\/span>pxheight<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"\\n"<\/span>+\r<\/span>"   Top marging: "<\/span>+<\/span>NumToStr<\/span>(<\/span>TopMargin<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"\\n"<\/span>+\r<\/span>" Right marging: "<\/span>+<\/span>NumToStr<\/span>(<\/span>RightMargin<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"\\n"<\/span>+\r<\/span>"Bottom marging: "<\/span>+<\/span>NumToStr<\/span>(<\/span>BottomMargin<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"\\n"<\/span>+\r<\/span>"  Left marging: "<\/span>+<\/span>NumToStr<\/span>(<\/span>LeftMargin<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>);\r<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

Important note: The AmiBroker 5.09.0 Beta introduced the following new GFX functions: Status(“pxchartleft”) – returns x-coordinate of top-left corner of chart area Status(“pxcharttop”) – returns y-coordinate of top-left corner of chart area Status(“pxchartright”) – returns x-coordinate of bottom-right corner of chart area Status(“pxchartbottom”) – returns y-coordinate of bottom-right corner of chart area Status(“pxchartwidth”) – returns […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[138],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1670"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1670"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1670\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1670"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}