Ejemplo n.º 1
0
def area_example():
    """ Basic Area Exampls """
    chart = Highchart()
    data = [i**2 for i in range(10)]
    chart.title("Area Example")
    chart.add_data_set(data, series_type="area", name="Area")
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 2
0
def spline_example():
    """ Basic Spline Example """
    chart = Highchart()
    data = [math.sin(x/100.0) \
        for x in range(0, int(4*math.pi*100), int(math.pi/16*100))]
    chart.title("Sin Spline")
    chart.add_data_set(data, series_type="spline", name="Sin")
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 3
0
def area_example():
    """ Basic Area Exampls """
    chart = Highchart()
    data = [i**2 for i in range(10)]
    chart.title("Area Example")
    chart.add_data_set(data, series_type="area", name="Area")
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 4
0
def spline_example():
    """ Basic Spline Example """
    chart = Highchart()
    data = [math.sin(x/100.0) \
        for x in range(0, int(4*math.pi*100), int(math.pi/16*100))]
    chart.title("Sin Spline")
    chart.add_data_set(data, series_type="spline", name="Sin")
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 5
0
 def creatDict(self): #insert other arguments
     'Create a Json dictionary incorporating queried data and the Highcharts functions.'
     
     # organize 2-D list into a 1-D list
     #=======================================================================
     # orgDataIndex = 0
     # for col in queriedData:
     #     for row in queriedData: # this may be inverted order to organize by
     #         organizedData[orgDataIndex].add(queriedData[row][col])
     #         orgDataIndex += 1
     #=======================================================================
     
     # create chart object--set appropriate chart options using the Highcharts functions (ie add_data_set) based on what options were passed to QueriedData constructor
     chart = Highchart()
     chart.title(self.title)
     
     for row in self.queriedData:
         orgDataIndex = 0
         for element in range(1, len(row)): # access individual elements of the list that is within the outer list (how the 2d list is build)
             # ^ skip first column because it has the name of the variable, not a value
             self.organizedData[orgDataIndex].append(element)
             orgDataIndex += 1
         chart.add_data_set(self.organizedData, series_type=self.sType, name=self.queriedData[row][0]) # name is assumed to be in the 0th column of each row
     
     chart.set_options(EXAMPLE_CONFIG) # add further configs
                                       # current EXAMPLE_CONFIG provides default visual options; can be found in examples.py
     
     # Using chart.__export_options__(), create a Json dictionary (member variable)
     return chart.__export_options__() # return new json dictionary
