<commit_before>/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @fileoverview Saving and restoring the state of a JS-Intepreter.
 * @author fraser@google.com (Neil Fraser)
 */
'use strict';

function deserialize(json, interpreter) {
  function decodeValue(value) {
    if (value && typeof value === 'object') {
      var data;
      if ((data = value['#'])) {
       // Object reference: {'#': 42}
       value = objectList[data];
        if (!value) {
          throw ReferenceError('Object reference not found: ' + data);
        }
        return value;
      }
      if ((data = value['Number'])) {
        // Special number: {'Number': 'Infinity'}
        return Number(data);
      }
      if ((data = value['Value'])) {
        // Special value: {'Value': 'undefined'}
        if (value['Value'] === 'undefined') {
          return undefined;
        }
      }
    }
    return value;
  }
  var stack = interpreter.stateStack;
  if (!Array.isArray(json)) {
    throw TypeError('Top-level JSON is not a list.');
  }
  if (!stack.length) {
    // Require native functions to be present.
    throw Error('Interpreter must be initialized prior to deserialization.');
  }
  // Find all native functions in existing interpreter.
  var objectList = [];
  objectHunt_(stack, objectList);
  var functionHash = Object.create(null);
  for (var i = 0; i < objectList.length; i++) {
    if (typeof objectList[i] == 'function') {
      functionHash[objectList[i].id] = objectList[i];
    }
  }
  // First pass: Create object stubs for every object.
  objectList = [];
  for (var i = 0; i < json.length; i++) {
    var jsonObj = json[i];
    var obj;
    switch (jsonObj['type']) {
      case 'Map':
        obj = Object.create(null);
        break;
      case 'Object':
        obj = {};
        break;
      case 'ScopeReference':
        obj = Interpreter.SCOPE_REFERENCE;
        break;
      case 'Function':
        obj = functionHash[jsonObj['id']];
        if (!obj) {
          throw RangeError('Function ID not found: ' + jsonObj['id']);
        }
        break;
      case 'Array':
        // Currently we assume that Arrays are not sparse.
        obj = [];
        break;
      case 'Date':
        obj = new Date(jsonObj['data']);
        if (isNaN(obj)) {
          throw TypeError('Invalid date: ' + jsonObj['data']);
        }
        break;
      case 'RegExp':
        obj = RegExp(jsonObj['source'], jsonObj['flags']);
        break;
      case 'PseudoObject':
        obj = new Interpreter.Object(null);
        break;
      case 'Scope':
        obj = new Interpreter.Scope(undefined, undefined, undefined);
        break;
      case 'State':
        obj = new Interpreter.State(undefined, undefined);
        break;
      case 'Node':
        obj = new interpreter.nodeConstructor();
        break;
      default:
        throw TypeError('Unknown type: ' + jsonObj['type']);
    }
    objectList[i] = obj;
  }
  // Second pass: Populate properties for every object.
  for (var i = 0; i < json.length; i++) {
    var jsonObj = json[i];
    var obj = objectList[i];
    // Repopulate objects.
    var props = jsonObj['props'];
    if (props) {
      var nonConfigurable = jsonObj['nonConfigurable'] || [];
      var nonEnumerable = jsonObj['nonEnumerable'] || [];
      var nonWritable = jsonObj['nonWritable'] || [];
      var getter = jsonObj['getter'] || [];
      var setter = jsonObj['setter'] || [];
      var names = Object.getOwnPropertyNames(props);
      for (var j = 0; j < names.length; j++) {
        var name = names[j];
        var descriptor = {
          configurable: nonConfigurable.indexOf(name) === -1,
          enumerable: nonEnumerable.indexOf(name) === -1
        };
        var hasGetter = getter.indexOf(name) !== -1;
        var hasSetter = setter.indexOf(name) !== -1;
        if (hasGetter || hasSetter) {
          if (hasGetter) {
            descriptor.get = interpreter.setProperty.placeholderGet_;
          }
          if (hasSetter) {
            descriptor.set = interpreter.setProperty.placeholderSet_;
          }
        } else {
          descriptor.value = decodeValue(props[name]);
          descriptor.writable = nonWritable.indexOf(name) === -1;
        }
        Object.defineProperty(obj, name, descriptor);
      }
    }
    // Repopulate arrays.
    if (Array.isArray(obj)) {
      var data = jsonObj['data'];
      if (data) {
        for (var j = 0; j < data.length; j++) {
          obj.push(decodeValue(data[j]));
        }
      }
    }
  }
  // First object is the interpreter.
  var root = objectList[0];
  for (var prop in root) {
    interpreter[prop] = root[prop];
  }
}

function serialize(interpreter) {
  function encodeValue(value) {
    if (value && (typeof value === 'object' || typeof value === 'function')) {
      var ref = objectList.indexOf(value);
      if (ref === -1) {
        throw RangeError('Object not found in table.');
      }
      return {'#': ref};
    }
    if (value === undefined) {
      return {'Value': 'undefined'};
    }
    if (typeof value === 'number') {
      if (value === Infinity) {
        return {'Number': 'Infinity'};
      } else if (value === -Infinity) {
        return {'Number': '-Infinity'};
      } else if (isNaN(value)) {
        return {'Number': 'NaN'};
      } else if (1 / value === -Infinity) {
        return {'Number': '-0'};
      }
    }
    return value;
  }
  // Shallow-copy all properties of interest onto a root object.
  var properties = [
    'OBJECT', 'OBJECT_PROTO',
    'FUNCTION', 'FUNCTION_PROTO',
    'ARRAY', 'ARRAY_PROTO',
    'REGEXP', 'REGEXP_PROTO',
    'BOOLEAN',
    'DATE',
    'NUMBER',
    'STRING',
    'ERROR',
    'EVAL_ERROR',
    'RANGE_ERROR',
    'REFERENCE_ERROR',
    'SYNTAX_ERROR',
    'TYPE_ERROR',
    'URI_ERROR',
    'globalScope',
    'globalObject',
    'stateStack'
  ];
  var root = Object.create(null);
  for (var i = 0; i < properties.length; i++) {
    root[properties[i]] = interpreter[properties[i]];
  }

  // Find all objects.
  var objectList = [];
  objectHunt_(root, objectList);
  // Serialize every object.
  var json = [];
  for (var i = 0; i < objectList.length; i++) {
    var jsonObj = Object.create(null);
    json.push(jsonObj);
    var obj = objectList[i];
    // Uncomment this line for a debugging label.
    //jsonObj['#'] = i;
    switch (Object.getPrototypeOf(obj)) {
      case null:
        jsonObj['type'] = 'Map';
        break;
      case Object.prototype:
        if (obj === Interpreter.SCOPE_REFERENCE) {
          jsonObj['type'] = 'ScopeReference';
          continue;  // No need to index properties.
        } else {
          jsonObj['type'] = 'Object';
        }
        break;
      case Function.prototype:
        jsonObj['type'] = 'Function';
        jsonObj['id'] = obj.id;
        if (obj.id === undefined) {
          throw Error('Native function has no ID: ' + obj);
        }
        continue;  // No need to index properties.
      case Array.prototype:
        // Currently we assume that Arrays are not sparse.
        jsonObj['type'] = 'Array';
        if (obj.length) {
          jsonObj['data'] = obj.map(encodeValue);
        }
        continue;  // No need to index properties.
      case Date.prototype:
        jsonObj['type'] = 'Date';
        jsonObj['data'] = obj.toJSON();
        continue;  // No need to index properties.
      case RegExp.prototype:
        jsonObj['type'] = 'RegExp';
        jsonObj['source'] = obj.source;
        jsonObj['flags'] = obj.flags;
        continue;  // No need to index properties.
      case Interpreter.Object.prototype:
        jsonObj['type'] = 'PseudoObject';
        break;
      case Interpreter.Scope.prototype:
        jsonObj['type'] = 'Scope';
        break;
      case Interpreter.State.prototype:
        jsonObj['type'] = 'State';
        break;
      case interpreter.nodeConstructor.prototype:
        jsonObj['type'] = 'Node';
        break;
      default:
        throw TypeError('Unknown type: ' + obj);
    }
    var props = Object.create(null);
    var nonConfigurable = [];
    var nonEnumerable = [];
    var nonWritable = [];
    var getter = [];
    var setter = [];
    var names = Object.getOwnPropertyNames(obj);
    for (var j = 0; j < names.length; j++) {
      var name = names[j];
      var descriptor = Object.getOwnPropertyDescriptor(obj, name);
      props[name] = encodeValue(descriptor.value);
      if (!descriptor.configurable) {
        nonConfigurable.push(name);
      }
      if (!descriptor.enumerable) {
        nonEnumerable.push(name);
      }
      if (!descriptor.writable) {
        nonWritable.push(name);
      }
      if (descriptor.get) {
        getter.push(name);
      }
      if (descriptor.set) {
        setter.push(name);
      }
    }
    if (names.length) {
      jsonObj['props'] = props;
    }
    if (nonConfigurable.length) {
      jsonObj['nonConfigurable'] = nonConfigurable;
    }
    if (nonEnumerable.length) {
      jsonObj['nonEnumerable'] = nonEnumerable;
    }
    if (nonWritable.length) {
      jsonObj['nonWritable'] = nonWritable;
    }
    if (getter.length) {
      jsonObj['getter'] = getter;
    }
    if (setter.length) {
      jsonObj['setter'] = setter;
    }
  }
  return json;
}

