assets/helpers.js
// Prepare data for horizontal bar as input to chartjs data
Prepare data for horizontal bar as input to chartjs data
Prepare data for horizontal bar as input to chartjs data
function generateTop(topEdcs, key) {
  var uniqueKeys = topEdcs
    .map(function (item) {
      return item[key];
    })
    .filter(function (v, i, a) {
      return a.indexOf(v) === i;
    })
    .slice(0, 5);
  var y2019 = [];
  var y2020 = [];
  uniqueKeys.map(function (ec) {
    var psp2019 = topEdcs.find(function (obj) {
      return obj[key] === ec && obj.Anno === "2019";
    });
    var psp2020 = topEdcs.find(function (obj) {
      return obj[key] === ec && obj.Anno === "2020";
    });
    y2019.push(psp2019 ? psp2019.total : null);
    y2020.push(psp2020 ? psp2020.total : null);
  });
  var colors = ECDBGCOLORS;
  var colors2019 = ECDBGCOLORS2019;
  if (key === "PSP") {
    colors = PSPBGCOLORS;
    colors2019 = PSPBGCOLORS2019;
  }
  uniqueKeys = uniqueKeys.map(function (item) {
    if (item == "AgID") {
      return "MyBank";
    } else if (item.startsWith("Automobile")) {
      return "ACI";
    } else if (item.startsWith("Agenzia delle")) {
      return "ADE";
    } else if (item.startsWith("Istituto Nazionale")) {
      return "INPS";
    } else {
      return item;
    }
  });
  return {
    labels: uniqueKeys,
    datasets: [
      {
        label: "2019",
        backgroundColor: colors2019,
        borderColor: "#ccc",
        borderWidth: 1,
        data: y2019,
      },
      {
        label: "2020",
        backgroundColor: colors,
        borderColor: "#ccc",
        borderWidth: 1,
        data: y2020,
      },
    ],
  };
}
function generateTop ( topEdcs , key ) { var uniqueKeys = topEdcs . map ( function ( item ) { return item [ key ] ; } ) . filter ( function ( v , i , a ) { return a . indexOf ( v ) === i ; } ) . slice ( 0 , 5 ) ; var y2019 = [ ] ; var y2020 = [ ] ; uniqueKeys . map ( function ( ec ) { var psp2019 = topEdcs . find ( function ( obj ) { return obj [ key ] === ec && obj . Anno === "2019" ; } ) ; var psp2020 = topEdcs . find ( function ( obj ) { return obj [ key ] === ec && obj . Anno === "2020" ; } ) ; y2019 . push ( psp2019 ? psp2019 . total : null ) ; y2020 . push ( psp2020 ? psp2020 . total : null ) ; } ) ; var colors = ECDBGCOLORS ; var colors2019 = ECDBGCOLORS2019 ; if ( key === "PSP" ) { colors = PSPBGCOLORS ; colors2019 = PSPBGCOLORS2019 ; } uniqueKeys = uniqueKeys . map ( function ( item ) { if ( item == "AgID" ) { return "MyBank" ; } else if ( item . startsWith ( "Automobile" ) ) { return "ACI" ; } else if ( item . startsWith ( "Agenzia delle" ) ) { return "ADE" ; } else if ( item . startsWith ( "Istituto Nazionale" ) ) { return "INPS" ; } else { return item ; } } ) ; return { labels : uniqueKeys , datasets : [ { label : "2019" , backgroundColor : colors2019 , borderColor : "#ccc" , borderWidth : 1 , data : y2019 , } , { label : "2020" , backgroundColor : colors , borderColor : "#ccc" , borderWidth : 1 , data : y2020 , } , ] , } ; }
Prepare data for horizontal bar as input to chartjs data
Prepare data for horizontal bar as input to chartjs data