[FIX] Graph According to type.
bzr revid: vda@tinyerp.com-20110415064241-3rq913vloy9mchc1
This commit is contained in:
parent
2a24a8218b
commit
b6564900ad
|
@ -1,7 +1,10 @@
|
|||
{
|
||||
"name": "Base Graph",
|
||||
"version": "2.0",
|
||||
"depends": [],
|
||||
"js": ["static/*/js/*.js"],
|
||||
"css": [],
|
||||
"depends": ['base'],
|
||||
"js": [
|
||||
"static/lib/dhtmlxGraph/codebase/dhtmlxchart.js",
|
||||
"static/src/js/graph.js"],
|
||||
"css": ["static/lib/dhtmlxGraph/codebase/dhtmlxchart.css"],
|
||||
"active": True
|
||||
}
|
|
@ -1,74 +1,10 @@
|
|||
import glob, os
|
||||
from xml.etree import ElementTree
|
||||
import math
|
||||
import simplejson
|
||||
from base.controllers.main import View
|
||||
import openerpweb
|
||||
import time
|
||||
import datetime
|
||||
from base.controllers.main import Xml2Json
|
||||
|
||||
|
||||
COLOR_PALETTE = ['#f57900', '#cc0000', '#d400a8', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400',
|
||||
'#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f',
|
||||
'#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
|
||||
'#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900', ]
|
||||
|
||||
_colorline = ['#%02x%02x%02x' % (25 + ((r + 10) % 11) * 23, 5 + ((g + 1) % 11) * 20, 25 + ((b + 4) % 11) * 23) for r in range(11) for g in range(11) for b in range(11) ]
|
||||
|
||||
def choice_colors(n):
|
||||
if n > len(COLOR_PALETTE):
|
||||
return _colorline[0:-1:len(_colorline) / (n + 1)]
|
||||
elif n:
|
||||
return COLOR_PALETTE[:n]
|
||||
return []
|
||||
|
||||
class GraphView(openerpweb.Controller):
|
||||
class GraphView(View):
|
||||
_cp_path = "/base_graph/graphview"
|
||||
|
||||
date_start = None
|
||||
date_delay = None
|
||||
date_stop = None
|
||||
color_field = None
|
||||
|
||||
day_length = 8
|
||||
fields = {}
|
||||
events = []
|
||||
calendar_fields = {}
|
||||
ids = []
|
||||
model = ''
|
||||
domain = []
|
||||
context = {}
|
||||
event_res = []
|
||||
colors = {}
|
||||
color_values = []
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def load(self, req, model, view_id):
|
||||
m = req.session.model(model)
|
||||
r = m.fields_view_get(view_id, 'graph')
|
||||
r["arch"] = Xml2Json.convert_to_structure(r["arch"])
|
||||
return {'fields_view':r}
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def get_events(self, req, **kw):
|
||||
self.model = kw['model']
|
||||
self.fields = kw['fields']
|
||||
|
||||
model = req.session.model(self.model)
|
||||
event_ids = model.search([])
|
||||
return self.create_event(event_ids, model)
|
||||
|
||||
def create_event(self, event_ids, model):
|
||||
self.events = model.read(event_ids, self.fields.values())
|
||||
|
||||
result = []
|
||||
for i, evt in enumerate(self.events):
|
||||
key = evt[self.fields.values()[1]]
|
||||
if isinstance(key, list):
|
||||
evt[self.fields.values()[1]] = key = key[-1]
|
||||
|
||||
self.events[i].pop('id')
|
||||
result.append(evt)
|
||||
|
||||
return result
|
||||
|
||||
fields_view = self.fields_view_get(req, model, view_id, 'graph')
|
||||
return {'fields_view': fields_view}
|
|
@ -1,162 +0,0 @@
|
|||
/*---------------------------------------------------------
|
||||
* OpenERP base_graph
|
||||
*---------------------------------------------------------*/
|
||||
|
||||
openerp.base.graph = function (openerp) {
|
||||
openerp.base.views.add('graph', 'openerp.base.GraphView');
|
||||
openerp.base.GraphView = openerp.base.Controller.extend({
|
||||
|
||||
init: function(view_manager, session, element_id, dataset, view_id) {
|
||||
|
||||
this._super(session, element_id);
|
||||
this.view_manager = view_manager;
|
||||
this.dataset = dataset;
|
||||
this.model = dataset.model;
|
||||
this.view_id = view_id;
|
||||
this.fields_views = {};
|
||||
this.widgets = {};
|
||||
this.widgets_counter = 0;
|
||||
this.fields = {};
|
||||
this.datarecord = {};
|
||||
this.calendar_fields = {};
|
||||
},
|
||||
do_show: function () {
|
||||
// TODO: re-trigger search
|
||||
this.$element.show();
|
||||
},
|
||||
do_hide: function () {
|
||||
this.$element.hide();
|
||||
},
|
||||
start: function() {
|
||||
this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded);
|
||||
},
|
||||
on_loaded: function(data) {
|
||||
this.fields_view = data.fields_view;
|
||||
var self = this;
|
||||
this.name = this.fields_view.name || this.fields_view.arch.attrs.string;
|
||||
this.view_id = this.fields_view.view_id;
|
||||
this.fields['id'] = this.fields_view.arch.children[0].attrs.name;
|
||||
this.fields['total'] = this.fields_view.arch.children[1].attrs.name;
|
||||
this.graph_type = this.fields_view.arch.attrs.type;
|
||||
|
||||
this.rpc('/base_graph/graphview/get_events',
|
||||
{'model': this.model,
|
||||
'fields': this.fields
|
||||
},
|
||||
function(res) {
|
||||
self.create_graph(res);
|
||||
})
|
||||
this.$element.html(QWeb.render("GraphView", {"view": this, "fields_view": this.fields_view}));
|
||||
},
|
||||
create_graph: function(res) {
|
||||
//if (this.graph_type == "bar"){
|
||||
var barChart = new dhtmlXChart({
|
||||
view:"bar",
|
||||
container:"barchart",
|
||||
value:"#"+this.fields['total']+"#",
|
||||
color:"#9abe00",
|
||||
width:40,
|
||||
tooltip: "#"+this.fields['id']+"#",
|
||||
xAxis:{
|
||||
template:"#"+this.fields['id']+"#"
|
||||
},
|
||||
yAxis:{
|
||||
title: "Total"
|
||||
}
|
||||
});
|
||||
barChart.parse(res, "json");
|
||||
//}
|
||||
var pieChart = new dhtmlXChart({
|
||||
view: "pie",
|
||||
container: "piechart",
|
||||
value: "#"+this.fields['total']+"#",
|
||||
label: "#"+this.fields['id']+"#",
|
||||
pieInnerText: "<b>#"+this.fields['total']+"#</b>",
|
||||
gradient: true,
|
||||
radius: 90,
|
||||
x: 280,
|
||||
y: 150
|
||||
});
|
||||
pieChart.parse(res, "json");
|
||||
|
||||
/*static data for stackedbar chart*/
|
||||
var data = [{
|
||||
total: "2.0",
|
||||
total1: "0.0",
|
||||
stage: "Lost"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "2.0",
|
||||
stage: "Negotiation"
|
||||
}, {
|
||||
total: "4.0",
|
||||
total1: "2.0",
|
||||
stage: "New"
|
||||
}, {
|
||||
total: "3.0",
|
||||
total1: "0.0",
|
||||
stage: "Proposition"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "1.0",
|
||||
stage: "Qualification"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "0.0",
|
||||
stage: "Won"
|
||||
}];
|
||||
|
||||
var stackedChart = new dhtmlXChart({
|
||||
view: "stackedBar",
|
||||
container: "stackedchart",
|
||||
value: "#total#",
|
||||
label: "#total#",
|
||||
width: 60,
|
||||
tooltip: {
|
||||
template: "#total#"
|
||||
},
|
||||
xAxis: {
|
||||
template: "#stage#"
|
||||
},
|
||||
yAxis: {
|
||||
title: "User"
|
||||
},
|
||||
gradient: "3d",
|
||||
color: "#66cc33",
|
||||
legend: {
|
||||
values: [{
|
||||
text: "Administrator",
|
||||
color: "#66cc33"
|
||||
}, {
|
||||
text: "Demo User",
|
||||
color: "#ff9933"
|
||||
}],
|
||||
valign: "top",
|
||||
align: "right",
|
||||
width: 120,
|
||||
layout: "y",
|
||||
marker: {
|
||||
width: 15,
|
||||
type: "round"
|
||||
}
|
||||
}
|
||||
});
|
||||
stackedChart.addSeries({
|
||||
value: "#total1#",
|
||||
color: "#ff9933",
|
||||
label: "#total1#",
|
||||
tooltip: {
|
||||
template: "#total1#"
|
||||
}
|
||||
});
|
||||
stackedChart.parse(data, "json");
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them
|
||||
|
||||
};
|
||||
|
||||
// vim:et fdc=0 fdl=0:
|
|
@ -0,0 +1,265 @@
|
|||
/*---------------------------------------------------------
|
||||
* OpenERP base_graph
|
||||
*---------------------------------------------------------*/
|
||||
|
||||
openerp.base_graph = function (openerp) {
|
||||
QWeb.add_template('/base_graph/static/src/xml/base_graph.xml');
|
||||
openerp.base.views.add('graph', 'openerp.base_graph.GraphView');
|
||||
openerp.base_graph.GraphView = openerp.base.Controller.extend({
|
||||
|
||||
init: function(view_manager, session, element_id, dataset, view_id) {
|
||||
|
||||
this._super(session, element_id);
|
||||
this.view_manager = view_manager;
|
||||
this.dataset = dataset;
|
||||
this.model = this.dataset.model;
|
||||
this.view_id = view_id;
|
||||
},
|
||||
do_show: function () {
|
||||
// TODO: re-trigger search
|
||||
this.$element.show();
|
||||
},
|
||||
do_hide: function () {
|
||||
this.$element.hide();
|
||||
},
|
||||
start: function() {
|
||||
this.rpc("/base_graph/graphview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded);
|
||||
},
|
||||
on_loaded: function(data) {
|
||||
var self = this;
|
||||
this.fields_view = data.fields_view;
|
||||
this.name = this.fields_view.name || this.fields_view.arch.attrs.string;
|
||||
this.view_id = this.fields_view.view_id;
|
||||
this.chart = this.fields_view.arch.attrs.type || 'pie';
|
||||
this.fields = this.fields_view.fields;
|
||||
this.chart_info_fields = [];
|
||||
this.operator_field = '';
|
||||
this.group_field = '';
|
||||
this.orientation = this.fields_view.arch.attrs.orientation || '';
|
||||
for(fld in this.fields_view.arch.children) {
|
||||
if (this.fields_view.arch.children[fld].attrs.operator) {
|
||||
this.operator_field = this.fields_view.arch.children[fld].attrs.name;
|
||||
}
|
||||
else if (this.fields_view.arch.children[fld].attrs.group) {
|
||||
this.group_field = this.fields_view.arch.children[fld].attrs.name
|
||||
}
|
||||
else {
|
||||
this.chart_info_fields.push(this.fields_view.arch.children[fld].attrs.name)
|
||||
}
|
||||
}
|
||||
|
||||
this.load_chart();
|
||||
},
|
||||
|
||||
load_chart: function() {
|
||||
var self = this;
|
||||
this.dataset.read_ids(
|
||||
this.dataset.ids,
|
||||
this.fields,
|
||||
function(result) {
|
||||
self.schedule_chart(result)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
schedule_chart: function(result) {
|
||||
|
||||
this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart}));
|
||||
|
||||
console.log('fields view >>>>>>',this.fields_view)
|
||||
|
||||
for(res in result) {
|
||||
for(fld in result[res]) {
|
||||
if(typeof result[res][fld] == 'object') {
|
||||
result[res][fld] = result[res][fld][result[res][fld].length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.chart == 'bar') {
|
||||
var xAxis = {};
|
||||
var yAxis = {};
|
||||
|
||||
if (this.orientation && this.orientation == 'horizontal') {
|
||||
this.chart = "barH";
|
||||
xAxis:{template:"#"+this.operator_field+"#"};
|
||||
yAxis:{title: this.chart_info_fields[0]};
|
||||
} else {
|
||||
xAxis:{template:"#"+this.chart_info_fields[0]+"#"};
|
||||
yAxis:{title: this.operator_field};
|
||||
}
|
||||
return this.schedule_bar(result, xAxis, yAxis, "barchart")
|
||||
} else if(this.chart == "pie") {
|
||||
return this.schedule_pie(result, "piechart");
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
schedule_bar: function(result, xAxis, yAxis, container) {
|
||||
var chart = new dhtmlXChart({
|
||||
view: this.chart,
|
||||
container: container,
|
||||
value: "#"+this.operator_field+"#",
|
||||
color:"#d2ed7e",
|
||||
width:30,
|
||||
gradient:"3d",
|
||||
tooltip: "#"+this.chart_info_fields[0]+"#",
|
||||
xAxis: xAxis,
|
||||
yAxis: yAxis,
|
||||
legend: {
|
||||
align:"right",
|
||||
valign:"top",
|
||||
marker:{
|
||||
type:"round",
|
||||
width:12
|
||||
},
|
||||
template:"#"+this.chart_info_fields[0]+"#"
|
||||
}
|
||||
});
|
||||
if(this.group_field) {
|
||||
// var map_fld = this.chart_info_fields[0];
|
||||
// chart.group({
|
||||
// by: "#"+this.group_field+"#",
|
||||
// map:{
|
||||
// map_fld :["#"+this.operator_field+"#", "sum"]
|
||||
// }
|
||||
// });
|
||||
}
|
||||
chart.parse(result, "json");
|
||||
},
|
||||
|
||||
schedule_pie: function(result, container) {
|
||||
var chart = new dhtmlXChart({
|
||||
view:"pie",
|
||||
container:container,
|
||||
value:"#"+this.operator_field+"#",
|
||||
color:"#d2ed7e",
|
||||
label:"#"+this.chart_info_fields[0]+"#",
|
||||
pieInnerText:"<b>#"+this.operator_field+"#</b>",
|
||||
gradient:"3d",
|
||||
legend: {
|
||||
width: 100,
|
||||
align:"right",
|
||||
valign:"top",
|
||||
marker:{
|
||||
type:"round",
|
||||
width:12
|
||||
},
|
||||
template:"#"+this.chart_info_fields[0]+"#"
|
||||
}
|
||||
});
|
||||
chart.parse(result,"json");
|
||||
},
|
||||
|
||||
create_graph: function(res) {
|
||||
//if (this.graph_type == "bar"){
|
||||
var barChart = new dhtmlXChart({
|
||||
view:"bar",
|
||||
container:"barchart",
|
||||
value:"#"+this.fields['total']+"#",
|
||||
color:"#9abe00",
|
||||
width:40,
|
||||
tooltip: "#"+this.fields['id']+"#",
|
||||
xAxis:{
|
||||
template:"#"+this.fields['id']+"#"
|
||||
},
|
||||
yAxis:{
|
||||
title: "Total"
|
||||
}
|
||||
});
|
||||
barChart.parse(res, "json");
|
||||
//}
|
||||
var pieChart = new dhtmlXChart({
|
||||
view: "pie",
|
||||
container: "piechart",
|
||||
value: "#"+this.fields['total']+"#",
|
||||
label: "#"+this.fields['id']+"#",
|
||||
pieInnerText: "<b>#"+this.fields['total']+"#</b>",
|
||||
gradient: true,
|
||||
radius: 90,
|
||||
x: 280,
|
||||
y: 150
|
||||
});
|
||||
pieChart.parse(res, "json");
|
||||
|
||||
/*static data for stackedbar chart*/
|
||||
var data = [{
|
||||
total: "2.0",
|
||||
total1: "0.0",
|
||||
stage: "Lost"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "2.0",
|
||||
stage: "Negotiation"
|
||||
}, {
|
||||
total: "4.0",
|
||||
total1: "2.0",
|
||||
stage: "New"
|
||||
}, {
|
||||
total: "3.0",
|
||||
total1: "0.0",
|
||||
stage: "Proposition"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "1.0",
|
||||
stage: "Qualification"
|
||||
}, {
|
||||
total: "1.0",
|
||||
total1: "0.0",
|
||||
stage: "Won"
|
||||
}];
|
||||
|
||||
var stackedChart = new dhtmlXChart({
|
||||
view: "stackedBar",
|
||||
container: "stackedchart",
|
||||
value: "#total#",
|
||||
label: "#total#",
|
||||
width: 60,
|
||||
tooltip: {
|
||||
template: "#total#"
|
||||
},
|
||||
xAxis: {
|
||||
template: "#stage#"
|
||||
},
|
||||
yAxis: {
|
||||
title: "User"
|
||||
},
|
||||
gradient: "3d",
|
||||
color: "#66cc33",
|
||||
legend: {
|
||||
values: [{
|
||||
text: "Administrator",
|
||||
color: "#66cc33"
|
||||
}, {
|
||||
text: "Demo User",
|
||||
color: "#ff9933"
|
||||
}],
|
||||
valign: "top",
|
||||
align: "right",
|
||||
width: 120,
|
||||
layout: "y",
|
||||
marker: {
|
||||
width: 15,
|
||||
type: "round"
|
||||
}
|
||||
}
|
||||
});
|
||||
stackedChart.addSeries({
|
||||
value: "#total1#",
|
||||
color: "#ff9933",
|
||||
label: "#total1#",
|
||||
tooltip: {
|
||||
template: "#total1#"
|
||||
}
|
||||
});
|
||||
stackedChart.parse(data, "json");
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them
|
||||
|
||||
};
|
||||
|
||||
// vim:et fdc=0 fdl=0:
|
|
@ -0,0 +1,17 @@
|
|||
<template>
|
||||
<t t-name="GraphView">
|
||||
<h2 class="oe_view_title"><t t-esc="fields_view.arch.attrs.string"/></h2>
|
||||
<table width="100%" height="100%" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td>
|
||||
<div t-att-id="chart+'chart'" style="width:900px;height:500px;border:1px solid #A4BED4;"></div>
|
||||
</td>
|
||||
<!--<td><div id="barchart" style="width:900px;height:500px;border:1px solid #A4BED4;"></div></td>
|
||||
<td>
|
||||
<div id="piechart" style="width:600px;height:250px;border:1px solid #A4BED4;"></div>
|
||||
<div id="stackedchart" style="width:600px;height:250px;border:1px solid #A4BED4;"></div>
|
||||
</td> -->
|
||||
</tr>
|
||||
</table>
|
||||
</t>
|
||||
</template>
|
Loading…
Reference in New Issue