Esempio n. 1
0
module.exports.showMapCountry = function(tooltipInstance, countryData, co2color, co2Colorbars) {
    if (countryData.co2intensity && co2Colorbars)
        co2Colorbars.forEach(function(c) { c.currentMarker(countryData.co2intensity) });
    var tooltip = d3.select(tooltipInstance._selector);
    tooltip.select('#country-flag')
        .attr('src', flags.flagUri(countryData.countryCode, 16));
    tooltip.select('#country-name')
        .text(translation.translate('zoneShortName.' + countryData.countryCode) || countryData.countryCode)
        .style('font-weight', 'bold');
    tooltip.select('.emission-rect')
        .style('background-color', countryData.co2intensity ? co2color(countryData.co2intensity) : 'gray');
    tooltip.select('.country-emission-intensity')
        .text(Math.round(countryData.co2intensity) || '?');

    var priceData = countryData.price || {};
    var hasPrice = priceData.value != null;
    tooltip.select('.country-spot-price')
        .text(hasPrice ? Math.round(priceData.value) : '?')
        .style('color', (priceData.value || 0) < 0 ? 'red' : undefined);
    tooltip.select('.country-spot-price-currency')
        .text(getSymbolFromCurrency(priceData.currency) || priceData.currency || '?')
    var hasFossilFuelData = countryData.fossilFuelRatio != null;
    var fossilFuelPercent = countryData.fossilFuelRatio * 100;
    tooltip.select('.lowcarbon-percentage')
        .text(hasFossilFuelData ? Math.round(100 - fossilFuelPercent) : '?');
    var hasRenewableData = countryData.renewableRatio != null;
    var renewablePercent = countryData.renewableRatio * 100;
    tooltip.select('.renewable-percentage')
        .text(hasRenewableData ? Math.round(renewablePercent) : '?');

    tooltipInstance.show()
}
Esempio n. 2
0
function constraintValue(entity, ontology){
  const key = constraintKey(entity);
  let value = '';
  const valueObj = entity[key][0];
  if (valueObj['@value']) {
    value = entity[key][0]['@value'];
  } else {
    const id = valueObj['@id'];
    value = ontology.entity[id].name;
  }

  let unit = entity['http://www.w3.org/ns/odrl/2/unit'];
  if (unit) {
    unit = unit[0]['@id'];

    const unitName = ontology.entity[unit];
    if (unitName !== undefined) {
      value = value + ' ' + unitName.name;
    } else {
      //Special case for currency codes
      if (unit.startsWith('http://cvx.iptc.org/iso4217a/')) {
        unit = unit.replace('http://cvx.iptc.org/iso4217a/', '');
        value = getSymbolFromCurrency(unit) + value;
      } else {
        value = value + ' ' + unit;
      }
    }
  }
  return value;
}