// Recursively search the stack to find all non-primitives.
function objectHunt_(node, objectList) {
  if (node && (typeof node === 'object' || typeof node === 'function')) {
    if (objectList.indexOf(node) != -1) {
      return;
    }
    objectList.push(node);
    if (typeof node === 'object') {  // Recurse.
      var names = Object.getOwnPropertyNames(node);
      for (var i = 0; i < names.length; i++) {
        try {
          objectHunt_(node[names[i]], objectList);
        } catch (e) {
          // Accessing some properties may trigger a placeholder getter.
          // Squelch this error, but re-throw any others.
          if (e.message !== 'Placeholder getter') {
            throw e;
          }
        }
      }
    }
  }
}
<commit_msg>Fix serialization/deserialization.<commit_after>/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @fileoverview Saving and restoring the state of a JS-Intepreter.
 * @author fraser@google.com (Neil Fraser)
 */
'use strict';

function deserialize(json, interpreter) {
  function decodeValue(value) {
    if (value && typeof value === 'object') {
      var data;
      if ((data = value['#'])) {
       // Object reference: {'#': 42}
       value = objectList[data];
        if (!value) {
          throw ReferenceError('Object reference not found: ' + data);
        }
        return value;
      }
      if ((data = value['Number'])) {
        // Special number: {'Number': 'Infinity'}
        return Number(data);
      }
      if ((data = value['Value'])) {
        // Special value: {'Value': 'undefined'}
        if (value['Value'] === 'undefined') {
          return undefined;
        }
      }
    }
    return value;
  }
  var stack = interpreter.stateStack;
  if (!Array.isArray(json)) {
    throw TypeError('Top-level JSON is not a list.');
  }
  if (!stack.length) {
    // Require native functions to be present.
    throw Error('Interpreter must be initialized prior to deserialization.');
  }
  // Find all native functions in existing interpreter.
  var objectList = [];
  objectHunt_(stack, objectList);
  var functionHash = Object.create(null);
  for (var i = 0; i < objectList.length; i++) {
    if (typeof objectList[i] == 'function') {
      functionHash[objectList[i].id] = objectList[i];
    }
  }
  // Constructors for objects within Acorn.
  var NODE_CONSTRUCTOR = interpreter.ast.constructor;
  var NODE_LOC_CONSTRUCTOR = interpreter.ast.loc &&
      interpreter.ast.loc.constructor;
  var LINE_LOC_CONSTRUCTOR = interpreter.ast.loc &&
      interpreter.ast.loc.end.constructor;
  // First pass: Create object stubs for every object.
  objectList = [];
  for (var i = 0; i < json.length; i++) {
    var jsonObj = json[i];
    var obj;
    switch (jsonObj['type']) {
      case 'Map':
        obj = Object.create(null);
        break;
      case 'Object':
        obj = {};
        break;
      case 'ScopeReference':
        obj = Interpreter.SCOPE_REFERENCE;
        break;
      case 'Function':
        obj = functionHash[jsonObj['id']];
        if (!obj) {
          throw RangeError('Function ID not found: ' + jsonObj['id']);
        }
        break;
      case 'Array':
        // Currently we assume that Arrays are not sparse.
        obj = [];
        break;
      case 'Date':
        obj = new Date(jsonObj['data']);
        if (isNaN(obj)) {
          throw TypeError('Invalid date: ' + jsonObj['data']);
        }
        break;
      case 'RegExp':
        obj = RegExp(jsonObj['source'], jsonObj['flags']);
        break;
      case 'PseudoObject':
        obj = new Interpreter.Object(null);
        break;
      case 'Scope':
        obj = new Interpreter.Scope(undefined, undefined, undefined);
        break;
      case 'State':
        obj = new Interpreter.State(undefined, undefined);
        break;
      case 'Node':
        obj = new NODE_CONSTRUCTOR();
        break;
      case 'NodeLoc':
        obj = new NODE_LOC_CONSTRUCTOR();
        break;
      case 'LineLoc':
        obj = new LINE_LOC_CONSTRUCTOR();
        break;
      default:
        throw TypeError('Unknown type: ' + jsonObj['type']);
    }
    objectList[i] = obj;
  }
  // Second pass: Populate properties for every object.
  for (var i = 0; i < json.length; i++) {
    var jsonObj = json[i];
    var obj = objectList[i];
    // Repopulate objects.
    var props = jsonObj['props'];
    if (props) {
      var nonConfigurable = jsonObj['nonConfigurable'] || [];
      var nonEnumerable = jsonObj['nonEnumerable'] || [];
      var nonWritable = jsonObj['nonWritable'] || [];
      var getter = jsonObj['getter'] || [];
      var setter = jsonObj['setter'] || [];
      var names = Object.getOwnPropertyNames(props);
      for (var j = 0; j < names.length; j++) {
        var name = names[j];
        var descriptor = {
          configurable: nonConfigurable.indexOf(name) === -1,
          enumerable: nonEnumerable.indexOf(name) === -1
        };
        var hasGetter = getter.indexOf(name) !== -1;
        var hasSetter = setter.indexOf(name) !== -1;
        if (hasGetter || hasSetter) {
          if (hasGetter) {
            descriptor.get = interpreter.setProperty.placeholderGet_;
          }
          if (hasSetter) {
            descriptor.set = interpreter.setProperty.placeholderSet_;
          }
        } else {
          descriptor.value = decodeValue(props[name]);
          descriptor.writable = nonWritable.indexOf(name) === -1;
        }
        Object.defineProperty(obj, name, descriptor);
      }
    }
    // Repopulate arrays.
    if (Array.isArray(obj)) {
      var data = jsonObj['data'];
      if (data) {
        for (var j = 0; j < data.length; j++) {
          obj.push(decodeValue(data[j]));
        }
      }
    }
  }
  // First object is the interpreter.
  var root = objectList[0];
  for (var prop in root) {
    interpreter[prop] = root[prop];
  }
}

