JSFiddle - React, Tailwind, and code Playground

by Kesav Telaprolu

HTML

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/6.1.1/highcharts.js"></script>
<script src="https://code.highcharts.com/6.1.1/highcharts-more.js"></script>
<div id="container" style="width: 1240px;        
             height: 688px;               
             border-radius: 10px;               
             border: 1px solid #dbdbdb;
             overflow:auto;
             position:relative">

</div>

CSS

/*
 * Legal Disclaimer
 *
    print '\n', 'Note that the webfonts share the TT sources'
 * These Fonts are licensed for unlimited use on domains and their subdomains of The Kantar Group.
 * It is illegal to download or use them on other websites.
 *
 * While the @font-face statements below may be modified by the client, this
 * disclaimer may not be removed.
 *
 * Lineto.com, 2016
 */

@font-face {
  font-family: "KantarBrownWeb-LightItalic";
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-LightItalic.eot");
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-LightItalic.eot?#iefix") format("embedded-opentype"), url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-LightItalic.woff2") format("woff2"), url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-LightItalic.woff") format("woff");
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: "KantarBrownWeb-BoldItalic";
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-BoldItalic.eot");
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-BoldItalic.eot?#iefix") format("embedded-opentype"), url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-BoldItalic.woff2") format("woff2"), url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-BoldItalic.woff") format("woff");
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: "KantarBrownWeb-Italic";
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-Italic.eot");
  src: url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-Italic.eot?#iefix") format("embedded-opentype"), url("https://riofontstorage.blob.core.windows.net/kantar-fonts/KantarBrownWeb-Italic.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
}

@font-face {
 ...

JavaScript

(input => {

var chosenBrandValues = [input.chosenBrand.marketShare, input.chosenBrand.powerInTheMind, input.chosenBrand.equityGap];
var categories = input.dataSeries.map(function(item) {
  return item.brandName;
});
var marketShareWidth;
var pimWidth;

var chartArray = [];
chartArray.push(chosenBrandValues[0]);
chartArray.push(chosenBrandValues[1]);
chartArray.sort(function(a, b) {
  return b - a
});

var scale = 105;

for (var i = 0; i < chartArray.length; i++) {
  if (chartArray[i] === chosenBrandValues[0]) {
    if (i === 0) {
      marketShareWidth = scale;
    } else {
      marketShareWidth = (chartArray[i] / chartArray[0]) * scale * scale;
      marketShareWidth = Math.sqrt(marketShareWidth);
    }
  } else if (chartArray[i] === chosenBrandValues[1]) {
    if (i === 0) {
      pimWidth = scale;
    } else {
      pimWidth = (chartArray[i] / chartArray[0]) * scale * scale;
      pimWidth = Math.sqrt(pimWidth);
    }

  }
}

//Calculating relative values
var barMaxHeight;
var chosenBData = input.dataSeries.map(function(item) {
  return item.marketFactorGain;
});
var compBData = input.dataSeries.map(function(item) {
  return item.marketFactorGLoss;
});
chosenBData.sort(function(a, b) {
  return b - a
});
compBData.sort(function(a, b) {
  return b - a
});
if (chosenBData[0] > compBData[0]) {
  barMaxHeight = chosenBData[0];
} else {
  barMaxHeight = compBData[0];
}
var chosenBrandData = input.dataSeries.map(function(item) {
  return item.marketFactorGLoss;
});
var compBrandData = input.dataSeries.map(function(item) {
  return item.marketFactorGain
});

GenerateChart(chosenBrandValues);

function GenerateChart(chosenBrandDetails) {
  //TITLE TEMPLATE

  var titleHtml =
    `
<div class="chartTitles">

<div id="title"></div>
<div id="subTitle"></div>

</div>`;


  //CHART TEMPLATE

  var chartHtml =
    `
<div id="chartContainer"><canvas id='chart' width='1180px' height='517px'></canvas></div>

`;


  //LEGEND TEMPLATE

  var legendHtml =
    `
<div...