Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend item wrap with layout.legend.orientation = h #1

Merged
merged 7 commits into from
Jul 27, 2016

Conversation

psalmody
Copy link
Owner

Should help with plotly#769:

  1. Keeps track of tallest legend item in list.
  2. Calculates the upcoming width of the legend item and sees if it will push the item past the right margin.
  3. If it will be pushed out of viewable range, creates a new row of legend items based on the previous rows tallest legend item.

@psalmody
Copy link
Owner Author

image

@psalmody
Copy link
Owner Author

image

@psalmody
Copy link
Owner Author

I used this test data: (DATA.data and DATA.layout):

DATA = {
    "data": [
      {
        "x": [1, 2, 3, 4],
        "y": [63.69, 62.55, 61.64, 61.39],
        "text": ["FiscalYear: 2012<br>Percent: 63.69<br>Students: 1235<br>Race: 1<br>Race: Average", "FiscalYear: 2013<br>Percent: 62.55<br>Students: 1149<br>Race: 1<br>Race: Average", "FiscalYear: 2014<br>Percent: 61.64<br>Students: 1080<br>Race: 1<br>Race: Average", "FiscalYear: 2015<br>Percent: 61.39<br>Students: 1035<br>Race: 1<br>Race: Average"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Average",
        "line": {
          "width": 1.8898,
          "color": "rgba(0,0,0,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [58.24, 54.93, 42.11, 50.75],
        "text": ["FiscalYear: 2012<br>Percent: 58.24<br>Students: 53<br>Race: 2<br>Race: African American", "FiscalYear: 2013<br>Percent: 54.93<br>Students: 39<br>Race: 2<br>Race: African American", "FiscalYear: 2014<br>Percent: 42.11<br>Students: 32<br>Race: 2<br>Race: African American", "FiscalYear: 2015<br>Percent: 50.75<br>Students: 34<br>Race: 2<br>Race: African American"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "African American",
        "line": {
          "width": 1.8898,
          "color": "rgba(248,118,109,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [51.49, 49.59, 37.12, 31.45],
        "text": ["FiscalYear: 2012<br>Percent: 51.49<br>Students: 69<br>Race: 3<br>Race: Alaska Native", "FiscalYear: 2013<br>Percent: 49.59<br>Students: 60<br>Race: 3<br>Race: Alaska Native", "FiscalYear: 2014<br>Percent: 37.12<br>Students: 49<br>Race: 3<br>Race: Alaska Native", "FiscalYear: 2015<br>Percent: 31.45<br>Students: 39<br>Race: 3<br>Race: Alaska Native"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Alaska Native",
        "line": {
          "width": 1.8898,
          "color": "rgba(216,144,0,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [49.09, 58.54, 53.91, 43.12],
        "text": ["FiscalYear: 2012<br>Percent: 49.09<br>Students: 54<br>Race: 4<br>Race: Alaska Native Multirace", "FiscalYear: 2013<br>Percent: 58.54<br>Students: 72<br>Race: 4<br>Race: Alaska Native Multirace", "FiscalYear: 2014<br>Percent: 53.91<br>Students: 62<br>Race: 4<br>Race: Alaska Native Multirace", "FiscalYear: 2015<br>Percent: 43.12<br>Students: 47<br>Race: 4<br>Race: Alaska Native Multirace"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Alaska Native<br>Multirace",
        "line": {
          "width": 1.8898,
          "color": "rgba(163,165,0,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [70.53, 72.51, 72.28, 78.65],
        "text": ["FiscalYear: 2012<br>Percent: 70.53<br>Students: 146<br>Race: 5<br>Race: Asian", "FiscalYear: 2013<br>Percent: 72.51<br>Students: 124<br>Race: 5<br>Race: Asian", "FiscalYear: 2014<br>Percent: 72.28<br>Students: 133<br>Race: 5<br>Race: Asian", "FiscalYear: 2015<br>Percent: 78.65<br>Students: 140<br>Race: 5<br>Race: Asian"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Asian",
        "line": {
          "width": 1.8898,
          "color": "rgba(57,182,0,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [62.69, 59.09, 63.82, 62],
        "text": ["FiscalYear: 2012<br>Percent: 62.69<br>Students: 84<br>Race: 6<br>Race: Hispanic", "FiscalYear: 2013<br>Percent: 59.09<br>Students: 91<br>Race: 6<br>Race: Hispanic", "FiscalYear: 2014<br>Percent: 63.82<br>Students: 97<br>Race: 6<br>Race: Hispanic", "FiscalYear: 2015<br>Percent: 62<br>Students: 93<br>Race: 6<br>Race: Hispanic"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Hispanic",
        "line": {
          "width": 1.8898,
          "color": "rgba(0,191,125,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [76.27, 71.43, 59.83, 64.34],
        "text": ["FiscalYear: 2012<br>Percent: 76.27<br>Students: 90<br>Race: 7<br>Race: Non Hispanic Multirace", "FiscalYear: 2013<br>Percent: 71.43<br>Students: 95<br>Race: 7<br>Race: Non Hispanic Multirace", "FiscalYear: 2014<br>Percent: 59.83<br>Students: 70<br>Race: 7<br>Race: Non Hispanic Multirace", "FiscalYear: 2015<br>Percent: 64.34<br>Students: 83<br>Race: 7<br>Race: Non Hispanic Multirace"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Non Hispanic Multirace",
        "line": {
          "width": 1.8898,
          "color": "rgba(0,191,196,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [71.15, 81.82, 88.46, 74.29],
        "text": ["FiscalYear: 2012<br>Percent: 71.15<br>Students: 37<br>Race: 8<br>Race: Non Resident Alien", "FiscalYear: 2013<br>Percent: 81.82<br>Students: 27<br>Race: 8<br>Race: Non Resident Alien", "FiscalYear: 2014<br>Percent: 88.46<br>Students: 23<br>Race: 8<br>Race: Non Resident Alien", "FiscalYear: 2015<br>Percent: 74.29<br>Students: 26<br>Race: 8<br>Race: Non Resident Alien"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Non Resident Alien",
        "line": {
          "width": 1.8898,
          "color": "rgba(0,176,246,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [57.89, 57.38, 52.08, 63.83],
        "text": ["FiscalYear: 2012<br>Percent: 57.89<br>Students: 44<br>Race: 9<br>Race: Unknown", "FiscalYear: 2013<br>Percent: 57.38<br>Students: 35<br>Race: 9<br>Race: Unknown", "FiscalYear: 2014<br>Percent: 52.08<br>Students: 25<br>Race: 9<br>Race: Unknown", "FiscalYear: 2015<br>Percent: 63.83<br>Students: 30<br>Race: 9<br>Race: Unknown"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "Unknown",
        "line": {
          "width": 1.8898,
          "color": "rgba(149,144,255,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [65.4, 63.27, 65.78, 64.03],
        "text": ["FiscalYear: 2012<br>Percent: 65.4<br>Students: 635<br>Race: 10<br>Race: White", "FiscalYear: 2013<br>Percent: 63.27<br>Students: 577<br>Race: 10<br>Race: White", "FiscalYear: 2014<br>Percent: 65.78<br>Students: 571<br>Race: 10<br>Race: White", "FiscalYear: 2015<br>Percent: 64.03<br>Students: 518<br>Race: 10<br>Race: White"],
        "key": null,
        "type": "scatter",
        "mode": "lines",
        "name": "White",
        "line": {
          "width": 1.8898,
          "color": "rgba(231,107,243,1)",
          "dash": "solid"
        },
        "showlegend": true,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [63.69, 62.55, 61.64, 61.39],
        "text": ["FiscalYear: 2012<br>Percent: 63.69<br>Students: 1235<br>Race: Average", "FiscalYear: 2013<br>Percent: 62.55<br>Students: 1149<br>Race: Average", "FiscalYear: 2014<br>Percent: 61.64<br>Students: 1080<br>Race: Average", "FiscalYear: 2015<br>Percent: 61.39<br>Students: 1035<br>Race: Average"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(0,0,0,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(0,0,0,1)"
          }
        },
        "name": "Average",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [58.24, 54.93, 42.11, 50.75],
        "text": ["FiscalYear: 2012<br>Percent: 58.24<br>Students: 53<br>Race: African American", "FiscalYear: 2013<br>Percent: 54.93<br>Students: 39<br>Race: African American", "FiscalYear: 2014<br>Percent: 42.11<br>Students: 32<br>Race: African American", "FiscalYear: 2015<br>Percent: 50.75<br>Students: 34<br>Race: African American"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(248,118,109,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(248,118,109,1)"
          }
        },
        "name": "African American",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [51.49, 49.59, 37.12, 31.45],
        "text": ["FiscalYear: 2012<br>Percent: 51.49<br>Students: 69<br>Race: Alaska Native", "FiscalYear: 2013<br>Percent: 49.59<br>Students: 60<br>Race: Alaska Native", "FiscalYear: 2014<br>Percent: 37.12<br>Students: 49<br>Race: Alaska Native", "FiscalYear: 2015<br>Percent: 31.45<br>Students: 39<br>Race: Alaska Native"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(216,144,0,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(216,144,0,1)"
          }
        },
        "name": "Alaska Native",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [49.09, 58.54, 53.91, 43.12],
        "text": ["FiscalYear: 2012<br>Percent: 49.09<br>Students: 54<br>Race: Alaska Native Multirace", "FiscalYear: 2013<br>Percent: 58.54<br>Students: 72<br>Race: Alaska Native Multirace", "FiscalYear: 2014<br>Percent: 53.91<br>Students: 62<br>Race: Alaska Native Multirace", "FiscalYear: 2015<br>Percent: 43.12<br>Students: 47<br>Race: Alaska Native Multirace"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(163,165,0,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(163,165,0,1)"
          }
        },
        "name": "Alaska Native Multirace",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [70.53, 72.51, 72.28, 78.65],
        "text": ["FiscalYear: 2012<br>Percent: 70.53<br>Students: 146<br>Race: Asian", "FiscalYear: 2013<br>Percent: 72.51<br>Students: 124<br>Race: Asian", "FiscalYear: 2014<br>Percent: 72.28<br>Students: 133<br>Race: Asian", "FiscalYear: 2015<br>Percent: 78.65<br>Students: 140<br>Race: Asian"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(57,182,0,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(57,182,0,1)"
          }
        },
        "name": "Asian",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [62.69, 59.09, 63.82, 62],
        "text": ["FiscalYear: 2012<br>Percent: 62.69<br>Students: 84<br>Race: Hispanic", "FiscalYear: 2013<br>Percent: 59.09<br>Students: 91<br>Race: Hispanic", "FiscalYear: 2014<br>Percent: 63.82<br>Students: 97<br>Race: Hispanic", "FiscalYear: 2015<br>Percent: 62<br>Students: 93<br>Race: Hispanic"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(0,191,125,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(0,191,125,1)"
          }
        },
        "name": "Hispanic",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [76.27, 71.43, 59.83, 64.34],
        "text": ["FiscalYear: 2012<br>Percent: 76.27<br>Students: 90<br>Race: Non Hispanic Multirace", "FiscalYear: 2013<br>Percent: 71.43<br>Students: 95<br>Race: Non Hispanic Multirace", "FiscalYear: 2014<br>Percent: 59.83<br>Students: 70<br>Race: Non Hispanic Multirace", "FiscalYear: 2015<br>Percent: 64.34<br>Students: 83<br>Race: Non Hispanic Multirace"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(0,191,196,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(0,191,196,1)"
          }
        },
        "name": "Non Hispanic Multirace",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [71.15, 81.82, 88.46, 74.29],
        "text": ["FiscalYear: 2012<br>Percent: 71.15<br>Students: 37<br>Race: Non Resident Alien", "FiscalYear: 2013<br>Percent: 81.82<br>Students: 27<br>Race: Non Resident Alien", "FiscalYear: 2014<br>Percent: 88.46<br>Students: 23<br>Race: Non Resident Alien", "FiscalYear: 2015<br>Percent: 74.29<br>Students: 26<br>Race: Non Resident Alien"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(0,176,246,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(0,176,246,1)"
          }
        },
        "name": "Non Resident Alien",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [57.89, 57.38, 52.08, 63.83],
        "text": ["FiscalYear: 2012<br>Percent: 57.89<br>Students: 44<br>Race: Unknown", "FiscalYear: 2013<br>Percent: 57.38<br>Students: 35<br>Race: Unknown", "FiscalYear: 2014<br>Percent: 52.08<br>Students: 25<br>Race: Unknown", "FiscalYear: 2015<br>Percent: 63.83<br>Students: 30<br>Race: Unknown"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(149,144,255,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(149,144,255,1)"
          }
        },
        "name": "Unknown",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      },
      {
        "x": [1, 2, 3, 4],
        "y": [65.4, 63.27, 65.78, 64.03],
        "text": ["FiscalYear: 2012<br>Percent: 65.4<br>Students: 635<br>Race: White", "FiscalYear: 2013<br>Percent: 63.27<br>Students: 577<br>Race: White", "FiscalYear: 2014<br>Percent: 65.78<br>Students: 571<br>Race: White", "FiscalYear: 2015<br>Percent: 64.03<br>Students: 518<br>Race: White"],
        "key": null,
        "type": "scatter",
        "mode": "markers",
        "marker": {
          "autocolorscale": false,
          "color": "rgba(231,107,243,1)",
          "opacity": 1,
          "size": 5.6693,
          "symbol": "circle",
          "line": {
            "width": 1.8898,
            "color": "rgba(231,107,243,1)"
          }
        },
        "name": "White",
        "showlegend": false,
        "xaxis": "x",
        "yaxis": "y",
        "hoverinfo": "text"
      }
    ],
    "layout": {
      "margin": {
        "t": 34.8976,
        "r": 75.5906,
        "b": 51.243,
        "l": 57.6191
      },
      "plot_bgcolor": "rgba(255,255,255,1)",
      "paper_bgcolor": "rgba(255,255,255,1)",
      "font": {
        "color": "rgba(34,34,34,1)",
        "family": "Roboto",
        "size": 15.9402
      },
      "xaxis": {
        "type": "linear",
        "autorange": false,
        "tickmode": "array",
        "range": [0.4, 4.6],
        "ticktext": ["2012", "2013", "2014", "2015"],
        "tickvals": [1, 2, 3, 4],
        "ticks": "",
        "tickcolor": null,
        "ticklen": 3.653,
        "tickwidth": 0,
        "showticklabels": true,
        "tickfont": {
          "color": "rgba(77,77,77,1)",
          "family": "Roboto",
          "size": 12.7522
        },
        "tickangle": -0,
        "showline": false,
        "linecolor": null,
        "linewidth": 0,
        "showgrid": true,
        "domain": [0, 1],
        "gridcolor": "rgba(216,216,216,1)",
        "gridwidth": 0.6642,
        "zeroline": false,
        "anchor": "y",
        "title": "Fiscal year",
        "titlefont": {
          "color": "rgba(34,34,34,1)",
          "family": "Roboto",
          "size": 15.9402
        },
        "hoverformat": ".2f"
      },
      "yaxis": {
        "type": "linear",
        "autorange": false,
        "tickmode": "array",
        "range": [-5, 105],
        "ticktext": ["0", "25", "50", "75", "100"],
        "tickvals": [0, 25, 50, 75, 100],
        "ticks": "",
        "tickcolor": null,
        "ticklen": 3.653,
        "tickwidth": 0,
        "showticklabels": true,
        "tickfont": {
          "color": "rgba(77,77,77,1)",
          "family": "Roboto",
          "size": 12.7522
        },
        "tickangle": -0,
        "showline": false,
        "linecolor": null,
        "linewidth": 0,
        "showgrid": true,
        "domain": [0, 1],
        "gridcolor": "rgba(216,216,216,1)",
        "gridwidth": 0.6642,
        "zeroline": false,
        "anchor": "x",
        "title": "% of students",
        "titlefont": {
          "color": "rgba(34,34,34,1)",
          "family": "Roboto",
          "size": 15.9402
        },
        "hoverformat": ".2f"
      },
      "shapes": [
        {
          "type": "rect",
          "fillcolor": "transparent",
          "line": {
            "color": "rgba(0,0,0,1)",
            "width": 0,
            "linetype": "solid"
          },
          "yref": "paper",
          "xref": "paper",
          "x0": 0,
          "x1": 1,
          "y0": 0,
          "y1": 1
        }
      ],
      "showlegend": true,
      "legend": {
        "bgcolor": "rgba(255,255,255,1)",
        "bordercolor": "transparent",
        "borderwidth": 1.8898,
        "font": {
          "color": "rgba(34,34,34,1)",
          "family": "Roboto",
          "size": 11.9552
        },
        "y": -0.4,
        "orientation": "h"
      },
      "hovermode": "closest"
    }
  }

@@ -568,18 +568,32 @@ function computeLegendDimensions(gd, groups, traces) {
else {
opts.width = 0;
opts.height = 0;
var rowHeight = 0;
var maxTraceHeight = 0;
var startX = 0;
Copy link

@n-riesco n-riesco Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention in Plotly.js is to write this using a single var:

        var rowHeight = 0,
            maxTraceHeight = 0,
            startX = 0;

Copy link

@n-riesco n-riesco Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'd rename startX to offsetX to be consistent with the naming used here.

@psalmody
Copy link
Owner Author

psalmody commented Jul 25, 2016

@n-riesco - Thanks for the comments. See commit d0934f3

@n-riesco
Copy link

@psalmody I can see a problem when I set the width of your example to 500px (one the traces gets truncated).

I'm still trying to understand why this happens.

@psalmody
Copy link
Owner Author

psalmody commented Jul 25, 2016

@n-riesco I think I actually found the problem - it wasn't calculating the margin width based on BOTH the left AND right margins. See e7a286f and now it works with 500px width. (Incidentally, I can't figure out in the Plotly test environment how to set the width of the graph... hacking it with jQuery from the console before plotting. Help?)

@psalmody
Copy link
Owner Author

newplot 1

@n-riesco
Copy link

@psalmody I think e7a286f is a good compromise.

The condition

if((borderwidth + offsetX + traceGap + traceWidth) > (fullLayout.width - (fullLayout.margin.r + fullLayout.margin.l))) {
   // ...
}

limits the width of horizontal legends so that they cannot extend into the margins (unlike vertical legends). I think if reproducing the behaviour of vertical legends is really needed, this could be done in another PR. This PR is already an improvement.


To answer your question about setting width. The easiest way is to set layout.width = 500. Currently, there is a bug/feature that means that the layout dimensions will be honoured only if both layout.width and layout.height are set (this will be fixed in plotly#635 ).

@psalmody
Copy link
Owner Author

@n-riesco Thanks. Assuming this PR is merged and approved, I'll work next on extending into the margins and iterating over all traces to line up horizontal legend items in a column.

Horizontal legend in columns
@psalmody psalmody merged commit 919d8c8 into master Jul 27, 2016
@psalmody psalmody deleted the h-legend-wrap branch July 27, 2016 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants