# -*- coding: utf-8 -*-

#    visigoth: A lightweight Python3 library for rendering data visualizations in SVG
#    Copyright (C) 2020  Visigoth Developers
#
#   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
#   and associated documentation files (the "Software"), to deal in the Software without 
#   restriction, including without limitation the rights to use, copy, modify, merge, publish,
#   distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be included in all copies or 
#   substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
#   BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
#   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import unittest
import datetime

from visigoth import Diagram
from visigoth.internal.utils.test_utils import TestUtils
from visigoth.charts.area import Area
from visigoth.utils import DiscreteHueManager
from visigoth.common import DiscreteHueLegend, Text
from visigoth.containers import Grid,Sequence

class TestArea(unittest.TestCase):

    def test_basic(self):
        d = Diagram(fill="white")

        dp = DiscreteHueManager()

        data = [
            (1,12,"A"),
            (2,14,"A"),
            (3,11,"A"),
            (4,9,"A"),
            (5,7,"A"),
            (1,2,"B"),
            (2,4,"B"),
            (3,7,"B"),
            (4,10,"B"),
            (5,11,"B"),
            (1,2,"C"),
            (2,3,"C"),
            (3,1,"C"),
            (4,3,"C"),
            (5,2,"C")
        ]

        d.add(Text("Individual areas"))

        g = Grid()
        row = 0
        col = 0
        for cat in ["A","B","C"]:
            s = Sequence()            
            s.add(Text(cat))
            area0 = Area([d for d in data if d[2] == cat], x=0, y=1, hue_manager=dp, height=300, width=300)
            s.add(area0)
            g.add(row,col,s)
            col += 1
            if col == 2:
                row += 1
                col = 0        
        d.add(g)

        d.add(Text("Smoothing"))

        d.add(Text("Stacked areas"))
        area1 = Area(data, x=0, y=1, size=1, hue=2, height=600, hue_manager=dp, width=600)
        area1.getMarkerManager().setMaxRadius(10)
        d.add(area1)

        legend1 = DiscreteHueLegend(dp,400,legend_columns=2)
        d.add(legend1)

        d.add(Text("Stepped"))
        area1a = Area(data, x=0, y=1, size=1, hue=2, height=600, hue_manager=dp, width=600, stepping=True)
        area1a.getMarkerManager().setMaxRadius(10)
        d.add(area1a)

        legend1 = DiscreteHueLegend(dp, 400, legend_columns=2)
        d.add(legend1)

        for smoothing in [0.1,0.3,0.5]:
            d.add(Text("Smoothing=%f"%(smoothing)))
            area2 = Area(data, x=0, y=1, hue=2, height=400, smoothing=smoothing, hue_manager=dp, width=400)
            d.add(area2)

        data3 = [{"y": i, "x": datetime.datetime(1999, 9, 3) + (i ** 1.5) * datetime.timedelta(days=1)} for i in
                 range(0, 20)]
        hue_manager3 = DiscreteHueManager()
        hue_manager3.setDefaultHue("purple")
        line3 = Area(data3, x="x", y="y", hue_manager=hue_manager3, width=600, height=600, smoothing=0.0)
        d.add(line3)

        data4 = [{"x": i, "y": (i ** 0.6) * datetime.timedelta(days=1)} for i in range(0, 20)]
        hue_manager4 = DiscreteHueManager()
        hue_manager4.setDefaultHue("red")
        line4 = Area(data4, x="x", y="y", hue_manager=hue_manager4, width=600, height=600, smoothing=00)
        d.add(line4)

        TestUtils.draw_output(d,"test_area")


if __name__ == "__main__":
    unittest.main()
# -*- coding: utf-8 -*-

#    visigoth: A lightweight Python3 library for rendering data visualizations in SVG
#    Copyright (C) 2020  Visigoth Developers
#
#   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
#   and associated documentation files (the "Software"), to deal in the Software without 
#   restriction, including without limitation the rights to use, copy, modify, merge, publish,
#   distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be included in all copies or 
#   substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
#   BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
#   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import unittest
import datetime

