<commit_before>/**
 * Copyright 2014-2015 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

 /**
  * Renders the sunburst visualization. The parameter is the tree as returned
  * from the Personality Insights JSON API.
  */

'use strict';

const _ = require('underscore');
const extend = _.extend;
const pick = _.pick;

const ChartRenderer = require('./personality-chart-renderer');
const D3PersonalityProfileV2 = require('../d3-profile-wrappers/v2/index');
const D3PersonalityProfileV3 = require('../d3-profile-wrappers/v3/index');
const colors = require('./utilities/colors');


// Dependencies check
var dependencies = {
  'd3' : 'D3js'
};

Object.keys(dependencies).forEach(function(dependency) {
  if (typeof window[dependency] === 'undefined') {
    throw new Error(dependencies[dependency] + ' is not present. Personality Sunburst Chart can\'t render without it.');
  }
});



class PersonalitySunburstChart {

  constructor(options) {
    this._options = extend(this.defaultOptions(), pick(options, 'selector', 'version'));
    this._version = this._options.version;
    this._selector = this._options.selector;
    this.containerId = this._selector;
    this.visualizationWidth  = this._options.width  || '100%';
    this.visualizationHeight = this._options.height || '100%';
    this.width  = ((1/this._options.scale || 1) * 45) * 16.58;
    this.height = ((1/this._options.scale || 1) * 45) * 16.58;
    this.exclude = this._options.exclude || [];
    this.container = $(this.containerId),
    this.d3Container = d3.select('#' + this.containerId),
    this.dimW = this.width,
    this.dimH = this.height,
    this.d3vis = undefined,
    this.touchDiv = undefined,
    this.data = undefined,
    this.id = 'SystemUWidget',
    this.COLOR_PALLETTE = colors,
    this.loadingDiv = 'dummy'
  }

  defaultOptions() {
    return {
      version: 'v2'
    };
  }

  /**
   * Renders the sunburst visualization. The parameter is the tree as returned
   * from the Personality Insights JSON API.
   * It uses the arguments widgetId, widgetWidth, widgetHeight and personImageUrl
   * declared on top of this script.
   */
  show(theProfile, personImageUrl) {
    var self = this;
    const d3Profile = self.version === 'v3' ? new D3PersonalityProfileV3(theProfile) : new D3PersonalityProfileV2(theProfile);
    var widgetId = self.containerId;

    // Clear DOM element that will display the sunburst chart
    $(self.containerId).innerHTML = null;

    // Create widget
    var widget = {
      d3vis: d3.select('#' + widgetId).append('svg:svg').attr('width', self.visualizationWidth).attr('height', self.visualizationHeight).attr('viewBox', '0 -30 ' + self.height + ', ' + self.width),
      data: d3Profile.d3Json(),
      dimH: self.height,
      dimW: self.width,
      id: self.id,
      exclude: self.exclude,
      COLOR_PALLETTE: colors,
      loadingDiv: self.loadingDiv,
      switchState: function() {
        console.debug('[switchState]');
      },
      _layout: function() {
        console.debug('[_layout]');
      },<commit_msg>lib/index.js: minor cleanup - var -> const<commit_after>/**
 * Copyright 2014-2015 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

 /**
  * Renders the sunburst visualization. The parameter is the tree as returned
  * from the Personality Insights JSON API.
  */

'use strict';

const _ = require('underscore');
const extend = _.extend;
const pick = _.pick;

const ChartRenderer = require('./personality-chart-renderer');
const D3PersonalityProfileV2 = require('../d3-profile-wrappers/v2/index');
const D3PersonalityProfileV3 = require('../d3-profile-wrappers/v3/index');
const colors = require('./utilities/colors');


// Dependencies check
var dependencies = {
  'd3' : 'D3js'
};

Object.keys(dependencies).forEach(function(dependency) {
  if (typeof window[dependency] === 'undefined') {
    throw new Error(dependencies[dependency] + ' is not present. Personality Sunburst Chart can\'t render without it.');
  }
});



class PersonalitySunburstChart {

  constructor(options) {
    this._options = extend(this.defaultOptions(), pick(options, 'selector', 'version'));
    this._version = this._options.version;
    this._selector = this._options.selector;
    this.containerId = this._selector;
    this.visualizationWidth  = this._options.width  || '100%';
    this.visualizationHeight = this._options.height || '100%';
    this.width  = ((1/this._options.scale || 1) * 45) * 16.58;
    this.height = ((1/this._options.scale || 1) * 45) * 16.58;
    this.exclude = this._options.exclude || [];
    this.container = $(this.containerId),
    this.d3Container = d3.select('#' + this.containerId),
    this.dimW = this.width,
    this.dimH = this.height,
    this.d3vis = undefined,
    this.touchDiv = undefined,
    this.data = undefined,
    this.id = 'SystemUWidget',
    this.COLOR_PALLETTE = colors,
    this.loadingDiv = 'dummy'
  }

  defaultOptions() {
    return {
      version: 'v2'
    };
  }

  /**
   * Renders the sunburst visualization. The parameter is the tree as returned
   * from the Personality Insights JSON API.
   * It uses the arguments widgetId, widgetWidth, widgetHeight and personImageUrl
   * declared on top of this script.
   */
  show(theProfile, personImageUrl) {
    const self = this;
    const d3Profile = self.version === 'v3' ? new D3PersonalityProfileV3(theProfile) : new D3PersonalityProfileV2(theProfile);
    const widgetId = self.containerId;

    // Clear DOM element that will display the sunburst chart
    $(self.containerId).innerHTML = null;

    // Create widget
    var widget = {
      d3vis: d3.select('#' + widgetId).append('svg:svg').attr('width', self.visualizationWidth).attr('height', self.visualizationHeight).attr('viewBox', '0 -30 ' + self.height + ', ' + self.width),
      data: d3Profile.d3Json(),
      dimH: self.height,
      dimW: self.width,
      id: self.id,
      exclude: self.exclude,
      COLOR_PALLETTE: colors,
      loadingDiv: self.loadingDiv,
      switchState: function() {
        console.debug('[switchState]');
      },
      _layout: function() {
        console.debug('[_layout]');
      },
{'fraction_non_alphanumeric': 0.12845054792620336, 'fraction_numerical': 0.016923290331530033, 'mean_word_length': 3.4260282381829343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4375040', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2113, 'n_words': 600}