Ejemplo n.º 6
0
def multiple_example():
    """ Basic Multiple Exampls """
    chart = Highchart()
    revenue = [random.randint(1000, 7000) for i in range(24)]
    spend = [random.randint(2000, 4000) for i in range(24)]
    profit = [r - spend[i] for i, r in enumerate(revenue)]
    cumulative_profit = [sum(profit[:i]) + 5000 for i in range(len(profit))]
    chart.title("Multiple Example")
    chart.add_data_set(revenue, series_type="line", name="Revenue", index=2)
    chart.add_data_set(spend, series_type="line", name="Spend", index=3)
    chart.add_data_set(cumulative_profit,
                       series_type="area",
                       name="Balance",
                       index=1)
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 7
0
def pie_example():
    """ Basic Piechart Example """
    chart = Highchart()
    chart.title("Pac Man Highchart")
    chart.add_data_set(
        [["Does Not Resemble Pac Man", 25], ["Resembes Pac Man", 75]],
        series_type="pie",
        name="",
        startAngle=45)
    chart.colors(["#99CCFF", "#FFFF66"])
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 8
0
def multiple_example():
    """ Basic Multiple Exampls """
    chart = Highchart()
    revenue = [random.randint(1000, 7000) for i in range(24)]
    spend = [random.randint(2000, 4000) for i in range(24)]
    profit = [r - spend[i] for i, r in enumerate(revenue)]
    cumulative_profit = [sum(profit[:i])+5000 for i in range(len(profit))]
    chart.title("Multiple Example")
    chart.add_data_set(revenue, series_type="line", name="Revenue", index=2)
    chart.add_data_set(spend, series_type="line", name="Spend", index=3)
    chart.add_data_set(cumulative_profit, 
        series_type="area", 
        name="Balance",
        index=1)
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
Ejemplo n.º 9
0
def pie_example():
    """ Basic Piechart Example """
    chart = Highchart()
    chart.title("Pac Man Highchart")
    chart.add_data_set([["Does Not Resemble Pac Man", 25],
        ["Resembes Pac Man", 75]],
        series_type="pie",
        name="",
        startAngle=45)
    chart.colors(["#99CCFF", "#FFFF66"])
    chart.set_options(EXAMPLE_CONFIG)
    chart.show()
    def buildHighchart(self):
        """
        Create a Highchart chart with the algorithm result
        @type self: koala.SortByFront.SortByFront
        """

        try:
            # Load files
            files = list_directory(self.path_runs.get_path_execution(), '*.xvg')

            methods = self.methods

            # Objectivies
            obj1 = ""
            obj2 = ""

            x = [[]]*len(files)
            y = [[]]*len(files)

            for i, f in enumerate(files):
                f = os.path.join(self.path_runs.get_path_execution(), f)
                arq = open(f, "r")

                # Loading File
                x[i] = []
                y[i] = []
                for line in arq:
                    if line.find("#") == -1:
                        x[i].append(float(line.split("\t")[0].strip()))
                        y[i].append(float(line.split("\t")[1]))
                    else:
                        col = line.split("\t")
                        if len(col) > 1:
                            obj1 = col[0].replace('#', ' ')
                            obj2 = col[2]
                arq.close()

            chart = Highchart(renderTo="container2")
            chart.title("Pareto Fronts")
            chart.subtitle(
                "A graph with %s and %s objectivies showing at most four fronts, "
                "but the first as line and the others as scatter"
                % (obj1, obj2))

            graph_options = {
                "xAxis": {
                    "minPadding": 0.05,
                    "maxPadding": 0.1,
                    "title": {
                        'offset': 30,
                        'text': obj1,
                        'rotation': 0,
                    },
                },

                "yAxis": {
                    "minPadding": 0.05,
                    "maxPadding": 0.1,
                    "title": {
                        'offset': 50,
                        'text': obj2,
                        'rotation': -90,
                    },
                },

                "tooltip": {
                    "shared": True,
                    "useHTML": False,
                    # "valueDecimals": 3,
                },

            }

            data = []
            it = {}
            i_file = 0
            context = Context(prec=3, rounding=ROUND_UP)

            if(len(x) > 5):
                fronts = 4
            else:
                fronts = len(x)

            for i in range(fronts):  # no máximo as duas primeiras fronteiras
                data = []
                z = x[i]
                for ii, w in enumerate(z):
                    if(i == 0):
                        it["name"] = methods[i_file]
                        i_file += 1
                    else:
                        it["name"] = "front%d" % i
                    if(not math.isinf(z[ii])):
                        it["x"] = (context.create_decimal_from_float(z[ii])).quantize(
                            Decimal('.2'),
                            rounding=ROUND_UP)
                    else:
                        it["x"] = "0.0"
                    if(not math.isinf(y[i][ii])):
                        it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize(
                            Decimal('.2'),
                            rounding=ROUND_UP)
                    else:
                        it["y"] = "0.0"
                    data.append(it)
                    it = {}

                if(i == 0):
                    chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True})
                else:
                    chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i)

            chart.set_options(graph_options)
            return chart.generate()

        except Exception, e:
            show_error_message("Error on building highcharts.\n%s" % e)
