Example #1
0
    def render(self, chart_data):
        chart_data.sampling(common.settings.chart_resolution)

        # adjust timezone if needed
        mode = ''
        if chart_data.mode == 'time':
            mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, lines: { fillOpacity:1.0, show: true, lineWidth:1 },'
            chart_data.adjust_timezone()

        # convert python array to js array
        raw_data = ''
        if len(chart_data.items) == 1:  # one item
            raw_data = chart_data.items[0].data.__repr__().replace(
                'None', 'null')
        else:  # multi item (display label)
            for item in chart_data.items:
                tmp = item.data.__repr__().replace('None', 'null')
                if len(chart_data.items) > 7:
                    raw_data += '%s,' % tmp
                else:
                    raw_data += '{ label: "%s", data: %s },' % (item.title,
                                                                tmp)

        idx = flot_line_renderer.idx + id(chart_data)  # to get unique idx
        flot_line_renderer.idx += 1

        #print (raw_data)
        js_template = self.get_js_template()
        return js_template % ('[ %s ]' % raw_data, idx, mode, chart_data.title,
                              idx)
	def render(self, chart_data):
		chart_data.sampling(common.settings.chart_resolution)

		# adjust timezone if needed
		mode = ''
		if chart_data.mode == 'time':
			mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, lines: { fillOpacity:1.0, show: true, lineWidth:1 },'
			chart_data.adjust_timezone()

		# convert python array to js array
		raw_data = ''
		if len(chart_data.items) == 1: # one item
			raw_data = chart_data.items[0].data.__repr__().replace('None', 'null')
		else: # multi item (display label)
			for item in chart_data.items:
				tmp = item.data.__repr__().replace('None', 'null')
				if len(chart_data.items) > 7:
					raw_data += '%s,' % tmp
				else:
					raw_data += '{ label: "%s", data: %s },' % (item.title, tmp)

		idx = flot_line_renderer.idx + id(chart_data) # to get unique idx
		flot_line_renderer.idx += 1

		#print (raw_data)
		js_template = self.get_js_template()
		return  js_template % ('[ %s ]' % raw_data, idx, mode, chart_data.title, idx)
Example #3
0
	def render(self, chart_data):
		chart_data.sampling(common.settings.chart_resolution)

		# adjust timezone if needed
		mode = 'series: {pie: {show: true, radius:1, label: {show:true, radius:2/3, formatter:labelFormatter, threshold:0.1}}}, legend: {show:false}'
		if chart_data.mode == 'time':
			chart_data.adjust_timezone()

		# convert python array to js array
		raw_data = ''
		if len(chart_data.items) == 1: # one item
			item = chart_data.items[-1]
			last_data = list(filter(None.__ne__, item.data))[-1][1]
			raw_data = '{ label: "%s", data: %s }'% (item.title , last_data)
		else: # multi item (display label)
			for item in chart_data.items:
				tmp = list(filter(None.__ne__, item.data))
				if len(chart_data.items) > 7:
					if (item.title != "total"):
						raw_data += '{ label: "%s", data: %s },' % (item.title, tmp[-1][1])
				else:
					if (item.title != "total"):
						raw_data += '{ label: "%s", data: %s },' % (item.title, tmp[-1][1])

		idx = flot_line_renderer.idx + id(chart_data) # to get unique idx
		flot_line_renderer.idx += 1

		js_template = self.get_js_template()
		return  js_template % ('[ %s ]' % raw_data, idx, mode, chart_data.title, idx)
