MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _genfrac

Method _genfrac

lib/matplotlib/_mathtext.py:2763–2831  ·  view source on GitHub ↗
(self, ldelim: str, rdelim: str, rule: float | None, style: _MathStyle,
                 num: Hlist, den: Hlist)

Source from the content-addressed store, hash-verified

2761 return [result]
2762
2763 def _genfrac(self, ldelim: str, rdelim: str, rule: float | None, style: _MathStyle,
2764 num: Hlist, den: Hlist) -> T.Any:
2765 state = self.get_state()
2766 thickness = state.get_current_underline_thickness()
2767
2768 axis_height = state.fontset.get_axis_height(
2769 state.font, state.fontsize, state.dpi)
2770 consts = state.fontset.get_font_constants()
2771 x_height = state.fontset.get_xheight(state.font, state.fontsize, state.dpi)
2772
2773 for _ in range(style.value):
2774 x_height *= SHRINK_FACTOR
2775 num.shrink()
2776 den.shrink()
2777 cnum = HCentered([num])
2778 cden = HCentered([den])
2779 width = max(num.width, den.width)
2780 cnum.hpack(width, 'exactly')
2781 cden.hpack(width, 'exactly')
2782
2783 # Align the fraction with a fraction line (node743, node744 and node746).
2784 if rule:
2785 if style is self._MathStyle.DISPLAYSTYLE:
2786 num_shift_up = consts.num1 * x_height
2787 den_shift_down = consts.denom1 * x_height
2788 clr = 3 * rule # The minimum clearance.
2789 else:
2790 num_shift_up = consts.num2 * x_height
2791 den_shift_down = consts.denom2 * x_height
2792 clr = rule # The minimum clearance.
2793 delta = rule / 2
2794 num_clr = max((num_shift_up - cnum.depth) - (axis_height + delta), clr)
2795 den_clr = max((axis_height - delta) - (cden.height - den_shift_down), clr)
2796 vlist = Vlist([cnum, # numerator
2797 Vbox(0, num_clr), # space
2798 Hrule(state, rule), # rule
2799 Vbox(0, den_clr), # space
2800 cden # denominator
2801 ])
2802 vlist.shift_amount = cden.height + den_clr + delta - axis_height
2803
2804 # Align the fraction without a fraction line (node743, node744 and node745).
2805 else:
2806 if style is self._MathStyle.DISPLAYSTYLE:
2807 num_shift_up = consts.num1 * x_height
2808 den_shift_down = consts.denom1 * x_height
2809 min_clr = 7 * thickness # The minimum clearance.
2810 else:
2811 num_shift_up = consts.num3 * x_height
2812 den_shift_down = consts.denom2 * x_height
2813 min_clr = 3 * thickness # The minimum clearance.
2814 def_clr = (num_shift_up - cnum.depth) - (cden.height - den_shift_down)
2815 clr = max(def_clr, min_clr)
2816 vlist = Vlist([cnum, # numerator
2817 Vbox(0, clr), # space
2818 cden # denominator
2819 ])
2820 vlist.shift_amount = den_shift_down

Callers 4

genfracMethod · 0.95
fracMethod · 0.95
dfracMethod · 0.95
binomMethod · 0.95

Calls 14

get_stateMethod · 0.95
_auto_sized_delimiterMethod · 0.95
HCenteredClass · 0.85
VlistClass · 0.85
VboxClass · 0.85
HruleClass · 0.85
HlistClass · 0.85
HboxClass · 0.85
hpackMethod · 0.80
get_axis_heightMethod · 0.45
get_font_constantsMethod · 0.45

Tested by

no test coverage detected