Ejemplo n.º 11
0
    def build_Highchart(self, objectivies, container="container"):
        """
        Create a Highchart chart with the algorithm result
        @type self: koala.DominanceRanking.DominanceRanking
        @type objectivies: string
        @type container: string
        """
        try:
            # Load files
            objs = objectivies.split(",")
            files = list_directory(
                self.path_runs.get_path_execution(), '*%s_%s*.xvg' % (objs[0], objs[1]))
            images = self.methods

            x = [[]]*len(files)
            y = [[]]*len(files)

            for i, f in enumerate(files):
                f = os.path.join(self.path_runs.get_path_execution(), f)
                arq = open(f, "r")

                # Loading File
                x[i] = []
                y[i] = []
                for line in arq:
                    if line.find("#") == -1:
                        x[i].append(float(line.split("\t")[0].strip()))
                        y[i].append(float(line.split("\t")[1]))
                arq.close()

            chart = Highchart(renderTo=container)
            chart.title("Pareto Fronts")
            chart.subtitle("A graph with %s and %s objectivies" % (objs[0], objs[1]))

            graph_options = {
                "xAxis": {
                    "minPadding": 0.05,
                    "maxPadding": 0.1,
                    "title": {
                        'offset': 30,
                        'text': objs[0],
                        'rotation': 0,
                    },
                },

                "yAxis": {
                    "minPadding": 0.05,
                    "maxPadding": 0.1,
                    "title": {
                        'offset': 50,
                        'text': objs[1],
                        'rotation': -90,
                    },
                },

                "tooltip": {
                    "shared": True,
                    "useHTML": False,
                    "valueDecimals": 3,
                },
            }

            data = []
            it = {}
            i_file = 0
            context = Context(prec=3, rounding=ROUND_UP)

            if(len(x) >= 4):
                fronts = 4
            else:
                # fronts = 2
                fronts = len(x)

            for i in range(fronts):
                data = []
                z = x[i]
                for ii, w in enumerate(z):
                    if(i_file < len(images)):
                        it["name"] = images[i_file]
                        i_file += 1
                    else:
                        it["name"] = "front%d" % i
                    it["x"] = (context.create_decimal_from_float(z[ii])).quantize(
                            Decimal('.1'),
                            rounding=ROUND_UP)
                    it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize(
                            Decimal('.1'),
                            rounding=ROUND_UP)
                    data.append(it)
                    it = {}

                if(i == 0):
                    chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True})
                else:
                    chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i)

            chart.set_options(graph_options)
            return chart.generate()

        except Exception, e:
            show_error_message("Error while building the Highchart:\n%s" % e)
Ejemplo n.º 12
0
def dau_line_example():
    """ Basic line Example """
    chart = Highchart()
    chart.set_options(EXAMPLE_CONFIG)
    chart.update_yAxis(title_text="活跃人数 (人)")
    chart.update_xAxis(categories=[
        '+0', '+1', '+2', '+3', '+4', '+5', '+6', '+7', '+8', '+9', '+10',
        '+11', '+12'
    ])
    chart.title("活跃用户留存(2014-07-09~2014-07-22)")
    chart.add_data_set([['2014-07-09', 223961], ['2014-07-10', 150964],
                        ['2014-07-11', 134088], ['2014-07-12', 119318],
                        ['2014-07-13', 110857], ['2014-07-14', 109625],
                        ['2014-07-15', 104971], ['2014-07-16', 100415],
                        ['2014-07-17', 96143], ['2014-07-18', 95523],
                        ['2014-07-19', 88619]],
                       series_type="line",
                       name="2014-07-09")
    chart.add_data_set([['2014-07-10', 243910], ['2014-07-11', 161951],
                        ['2014-07-12', 133382], ['2014-07-13', 121328],
                        ['2014-07-14', 122070], ['2014-07-15', 115963],
                        ['2014-07-16', 110135], ['2014-07-17', 104766],
                        ['2014-07-18', 105800], ['2014-07-19', 95100]],
                       series_type="line",
                       name="2014-07-10")

    json_data = json.dumps(chart.__export_json_options__(), ensure_ascii=False)

    # json_data =chart.__export_json_options__()

    chart.show()