function serialize(interpreter) {
  function encodeValue(value) {
    if (value && (typeof value === 'object' || typeof value === 'function')) {
      var ref = objectList.indexOf(value);
      if (ref === -1) {
        throw RangeError('Object not found in table.');
      }
      return {'#': ref};
    }
    if (value === undefined) {
      return {'Value': 'undefined'};
    }
    if (typeof value === 'number') {
      if (value === Infinity) {
        return {'Number': 'Infinity'};
      } else if (value === -Infinity) {
        return {'Number': '-Infinity'};
      } else if (isNaN(value)) {
        return {'Number': 'NaN'};
      } else if (1 / value === -Infinity) {
        return {'Number': '-0'};
      }
    }
    return value;
  }
  // Shallow-copy all properties of interest onto a root object.
  var properties = [
    'OBJECT', 'OBJECT_PROTO',
    'FUNCTION', 'FUNCTION_PROTO',
    'ARRAY', 'ARRAY_PROTO',
    'REGEXP', 'REGEXP_PROTO',
    'BOOLEAN',
    'DATE',
    'NUMBER',
    'STRING',
    'ERROR',
    'EVAL_ERROR',
    'RANGE_ERROR',
    'REFERENCE_ERROR',
    'SYNTAX_ERROR',
    'TYPE_ERROR',
    'URI_ERROR',
    'globalScope',
    'globalObject',
    'stateStack'
  ];
  var root = Object.create(null);
  for (var i = 0; i < properties.length; i++) {
    root[properties[i]] = interpreter[properties[i]];
  }

  // Constructors for objects within Acorn.
  var NODE_CONSTRUCTOR = interpreter.ast.constructor;
  var NODE_LOC_CONSTRUCTOR = interpreter.ast.loc &&
      interpreter.ast.loc.constructor;
  var LINE_LOC_CONSTRUCTOR = interpreter.ast.loc &&
      interpreter.ast.loc.end.constructor;
  // Find all objects.
  var objectList = [];
  objectHunt_(root, objectList);
  // Serialize every object.
  var json = [];
  for (var i = 0; i < objectList.length; i++) {
    var jsonObj = Object.create(null);
    json.push(jsonObj);
    var obj = objectList[i];
    // Uncomment this line for a debugging label.
    //jsonObj['#'] = i;
    switch (Object.getPrototypeOf(obj)) {
      case null:
        jsonObj['type'] = 'Map';
        break;
      case Object.prototype:
        if (obj === Interpreter.SCOPE_REFERENCE) {
          jsonObj['type'] = 'ScopeReference';
          continue;  // No need to index properties.
        } else {
          jsonObj['type'] = 'Object';
        }
        break;
      case Function.prototype:
        jsonObj['type'] = 'Function';
        jsonObj['id'] = obj.id;
        if (obj.id === undefined) {
          throw Error('Native function has no ID: ' + obj);
        }
        continue;  // No need to index properties.
      case Array.prototype:
        // Currently we assume that Arrays are not sparse.
        jsonObj['type'] = 'Array';
        if (obj.length) {
          jsonObj['data'] = obj.map(encodeValue);
        }
        continue;  // No need to index properties.
      case Date.prototype:
        jsonObj['type'] = 'Date';
        jsonObj['data'] = obj.toJSON();
        continue;  // No need to index properties.
      case RegExp.prototype:
        jsonObj['type'] = 'RegExp';
        jsonObj['source'] = obj.source;
        jsonObj['flags'] = obj.flags;
        continue;  // No need to index properties.
      case Interpreter.Object.prototype:
        jsonObj['type'] = 'PseudoObject';
        break;
      case Interpreter.Scope.prototype:
        jsonObj['type'] = 'Scope';
        break;
      case Interpreter.State.prototype:
        jsonObj['type'] = 'State';
        break;
      case NODE_CONSTRUCTOR.prototype:
        jsonObj['type'] = 'Node';
        break;
      case NODE_LOC_CONSTRUCTOR.prototype:
        jsonObj['type'] = 'NodeLoc';
        break;
      case LINE_LOC_CONSTRUCTOR.prototype:
        jsonObj['type'] = 'LineLoc';
        break;
      default:
        throw TypeError('Unknown type: ' + obj);
    }
    var props = Object.create(null);
    var nonConfigurable = [];
    var nonEnumerable = [];
    var nonWritable = [];
    var getter = [];
    var setter = [];
    var names = Object.getOwnPropertyNames(obj);
    for (var j = 0; j < names.length; j++) {
      var name = names[j];
      var descriptor = Object.getOwnPropertyDescriptor(obj, name);
      props[name] = encodeValue(descriptor.value);
      if (!descriptor.configurable) {
        nonConfigurable.push(name);
      }
      if (!descriptor.enumerable) {
        nonEnumerable.push(name);
      }
      if (!descriptor.writable) {
        nonWritable.push(name);
      }
      if (descriptor.get) {
        getter.push(name);
      }
      if (descriptor.set) {
        setter.push(name);
      }
    }
    if (names.length) {
      jsonObj['props'] = props;
    }
    if (nonConfigurable.length) {
      jsonObj['nonConfigurable'] = nonConfigurable;
    }
    if (nonEnumerable.length) {
      jsonObj['nonEnumerable'] = nonEnumerable;
    }
    if (nonWritable.length) {
      jsonObj['nonWritable'] = nonWritable;
    }
    if (getter.length) {
      jsonObj['getter'] = getter;
    }
    if (setter.length) {
      jsonObj['setter'] = setter;
    }
  }
  return json;
}

// Recursively search the stack to find all non-primitives.
function objectHunt_(node, objectList) {
  if (node && (typeof node === 'object' || typeof node === 'function')) {
    if (objectList.indexOf(node) != -1) {
      return;
    }
    objectList.push(node);
    if (typeof node === 'object') {  // Recurse.
      var names = Object.getOwnPropertyNames(node);
      for (var i = 0; i < names.length; i++) {
        try {
          objectHunt_(node[names[i]], objectList);
        } catch (e) {
          // Accessing some properties may trigger a placeholder getter.
          // Squelch this error, but re-throw any others.
          if (e.message !== 'Placeholder getter') {
            throw e;
          }
        }
      }
    }
  }
}
<|endoftext|>


<commit_before>
var notes_flat = ['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B'];
var notes_sharp = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];

var chord_type = ['', 'm', 'dim', 'aug', 'Maj7', 'm7', '7', 'm7b5', 'mMaj7', 'dim7', 'aug7', 'sus2', 'sus4', '7sus4'];
var extensions = ['9', 'b9', '#9', '11', '#11', '13', 'b13'];
var inversions = ['', '6', '6/4', '7', '6/5', '4/3', '4/2'];

var scale = ['major', 'minor'];

function rng(l, u) {
    // random integer in range [l,u)
    return (Math.random() * (u  - l) + l)|0;
}

function getRandom(arr) {
    return arr[rng(0, arr.length)];
}

function getNote(sharp) {
    var n = sharp ? notes_sharp : notes_flat;
    return getRandom(n);
}

function getChord(sharp) {
    return getNote(sharp) + getRandom(chord_type);
}

function getInversion() {
    return getRandom(inversions);
}

function getScale(sharp) {
    return getNote(sharp) + ' ' + getRandom(scale);
}

var roman = ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii'];

function toRoman(n) {
    var t = roman[rng(0, roman.length)];
    return Math.random() < 0.5 ? t.toUpperCase() : t;
}

