Commit 5ca25d9c authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Changed ratio from explicit to unexplicit optional argument to allow

the user to overwrite an Axes Class without ratio argument.

Changed the name of computeSmartRect to computeFitRect to be more explicit
and moved it into mytool/myTool.py loaded in __init__
parent 65e6a085
......@@ -97,7 +97,7 @@ from .mytool import window_exists, getCurrentWindowIDs
from .mytool import print2file, print2screen, printListCurrentWindows
from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .mytool import closeWindow, closeAllWindows
from .mytool import FigOneAxes
from .mytool import FigOneAxes, computeFitRect
from .test import myTest
......
......@@ -46,62 +46,23 @@
# IMPORT ---------------------------------------------------------------
from . import SEVR, DBUG
from . import Axes
from .mytool import computeFitRect
from . import rcParams
# COMPUTE SMART FRAME -----------------------------------------------
def computeSmartRect(fig, ratio, frameRect):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
figWidth = fig.get_figwidth()
figHeight = fig.get_figheight()
figDpi = fig.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
# the largest width and height allowed in inches
maxWidth = figWidth * frameWidth - 8. * (figDpi / 75.) * fontsize
maxHeight = figHeight * frameHeight - 4. * (figDpi / 75.) * fontsize
# the hypothetical width and height in inches
# for a given aspect ratio
hypoWidth = maxHeight / ratio
hypoHeight = maxWidth * ratio
# if the hypothetical width is larger that the
# maximum allowed width (in inches) then chose
# the hypothetical Height
if (hypoWidth > maxWidth):
height = hypoHeight / figHeight # height in percent
width = maxWidth / figWidth # width in percent
posX = framePosX + 4. * (figDpi / 75.) * fontsize / figWidth # posX
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight # posY
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
rect = [posX, posY, width, height]
return(rect)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, frameRect, ratio=None, *args, **kwargs):
def __init__(self, fig, frameRect, *args, **kwargs):
self.fig = fig
self.declareKeywords()
rect = self.computeRect(frameRect, ratio=ratio, *args, **kwargs)
rect = self.computeRect(frameRect, *args, **kwargs)
# clean kwargs
kwargs.pop('ratio', None)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
kwargs.pop('fitInFrame', None)
......@@ -113,9 +74,10 @@ class MyAxes(Axes):
self.name = 'default'
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, frameRect, ratio=None, *args, **kwargs):
def computeRect(self, frameRect, *args, **kwargs):
# Get the optional keyword
ratio = kwargs.pop('ratio', None)
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
fitInFrame = kwargs.pop('fitInFrame', None)
......@@ -143,7 +105,7 @@ class MyAxes(Axes):
if ratio is None:
ratio = rect[3]/rect[2]
rect = computeSmartRect(self, ratio, rect)
rect = computeFitRect(self, ratio, rect)
return(rect)
......
......@@ -11,6 +11,7 @@ from .myTool import giveDataToWindow
from .myTool import drawFigOnWindow
from .myTool import closeAllWindows
from .myTool import closeWindow
from .myTool import computeFitRect
from .figOneAxes import FigOneAxes
from .axPlot2D import AxPlot2D
......
......@@ -371,3 +371,44 @@ def print2file(ClassName, inputArg, filename, *args, **kwargs):
# end
return(True)
# COMPUTE SMART FRAME -----------------------------------------------
def computeFitRect(fig, ratio, frameRect):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
figWidth = fig.get_figwidth()
figHeight = fig.get_figheight()
figDpi = fig.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
# the largest width and height allowed in inches
maxWidth = figWidth * frameWidth - 8. * (figDpi / 75.) * fontsize
maxHeight = figHeight * frameHeight - 4. * (figDpi / 75.) * fontsize
# the hypothetical width and height in inches
# for a given aspect ratio
hypoWidth = maxHeight / ratio
hypoHeight = maxWidth * ratio
# if the hypothetical width is larger that the
# maximum allowed width (in inches) then chose
# the hypothetical Height
if (hypoWidth > maxWidth):
height = hypoHeight / figHeight # height in percent
width = maxWidth / figWidth # width in percent
posX = framePosX + 4. * (figDpi / 75.) * fontsize / figWidth # posX
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight # posY
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
rect = [posX, posY, width, height]
return(rect)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment