Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const plotLinesChart = function() {
  2.   const data = this.dyk.linesChart.data;
  3.   if (data.length == 0 || this.commitLocsChartPlotted) {
  4.     return;
  5.   }
  6.  
  7.   const countTicks = 10;
  8.   const { width, height } = this.box;
  9.   const { left, bottom, top } = this.offset;
  10.   const linesSvg = d3.select(this.$refs.linesSvg);
  11.  
  12.   const g = linesSvg.append('g');
  13.  
  14.   const allData = data.slice().sort((a, b) => {
  15.     a = +a.lines;
  16.     b = +b.lines;
  17.  
  18.     return a < b ? -1 : (a > b ? 1 : 0);
  19.   });
  20.  
  21.   let represented = splitByBins(allData);
  22.   represented = represented.concat([{
  23.     lines: represented.slice(-1)[0].lines * 2,
  24.     freq: 0
  25.   }]);
  26.  
  27.   const xDomain = represented.map(d => d.lines);
  28.  
  29.   const x = d3.scalePoint()
  30.     .rangeRound([left, width])
  31.     .domain(xDomain)
  32.     .padding(0.15);
  33.  
  34.   const linesAxis = d3.axisBottom()
  35.     .scale(x)
  36.     .tickFormat(siFormatter)
  37.     .tickSizeInner(this.tickSize);
  38.   const xg = g.append('g')
  39.     .call(linesAxis)
  40.     .call(move(0, height - bottom));
  41.  
  42.   const freqsDomain = d3.extent(represented, d => d.freq);
  43.   const y = d3.scaleLinear()
  44.     .range([height - bottom, top])
  45.     .domain(freqsDomain);
  46.   const freqsAxis = d3.axisLeft()
  47.     .scale(y)
  48.     .tickFormat(siFormatter)
  49.     .tickSizeInner(this.tickSize);
  50.   const yg = g.append('g')
  51.     .call(freqsAxis)
  52.     .call(move(left, 0));
  53.  
  54.   const xTextGroup = xg.append('g')
  55.     .call(move(width/2 + left/2, bottom - 5));
  56.  
  57.   xTextGroup.append('text')
  58.     .text('Number of lines per commit')
  59.     .attr('text-anchor', 'middle')
  60.     .attr('alignment-baseline', 'middle');
  61.  
  62.   const yTextGroup = yg.append('g')
  63.     .call(move(-left + 5, height/2 - bottom/2));
  64.  
  65.   yTextGroup.append('text')
  66.     .attr('text-anchor', 'middle')
  67.     .attr('alignment-baseline', 'middle')
  68.     .attr('transform', 'rotate(270)')
  69.     .text('Number of commits');
  70.  
  71.   // // Bars with relatively small value may have zero height due to interpolation.
  72.   const barWidth = 3;
  73.   g.append('g')
  74.     .selectAll('g')
  75.     .data(represented)
  76.     .enter()
  77.       .append('rect')
  78.       .attr('width', x(xDomain[1]) - x(xDomain[0]) - 2)
  79.       .attr('height', d => height - bottom - y(d.freq))
  80.       .attr('transform', d => {
  81.  
  82.         const _x = x(d.lines) + 1;
  83.         const _y = y(d.freq);
  84.         return `translate(${_x}, ${_y})`;
  85.       })
  86.       .attr('fill', colors.primary);
  87.  
  88. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement