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

[ENH] Pythagorean tree: Make border scale invariant #2141

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Orange/widgets/visualize/pythagorastreeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from collections import namedtuple, defaultdict, deque
from math import pi, sqrt, cos, sin, degrees

from AnyQt.QtCore import Qt, QPointF, QTimer, QRectF, QSizeF
from AnyQt.QtGui import QColor, QBrush, QPen
from AnyQt.QtWidgets import (
QSizePolicy, QGraphicsItem, QGraphicsRectItem, QGraphicsWidget, QStyle
)
from AnyQt.QtGui import QColor, QBrush, QPen
from AnyQt.QtCore import Qt, QPointF, QTimer, QRectF, QSizeF

from Orange.widgets.visualize.utils.tree.treeadapter import TreeAdapter

Expand Down Expand Up @@ -245,9 +245,7 @@ def clear_tree(self):

def _calculate_tree(self, tree_adapter, weight_adjustment):
"""Actually calculate the tree squares"""
tree_builder = PythagorasTree(
weight_adjustment=weight_adjustment
)
tree_builder = PythagorasTree(weight_adjustment=weight_adjustment)
return tree_builder.pythagoras_tree(
tree_adapter, tree_adapter.root, Square(Point(0, 0), 200, -pi / 2)
)
Expand Down Expand Up @@ -367,8 +365,6 @@ class SquareGraphicsItem(QGraphicsRectItem):
The tree node the square represents.
brush : QColor, optional
The brush to be used as the backgound brush.
pen : QPen, optional
The pen to be used for the border.

"""

Expand All @@ -386,7 +382,11 @@ def __init__(self, tree_node, parent=None, **kwargs):
self.setRotation(degrees(angle))

self.setBrush(kwargs.get('brush', QColor('#297A1F')))
self.setPen(kwargs.get('pen', QPen(QColor('#000'))))
# The border should be invariant to scaling
pen = QPen(QColor(Qt.black))
pen.setWidthF(0.75)
pen.setCosmetic(True)
self.setPen(pen)

self.setAcceptHoverEvents(True)
self.setZValue(kwargs.get('zvalue', 0))
Expand Down Expand Up @@ -544,10 +544,11 @@ def paint(self, painter, option, widget=None):
super().paint(painter, option, widget)
painter.save()
pen = QPen(QColor(Qt.black))
pen.setWidth(4)
pen.setWidthF(2)
pen.setCosmetic(True)
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.drawRect(rect.adjusted(2, 2, -2, -2))
painter.drawRect(rect)
painter.restore()
else:
super().paint(painter, option, widget)
Expand Down