def test_nice_2(self):
        # has no effect on degenerate domains
        x = LinearScale().domain([0, 0]).nice()
        self.assertEqual(x.domain(), [0, 0])

        x = LinearScale().domain([0.5, 0.5]).nice()
        self.assertEqual(x.domain(), [0.5, 0.5])
Beispiel #2
0
    def test_clamp_2(self):
        # can clamp to domain
        x = LinearScale().clamp(True)
        self.assertAlmostEqual(x(-0.5), 0)
        self.assertAlmostEqual(x(0.5), 0.5)
        self.assertAlmostEqual(x(1.5), 1)

        x = LinearScale().domain([1, 0]).clamp(True)
        self.assertAlmostEqual(x(-0.5), 1)
        self.assertAlmostEqual(x(0.5), 0.5)
        self.assertAlmostEqual(x(1.5), 0)
 def test_copy_3(self):
     # changes to clamping are isolated
     x = LinearScale().clamp(True)
     y = x.copy()
     x.clamp(False)
     self.assertEqual(x(2), 2)
     self.assertEqual(y(2), 1)
     self.assertTrue(y.clamp())
     y.clamp(False)
     self.assertEqual(x(2), 2)
     self.assertEqual(y(2), 2)
     self.assertFalse(x.clamp())
 def test_copy_1(self):
     # changes to the domain are isolated
     x = LinearScale()
     y = x.copy()
     x.domain([1, 2])
     self.assertEqual(y.domain(), [0, 1])
     self.assertEqual(x(1), 0)
     self.assertEqual(y(1), 1)
     y.domain([2, 3])
     self.assertEqual(x(2), 1)
     self.assertEqual(y(2), 0)
     self.assertEqual(x.domain(), [1, 2])
     self.assertEqual(y.domain(), [2, 3])
Beispiel #5
0
    def test_nice_3(self):
        # accepts a tick count to control nicing step
        x = LinearScale().domain([12, 87]).nice(5)
        self.assertEqual(x.domain(), [0, 100])

        x = LinearScale().domain([12, 87]).nice(10)
        self.assertEqual(x.domain(), [10, 90])

        x = LinearScale().domain([12, 87]).nice(100)
        self.assertEqual(x.domain(), [12, 87])
Beispiel #6
0
 def test_map(self):
     # maps a number to a number
     x = LinearScale().domain([1, 2])
     self.assertAlmostEqual(x(0.5), -0.5)
     self.assertAlmostEqual(x(1), 0)
     self.assertAlmostEqual(x(1.5), 0.5)
     self.assertAlmostEqual(x(2), 1)
     self.assertAlmostEqual(x(2.5), 1.5)
Beispiel #7
0
    def test_clamp_3(self):
        # can clamp to the range
        x = LinearScale().clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 0)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 1)

        x = LinearScale().range([1, 0]).clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 1)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 0)
Beispiel #8
0
 def test_invert_1(self):
     # maps a number to a number
     x = LinearScale().range([1, 2])
     self.assertAlmostEqual(x.invert(0.5), -0.5)
     self.assertAlmostEqual(x.invert(1), 0)
     self.assertAlmostEqual(x.invert(1.5), 0.5)
     self.assertAlmostEqual(x.invert(2), 1)
     self.assertAlmostEqual(x.invert(2.5), 1.5)
Beispiel #9
0
 def test_copy_2(self):
     # change to the range are isolated
     x = LinearScale()
     y = x.copy()
     x.range([1, 2])
     self.assertEqual(x.invert(1), 0)
     self.assertEqual(y.invert(1), 1)
     self.assertEqual(y.range(), [0, 1])
     y.range([2, 3])
     self.assertEqual(x.invert(2), 1)
     self.assertEqual(y.invert(2), 0)
     self.assertEqual(x.range(), [1, 2])
     self.assertEqual(y.range(), [2, 3])
Beispiel #10
0
    def test_nice_2(self):
        # has no effect on degenerate domains
        x = LinearScale().domain([0, 0]).nice()
        self.assertEqual(x.domain(), [0, 0])

        x = LinearScale().domain([0.5, 0.5]).nice()
        self.assertEqual(x.domain(), [0.5, 0.5])
