Skip to content

Small Improvements for LegendItem#64

Closed
CPrescher wants to merge 1 commit intopyqtgraph:developfrom
CPrescher:develop
Closed

Small Improvements for LegendItem#64
CPrescher wants to merge 1 commit intopyqtgraph:developfrom
CPrescher:develop

Conversation

@CPrescher
Copy link
Copy Markdown

Added 3 new parameters LegendItem:
horSpacing: Specifies the spacing between the line symbol and the label.
verSpacing: Specifies the spacing between individual entries of the
legend vertically. (Can also be negative to have them really close)
box: Specifies if the Legend should will be drawn with a rectangle
around it.

This made it possible to change the resize behavior by just using
layout.setVerticalSpacing and layout.setVerticalSpacing.

Changed the removeItem function to accept either name or the originally
added Item. I found the latter more useful, especially if several items
happen to have the same name.

Changed the rows in which addItem inserts a new item. Now the number
increases all the time. This was needed because there where some
overwriting issues (it did want to write in a row were already an item was existent, in the previous version) when using several times removeItem and addItem on
the same legend (in random order). The GraphicsGridLayout does not care
about empty rows. I found this approach to work best.

Added 3 new parameters LegendItem:
horSpacing: Specifies the spacing between the line symbol and the label.
verSpacing: Specifies the spacing between individual entries of the
legend vertically. (Can also be negative to have them really close)
box: Specifies if the Legend should will be drawn with a rectangle
around it.

This made it possible to change the resize behavior by just using
layout.setVerticalSpacing and layout.setVerticalSpacing.

Changed the removeItem function to accept either name or the originally
added Item. I found the latter more useful, especially if several items
happen to have the same name.

Changed the rows in which addItem inserts a new item. Now the number
increases all the time. This was needed because there where some
overwriting issues when using several times removeItem and addItem on
the same legend (in random order). The GraphicsGridLayout does not care
about empty rows, so this seems to work best.
@rkoyama1623-2021
Copy link
Copy Markdown

rkoyama1623-2021 commented Mar 14, 2017

Hello, I'm a master student in Japan.
I want this PR to be merged, too.
Could you rebase devel branch? @CPrescher

In this PR, LegendItem.items is renamed to LegendItem.legenditems,
but I don't think this renaming is good decision in terms of backward compatibility.

Also, I think the options used in LegendItem.__init__ should be given in PlotItem.addLegend's keyword arguments.

Regards,

samschott pushed a commit to samschott/pyqtgraph that referenced this pull request Jun 18, 2019
@samschott
Copy link
Copy Markdown
Contributor

I just had a look at this and really like the new parameters horSpacing and verSpacing and the simpler control of the legend size that comes with them. A few points:

  • Why is it necessary to keep track of the number of rows in numItems? As far as I understand, adding new items to the row number returned by layout.rowCount() works just as well (see Qt docs here). Or is there any case where not numItems == layout.rowCount()?
  • Why do we need to track plotItems separately? You can always access them through sample.item.
  • The current implementation of removeItem already accepts both the actual plot item and its name. No need for changes (which only complicate things). Or am I missing something?

Finally, I would suggest new parameters brush and pen for the background and border of the legend, respectively, instead of the boolean parameter box. They can be set to None by default, resulting in no box being drawn. This seems to be more in line with the coding style of pyqtgraph but may be less intuitive.

What do you think? I have incorporated in some of this PR here. If there is sufficient interest, I can submit a new pull request from that branch.

@samschott samschott mentioned this pull request Jun 24, 2019
samschott pushed a commit to OE-FET/cx-pyqtgraph that referenced this pull request Sep 16, 2019
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 20, 2019

@CPrescher thanks for this PR, sorry it's taken us so long to properly follow up. I'm going to close this as #958 took components of this PR and added more on top of it, but still wanted to thank you for your contribution!

@j9ac9k j9ac9k closed this Nov 20, 2019
campagnola added a commit to acq4/pyqtgraph that referenced this pull request May 1, 2020
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.

4 participants