cms/app-client/app/components/visu-langues.js
changeset 393 5ef3bfef0bff
parent 392 4fbe94af93e8
child 394 48458e099b05
equal deleted inserted replaced
392:4fbe94af93e8 393:5ef3bfef0bff
     5 
     5 
     6 export default Ember.Component.extend({
     6 export default Ember.Component.extend({
     7 
     7 
     8     constants: Ember.inject.service(),
     8     constants: Ember.inject.service(),
     9     filter: Ember.inject.service(),
     9     filter: Ember.inject.service(),
       
    10     colors: Ember.inject.service(),
    10 
    11 
    11     filterObserver: Ember.observer('filter.language', function() {
    12     filterObserver: Ember.observer('filter.language', function() {
    12         Ember.$('.node').removeClass("selected");
    13         Ember.$('.node').removeClass("selected");
    13         Ember.$('.node[data-id="' + this.get('filter').get('language') + '"]').addClass("selected");
    14         Ember.$('.node[data-id="' + this.get('filter').get('language') + '"]').addClass("selected");
    14     }),
    15     }),
    45                 .value(function(d){
    46                 .value(function(d){
    46                     return Math.floor((((d.value - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin);
    47                     return Math.floor((((d.value - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin);
    47                 })
    48                 })
    48                 .round(false);
    49                 .round(false);
    49 
    50 
    50                 console.log('width', width, Ember.$('#' + self.get('elementId')).parent().width(), Ember.$('#' + self.get('elementId')).parent().parent().width(), Ember.$('#' + self.get('elementId')).parent().parent().parent().width());
       
    51             var element = d3.select('#' + self.get('elementId'))
    51             var element = d3.select('#' + self.get('elementId'))
    52                 .style("width", width + margin.left + margin.right + 'px')
    52                 .style("width", width + margin.left + margin.right + 'px')
    53                 .style("height", height + margin.bottom + margin.top + 'px')
    53                 .style("height", height + margin.bottom + margin.top + 'px')
    54                 .style("margin-left", -margin.left + "px")
    54                 .style("margin-left", -margin.left + "px")
    55                 .style("margin-right", -margin.right + "px")
    55                 .style("margin-right", -margin.right + "px")
   120                     .style("height", function(d) { return y(d.y + d.dy) - y(d.y) + 'px'; })
   120                     .style("height", function(d) { return y(d.y + d.dy) - y(d.y) + 'px'; })
   121                     .style("left", function(d) { return x(d.x) + 'px'; })
   121                     .style("left", function(d) { return x(d.x) + 'px'; })
   122                     .style("top", function(d) { return y(d.y) + 'px'; });
   122                     .style("top", function(d) { return y(d.y) + 'px'; });
   123             }
   123             }
   124 
   124 
   125             function hexadecimalToInteger(hexadecimal) {
       
   126                 var integer = [];
       
   127                 for(var i = 1; i < 7; i += 2) {
       
   128                     integer.push(parseInt(hexadecimal.slice(i, i + 2), 16));
       
   129                 }
       
   130                 return integer;
       
   131             }
       
   132 
       
   133             function display(d) {
   125             function display(d) {
   134                 breadcrumbs
   126                 breadcrumbs
   135                     .datum(d.parent)
   127                     .datum(d.parent)
   136                     .html(name(d))
   128                     .html(name(d))
   137                     .on("click", transition);
   129                     .on("click", transition);
   147                     .attr("data-id", function(d) { return d.id; });
   139                     .attr("data-id", function(d) { return d.id; });
   148 
   140 
   149                 var dMin = Math.min.apply(null, d._children.map(function(d){ return d.count; }));
   141                 var dMin = Math.min.apply(null, d._children.map(function(d){ return d.count; }));
   150                 var dMax = Math.max.apply(null, d._children.map(function(d){ return d.count; }));
   142                 var dMax = Math.max.apply(null, d._children.map(function(d){ return d.count; }));
   151 
   143 
   152                 function shade(d) {
       
   153                     var color = "#777777";
       
   154                     var aColor = hexadecimalToInteger(color);
       
   155                     var solidColor = "#333333";
       
   156                     var aSolidColor = hexadecimalToInteger(solidColor);
       
   157                     var aFillColor = [];
       
   158                     for(var i = 0; i < 3; i++) {
       
   159                         aFillColor.push((d.count - dMin) * (aSolidColor[i] - aColor[i]) / (dMax - dMin) + aColor[i]);
       
   160                     }
       
   161                     return '#' + (aFillColor.map(i => parseInt(i).toString(16))).join('');
       
   162                 }
       
   163 
       
   164                 node.attr("class", function(d) { return "node" + ( d.id === self.get('filter').get('language') ? " selected" : "" ); })
   144                 node.attr("class", function(d) { return "node" + ( d.id === self.get('filter').get('language') ? " selected" : "" ); })
   165                     .call(position)
   145                     .call(position)
   166                     .style("background-color", function(d) { return shade(d); })
   146                     .style("background-color", function(d) { return self.get('colors').shadeLinear(d.count,dMin,dMax); })
   167                     .on("click", selectHandler);
   147                     .on("click", selectHandler);
   168 
   148 
   169                 node.filter(function(d) { return d._children; })
   149                 node.filter(function(d) { return d._children; })
   170                     .classed("children", true)
   150                     .classed("children", true)
   171                     .on("click", transition)
   151                     .on("click", transition)