function getProgression() {
    var s = '';
    for(var n = rng(2,6); n > 0; n--) {
	var t = getRandom(roman);
	s += ' ' + (Math.random() < 0.5 ? t.toUpperCase() : t);
    }
    return s;
}

<commit_msg>fixing good<commit_after>
var notes_flat = ['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B'];
var notes_sharp = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];

var chord_type = ['', 'm', 'dim', 'aug', 'Maj7', 'm7', '7', 'm7b5', 'mMaj7', 'dim7', 'aug7', 'sus2', 'sus4', '7sus4'];
var extensions = ['9', 'b9', '#9', '11', '#11', '13', 'b13'];
var inversions = ['', '6', '6/4', '7', '6/5', '4/3', '4/2'];

var scale = ['major', 'minor'];

function rng(l, u) {
    // random integer in range [l,u)
    return (Math.random() * (u  - l) + l)|0;
}

function getRandom(arr) {
    return arr[rng(0, arr.length)];
}

function getNote(sharp) {
    var n = sharp ? notes_sharp : notes_flat;
    return getRandom(n);
}

function getChord(sharp) {
    return getNote(sharp) + getRandom(chord_type);
}

function getInversion() {
    return getRandom(inversions);
}

function getScale(sharp) {
    return getNote(sharp) + ' ' + getRandom(scale);
}

var roman = ['I', 'bII', 'II', 'bIII', 'III', 'IV', 'bV', 'V', 'bVI', 'VI', 'bVII', 'VII'];

function toRoman(n) {
    return roman[n];
}

function getRoman() {
    var t = getRandom(roman);
    return Math.random() < 0.5 ? t.toLowerCase() : t;
}

function getProgression() {
    var s = '';
    for(var n = rng(2,6); n > 0; n--) {
	var t = getRandom(roman);
	s += ' ' + (Math.random() < 0.5 ? t.toLowerCase() : t);
    }
    return s;
}

<|endoftext|>


<commit_before>// it's amazing that old freemap is using at least three different url param formats

// either freemap.sk/#m=T,p=48.21836|17.4166|16|T or freemap.sk/?m=A&p=48.1855|17.4029|14
export function getTrasformedParamsIfIsOldFreemapUrl(location) {
  const isFromOldFreemapUrlFormat1 = location.hash && (location.hash.indexOf('#p=') === 0 || location.hash.indexOf('#m=') === 0); // #m=T,p=48.21836|17.4166|16|T
  const isFromOldFreemapUrlFormat2 = location.search && location.search.indexOf('m=') >= 0; // "?m=A&p=48.1855|17.4029|14"
  if (isFromOldFreemapUrlFormat1 || isFromOldFreemapUrlFormat2) {
    let oldFreemapUrlParams;
    if (isFromOldFreemapUrlFormat1) {
      oldFreemapUrlParams = rawUrlParamsToHash(location.hash, ','); // #m=T,p=48.21836|17.4166|16|T -> {'m': 'T', 'p' : '48.21836|17.4166|16|T'}
    } else { // isFromOldFreemapUrlFormat2
      oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&'); // ?m=A&p=48.1855|17.4029|14
    }
    const [latFrag, lonFrag, zoomFrag, anotherMapTypeParam] = oldFreemapUrlParams.p.split('|');
    const mapType = oldFreemapUrlParams.m || anotherMapTypeParam || 'T';
    return {
      lat: parseFloat(latFrag),
      lon: parseFloat(lonFrag),
      zoom: parseInt(zoomFrag, 10),
      mapType,
      overlays: [],
    };
  }
  return false;
}

// http://embedded.freemap.sk/?lon=19.35&lat=48.55&zoom=8&marker=1&layers=A
// http://embed2.freemap.sk/index.html?lat=48.79&lon=19.55&zoom=12&layers=T&markerLat=48.8&markerLon=19.6&markerHtml=Hello&markerShowPopup=1
export function getTrasformedParamsIfIsOldEmbeddedFreemapUrl(location) {
  if (location.search && (location.search.indexOf('marker=1') >= 0 || location.search.indexOf('markerLat') >= 0)) {
    const oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&');
    const out = {
      lat: parseFloat(oldFreemapUrlParams.lat),
      lon: parseFloat(oldFreemapUrlParams.lon),
      zoom: parseInt(oldFreemapUrlParams.zoom, 10),
      mapType: oldFreemapUrlParams.layers,
      overlays: [],
    };
    return out;
  }
  return false;
}

// http://embed2.freemap.sk/index.html?lat=48.79&lon=19.55&zoom=12&layers=T&markerLat=48.8&markerLon=19.6&markerHtml=Hello&markerShowPopup=1
export function getInfoPointDetailsIfIsOldEmbeddedFreemapUrlFormat2(location) {
  if (location.search && location.search.indexOf('markerLat') >= 0) {
    const oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&');
    return {
      lat: parseFloat(oldFreemapUrlParams.markerLat),
      lon: parseFloat(oldFreemapUrlParams.markerLon),
      label: oldFreemapUrlParams.markerHtml,
    };
  }
  return false;
}

function rawUrlParamsToHash(rawParams, separator) {
  const oldFreemapRawUrlParams = rawParams.substring(1).split(separator);
  const oldFreemapUrlParams = {};
  oldFreemapRawUrlParams.forEach((s) => {
    const [key, value] = s.split('=');
    oldFreemapUrlParams[key] = value;
  });

  return oldFreemapUrlParams;
}
<commit_msg>fixed & optimized incorrect detection of old URL parameter<commit_after>// it's amazing that old freemap is using at least three different url param formats

// either freemap.sk/#m=T,p=48.21836|17.4166|16|T or freemap.sk/?m=A&p=48.1855|17.4029|14
export function getTrasformedParamsIfIsOldFreemapUrl(location) {
  const isFromOldFreemapUrlFormat1 = location.hash && (location.hash.indexOf('#p=') === 0 || location.hash.indexOf('#m=') === 0); // #m=T,p=48.21836|17.4166|16|T
  const isFromOldFreemapUrlFormat2 = location.search && /[?&]m=/.test(location.search); // "?m=A&p=48.1855|17.4029|14"
  if (isFromOldFreemapUrlFormat1 || isFromOldFreemapUrlFormat2) {
    let oldFreemapUrlParams;
    if (isFromOldFreemapUrlFormat1) {
      oldFreemapUrlParams = rawUrlParamsToHash(location.hash, ','); // #m=T,p=48.21836|17.4166|16|T -> {'m': 'T', 'p' : '48.21836|17.4166|16|T'}
    } else { // isFromOldFreemapUrlFormat2
      oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&'); // ?m=A&p=48.1855|17.4029|14
    }
    const [latFrag, lonFrag, zoomFrag, anotherMapTypeParam] = oldFreemapUrlParams.p.split('|');
    const mapType = oldFreemapUrlParams.m || anotherMapTypeParam || 'T';
    return {
      lat: parseFloat(latFrag),
      lon: parseFloat(lonFrag),
      zoom: parseInt(zoomFrag, 10),
      mapType,
      overlays: [],
    };
  }
  return false;
}

