Skip to content

(JS) Legend text gets cutoff #1195

@Jason94

Description

@Jason94

For longer legend labels, the character at the end gets cutoff slightly:
cutoff-legend

I noticed that padding one of the lines with spaces seems to fix the problem:
fixed-legend

Here is the code that we use to render the plot, with the spaces added (2nd line):

 // Extra space on legend keys is a workaround for plotly cutting off the last character
  const oldBars = bar(getOldData(metrics).reverse(), names, `Submitted before ${cutoff}   `, OldColor);
  const newBars = bar(getNewData(metrics).reverse(), names, `Submitted since ${cutoff}`, NewColor);

const bar = (values, labels, name, color) => ({
  type: 'bar',
  y: labels,
  x: values,
  hoverinfo: 'x',
  orientation: 'h',
  marker: { color },
  name,
});

    <Plot
      data={[newBars, oldBars]}
      layout={{
        autosize: false,
        barmode: 'stack',
        width: 900,
        height: 600,
        margin: { l: 5, r: 0, t: 0, b: 60, pad: 1 },
        xaxis: {
          fixedrange: true,
          showline: false,
          showticklabels: false,
          zeroline: false
        },
        yaxis: {
          fixedrange: true,
          showline: true,
          showgrid: true,
          showticklabels: false,
          zeroline: false
        },
        legend: {
          font: {
            color: 'black',
            family: 'Helvetica',
            size: 16
          },
          traceorder: 'grouped'
        }
      }}
      config={{
        displayModeBar: false,
        scrollZoom: false,
        showAxisDragHandles: false,
        showAxisRangeEntryBoxes: false,
        sendData: false
      }}
      onClick={handleClick}
    />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions