Menu

Make Legend colorbox border optional

Toewe
2012-12-05
2013-01-16
  • Toewe

    Toewe - 2012-12-05

    First off, thanks for a great application. It is a distinct pleasure to use a product that works as documented after wrestling with JpGraph for too long.

    We're using the 'bars' style of plot and legend with a user selected number of data points. To make the plot and legend look alike, we have borders on the plot bars and have set the shading to 0. As more data points are included, the plot bars naturally get narrower. To keep the legend 'bars' looking similar, we scale the class variable, legend_colorbox_width, as more data points are selected, thus narrowing the legend bars.

    This works well until the plot bars collapse to where only the border is displayed. At that point we make the plot bar border color the same as the data color. However the legend does not provide control of this feature, so the legend bars no longer look the same as the plot bars.

    My request is to add a feature to permit either:
    1) the legend colorbox border to be turned on/off
    2) set the colorbox border color explicitly

    Thanks for your consideration.

     
  • lbayuk

    lbayuk - 2012-12-05

    Good ideas. I wrote up [feature-requests:#50] to document this.

    I've already done something along these lines for pie charts [feature-requests:#46] - added color and on/off control methods.

    Although your case needs a little thought to do it right. The borders on your unshaded bar charts use the data border colors, but there is no way to turn them off. The legend color box borders use the text color, and there is no way to turn them off nor a way to control the color (without also affecting the colors of other items, such as legend text).

    (I assume you did not change the data border colors from their black defaults, or your bar chart borders would not match the legend colorbox borders.)

    Let me think about a way to fix these limitations, without any compatibility problems. Feel free to offer any ideas or thoughts.

     

    Related

    Feature Requests: #46
    Feature Requests: #50

  • lbayuk

    lbayuk - 2012-12-06

    OK, I thought about it a little and came up with this proposal for 2 new methods.

    $plot->SetLegendColorboxBorders($borders_on, $use_data_border_colors = False)
    

    Controls the legend color-box borders. $borders_on is TRUE to draw them, FALSE to not draw them. (Default is TRUE.) $use_data_border_colors is TRUE to use the color entries in the SetDataBorderColors() array for color-box borders, or FALSE to use the SetTextColor() color. (Default is FALSE.)

    $plot->SetDrawDataBorders($borders_on)
    

    Enables or disables the data borders for bars and stackedbars plots. $borders_on is TRUE to draw the borders, FALSE to not draw them. Default depends on shading: TRUE for unshaded plots, FALSE for shaded plots. This makes the default compatible with the current PHPlot behavior. (A similar new method for controlling pie chart borders will be in the next release.)

    (This would let us have data borders on bar charts with shading, if we want, which isn't possible now. I'm not sure how that would look, though.)

     
    • Toewe

      Toewe - 2012-12-07

      Please excuse if this response shows up twice - it seemed to not appear when submitted the first time.

      Thanks for your quick and positive response.

      You missed one point in my request. When the plot bars are few and wide, we allow PHPlot to use the text color as the plot bar border, but as the number increases and they necessarily become narrower, we change the bar border color to match the assigned bar color. It is at this point that the legend bars look so different than the plot bars because the legend bars still have borders using the assigned text color and this caused our request.

      The first of your two proposed improvements more than covers my request and so if I had to pick one that would be it. The second proposal certainly offers still more flexibility, but I share your concern that borders on a shaded bar may defeat the 3D effect.

      At the risk of piling one request on top of another let me expand this discussion to line weights within the legend. It is a related issue.

      In one of our plots, we display up to 9 different line types. Basically this is a plot of measured temperatures and thermostat settings versus time. At each point in time we plot the measured temperature of the room in either of two green line weights - a thin dark green line to indicate that the thermostat is NOT calling for heating or cooling; or thick and in a lighter shade of green to indicate that it IS calling for heat or cooling.

      The next 3 lines are red and are used to display the stored program for heating. A thin line indicates the stored heating program versus time. A thick line follows the same stored heating program, but indicates when the HVAC is actually heating. The third line is also thin, but indicates the temporary override heating temperature that the user has set the thermostat to. It does get a bit confusing at times.

      The next 3 lines are green and as you can guess, display the cooling program values.

      The last line is a grey and displays the outdoor temperature that we fetch from Wunderground.com for a nearby weather station.

      My reason for raising this issue is that we cannot indicate the line weight differences within the legend. We can change all of the color_box widths to simulate a line weight difference, but not individually.

      Thanks again.

      P.S. I am going to try to add a screen capture of our old plot to clarify this.

       

      Last edit: Toewe 2012-12-07
  • lbayuk

    lbayuk - 2012-12-07

    The first of your two proposed improvements more than covers my request and so if I had to pick one that would be it.

    No, I meant I would like to do both. They are not separate.

    we cannot indicate the line weight differences within the legend.

    For 'points' and 'linepoints' plots, PHPlot can use the actual point shape in the legend, rather than a color-box. (I think this was originally added for accessibility purposes - not using only color to distinguish things - or maybe also so that the legend in a black-and-white print was usable.) Perhaps we can do something like that for line plots - a color line with the right thickness replacing the color-box.

     
    • Toewe

      Toewe - 2012-12-09

      The legend color_box already tracks the corresponding line color. That is great.

      But the legend color_box should NOT be a color_box unless the plot type is a bar or stacked bar. In the cases of line and squared graphs the legend 'symbol' should be a line of the same color, weight and style as the corresponding graph line. Otherwise identification of the lines is compromised, IMHO.

       
  • lbayuk

    lbayuk - 2012-12-09

    While I don't agree that having colorboxes in the legend for a line plot is wrong, I want to provide the option to have lines instead (with correct color and thickness). That was your suggestion above. I'm not 100% sure this will work visually though. The lines in the legend will have to be short segments, and the colors of the short lines might be hard to distinguish. I'll try it and see what it looks like.

    I already have the new functions to 1) turn off the colorbox borders or change their colors (close but not exactly as above), and 2) control the data border for bars in a bar chart - on or off. Test scripts are done, but no updates to documentation yet. Next up is to try the lines instead of color-boxes in the legend.

    Unfortunately, I am not sure when this (and the other changes and new features) would make it into a release. I've been working on PHPlot-6.0, which has all the new features so far, but I'm stuck on the big change - fixing the automatic scaling and tick interfaces. It still doesn't work well enough. If I can't see the way to fix this soon, I might have to look into "back-porting" some of the new features into a 5.9 release.

     
  • lbayuk

    lbayuk - 2012-12-09

    Created [feature-requests:#51] "Lines instead of colorboxes in legend"

     

    Related

    Feature Requests: #51

    • Toewe

      Toewe - 2012-12-10

      Thanks for being so supportive. The product is great and getting better and your attitude is wonderful.

       
  • lbayuk

    lbayuk - 2012-12-10

    Please take a look at [wiki:LegendLineMarkers] for sample output images. Comments?

    I currently have it doing a diagonal line through the color-box area. I did that first, thinking I would go back and make it horizontal or vertical, but now I think I like it. Except for the really thick lines when background is on.

    This implementation doesn't add any new functions - it just extends what SetLegendUseShapes(True) means for other plot types:

    • points, linepoints : display point shape markers (same as current releases)
    • lines, squared, thinbarline : will display line segments
    • All other plot types : ignored, and you get color-boxes.
     

    Related

    Wiki: LegendLineMarkers

  • lbayuk

    lbayuk - 2012-12-13

    I added a 6th picture, section (5) in [wiki:LegendLineMarkers], with a change to make short horizontal line segments instead of diagonals. It does look better, but only if the legend_colorbox_width is increased to 4 or more, giving 4x width for the lines.

    Question: should PHPlot automatically make the colorboxes wider when using line segments? I don't like that. But it needs to look decent by default, and changing class variables ('tuning variables') should not be necessary.

     

    Related

    Wiki: LegendLineMarkers

    • Toewe

      Toewe - 2012-12-19

      I cannot see the 6th picture so cannot comment on it.

      Re: your question, by default I believe PHPlot should mimick the plot line thickness (and color and style). If the line is thick enough to work as a plot line, it's thick enough for a legend line too, IMHO.

       
  • Toewe

    Toewe - 2012-12-19

    The sample "(1) Line markers in legend" looks great for the case of variable width, colored lines without borders. The case of dashed line styles is not represented at wiki sample and should be mimicked in the legend if the plotted line is dashed. Not sure where you stand on that question.

    I think your suggested implementation otherwise is right on.

     
  • lbayuk

    lbayuk - 2012-12-19

    I didn't implement line styles in the legend (yet). There are 2 reasons I didn't want to do them: (1) The line segments are so short that I think visibility would suffer if there are gaps, and (2) there is what I consider a PHP/GD bug that makes styled lines unusable with widths above 1. There are bug reports (both PHPlot and PHP) on this, but no response in 5 years on the PHP/GD side.

    I guess I need to try line styles and see how it looks.

     
  • lbayuk

    lbayuk - 2012-12-19

    I cannot see the 6th picture so cannot comment on it.

    Sorry for the confusion; since that post I decided the horizontal lines (previously the 6th picture) were the way to go, so I redid the code and the page, eliminating the diagonal line versions.

     
  • lbayuk

    lbayuk - 2012-12-20

    I added the line styles, so now the legend line markers show the color, width, and line style (dashed or solid). This can be seen at (4) at [wiki:LegendLineMarkers].

    Although both plot and legend will draw a dashed lines with width greater than 1, this is not recommended, since the result is weird. Any given line should either be plain, wide, or dashed, but not both wide and dashed.

    (I need to take a look at the way PHPlot handles dashed lines, though. Only a single style can be defined, and this is used for anything which is dashed - grid, data label lines, and plot lines. This isn't ideal, but probably not simple to fix.)

     

    Related

    Wiki: LegendLineMarkers

    • Toewe

      Toewe - 2012-12-22

      Again thanks for being so supportive. Love the product and your support.

       
    • Toewe

      Toewe - 2013-01-16

      I am finally getting around to implementing some of these improvements and find that for the case of squared plots the legend background color is set to $this->ndx_bg_color, while the colorbox background color is set to $this->ndx_plot_bg_color. These are good choices if the legend is placed on top of the plot area. However as I cannot predict where the lines of the graph will be located and do not want to obscure them, I always place the legend in the margin area.

      As the margin color is grey and the plot area is white in my color scheme, the legend has a grey background on a grey margin. The colorboxes have the newly formatted lines of the proper color, thickness and style and the colorbox backgrounds are the same color as the plot area background, as they should, IMHO.

      The problem is that the little white (in my case) colorboxes do not look good within the grey background of the legend. They look much better when the legend background is also white and the legend stands out better on the margin. So my new request is for a way to control the legend background color independent of the image background.

      Thanks in advance for your serious consideration.

       

      Last edit: Toewe 2013-01-16
      • lbayuk

        lbayuk - 2013-01-16

        This should be how it works now: The legend background color is the image background color. If you use SetLegendUseShapes(True), to use shape markers instead of color boxes, then the shape marker is drawn against a color background that matches the plot area background (not necessarily the same as the image background). This can be see in figure (2) in [LegendLineMarkers]. The idea is to match the background/foreground color pairs between the legend and plot. This should be correct whether the legend is over the plot area or in the margin area.

        If I understand correctly, you are OK with that behavior, but you want to be able to change the background color in the rest of the legend (behind the text lines, and around the color boxes). Is that correct? If so, that should be easy enough, and I already have a feature request [feature-requests:#29] for better control over colors of plot elements, with the goal of fixing cases where colors of different elements cannot be independently changed.

         

        Related

        Feature Requests: #29
        Wiki: LegendLineMarkers

    • Toewe

      Toewe - 2013-01-16

      Maybe I missed some of your explanation, but in the case of stackedbars plot, the new function $plot->SetLegendColorboxBorders seems to take only a single argument with one of three specific values: 'none', 'textcolor' or 'databordercolor'. That still works for me. I just wanted to point this out for closure.

      Thanks again.

       
      • lbayuk

        lbayuk - 2013-01-16

        I'm not following. Yes, this would have a single argument that controls the color used for the borders in the legend color boxes. What is special about stackedbars plots?

        My intent was that 'databordercolor' would be used mostly with a bars or stackedbars plot. Each bar segment in the plot uses a fill color and a border color, and the legend color box which corresponds to that bar segment would then use the same 2 colors. This makes it easier to visually match the legend entries and plotted bars.

        If the 'databordercolor' choice was used with other plot types, then the legend color box borders are directly controllable with SetDataBorderColors (since those colors aren't used for anything else with these plot types).

        Am I missing something?

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.