How to use the leather.Linear function in leather

To help you get started, we’ve selected a few leather examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireservice / leather / tests / test_scales.py View on Github external
def test_no_spread(self):
        scale = leather.Linear(0, 0)

        self.assertEqual(scale.project(0, 0, 10), 0)
        self.assertEqual(scale.project(1, 0, 10), 10)
github wireservice / leather / tests / test_scales.py View on Github external
def test_project(self):
        scale = leather.Linear(0, 10)

        self.assertEqual(scale.project(2, 0, 20), 4)
        self.assertEqual(scale.project(10, 0, 40), 40)
        self.assertEqual(scale.project(5, 10, 40), 25)
        self.assertEqual(scale.project(5, 10, 41), 25.5)

        scale = leather.Linear(10, 40)

        self.assertEqual(scale.project(25, 0, 10), 5)
        self.assertEqual(scale.project(4, 0, 20), -4)

        scale = leather.Linear(-10, 10)

        self.assertEqual(scale.project(0, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), -5)

        scale = leather.Linear(-20, -10)

        self.assertEqual(scale.project(-15, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), 10)

        with self.assertRaises(ValueError):
            leather.Linear(10, 0)
github wireservice / leather / tests / test_chart.py View on Github external
def test_set_scales(self):
        chart = leather.Chart()
        chart.set_x_scale(leather.Linear(0, 20))
        chart.set_y_scale(leather.Linear(0, 20))
        chart.add_dots(self.data1)

        svg = self.render_chart(chart)

        self.assertTickLabels(svg, 'left', ['5', '10', '15', '20', '0'])
        self.assertTickLabels(svg, 'bottom', ['5', '10', '15', '20', '0'])
github wireservice / leather / tests / test_chart.py View on Github external
def test_set_scales(self):
        chart = leather.Chart()
        chart.set_x_scale(leather.Linear(0, 20))
        chart.set_y_scale(leather.Linear(0, 20))
        chart.add_dots(self.data1)

        svg = self.render_chart(chart)

        self.assertTickLabels(svg, 'left', ['5', '10', '15', '20', '0'])
        self.assertTickLabels(svg, 'bottom', ['5', '10', '15', '20', '0'])
github wireservice / leather / tests / test_shapes.py View on Github external
def setUp(self):
        self.shape = leather.Dots('red')
        self.linear = leather.Linear(0, 10)
        self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
        self.palette = (color for color in ['red', 'white', 'blue'])
github wireservice / leather / tests / test_shapes.py View on Github external
def setUp(self):
        self.shape = leather.Bars('red')
        self.linear = leather.Linear(0, 10)
        self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
        self.palette = (color for color in ['red', 'white', 'blue'])
github wireservice / leather / tests / test_scales.py View on Github external
def test_decimal(self):
        scale = leather.Linear(Decimal(0), Decimal(10))

        self.assertEqual(scale.project(Decimal(2), Decimal(0), Decimal(20)), Decimal(4))
        self.assertEqual(scale.project(Decimal(10), Decimal(0), Decimal(40)), Decimal(40))
        self.assertEqual(scale.project(Decimal(5), Decimal(10), Decimal(40)), Decimal(25))
        self.assertEqual(scale.project(Decimal(5), Decimal(10), Decimal(41)), Decimal(25.5))

        self.assertEqual(scale.ticks()[1], Decimal(2.5))
github wireservice / leather / tests / test_scales.py View on Github external
self.assertEqual(scale.project(2, 0, 20), 4)
        self.assertEqual(scale.project(10, 0, 40), 40)
        self.assertEqual(scale.project(5, 10, 40), 25)
        self.assertEqual(scale.project(5, 10, 41), 25.5)

        scale = leather.Linear(10, 40)

        self.assertEqual(scale.project(25, 0, 10), 5)
        self.assertEqual(scale.project(4, 0, 20), -4)

        scale = leather.Linear(-10, 10)

        self.assertEqual(scale.project(0, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), -5)

        scale = leather.Linear(-20, -10)

        self.assertEqual(scale.project(-15, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), 10)

        with self.assertRaises(ValueError):
            leather.Linear(10, 0)
github wireservice / leather / tests / test_scales.py View on Github external
def test_contains(self):
        scale = leather.Linear(-5, 5)

        self.assertTrue(scale.contains(-5))
        self.assertTrue(scale.contains(0))
        self.assertTrue(scale.contains(5))
        self.assertFalse(scale.contains(-6))
        self.assertFalse(scale.contains(6))
github wireservice / leather / tests / test_scales.py View on Github external
self.assertEqual(scale.project(25, 0, 10), 5)
        self.assertEqual(scale.project(4, 0, 20), -4)

        scale = leather.Linear(-10, 10)

        self.assertEqual(scale.project(0, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), -5)

        scale = leather.Linear(-20, -10)

        self.assertEqual(scale.project(-15, 0, 10), 5)
        self.assertEqual(scale.project(-10, -5, 10), 10)

        with self.assertRaises(ValueError):
            leather.Linear(10, 0)