// http://embedded.freemap.sk/?lon=19.35&lat=48.55&zoom=8&marker=1&layers=A
// http://embed2.freemap.sk/index.html?lat=48.79&lon=19.55&zoom=12&layers=T&markerLat=48.8&markerLon=19.6&markerHtml=Hello&markerShowPopup=1
export function getTrasformedParamsIfIsOldEmbeddedFreemapUrl(location) {
  if (location.search && (location.search.indexOf('marker=1') >= 0 || location.search.indexOf('markerLat') >= 0)) {
    const oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&');
    const out = {
      lat: parseFloat(oldFreemapUrlParams.lat),
      lon: parseFloat(oldFreemapUrlParams.lon),
      zoom: parseInt(oldFreemapUrlParams.zoom, 10),
      mapType: oldFreemapUrlParams.layers,
      overlays: [],
    };
    return out;
  }
  return false;
}

// http://embed2.freemap.sk/index.html?lat=48.79&lon=19.55&zoom=12&layers=T&markerLat=48.8&markerLon=19.6&markerHtml=Hello&markerShowPopup=1
export function getInfoPointDetailsIfIsOldEmbeddedFreemapUrlFormat2(location) {
  if (location.search && location.search.indexOf('markerLat') >= 0) {
    const oldFreemapUrlParams = rawUrlParamsToHash(location.search, '&');
    return {
      lat: parseFloat(oldFreemapUrlParams.markerLat),
      lon: parseFloat(oldFreemapUrlParams.markerLon),
      label: oldFreemapUrlParams.markerHtml,
    };
  }
  return false;
}

function rawUrlParamsToHash(rawParams, separator) {
  const oldFreemapRawUrlParams = rawParams.substring(1).split(separator);
  const oldFreemapUrlParams = {};
  oldFreemapRawUrlParams.forEach((s) => {
    const [key, value] = s.split('=');
    oldFreemapUrlParams[key] = value;
  });

  return oldFreemapUrlParams;
}
<|endoftext|>


<commit_before><commit_msg>remove the only from recognition test<commit_after><|endoftext|>


<commit_before>'use strict';

angular.module('confRegistrationWebApp')
  .controller('ConferenceCardCtrl', function ($scope, $rootScope) {

	$scope.$on('flipevent', function (event, idToFlip) {
		if ($scope.$id === idToFlip && !$scope.flip) {
			$scope.flip = 'js-flip'; // js-flip is a css class
		} else {
			$scope.flip = '';
		}
	});

	$scope.flipCard = function () {
		$rootScope.$broadcast('flipevent', $scope.$id);
	};
});
<commit_msg>Update conferenceCard.js<commit_after>'use strict';

angular.module('confRegistrationWebApp')
  .controller('ConferenceCardCtrl', function ($scope, $rootScope) {

	$scope.$on('flipevent', function (event, idToFlip) {
		if ($scope.$id === idToFlip && !$scope.flip) {
			$scope.flip = 'js-flip'; // js-flip is a css class
		} else {
			$scope.flip = '';
		}
	});

	$scope.flipCard = function () {
		$rootScope.$broadcast('flipevent', $scope.$id);
	};
});
<|endoftext|>


<commit_before>/**
 * Created by ar on 3/8/17.
 */

var idRepo = require("./../blogic/IdReposition");;
var auxConcept=require("../model/auxConcept");
var auxDescription=require("../model/auxDescription");
var auxRelationship=require("../model/auxRelationship");

var db=require("../config/MysqlInit");

var conceptIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step conceptIdBulkCreation");

    testQuantity(auxConcept, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxConcept SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxConcept c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                        idRepo.idBulkCreation(auxDescription, namespace, partitionId, idsTotal, function (err) {
                                            //console.log("End of concept id generation");
                                            if (err) {
                                                var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                console.log(str);
                                            }
                                        });
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};

var descriptionIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step descriptionIdBulkCreation");

    testQuantity(auxDescription, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxDescription SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxDescription c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                            idRepo.idBulkCreation(auxDescription, namespace, partitionId, idsTotal, function (err) {
                                                //console.log("End of description id generation");
                                                if (err) {
                                                    var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                    console.log(str);
                                                }
                                            });
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};
var relationshipIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step relationshipIdBulkCreation");

    testQuantity(auxRelationship, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxRelationship SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxRelationship c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                            idRepo.idBulkCreation(auxRelationship, namespace, partitionId, idsTotal, function (err) {
                                                //console.log("End of relationship id generation");
                                                if (err) {
                                                    var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                    console.log(str);
                                                }
                                            });
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};

var testQuantity = function (auxTable, namespace, partitionId, idsTotal, callback) {
    var query = {partitionId: partitionId, namespace: namespace, modified_at: null};

    auxTable.availableCount(query, function (err, recs) {
        if (err == null) {
            var quant = idsTotal - recs;
            //console.log("step testing quantity in aux table, required - existent: " + quant);
            if (quant > 0) {
                callback("It is necesary wait for ids reposition. Try again in few minutes");
                createIds(auxTable, namespace, partitionId, idsTotal,function(err) {
                    if (err){
                        console.log("Cannot create ids:" + err);
                    }
                });
            } else {
                callback(null);
            }

        }
    });
};
var createIds = function (auxTable, namespace, partitionId, idsTotal, callback) {
    var query = {partitionId: partitionId, namespace: namespace, modified_at: null};

    auxTable.availableCount(query, function (err, recs) {
        if (err == null) {
            var quant = idsTotal - recs;
            //console.log("step create Ids, checking quantity" );
            if (quant > 0) {
                //console.log("need to create " + quant + " ids, up to " + idsTotal);
                idRepo.idBulkCreation(auxTable, namespace, partitionId, idsTotal, function (err) {
                    //console.log("End of id generation");
                    if (err) {
                        var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                        //console.log(str);
                        callback(str);
                    } else {
                        callback(null);
                    }
                });

            } else {
                //console.log("ids quantity in aux table is ok");
                callback(null);
            }

        }
    });
};

var createAvailableIds = function (request, callback) {
    //var t1 = new Date().getTime();
    var auxTable;
    if (request.partitionId.substr(1,1)=="0") {
        auxTable = auxConcept;
    }else if (request.partitionId.substr(1,1)=="1"){
        auxTable = auxDescription;
    }else if (request.partitionId.substr(1,1)=="2") {
        auxTable = auxRelationship;
    }
    createIds(auxTable, request.namespace, request.partitionId, request.quantity,function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing available ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err);
        } else {
            callback(null);
        }
    });
};

var idsRetrieve = function (request, callback) {

    if (request.partitionId.substr(1,1)=="0") {
        conceptIdBulkCreation( request.namespace, request.partitionId, request.quantity, request, function(err, result){

            if (err) {
                callback(err,null);
            } else {
                callback(null,result);
            }
        });
    }else if (request.partitionId.substr(1,1)=="1") {
        descriptionIdBulkCreation(request.namespace, request.partitionId, request.quantity, request, function (err, result) {

            if (err) {
                callback(err, null);
            } else {
                callback(null, result);
            }
        });
    }else if (request.partitionId.substr(1,1)=="2") {
        relationshipIdBulkCreation( request.namespace, request.partitionId, request.quantity, request, function(err, result){

            if (err) {
                callback(err,null);
            } else {
                callback(null,result);
            }
        });
    }

};

module.exports.createAvailableIds=createAvailableIds;
module.exports.testQuantity=testQuantity;
module.exports.conceptIdBulkCreation=conceptIdBulkCreation;
module.exports.descriptionIdBulkCreation=descriptionIdBulkCreation;
module.exports.relationshipIdBulkCreation=relationshipIdBulkCreation;
module.exports.idsRetrieve=idsRetrieve;

