Menu

Legend Dashed Lines Drawn Wrong

gw1500se
2015-08-24
2015-08-27
  • gw1500se

    gw1500se - 2015-08-24

    I am almost done but still have one cosmetic problem. I have the following dashed line customization and legend box:

    $plot->SetDefaultDashedStyle('20-10');
    $plot->SetLegendUseShapes(true);
    $plot->end_colorbox_width=2;

    The problem is that the legend box dashes do not look like the respective plot line. In the legend what should be the solid segment appears as transparent with a border around it and the transparent part appears solid.

     
  • lbayuk

    lbayuk - 2015-08-25

    Here is what I get with a 3-line legend, using your dashed line pattern '20-10', SetLegendUseShapes(true), and $plot->legend_colorbox_width=2 as you have above (note correction from typo "end_colorbox_width"). This looks right to me. The colorboxes end up 48 pixels wide, and the dashed pattern is 30 pixels, so you can see a full on/off/on pattern. What are you seeing on yours?

     
  • gw1500se

    gw1500se - 2015-08-26

    That was a copy paste error.

     
  • lbayuk

    lbayuk - 2015-08-27

    OK, I know exactly what that is. You are using a line width greater than 1, right? (SetLineWidths(3) I think in fact.)

    Unfortunately, there is an unexpected interaction between line width and dashed line style in the PHP graphics library GD. I wrote a PHPlot bug report on it [bugs:#95] - (that's almost 9 years ago), and there is also a PHP bug report. But the response to the PHP bug report is that it is working as designed and they just think it should be documented better.

    The explanation they gave me is that the bits in the line style pattern are first applied across the width of the line, then along the length.

    But it gets worse: there is another bug, which applies only to horizontal lines that are dashed and thick (like those in the legend). This bug came up during discussion of the original dashed+thick line bug. The patterns are not applied right, even with the 'corrected' explanation. The PHP maintainer for GD has opened a libgd bug ticket for that one.

    Summary: use dashed lines or thick lines, but avoid using dashed and thick lines if possible.

     

    Related

    Bugs: #95

  • gw1500se

    gw1500se - 2015-08-27

    Oh! That is a problem because the thick lines are necessary to distinguish colors between the lines themselves. Leaving them at 1 pixel, one cannot really see the colors well enough to know which line is which. Especially where they come close to each other. Given the choice it is more important to do that than have the legend look correct.

    I guess I just need to live with it until libgd is fixed. Whenever that will be.

     

Log in to post a comment.