Commit 17a768f85a786f38716f1d6863fb4bddcf3213bf
1 parent
1b604951
Exists in
master
and in
4 other branches
Enhance agent charge tooltip
Showing
1 changed file
with
79 additions
and
44 deletions
Show diff stats
app/main/templates/agent.html
... | ... | @@ -18,16 +18,17 @@ |
18 | 18 | |
19 | 19 | .tooltip { |
20 | 20 | position: absolute; |
21 | - opacity: 0.8; | |
21 | + opacity: 1.0; | |
22 | 22 | z-index: 1000; |
23 | 23 | text-align: left; |
24 | 24 | border-radius: 4px; |
25 | 25 | -moz-border-radius: 4px; |
26 | 26 | -webkit-border-radius: 4px; |
27 | - padding: 8px; | |
28 | - color: #fff; | |
29 | - background-color: #000; | |
30 | - font: 12px sans-serif; | |
27 | + padding: 10px; | |
28 | + border: 1px solid; | |
29 | + background-color: white; | |
30 | + color: black; | |
31 | + /*font: 12px sans-serif;*/ | |
31 | 32 | max-width: 300px; |
32 | 33 | } |
33 | 34 | |
... | ... | @@ -61,21 +62,37 @@ |
61 | 62 | .append("g") |
62 | 63 | .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
63 | 64 | |
64 | - const div = d3.select("body").append("div") | |
65 | - .attr("class", "tooltip") | |
66 | - .style("opacity", 0); | |
67 | 65 | |
68 | 66 | // On demande à D3JS de charger notre fichier |
69 | 67 | d3.json("{{url_for('main.charge_agent', agent_id=agent.id)}}").then(data => { |
70 | 68 | |
71 | 69 | // waiting for structure of the form: |
72 | 70 | // |
71 | + // { | |
72 | + // '2014_S1': {'4Q++': None, | |
73 | + // 'Activité service C2L': None, | |
74 | + // 'Activité service COMCL': None, | |
75 | + // . | |
76 | + // ...}, | |
77 | + // '2014_S2': {'4Q++': None, | |
78 | + // 'Activité service C2L': None, | |
79 | + // . | |
80 | + // . | |
81 | + // . | |
82 | + // '2021_S2': {'4Q++': None, | |
83 | + // . | |
84 | + // . | |
85 | + // 'Test IAS': None, | |
86 | + // 'cahier des charges DT insu': None, | |
87 | + // 'ŒIL': None | |
88 | + // } | |
89 | + // } | |
90 | + | |
91 | + | |
73 | 92 | var periods = Object.keys(data) |
74 | 93 | var first_stacked_charges = Object.values(data)[0] |
75 | 94 | var projects = Object.keys(first_stacked_charges) |
76 | - console.log(projects) | |
77 | 95 | |
78 | - // periods = data | |
79 | 96 | var x = d3.scaleBand() |
80 | 97 | .domain(periods) |
81 | 98 | .range([0, width]) |
... | ... | @@ -109,33 +126,62 @@ |
109 | 126 | "#800080", |
110 | 127 | ]); |
111 | 128 | |
112 | - var stack_generator = d3.stack() | |
113 | - .keys(projects) | |
129 | + var stack_generator = d3.stack().keys(projects) | |
114 | 130 | |
131 | + // Building a list of dict, with projects as keys, like in the input dat, | |
132 | + // but with a new key, 'period' wich value is the period string for that line | |
133 | + // This is need for the d3js stack_generator function | |
115 | 134 | var stackable_data = [] |
116 | - Object.keys(data).forEach( function (period){ | |
135 | + Object.keys(data).forEach(function (period) { | |
117 | 136 | line = data[period]; |
118 | - line['period']=period; | |
137 | + line['period'] = period; | |
119 | 138 | stackable_data.push(line) |
120 | 139 | }); |
121 | 140 | |
122 | 141 | var stacked_data = stack_generator(stackable_data) |
123 | 142 | |
124 | - // var sel = d3.select("#demo2") | |
125 | - // .select('g') | |
126 | - // .selectAll('g.series') | |
127 | - // .data(stackedSeries) | |
128 | - // .join('g') | |
129 | - // .classed('series', true) | |
130 | - // .style('fill', (d) => colorScale(d.key)); | |
131 | - // | |
132 | - // sel.selectAll('rect') | |
133 | - // .data((d) => d) | |
134 | - // .join('rect') | |
135 | - // .attr('width', 40) | |
136 | - // .attr('y', (d) => yScale(d[1])) | |
137 | - // .attr('x', (d) => xScale(d.data.month) - 20) | |
138 | - // .attr('height', (d) => yScale(d[0]) - yScale(d[1])); | |
143 | + | |
144 | + // ---------------- | |
145 | + // Create a tooltip | |
146 | + // ---------------- | |
147 | + var tooltip = d3.select("#charge_div") | |
148 | + .append("div") | |
149 | + .style("opacity", 0) | |
150 | + .attr("class", "tooltip") | |
151 | + | |
152 | + // // Three function that change the tooltip when user hover / move / leave a cell | |
153 | + // var mouseover = function (d) { | |
154 | + // var subgroupName = d3.select(this.parentNode).datum().key; | |
155 | + // // var subgroupValue = d.data[subgroupName]; | |
156 | + // tooltip | |
157 | + // .html("subgroup: " + subgroupName + "<br>" + "Value: " + subgroupValue) | |
158 | + // .style("opacity", 1) | |
159 | + // } | |
160 | + | |
161 | + var mousemove = function (e, d) { | |
162 | + tooltip | |
163 | + .style("left", (e.x - 400) + "px") | |
164 | + .style("top", (e.y - 90) + "px") | |
165 | + } | |
166 | + | |
167 | + var mouseleave = function (d) { | |
168 | + tooltip | |
169 | + .transition() | |
170 | + .duration(100) | |
171 | + .style("opacity", 0) | |
172 | + } | |
173 | + | |
174 | + var mouseover = function (e, d) { | |
175 | + var project_name = d3.select(this.parentNode).datum().key | |
176 | + var project_charge = d.data[project_name] | |
177 | + tooltip.transition() | |
178 | + .duration(200) | |
179 | + .style("opacity", 1); | |
180 | + tooltip | |
181 | + .html("Project: " + project_name + "<br>" + "Charge: " + project_charge+"%") | |
182 | + .style("left", (e.x - 400) + "px") | |
183 | + .style("top", (e.y - 90) + "px"); | |
184 | + } | |
139 | 185 | |
140 | 186 | svg.append('g') |
141 | 187 | .selectAll('g') |
... | ... | @@ -152,21 +198,10 @@ |
152 | 198 | .attr("y", d => y(d[1])) |
153 | 199 | .attr("height", d => y(d[0]) - y(d[1])) |
154 | 200 | .attr("width", x.bandwidth()) |
155 | - | |
156 | - .on("mouseover", function (e, d) { | |
157 | - console.log(d) | |
158 | - div.transition() | |
159 | - .duration(200) | |
160 | - .style("opacity", .9); | |
161 | - div.html("Charge: " + d) | |
162 | - .style("left", (e.x + 10) + "px") | |
163 | - .style("top", (e.y - 50) + "px"); | |
164 | - }) | |
165 | - .on("mouseout", function (d) { | |
166 | - div.transition() | |
167 | - .duration(500) | |
168 | - .style("opacity", 0); | |
169 | - }); | |
201 | + .attr("stroke", "black") | |
202 | + .on("mouseover", mouseover) | |
203 | + .on("mousemove", mousemove) | |
204 | + .on("mouseleave", mouseleave); | |
170 | 205 | }); |
171 | 206 | </script> |
172 | 207 | {% endblock %} | ... | ... |