//var t1 = new Date().getTime();
//
//conceptIdBulkCreation( 0, "00", 100000, function(err, result){
//    if (err){
//        console.log("error: " + err);
//    }else{
//
//        if (result){
//            if (result.length){
//
//                console.log("result length:" + result.length);
//            }else{
//                console.log("There is not an array");
//            }
//        }else{
//            console.log("Result is null");
//
//        }
//    }
//        var t2 = new Date().getTime();
//        console.log("Final call to retrieve ids took: " + (t2 - t1) + " milisecs");
//});<commit_msg>Added config to generate ids for any namespace<commit_after>/**
 * Created by ar on 3/8/17.
 */

var idRepo = require("./../blogic/IdReposition");;
var auxConcept=require("../model/auxConcept");
var auxDescription=require("../model/auxDescription");
var auxRelationship=require("../model/auxRelationship");

var db=require("../config/MysqlInit");

var conceptIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step conceptIdBulkCreation");

    testQuantity(auxConcept, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxConcept SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null and namespace=" + connection.escape(namespace) + " limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxConcept c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxConcept where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                        idRepo.idBulkCreation(auxDescription, namespace, partitionId, idsTotal, function (err) {
                                            //console.log("End of concept id generation");
                                            if (err) {
                                                var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                console.log(str);
                                            }
                                        });
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};

var descriptionIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step descriptionIdBulkCreation");

    testQuantity(auxDescription, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxDescription SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null and namespace=" + connection.escape(namespace) + " limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxDescription c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                            idRepo.idBulkCreation(auxDescription, namespace, partitionId, idsTotal, function (err) {
                                                //console.log("End of description id generation");
                                                if (err) {
                                                    var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                    console.log(str);
                                                }
                                            });
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxDescription where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};
var relationshipIdBulkCreation = function (namespace, partitionId, idsTotal, request, callback) {

    //console.log("step relationshipIdBulkCreation");

    testQuantity(auxRelationship, namespace, partitionId, idsTotal, function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing space ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err,null);
        }else{

            db.getDB(function (err,connection)
            {
                //var t3 = new Date().getTime();
                //console.log("Partial call to get db connection took: " + (t3 - t2) + " milisecs");
                var now = new Date();
                var jsonDate = now.toJSON();
                var modified_at = new Date(jsonDate);

                //console.log("modified_at:" + connection.escape(modified_at));
                var sql="UPDATE auxRelationship SET modified_at=" + connection.escape(modified_at) + "  where modified_at is null and namespace=" + connection.escape(namespace) + " limit " + idsTotal;
                connection.query(sql, function (error, result) {
                    //connection.release();
                    //var t4 = new Date().getTime();
                    //console.log("Partial call to update data took: " + (t4 - t3) + " milisecs");
                    if (error) {
                        callback (error,null);
                    }
                    else {
                        sql="SELECT sctid, systemId from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                        connection.query(sql, function (error, result) {
                            //var t5 = new Date().getTime();
                            //console.log("Partial call to select data took: " + (t5 - t4) + " milisecs");
                            if (error) {
                                callback(error, null);
                            }
                            else {

                                if (request) {

                                    callback(null, result);

                                    sql = "update sctId s inner join auxRelationship c on c.sctid=s.sctId set s.author= " + connection.escape(request.author) +
                                        ",s.software= " + connection.escape(request.software) +
                                        ",s.comment= " + connection.escape(request.comment) +
                                        ",s.jobId= " + connection.escape(request.jobId) +
                                        " where c.modified_at=" + connection.escape(modified_at)  ;

                                    connection.query(sql, function (error, result) {

                                        sql = "Delete from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                        connection.query(sql, function (error, result) {
                                            connection.release();
                                            idRepo.idBulkCreation(auxRelationship, namespace, partitionId, idsTotal, function (err) {
                                                //console.log("End of relationship id generation");
                                                if (err) {
                                                    var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                                                    console.log(str);
                                                }
                                            });
                                        });
                                    });

                                }else{
                                    sql = "Delete from auxRelationship where modified_at=" + connection.escape(modified_at) + " limit " + idsTotal;
                                    connection.query(sql, function (error, result) {
                                        connection.release();
                                    });
                                }
                            }
                        });
                    }
                });
            });

        }

    });
};

var testQuantity = function (auxTable, namespace, partitionId, idsTotal, callback) {
    var query = { namespace: namespace};

    auxTable.availableCount(query, function (err, recs) {
        if (err == null) {
            var quant = idsTotal - recs;
            //console.log("step testing quantity in aux table, required - existent: " + quant);
            if (quant > 0) {
                callback("It is necesary wait for ids reposition. Try again in few minutes");
                createIds(auxTable, namespace, partitionId, idsTotal,function(err) {
                    if (err){
                        console.log("Cannot create ids:" + err);
                    }
                });
            } else {
                callback(null);
            }

        }
    });
};
var createIds = function (auxTable, namespace, partitionId, idsTotal, callback) {
    var query = {namespace: namespace};

    auxTable.availableCount(query, function (err, recs) {
        if (err == null) {
            var quant = idsTotal - recs;
            //console.log("step create Ids, checking quantity" );
            if (quant > 0) {
                //console.log("need to create " + quant + " ids, up to " + idsTotal);
                idRepo.idBulkCreation(auxTable, namespace, partitionId, idsTotal, function (err) {
                    //console.log("End of id generation");
                    if (err) {
                        var str = "[ERROR] " + (new Date()).getTime() + ": namespace=" + namespace + ", partition=" + partitionId + ". " + err;
                        //console.log(str);
                        callback(str);
                    } else {
                        callback(null);
                    }
                });

            } else {
                //console.log("ids quantity in aux table is ok");
                callback(null);
            }

        }
    });
};

var createAvailableIds = function (request, callback) {
    //var t1 = new Date().getTime();
    var auxTable;
    if (request.partitionId.substr(1,1)=="0") {
        auxTable = auxConcept;
    }else if (request.partitionId.substr(1,1)=="1"){
        auxTable = auxDescription;
    }else if (request.partitionId.substr(1,1)=="2") {
        auxTable = auxRelationship;
    }
    createIds(auxTable, request.namespace, request.partitionId, request.quantity,function (err) {

        //var t2 = new Date().getTime();
        //console.log("Partial call to testing available ids took: " + (t2 - t1) + " milisecs");
        if (err) {
            callback(err);
        } else {
            callback(null);
        }
    });
};

var idsRetrieve = function (request, callback) {

    if (request.partitionId.substr(1,1)=="0") {
        conceptIdBulkCreation( request.namespace, request.partitionId, request.quantity, request, function(err, result){

            if (err) {
                callback(err,null);
            } else {
                callback(null,result);
            }
        });
    }else if (request.partitionId.substr(1,1)=="1") {
        descriptionIdBulkCreation(request.namespace, request.partitionId, request.quantity, request, function (err, result) {

            if (err) {
                callback(err, null);
            } else {
                callback(null, result);
            }
        });
    }else if (request.partitionId.substr(1,1)=="2") {
        relationshipIdBulkCreation( request.namespace, request.partitionId, request.quantity, request, function(err, result){

            if (err) {
                callback(err,null);
            } else {
                callback(null,result);
            }
        });
    }

};

module.exports.createAvailableIds=createAvailableIds;
module.exports.testQuantity=testQuantity;
module.exports.conceptIdBulkCreation=conceptIdBulkCreation;
module.exports.descriptionIdBulkCreation=descriptionIdBulkCreation;
module.exports.relationshipIdBulkCreation=relationshipIdBulkCreation;
module.exports.idsRetrieve=idsRetrieve;