from visigoth import Diagram
from visigoth.internal.utils.test_utils import TestUtils
from visigoth.charts.area import Area
from visigoth.utils import DiscreteHueManager
from visigoth.common import DiscreteHueLegend, Text
from visigoth.containers import Grid,Sequence

class TestArea(unittest.TestCase):

    def test_basic(self):
        d = Diagram(fill="white")

        dp = DiscreteHueManager()

        data = [
            (1,12,"A"),
            (2,14,"A"),
            (3,11,"A"),
            (4,9,"A"),
            (5,7,"A"),
            (1,2,"B"),
            (2,4,"B"),
            (3,7,"B"),
            (4,10,"B"),
            (5,11,"B"),
            (1,2,"C"),
            (2,3,"C"),
            (3,1,"C"),
            (4,3,"C"),
            (5,2,"C")
        ]

        d.add(Text("Individual areas"))

        g = Grid()
        row = 0
        col = 0
        for cat in ["A","B","C"]:
            s = Sequence()            
            s.add(Text(cat))
            area0 = Area([d for d in data if d[2] == cat], x=0, y=1, hue_manager=dp, height=300, width=300)
            s.add(area0)
            g.add(row,col,s)
            col += 1
            if col == 2:
                row += 1
                col = 0        
        d.add(g)

        d.add(Text("Smoothing"))

        d.add(Text("Stacked areas"))
        area1 = Area(data, x=0, y=1, size=1, hue=2, height=600, hue_manager=dp, width=600)
        area1.getMarkerManager().setMaxRadius(10)
        d.add(area1)

        legend1 = DiscreteHueLegend(dp,400,legend_columns=2)
        d.add(legend1)

        d.add(Text("Stepped"))
        area1a = Area(data, x=0, y=1, size=1, hue=2, height=600, hue_manager=dp, width=600, stepping=True)
        area1a.getMarkerManager().setMaxRadius(10)
        d.add(area1a)

        legend1 = DiscreteHueLegend(dp, 400, legend_columns=2)
        d.add(legend1)

        for smoothing in [0.1,0.3,0.5]:
            d.add(Text("Smoothing=%f"%(smoothing)))
            area2 = Area(data, x=0, y=1, hue=2, height=400, smoothing=smoothing, hue_manager=dp, width=400)
            d.add(area2)

        data3 = [{"y": i, "x": datetime.datetime(1999, 9, 3) + (i ** 1.5) * datetime.timedelta(days=1)} for i in
                 range(0, 20)]
        hue_manager3 = DiscreteHueManager()
        hue_manager3.setDefaultHue("purple")
        line3 = Area(data3, x="x", y="y", hue_manager=hue_manager3, width=600, height=600, smoothing=0.0)
        d.add(line3)

        data4 = [{"x": i, "y": (i ** 0.6) * datetime.timedelta(days=1)} for i in range(0, 20)]
        hue_manager4 = DiscreteHueManager()
        hue_manager4.setDefaultHue("red")
        line4 = Area(data4, x="x", y="y", hue_manager=hue_manager4, width=600, height=600, smoothing=00)
        d.add(line4)

        TestUtils.draw_output(d,"test_area")


if __name__ == "__main__":
    unittest.main()
# -*- coding: utf-8 -*- #    visigoth: A lightweight Python3 library for rendering data visualizations in SVG #    Copyright (C) 2020  Visigoth Developers # #   Permission is hereby granted, free of charge, to any person obtaining a copy of this software #   and associated documentation files (the "Software"), to deal in the Software without #   restriction, including without limitation the rights to use, copy, modify, merge, publish, #   distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the #   Software is furnished to do so, subject to the following conditions: # #   The above copyright notice and this permission notice shall be included in all copies or #   substantial portions of the Software. # #   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING #   BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND #   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, #   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.