Example #4
0
    def render(self, chart_data):
        chart_data.sampling(common.settings.chart_resolution)

        # adjust timezone if needed
        mode = ''
        if chart_data.mode == 'time':
            mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, lines: { fillOpacity:1.0, show: true, lineWidth:1 },'
            chart_data.adjust_timezone()

        mode = mode + "cursors: [ { mode: 'x', showIntersections: true, showLabel: false,snapToPlot: 0, symbol: 'diamond', position: { relativeX: 0, relativeY:0} }], grid: {hoverable: true, autoHighlight: false },"
        # convert python array to js array
        raw_data = ''
        if len(chart_data.items) == 1:  # one item
            item = chart_data.items[0]
            tmp = list(filter(None.__ne__, item.data))
            tmp = tmp.__repr__()
            raw_data = '{ label: "%s", data: %s}' % (item.title, tmp)
        else:  # multi item (display label)
            for item in chart_data.items:
                tmp = list(filter(None.__ne__, item.data))
                tmp = tmp.__repr__()
                if len(chart_data.items) > 7:
                    raw_data += '%s,' % tmp
                else:
                    raw_data += '{ label: "%s", data: %s },' % (item.title,
                                                                tmp)

        idx = flot_line_renderer.idx + id(chart_data)  # to get unique idx
        flot_line_renderer.idx += 1

        #print (raw_data)
        js_template = self.get_js_template()
        return js_template % ('%s' % idx, raw_data, idx, idx, mode, idx, idx,
                              idx, idx, idx, idx, idx, chart_data.title, idx,
                              idx, idx, chart_data.title, idx)
Example #5
0
	def render(self, chart_data):
		chart_data.sampling(common.settings.chart_resolution)

		# adjust timezone if needed
		mode = ''
		if chart_data.mode == 'time':
			mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, lines: { fillOpacity:1.0, show: true, lineWidth:1 },'
			chart_data.adjust_timezone()

		mode = mode + "cursors: [ { mode: 'x', showIntersections: true, showLabel: false,snapToPlot: 0, symbol: 'diamond', position: { relativeX: 0, relativeY:0} }], grid: {hoverable: true, autoHighlight: false },"
		# convert python array to js array
		raw_data = ''
		if len(chart_data.items) == 1: # one item
			item = chart_data.items[0];
			tmp = list(filter(None.__ne__, item.data))
			tmp = tmp.__repr__()
			raw_data = '{ label: "%s", data: %s}' %(item.title, tmp)
		else: # multi item (display label)
			for item in chart_data.items:
				tmp = list(filter(None.__ne__, item.data))
				tmp = tmp.__repr__()
				if len(chart_data.items) > 7:
					raw_data += '%s,' % tmp
				else:
					raw_data += '{ label: "%s", data: %s },' % (item.title, tmp)

		idx = flot_line_renderer.idx + id(chart_data) # to get unique idx
		flot_line_renderer.idx += 1

		#print (raw_data)
		js_template = self.get_js_template()
		return  js_template % ('%s' %idx, raw_data,idx, idx, mode,idx,idx,idx,idx,idx, idx,idx,chart_data.title, idx,idx,idx, chart_data.title, idx)