//var t1 = new Date().getTime();
//
//conceptIdBulkCreation( 0, "00", 100000, function(err, result){
//    if (err){
//        console.log("error: " + err);
//    }else{
//
//        if (result){
//            if (result.length){
//
//                console.log("result length:" + result.length);
//            }else{
//                console.log("There is not an array");
//            }
//        }else{
//            console.log("Result is null");
//
//        }
//    }
//        var t2 = new Date().getTime();
//        console.log("Final call to retrieve ids took: " + (t2 - t1) + " milisecs");
//});<|endoftext|>


<commit_before>(function(ng) {
  'use strict';

  /**
   * generate directive link function
   *
   * @param {function} $http service to make ajax requests from angular
   * @param {object}   util  service to get echart
   * @param {string}   type  chart type
   */

  var getLinkFunction = function($http, util, type) {
    return function(scope, element, attrs) {
      scope.config = scope.config || {};

      var dom = element.find('div')[0],
        width, height, chart, radius;

      function getSizes(config) {
        width = config.width || attrs.width || 320;
        height = config.height || attrs.height || 240;

        if (type === 'easyPie') {
          width = config.width || attrs.width || 150;
          height = config.height || attrs.height || 150;
        }

        if (type === 'ntdPie') {
            width = config.width || attrs.pieWidth || 800;
            height = config.height || attrs.pieHeight || 300;
            radius = Math.min(width, height) / 2;
        }

        dom.style.width = width + 'px';
        dom.style.height = height + 'px';
      }

      function getOptions(data, config, type) {
        // merge default config
        config = ng.extend({
          showXAxis: true,
          showYAxis: true,
          showLegend: true
        }, config);

        var xAxis = ng.extend({
          orient: 'top',
          axisLine: { show: true}
        }, ng.isObject(config.xAxis) ? config.xAxis : {});

        var yAxis = ng.extend({
          type: 'value',
          orient: 'right',
          scale: true,
          axisLine: {
            show: true
          },
          axisLabel: {
            formatter: function(v) {
              return util.formatKMBT(v);
            }
          }
        }, ng.isObject(config.yAxis) ? config.yAxis : {});

        var toolbox = {show: false};

        if (type === 'bubble') {
          var bubbleXAxis = {
            type: 'value',
            power: 1,
            splitNumber: 4,
            scale: true
          };
          xAxis = ng.extend(bubbleXAxis, xAxis);
          yAxis = ng.extend(bubbleXAxis, yAxis);
          toolbox = {
            show: true,
            feature: {
              dataZoom: {show: true},
              restore: {show: true}
            }
          };
        }
        if (type === 'scatter') {
          var scatterXAxis = {
            type: 'category',
            axisLabel: {
              formatter: function(v) {
                return '类目' + v;
              }
            },
            data: (function() {
              var list = [];
              var len = 0;
              while (len++ < data[0].data.length) {
                list.push(len);
              }
              return list;
            })()
          };
          xAxis = ng.extend(scatterXAxis, xAxis);
        }

        // basic config
        var options = {
          title: util.getTitle(data, config),
          tooltip: util.getTooltip(data, config, type),
          legend: util.getLegend(data, config, type),
          toolbox:
            ng.extend(toolbox,
              ng.isObject(config.toolbox) ? config.toolbox : {}),
          xAxis: ng.isArray(config.xAxis) ? config.xAxis :
            [ng.extend(xAxis, util.getAxisTicks(data, config, type))],
          yAxis: ng.isArray(config.yAxis) ? config.yAxis : [yAxis],
          series: util.getSeries(data, config, type, scope, radius),
          calculable: config.calculable
        };

        if (!config.showXAxis) {
          ng.forEach(options.xAxis, function(axis) {
            axis.axisLine = { show: false };
            axis.axisLabel = { show: false };
            axis.axisTick = { show: false };
          });
        }

        if (!config.showYAxis) {
          ng.forEach(options.yAxis, function(axis) {
            axis.axisLine = { show: false };
            axis.axisLabel = { show: false };
            axis.axisTick = { show: false };
          });
        }

        if (!config.showLegend || type === 'gauge' || type === 'easyPie') {
          delete options.legend;
        }

        if (ng.isObject(config.grid)) {
          options.grid = config.grid;
        }
        if (util.isPieChart(type) || type === 'gauge' || type === 'radar') {
          delete options.xAxis;
          delete options.yAxis;
          delete options.grid;
        }

        if (util.isScatterChart(type)) {
          delete options.grid;
        }

        if (type === 'easyPie') {
          delete options.tooltip;
        }
        if (type === 'scatter') {
          options.dataZoom = ng.extend({
            show: true,
            start: 30,
            end: 70
          }, options.dataZoom);
          options.dataRange = ng.extend({
            min: 0,
            max: 100,
            orient: 'horizontal',
            y: 30,
            x: 'center',
            color: ['lightgreen', 'orange'],
            splitNumber: 5
          }, options.dataRange);
          options.animation = options.animation || false;
        }
        if (type === 'radar') {
          options.polar = [];
          ng.forEach(data, function(value, index) {
            var conf = {
              indicator: value.indicator
            };
            if (data.length > 1) {
              conf.radius = data.radius || 80;
              conf.center = data.center || [((index + 1) * 25) + '%', 200];
            }
            options.polar.push(conf);
          });
        }
        return options;
      }

      function setOptions() {
        if (!scope.data || !scope.config) {
          return;
        }

        var options;

        getSizes(scope.config);

        if (!chart) {
          chart = echarts.init(dom, scope.config.theme || util.theme());
        }

        // string type for data param is assumed to ajax datarequests
        if (ng.isString(scope.data)) {
          // show loading
          chart.showLoading({ text: scope.config.loading || '奋力加载中...' });

          // fire data request
          $http.get(scope.data).success(function(response) {
            chart.hideLoading();
            if (response.data) {
              options = getOptions(response.data, scope.config, type);
              if (scope.config.debug) {
                console.log(response);
              }
              if (scope.config.forceClear) {
                chart.clear();
              }
              chart.setOption(options);
              chart.resize();
            } else {
              throw new Error(
                'angular-echarts: no data loaded from ' + scope.data);
            }
          }).error(function() {
            chart.hideLoading();
            throw new Error(
              'angular-echarts: error loading data from ' + scope.data);
          });

          // if data is avaliable, render immediately
        } else {
          options = getOptions(scope.data, scope.config, type);
          if (scope.config.debug) {
            console.log(options);
          }
          if (scope.config.forceClear) {
            chart.clear();
          }
          chart.setOption(options, true);
          chart.resize();
        }
      }

      // update when charts config changes
      scope.$watch(function() {
        return scope.config;
      }, function(value) {
        if (value) {
          setOptions();
        }
      },true);

      // update when charts data changes
      scope.$watch(function() {
        return scope.data;
      }, function(value) {
        if (value) {
          setOptions();
        }
      },true);

    };
  };
  /**
   * add directives
   */
  ng.module('angular-echarts',
      ['angular-echarts.util'])
    .directive('lineChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'line')
        };
      }])
    .directive('barChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'bar')
        };
      }])
    .directive('areaChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'area')
        };
      }])
    .directive('pieChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'pie')
        };
      }])
    .directive('donutChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'donut')
        };
      }])
    .directive('easyPieChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            data: '=easyPieChart'
          },
          link: getLinkFunction($http, util, 'easyPie')
        };
      }])
    .directive('ntdPie',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            data: '=data'
          },
          link: getLinkFunction($http, util, 'ntdPie')
        };
      }])
    .directive('gaugeChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'gauge')
        };
      }])
    .directive('bubbleChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'bubble')
        };
      }])
    .directive('scatterChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'scatter')
        };
      }])
    .directive('radarChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'radar')
        };
      }]);

})(angular);

