Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plotter/view/puzzletree/nodes/absolutevalue.py
blob: db569f57a5be5763a95920640e23db555e4b084a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

from .simplenode import SimpleNode
from gettext import gettext as _


class AbsoluteValue(SimpleNode):
    """Node representing the absolute value function: f(x) = abs(x)."""

    CLASS = "absolutevalue"
    background = SimpleNode.loadbackground("absolutevalue.svg")
    title = _("Absolute Value")
    description = _(u"Returns the distance a value is from zero.\n"
        u"For example, f(-3) = 3 and f(3) = 3.")

    def __call__(self, x):
        """Calls the absolute value function."""
        return abs(x)


    def get_equation_string(self, variable):
        """Returns abs(x) given variable, x."""
        return "abs(%s)" % variable