Example #6
0
    def render(self, chart_data):
        chart_data.sampling(common.settings.chart_resolution)

        # adjust timezone if needed
        mode = ''
        if chart_data.mode == 'time':
            # add click event listener to label
            labelFormatter = '''
                               function(label, series){
					var idx = %s;
					var labelList = %s;
                                        return "<a name=" + "'" + idx + " " + label + " " + labelList + "'" + " onclick='(function(elem){\
									var data = elem.name.split(/ /);\
									var id = data[0];\
									var label = data[1];\
									var labelList = data[2].split(/,/);\
                                                                        var bars = dic_plot[id].getData()[labelList.indexOf(label)].bars;\
									bars.show ? bars.show=false : bars.show=true;\
                                                                        dic_plot[id].draw();\
                                                                })(this)'>" + label + "</a>";
                                }
                        '''

            #set bar width

            #push num1(time in millisecond) which matches '[num1, num2]'
            tmp_data = re.findall('\d+(?=, \d+)',
                                  chart_data.items[0].data.__repr__())
            if len(tmp_data) >= 2:
                start_time = int(tmp_data[0])
                end_time = int(tmp_data[-1])
                time_gap = end_time - start_time
                #unit of barWidth = unit of x axis(1 millisecond)
                barWidth = time_gap / len(chart_data.items[0].data) * 0.8
            else:
                barWidth = 1

            mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, bars: { fill: 0.8, show: true, lineWidth: 0, barWidth: %d, fillColors: false}, legend: { labelFormatter: %s }, ' % (
                barWidth, labelFormatter)

            chart_data.adjust_timezone()

        # convert python array to js array
        raw_data = ''
        labelList = []  # list of all label
        if len(chart_data.items) == 1:  # one item
            raw_data = chart_data.items[0].data.__repr__().replace(
                'None', 'null')
        else:  # multi item (display label)
            for item in chart_data.items:
                tmp = item.data.__repr__().replace('None', 'null')
                if len(chart_data.items) > 7:
                    raw_data += '%s,' % tmp
                else:
                    labelList.append(item.title)
                    raw_data += '{ label: "%s", data: %s, },' % (item.title,
                                                                 tmp)

        idx = flot_bar_renderer.idx + id(chart_data)  # to get unique idx
        flot_bar_renderer.idx += 1

        #print (raw_data)
        js_template = self.get_js_template()
        return js_template % ('[ %s ]' % raw_data, idx, mode %
                              (idx, labelList), idx, chart_data.title, idx)
Example #7
0
	def render(self, chart_data):
		chart_data.sampling(common.settings.chart_resolution)

		# adjust timezone if needed
		mode = ''
		if chart_data.mode == 'time':
			# add click event listener to label
			labelFormatter = '''
                               function(label, series){
					var idx = %s;
					var labelList = %s;
                                        return "<a name=" + "'" + idx + " " + label + " " + labelList + "'" + " onclick='(function(elem){\
									var data = elem.name.split(/ /);\
									var id = data[0];\
									var label = data[1];\
									var labelList = data[2].split(/,/);\
                                                                        var bars = dic_plot[id].getData()[labelList.indexOf(label)].bars;\
									bars.show ? bars.show=false : bars.show=true;\
                                                                        dic_plot[id].draw();\
                                                                })(this)'>" + label + "</a>";
                                }
                        '''

			#set bar width

			#push num1(time in millisecond) which matches '[num1, num2]'
			tmp_data = re.findall('\d+(?=, \d+)', chart_data.items[0].data.__repr__())
			if len(tmp_data) >= 2:
				start_time = int(tmp_data[0])
				end_time = int(tmp_data[-1])
				time_gap = end_time - start_time
				#unit of barWidth = unit of x axis(1 millisecond)
				barWidth = time_gap / len(chart_data.items[0].data) * 0.8
			else:
				barWidth = 1

			mode = 'xaxis: { mode: "time" }, yaxis: { tickFormatter: tickFunc, min: 0 }, bars: { fill: 0.8, show: true, lineWidth: 0, barWidth: %d, fillColors: false}, legend: { labelFormatter: %s }, ' %(barWidth, labelFormatter)


			chart_data.adjust_timezone()

		# convert python array to js array
		raw_data = ''
		labelList = [] # list of all label
		if len(chart_data.items) == 1: # one item
			raw_data = chart_data.items[0].data.__repr__().replace('None', 'null')
		else: # multi item (display label)
			for item in chart_data.items:
				tmp = item.data.__repr__().replace('None', 'null')
				if len(chart_data.items) > 7:
					raw_data += '%s,' % tmp
				else:
					labelList.append(item.title)
					raw_data += '{ label: "%s", data: %s, },' % (item.title, tmp)

		idx = flot_bar_renderer.idx + id(chart_data) # to get unique idx
		flot_bar_renderer.idx += 1

		#print (raw_data)
		js_template = self.get_js_template()
		return  js_template % ('[ %s ]' % raw_data, idx, mode %(idx, labelList), idx, chart_data.title, idx)