<commit_msg>fix echarts<commit_after>(function(ng) {
  'use strict';

  /**
   * generate directive link function
   *
   * @param {function} $http service to make ajax requests from angular
   * @param {object}   util  service to get echart
   * @param {string}   type  chart type
   */

  var getLinkFunction = function($http, util, type) {
    return function(scope, element, attrs) {
      scope.config = scope.config || {};

      var dom = element.find('div')[0],
        width, height, chart, radius;

      function getSizes(config) {
        width = config.width || attrs.width || 320;
        height = config.height || attrs.height || 240;

        if (type === 'easyPie') {
          width = config.width || attrs.width || 150;
          height = config.height || attrs.height || 150;
        }

        if (type === 'ntdPie') {
            width = config.width || attrs.pieWidth || 800;
            height = config.height || attrs.pieHeight || 300;
            radius = Math.min(width, height) / 2;
        }

        dom.style.width = width + 'px';
        dom.style.height = height + 'px';
      }

      function getOptions(data, config, type) {
        // merge default config
        config = ng.extend({
          showXAxis: true,
          showYAxis: true,
          showLegend: true
        }, config);

        var xAxis = ng.extend({
          orient: 'top',
          axisLine: { show: true}
        }, ng.isObject(config.xAxis) ? config.xAxis : {});

        var yAxis = ng.extend({
          type: 'value',
          orient: 'right',
          scale: true,
          axisLine: {
            show: true
          },
          axisLabel: {
            formatter: function(v) {
              return util.formatKMBT(v);
            }
          }
        }, ng.isObject(config.yAxis) ? config.yAxis : {});

        var toolbox = {show: false};

        if (type === 'bubble') {
          var bubbleXAxis = {
            type: 'value',
            power: 1,
            splitNumber: 4,
            scale: true
          };
          xAxis = ng.extend(bubbleXAxis,
            ng.isObject(config.yAxis) ? config.yAxis : {});
          yAxis = ng.extend(bubbleXAxis,
            ng.isObject(config.yAxis) ? config.yAxis : {});
          toolbox = {
            show: true,
            feature: {
              dataZoom: {show: true},
              restore: {show: true}
            }
          };
        }
        if (type === 'scatter') {
          var scatterXAxis = {
            type: 'category',
            axisLabel: {
              formatter: function(v) {
                return '类目' + v;
              }
            },
            data: (function() {
              var list = [];
              var len = 0;
              while (len++ < data[0].data.length) {
                list.push(len);
              }
              return list;
            })()
          };
          xAxis = ng.extend(scatterXAxis, xAxis);
        }

        // basic config
        var options = {
          title: util.getTitle(data, config),
          tooltip: util.getTooltip(data, config, type),
          legend: util.getLegend(data, config, type),
          toolbox:
            ng.extend(toolbox,
              ng.isObject(config.toolbox) ? config.toolbox : {}),
          xAxis: ng.isArray(config.xAxis) ? config.xAxis :
            [ng.extend(xAxis, util.getAxisTicks(data, config, type))],
          yAxis: ng.isArray(config.yAxis) ? config.yAxis : [yAxis],
          series: util.getSeries(data, config, type, scope, radius),
          calculable: config.calculable
        };

        if (!config.showXAxis) {
          ng.forEach(options.xAxis, function(axis) {
            axis.axisLine = { show: false };
            axis.axisLabel = { show: false };
            axis.axisTick = { show: false };
          });
        }

        if (!config.showYAxis) {
          ng.forEach(options.yAxis, function(axis) {
            axis.axisLine = { show: false };
            axis.axisLabel = { show: false };
            axis.axisTick = { show: false };
          });
        }

        if (!config.showLegend || type === 'gauge' || type === 'easyPie') {
          delete options.legend;
        }

        if (ng.isObject(config.grid)) {
          options.grid = config.grid;
        }
        if (util.isPieChart(type) || type === 'gauge' || type === 'radar') {
          delete options.xAxis;
          delete options.yAxis;
          delete options.grid;
        }

        if (util.isScatterChart(type)) {
          delete options.grid;
        }

        if (type === 'easyPie') {
          delete options.tooltip;
        }
        if (type === 'scatter') {
          options.dataZoom = ng.extend({
            show: true,
            start: 30,
            end: 70
          }, options.dataZoom);
          options.dataRange = ng.extend({
            min: 0,
            max: 100,
            orient: 'horizontal',
            y: 30,
            x: 'center',
            color: ['lightgreen', 'orange'],
            splitNumber: 5
          }, options.dataRange);
          options.animation = options.animation || false;
        }
        if (type === 'radar') {
          options.polar = [];
          ng.forEach(data, function(value, index) {
            var conf = {
              indicator: value.indicator
            };
            if (data.length > 1) {
              conf.radius = data.radius || 80;
              conf.center = data.center || [((index + 1) * 25) + '%', 200];
            }
            options.polar.push(conf);
          });
        }
        return options;
      }

      function setOptions() {
        if (!scope.data || !scope.config) {
          return;
        }

        var options;

        getSizes(scope.config);

        if (!chart) {
          chart = echarts.init(dom, scope.config.theme || util.theme());
        }

        // string type for data param is assumed to ajax datarequests
        if (ng.isString(scope.data)) {
          // show loading
          chart.showLoading({ text: scope.config.loading || '奋力加载中...' });

          // fire data request
          $http.get(scope.data).success(function(response) {
            chart.hideLoading();
            if (response.data) {
              options = getOptions(response.data, scope.config, type);
              if (scope.config.debug) {
                console.log(response);
              }
              if (scope.config.forceClear) {
                chart.clear();
              }
              chart.setOption(options);
              chart.resize();
            } else {
              throw new Error(
                'angular-echarts: no data loaded from ' + scope.data);
            }
          }).error(function() {
            chart.hideLoading();
            throw new Error(
              'angular-echarts: error loading data from ' + scope.data);
          });

          // if data is avaliable, render immediately
        } else {
          options = getOptions(scope.data, scope.config, type);
          if (scope.config.debug) {
            console.log(options);
          }
          if (scope.config.forceClear) {
            chart.clear();
          }
          chart.setOption(options, true);
          chart.resize();
        }
      }

      // update when charts config changes
      scope.$watch(function() {
        return scope.config;
      }, function(value) {
        if (value) {
          setOptions();
        }
      },true);

      // update when charts data changes
      scope.$watch(function() {
        return scope.data;
      }, function(value) {
        if (value) {
          setOptions();
        }
      },true);

    };
  };
  /**
   * add directives
   */
  ng.module('angular-echarts',
      ['angular-echarts.util'])
    .directive('lineChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'line')
        };
      }])
    .directive('barChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'bar')
        };
      }])
    .directive('areaChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'area')
        };
      }])
    .directive('pieChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'pie')
        };
      }])
    .directive('donutChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'donut')
        };
      }])
    .directive('easyPieChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            data: '=easyPieChart'
          },
          link: getLinkFunction($http, util, 'easyPie')
        };
      }])
    .directive('ntdPie',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            data: '=data'
          },
          link: getLinkFunction($http, util, 'ntdPie')
        };
      }])
    .directive('gaugeChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'gauge')
        };
      }])
    .directive('bubbleChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'bubble')
        };
      }])
    .directive('scatterChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'scatter')
        };
      }])
    .directive('radarChart',
      ['$http', 'util', function($http, util) {
        return {
          restrict: 'EA',
          template: '

',
          scope: {
            config: '=config',
            data: '=data'
          },
          link: getLinkFunction($http, util, 'radar')
        };
      }]);

})(angular);

<|endoftext|>