Beispiel #11
0
    def test_ticks_2(self):
        # generates tixcks of varying degree
        x = LinearScale([1, 0])
        exp = [0, 1]
        res = [float(y) for y in list(map(x.tickFormat(1), x.ticks(1)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.5, 1]
        res = [float(y) for y in list(map(x.tickFormat(2), x.ticks(2)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.2, 0.4, 0.6, 0.8, 1]
        res = [float(y) for y in list(map(x.tickFormat(5), x.ticks(5)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
        res = [float(y) for y in list(map(x.tickFormat(10), x.ticks(10)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)
 def test_invert_1(self):
     # maps a number to a number
     x = LinearScale().range([1, 2])
     self.assertAlmostEqual(x.invert(0.5), -0.5)
     self.assertAlmostEqual(x.invert(1), 0)
     self.assertAlmostEqual(x.invert(1.5), 0.5)
     self.assertAlmostEqual(x.invert(2), 1)
     self.assertAlmostEqual(x.invert(2.5), 1.5)
 def test_copy_2(self):
     # change to the range are isolated
     x = LinearScale()
     y = x.copy()
     x.range([1, 2])
     self.assertEqual(x.invert(1), 0)
     self.assertEqual(y.invert(1), 1)
     self.assertEqual(y.range(), [0, 1])
     y.range([2, 3])
     self.assertEqual(x.invert(2), 1)
     self.assertEqual(y.invert(2), 0)
     self.assertEqual(x.range(), [1, 2])
     self.assertEqual(y.range(), [2, 3])
    def test_nice_3(self):
        # accepts a tick count to control nicing step
        x = LinearScale().domain([12, 87]).nice(5)
        self.assertEqual(x.domain(), [0, 100])

        x = LinearScale().domain([12, 87]).nice(10)
        self.assertEqual(x.domain(), [10, 90])

        x = LinearScale().domain([12, 87]).nice(100)
        self.assertEqual(x.domain(), [12, 87])
    def test_ticks_2(self):
        # generates tixcks of varying degree
        x = LinearScale([1, 0])
        exp = [0, 1]
        res = [float(y) for y in list(map(x.tickFormat(1), x.ticks(1)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.5, 1]
        res = [float(y) for y in list(map(x.tickFormat(2), x.ticks(2)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.2, 0.4, 0.6, 0.8, 1]
        res = [float(y) for y in list(map(x.tickFormat(5), x.ticks(5)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)

        exp = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
        res = [float(y) for y in list(map(x.tickFormat(10), x.ticks(10)))]
        for i, j in zip(res, exp):
            self.assertEqual(i, j)
    def test_clamp_3(self):
        # can clamp to the range
        x = LinearScale().clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 0)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 1)

        x = LinearScale().range([1, 0]).clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 1)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 0)
Beispiel #17
0
 def test_copy_3(self):
     # changes to clamping are isolated
     x = LinearScale().clamp(True)
     y = x.copy()
     x.clamp(False)
     self.assertEqual(x(2), 2)
     self.assertEqual(y(2), 1)
     self.assertTrue(y.clamp())
     y.clamp(False)
     self.assertEqual(x(2), 2)
     self.assertEqual(y(2), 2)
     self.assertFalse(x.clamp())
Beispiel #18
0
 def test_copy_1(self):
     # changes to the domain are isolated
     x = LinearScale()
     y = x.copy()
     x.domain([1, 2])
     self.assertEqual(y.domain(), [0, 1])
     self.assertEqual(x(1), 0)
     self.assertEqual(y(1), 1)
     y.domain([2, 3])
     self.assertEqual(x(2), 1)
     self.assertEqual(y(2), 0)
     self.assertEqual(x.domain(), [1, 2])
     self.assertEqual(y.domain(), [2, 3])
Beispiel #19
0
def main():
    items = [
            {'time': 1, 'width': 50},
            {'time': 2, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 304, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 804, 'width': 50},
            {'time': 804, 'width': 70},
            {'time': 804, 'width': 50},
            {'time': 804, 'width': 50},
            {'time': 854, 'width': 50},
            {'time': 854, 'width': 50}]

    options = {
        'initialWidth': 1000,
        'initialHeight': 112,
        'scale': LinearScale(),
        'direction': 'up',
        'dotColor': '#000000',
        'labelBgColor': COLOR_10,
        'linkColor': COLOR_10,
        'labelPadding': {'left': 0, 'right': 0, 'top': 0, 'bottom': 0},
        'labella': {
            'minPos': 0,
            'maxPos': 960,
            'nodeHeight': 12
            },
        'showTicks': False
        }

    tl = TimelineSVG(items, options=options)
    tl.export('timeline_up.svg')

    tl = TimelineTex(items, options=options)
    tl.export('timeline_up.tex', build_pdf=True)
Beispiel #20
0
def main():
    data = [
        {"time": 1, "name": "Müller", "team": "GER"},
        {"time": 23, "name": "Klose", "team": "GER"},
        {"time": 24, "name": "Kroos", "team": "GER"},
        {"time": 26, "name": "Kroos", "team": "GER"},
        {"time": 29, "name": "Khedira", "team": "GER"},
        {"time": 69, "name": "Schürrle", "team": "GER"},
        {"time": 79, "name": "Schürrle", "team": "GER"},
        {"time": 90, "name": "Oscar", "team": "BRA"},
    ]

    options = {
        "direction": "up",
        "initialWidth": 804,
        "initialHeight": 120,
        "scale": LinearScale(),
        "domain": [0, 90],
        "margin": {"left": 20, "right": 20, "top": 30, "bottom": 20},
        "textFn": lambda d: d["name"],
        "layerGap": 40,
        "dotColor": color5,
        "labelBgColor": color5,
        "linkColor": color5,
        "labella": {
            "maxPos": 764,
            "algorithm": "simple",
        },
        "labelPadding": {"left": 0, "right": 2, "top": 0, "bottom": 0},
        "latex": {"reproducible": True},
    }

    tl = TimelineSVG(data, options=options)
    tl.export("timeline_kit_5.svg")

    tl = TimelineTex(data, options=options)
    tl.export("timeline_kit_5.tex")
 def test_domain_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.domain(), [0, 1])
     self.assertAlmostEqual(x(0.5), 0.5)
Beispiel #22
0
 def test_clamp_1(self):
     # defaults to false
     x = LinearScale()
     self.assertFalse(x.clamp())
     self.assertAlmostEqual(x(-0.5), -0.5)
     self.assertAlmostEqual(x(1.5), 1.5)
Beispiel #23
0
    def test_nice_1(self):
        # nices the domain, extending it to round numbers
        x = LinearScale().domain([1.1, 10.9]).nice()
        self.assertEqual(x.domain(), [1, 11])

        x = LinearScale().domain([10.9, 1.1]).nice()
        self.assertEqual(x.domain(), [11, 1])

        x = LinearScale().domain([0.7, 11.001]).nice()
        self.assertEqual(x.domain(), [0, 12])

        x = LinearScale().domain([123.1, 6.7]).nice()
        self.assertEqual(x.domain(), [130, 0])

        x = LinearScale().domain([0, 0.49]).nice()
        self.assertEqual(x.domain(), [0, 0.5])

        x = LinearScale().domain([-0.1, 51.1]).nice(8)
        self.assertEqual(x.domain(), [-10, 60])
Beispiel #24
0
 def test_domain_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.domain(), [0, 1])
     self.assertAlmostEqual(x(0.5), 0.5)
Beispiel #25
0
# werkervaring.py
import pandas as pd
from labella.scale import LinearScale
from labella.timeline import TimelineTex


def makeInput(_df):
    length = len(_df.year_start)
    out = []
    print(_df)
    for i in range(length):
        _dict = {}
        _dict['time'] = _df.year_start[i]
        #dict['year_end'] = _df.year_end[i]
        _dict['text'] = _df.employer[i]
        #dict['job_title'] = _df.job_title[i]
        out = out + [_dict]
    return out


header_list = ['year_start', 'year_end', 'employer', 'job_title']
df = pd.read_csv('werkervaring.csv', names=header_list)
xtimeline = makeInput(df)
ttimeline = TimelineTex(xtimeline, options={'scale': LinearScale()})

ttimeline.export('werkervaring.tex')
 def test_clamp_1(self):
     # defaults to false
     x = LinearScale()
     self.assertFalse(x.clamp())
     self.assertAlmostEqual(x(-0.5), -0.5)
     self.assertAlmostEqual(x(1.5), 1.5)
Beispiel #27
0
 def test_range_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.range(), [0, 1])
     self.assertAlmostEqual(x.invert(0.5), 0.5)
    def test_nice_1(self):
        # nices the domain, extending it to round numbers
        x = LinearScale().domain([1.1, 10.9]).nice()
        self.assertEqual(x.domain(), [1, 11])

        x = LinearScale().domain([10.9, 1.1]).nice()
        self.assertEqual(x.domain(), [11, 1])

        x = LinearScale().domain([0.7, 11.001]).nice()
        self.assertEqual(x.domain(), [0, 12])

        x = LinearScale().domain([123.1, 6.7]).nice()
        self.assertEqual(x.domain(), [130, 0])

        x = LinearScale().domain([0, 0.49]).nice()
        self.assertEqual(x.domain(), [0, 0.5])

        x = LinearScale().domain([-0.1, 51.1]).nice(8)
        self.assertEqual(x.domain(), [-10, 60])
Beispiel #29
0
def main():
    data = [
        {
            'time': 1,
            'name': 'Müller',
            'team': 'GER'
        },
        {
            'time': 23,
            'name': 'Klose',
            'team': 'GER'
        },
        {
            'time': 24,
            'name': 'Kroos',
            'team': 'GER'
        },
        {
            'time': 26,
            'name': 'Kroos',
            'team': 'GER'
        },
        {
            'time': 29,
            'name': 'Khedira',
            'team': 'GER'
        },
        {
            'time': 69,
            'name': 'Schürrle',
            'team': 'GER'
        },
        {
            'time': 79,
            'name': 'Schürrle',
            'team': 'GER'
        },
        {
            'time': 90,
            'name': 'Oscar',
            'team': 'BRA'
        },
    ]

    options = {
        'direction': 'up',
        'initialWidth': 804,
        'initialHeight': 120,
        'scale': LinearScale(),
        'domain': [0, 90],
        'margin': {
            'left': 20,
            'right': 20,
            'top': 30,
            'bottom': 20
        },
        'textFn': lambda d: d['name'],
        'layerGap': 40,
        'dotColor': color5,
        'labelBgColor': color5,
        'linkColor': color5,
        'labella': {
            'maxPos': 764,
            'algorithm': 'simple',
        },
        'labelPadding': {
            'left': 0,
            'right': 2,
            'top': 0,
            'bottom': 0
        },
    }

    tl = TimelineSVG(data, options=options)
    tl.export('timeline_kit_5.svg')

    tl = TimelineTex(data, options=options)
    tl.export('timeline_kit_5.tex')
    def test_ticks_3(self):
        # formats ticks with the appropriate precision
        x = LinearScale([0.123456789, 1.23456789])
        res = list(map(x.tickFormat(1), x.ticks(1)))[0]
        self.assertEqual(res, "1")

        res = list(map(x.tickFormat(2), x.ticks(2)))[0]
        self.assertEqual(res, "0.5")

        res = list(map(x.tickFormat(4), x.ticks(4)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(8), x.ticks(8)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(16), x.ticks(16)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(32), x.ticks(32)))[0]
        self.assertEqual(res, "0.15")

        res = list(map(x.tickFormat(64), x.ticks(64)))[0]
        self.assertEqual(res, "0.14")

        res = list(map(x.tickFormat(128), x.ticks(128)))[0]
        self.assertEqual(res, "0.13")

        res = list(map(x.tickFormat(256), x.ticks(256)))[0]
        self.assertEqual(res, "0.125")
Beispiel #31
0
def make_rank_plot(
    results,
    output_file,
    keep_methods=None,
    higher_better=True,
    return_ranks=False,
):
    methods = keep_methods[:]
    avg_ranks, all_ranks = compute_ranks(results,
                                         keep_methods=keep_methods,
                                         higher_better=higher_better)
    plot_data = [{
        "time": rank,
        "text": method_name(method)
    } for method, rank in avg_ranks.items()]

    color = "#000"

    options = {
        "scale": LinearScale(),
        "direction": "up",
        "domain": [1, len(methods)],
        "layerGap": 20,
        "borderColor": "#000",
        "showBorder": False,
        "labelBgColor": "#fff",
        "linkColor": color,
        "labelTextColor": color,
        "dotColor": color,
        "initialWidth": 600,
        "initialHeight": 75,
        "latex": {
            "linkThickness": "thin",
            "reproducible": True
        },
        "dotRadius": 2,
        "margin": {
            "left": 0,
            "bottom": 0,
            "right": 0,
            "top": 0
        },
    }

    tl = TimelineTex(plot_data, options=options)
    texlines = tl.export()

    n_datasets = len(all_ranks)

    ref_method, CD, _ = reference_difference(avg_ranks, n_datasets)

    # we're going to insert the critical difference line after the dots
    # scope,·so we first have to figure out where that is.
    lines = texlines.split("\n")
    idx = None
    find_scope = False
    for i, line in enumerate(lines):
        if line.strip() == "% dots":
            find_scope = True
        if find_scope and "\\end{scope}" in line:
            idx = i + 1
            break

    before = lines[:idx]
    after = lines[idx:]

    nodes, _ = tl.compute()
    bestnode = next(
        (n for n in nodes if n.data.text == method_name(ref_method)), None)
    # idealPos is the position on the axis
    posBest = bestnode.getRoot().idealPos
    posCD = tl.options["scale"](bestnode.data.time + CD)

    CDlines = [
        "% Critical difference",
        "\\def\\posBest{%.16f}" % posBest,
        "\\def\\posCD{%.16f}" % posCD,
        "\\begin{scope}",
        "\\draw (\\posBest, 30) -- (\\posBest, 20);",
        "\\draw (\\posBest, 25) --node[below] {CD} (\\posCD, 25);",
        "\\draw (\\posCD, 30) -- (\\posCD, 20);",
        "\\end{scope}",
    ]

    all_lines = before + [""] + CDlines + after

    with open(output_file, "w") as fp:
        fp.write("\n".join(all_lines))
 def test_range_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.range(), [0, 1])
     self.assertAlmostEqual(x.invert(0.5), 0.5)
Beispiel #33
0
def main():
    items = [
        {
            "time": 1,
            "width": 50
        },
        {
            "time": 2,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 304,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 804,
            "width": 70
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 854,
            "width": 50
        },
        {
            "time": 854,
            "width": 50
        },
    ]

    options = {
        "initialWidth": 1000,
        "initialHeight": 112,
        "scale": LinearScale(),
        "direction": "up",
        "dotColor": "#000000",
        "labelBgColor": COLOR_10,
        "linkColor": COLOR_10,
        "labelPadding": {
            "left": 0,
            "right": 0,
            "top": 0,
            "bottom": 0
        },
        "labella": {
            "minPos": 0,
            "maxPos": 960,
            "nodeHeight": 12
        },
        "showTicks": False,
        "latex": {
            "reproducible": True
        },
    }

    tl = TimelineSVG(items, options=options)
    tl.export("timeline_up.svg")

    tl = TimelineTex(items, options=options)
    tl.export("timeline_up.tex", build_pdf=True)
Beispiel #34
0
    def test_ticks_3(self):
        # formats ticks with the appropriate precision
        x = LinearScale([0.123456789, 1.23456789])
        res = list(map(x.tickFormat(1), x.ticks(1)))[0]
        self.assertEqual(res, "1")

        res = list(map(x.tickFormat(2), x.ticks(2)))[0]
        self.assertEqual(res, "0.5")

        res = list(map(x.tickFormat(4), x.ticks(4)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(8), x.ticks(8)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(16), x.ticks(16)))[0]
        self.assertEqual(res, "0.2")

        res = list(map(x.tickFormat(32), x.ticks(32)))[0]
        self.assertEqual(res, "0.15")

        res = list(map(x.tickFormat(64), x.ticks(64)))[0]
        self.assertEqual(res, "0.14")

        res = list(map(x.tickFormat(128), x.ticks(128)))[0]
        self.assertEqual(res, "0.13")

        res = list(map(x.tickFormat(256), x.ticks(256)))[0]
        self.assertEqual(res, "0.125")