Projet

Général

Profil

0001-implement-line-charts.patch

Benjamin Dauvergne, 25 juillet 2016 17:08

Télécharger (4,57 ko)

Voir les différences:

Subject: [PATCH] implement line charts

 bijoe/forms.py                        |  3 ++-
 bijoe/static/js/bijoe.js              | 32 +++++++++++++++++++++++++-------
 bijoe/templates/bijoe/cube_chart.html |  7 +++++--
 3 files changed, 32 insertions(+), 10 deletions(-)
bijoe/forms.py
72 72
    representation = forms.ChoiceField(
73 73
        label=_(u'Représentation'),
74 74
        choices=[('table', _('tableau')),
75
                 ('graphical', _('graphique')),],
75
                 ('bar', _('batons')),
76
                 ('line', _('lignes')),],
76 77
        widget=forms.RadioSelect())
77 78

  
78 79
    def __init__(self, *args, **kwargs):
bijoe/static/js/bijoe.js
174 174
}
175 175

  
176 176
function draw_barchart(canvas, dimensions, measures, measure, data) {
177
    draw_chart("Bar", canvas, dimensions, measures, measure, data);
178
}
179

  
180
function draw_linechart(canvas, dimensions, measures, measure, data) {
181
    draw_chart("Line", canvas, dimensions, measures, measure, data);
182
}
183

  
184
function draw_chart(kind, canvas, dimensions, measures, measure, data) {
177 185
  /* Draw bar chart given a cavans element, a list of dimensions, a list of measure, the name of the
178 186
   * measure to represent and data rows containing in the same order the dimensions and measures
179 187
   * values */
......
207 215
  option.graphTitle = wrap_text(
208 216
      capfirst(measures[j].label) + " par " + human_join(dimension_labels), 30)
209 217

  
210
  dataset.fillColor = spaced_hsla(j, measures.length, 100, 30, 0.5);
211
  dataset.strokeColor = spaced_hsla(j, measures.length, 100, 30, 0.75);
212
  dataset.highlightFill = spaced_hsla(j, measures.length, 100, 30, 0.75);
213
  dataset.highlightStroke = spaced_hsla(j, measures.length, 100, 30, 1);
218
  if (kind != "Line") {
219
    dataset.fillColor = spaced_hsla(j, measures.length, 100, 30, 0.5);
220
    dataset.highlightFill = spaced_hsla(j, measures.length, 100, 30, 0.75);
221
    dataset.strokeColor = spaced_hsla(j, measures.length, 100, 30, 0.75);
222
    dataset.highlightStroke = spaced_hsla(j, measures.length, 100, 30, 1);
223
  } else {
224
    dataset.fillColor = "rgba(250,250,250,0)";
225
    dataset.highlightFill = "rgba(250,250,250,0)";
226
    dataset.strokeColor = spaced_hsla(j, measures.length, 100, 20, 0.5);
227
    dataset.highlightStroke = spaced_hsla(j, measures.length, 100, 20, 0.75);
228
    dataset.pointColor = spaced_hsla(j, measures.length, 100, 30, 1);
229
    dataset.pointStrokeColor = "rgba(250,250,250,1)";
230
    dataset.pointDotRadius = 4;
231
    dataset.pointDotStrokeWidth = 5;
232
  }
214 233

  
215 234
  var n = data.length;
216 235
  for (var i = 0; i < n; i++) {
......
257 276
      scaleShowVerticalLines: true,
258 277

  
259 278
      //Boolean - If there is a stroke on each bar
260
      // barShowStroke : true,
279
      barShowStroke : true,
261 280

  
262 281
      //Number - Pixel width of the bar stroke
263 282
      barStrokeWidth : 2,
......
268 287
      //Number - Spacing between data sets within X values
269 288
      barDatasetSpacing : 1,
270 289
  });
271
  console.log(linedata);
272
  new Chart(ctx).Bar(linedata, option);
290
  new Chart(ctx)[kind](linedata, option);
273 291
}
274 292

  
275 293
/* jQuery event handlers and widget setup */
bijoe/templates/bijoe/cube_chart.html
16 16
    if ("{{ measure.name }}" == "percent") {
17 17
      draw_piechart(canvas, dimensions, measures, "{{ measure.name }}", data);
18 18
    } else {
19
      draw_barchart(canvas, dimensions, measures, "{{ measure.name }}", data);
20

  
19
      {% if representation == 'bar' %}
20
        draw_barchart(canvas, dimensions, measures, "{{ measure.name }}", data);
21
      {% else %}
22
        draw_linechart(canvas, dimensions, measures, "{{ measure.name }}", data);
23
      {% endif %}
21 24
      /* Allow getting a PNG without using 'Save image as' */
22 25
      $(".bijoe-png-button").on('click', function() {
23 26
         this.href = toDataURL($(this).next("canvas")[0], "graph.png");
24
-