Skip to content

Commit

Permalink
Display percentage on pov pie chart as a tooltip, closes #1435
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Oct 15, 2024
1 parent 2560686 commit 2aebc6b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/python/plotlyst/view/report/scene.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional, Dict

from PyQt6.QtCharts import QPieSeries
from PyQt6.QtCharts import QPieSeries, QPieSlice
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QCursor
from PyQt6.QtWidgets import QToolTip
from overrides import overrides

from plotlyst.core.domain import Novel, Character
Expand Down Expand Up @@ -65,14 +67,18 @@ def refresh(self, novel: Novel):

series = QPieSeries()
series.setHoleSize(0.45)
series.hovered.connect(self._hovered)
for k, v in self.pov_number.items():
if v:
slice = series.append(k.name, v)
slice.setLabel(icon_to_html_img(avatars.avatar(k)))
slice.setLabelVisible()

for slice in series.slices():
slice.setLabel(slice.label() + " {:.1f}%".format(100 * slice.percentage()))

self.removeAllSeries()
self.addSeries(series)

def _hovered(self, slice: QPieSlice, state: bool):
if state:
QToolTip.showText(QCursor.pos(), slice.label() + " {:.1f}%".format(100 * slice.percentage()))
else:
QToolTip.hideText()

0 comments on commit 2aebc6b

Please sign in to comment.