/*
Method: compute

Called by loadJSON to calculate recursively all node positions and lay out the tree.

Parameters:

json - A JSON tree. See also <Loader.loadJSON>.
coord - A coordinates object specifying width, height, left and top style properties.
356299
function(prop) {
    prop = prop || "current";
    var root = this.graph.getNode(this.clickedNode && this.clickedNode.id || this.root);
    this.controller.onBeforeCompute(root);
    var config = this.config,
        size = this.canvas.getSize(),
        width = size.width,
        height = size.height,
        offst = config.offset,
        offwdth = width - offst,
        offhght = height - offst;
    this.graph.computeLevels(this.root, 0, "ignore");
    //set root position and dimensions
    root.getPos(prop).setc(-width/2, -height/2);
    root.setData('width', width, prop);
    root.setData('height', height, prop);
    //create a coordinates object
    var coord = {
        'top': -height/2 + config.titleHeight,
        'left': -width/2,
        'width': offwdth,
        'height': offhght - config.titleHeight
    };
    this.computePositions(root, coord, prop);
    this.controller.onAfterCompute(root);
 }
275638
function json_cmp(a, b) {
	a = JSON.stringify(a);
	b = JSON.stringify(b);
	var ret = (a === b) ? true : false;
	return ret;
}
390353
function formatNode(node) {
  var log = node.type
  var location = node.position || {}
  var position = stringify(location.start, location.end)
  var key
  var values = []
  var value

  if (node.children) {
    log += dim('[') + yellow(node.children.length) + dim(']')
  } else if (typeof node.value === 'string') {
    log += dim(': ') + green(JSON.stringify(node.value))
  }

  if (position) {
    log += ' (' + position + ')'
  }

  for (key in node) {
    value = node[key]

    if (
      ignore.indexOf(key) !== -1 ||
      value === null ||
      value === undefined ||
      (typeof value === 'object' && isEmpty(value))
    ) {
      continue
    }

    values.push('[' + key + '=' + JSON.stringify(value) + ']')
  }

  if (values.length !== 0) {
    log += ' ' + values.join('')
  }

  return log
}
899112
public void fromJSON(JSONObject json, String rootPath) {

        try {
            // language versions
            if (json.has(JSON_LANGUAGES)) {
                JSONArray jsonLanguages = json.getJSONArray(JSON_LANGUAGES);
                for (int i = 0; i < jsonLanguages.length(); i++) {
                    JSONObject jsonLang = (JSONObject)jsonLanguages.get(i);

                    CmsDocumentDependency lang = new CmsDocumentDependency(null, jsonLang.getString(JSON_PATH));
                    lang.fromJSON(jsonLang, rootPath);
                    addVariant(lang);
                }
            }

            // attachments
            if (json.has(JSON_ATTACHMENTS)) {
                JSONArray jsonAttachments = json.getJSONArray(JSON_ATTACHMENTS);
                for (int i = 0; i < jsonAttachments.length(); i++) {
                    try {
                        JSONObject jsonAttachment = (JSONObject)jsonAttachments.get(i);

                        CmsDocumentDependency att = new CmsDocumentDependency(
                            null,
                            jsonAttachment.getString(JSON_PATH));
                        att.fromJSON(jsonAttachment, rootPath);

                        // language versions of attachment
                        if (jsonAttachment.has(JSON_LANGUAGES)) {
                            JSONArray jsonAttLanguages = jsonAttachment.getJSONArray(JSON_LANGUAGES);
                            for (int j = 0; j < jsonAttLanguages.length(); j++) {
                                JSONObject jsonAttLanguage = (JSONObject)jsonAttLanguages.get(j);

                                CmsDocumentDependency attLang = new CmsDocumentDependency(
                                    null,
                                    jsonAttLanguage.getString(JSON_PATH));
                                attLang.fromJSON(jsonAttLanguage, rootPath);
                                att.addVariant(attLang);
                            }
                        }
                        addAttachment(att);
                    } catch (Exception e) {
                        LOG.error(e);
                    }
                }
            }
        } catch (Exception ex) {
            if (LOG.isErrorEnabled()) {
                LOG.error(ex.getLocalizedMessage(), ex);
            }
        }
    }
1225961
function (jsonConfig, treeId ) {

        /**
         * @param {object} jsonConfig
         * @param {number} treeId
         * @returns {Tree}
         */
        this.reset = function( jsonConfig, treeId ) {
            this.initJsonConfig = jsonConfig;
            this.initTreeId = treeId;

            this.id = treeId;

            this.CONFIG = UTIL.extend( Tree.CONFIG, jsonConfig.chart );
            this.drawArea = UTIL.findEl( this.CONFIG.container, true );
            if ( !this.drawArea ) {
                throw new Error( 'Failed to find element by selector "'+this.CONFIG.container+'"' );
            }

            UTIL.addClass( this.drawArea, 'Treant' );

            // kill of any child elements that may be there
            this.drawArea.innerHTML = '';

            this.imageLoader = new ImageLoader();

            this.nodeDB = new NodeDB( jsonConfig.nodeStructure, this );

            // key store for storing reference to node connectors,
            // key = nodeId where the connector ends
            this.connectionStore = {};

            this.loaded = false;

            this._R = new Raphael( this.drawArea, 100, 100 );

            return this;
        };

        /**
         * @returns {Tree}
         */
        this.reload = function() {
            this.reset( this.initJsonConfig, this.initTreeId ).redraw();
            return this;
        };

        this.reset( jsonConfig, treeId );
    }
1106544
function Node(key, value) {
        this.key = key;
        this.value = value;
        this.color = RED;
        this.left = null;
        this.right = null;
        this.parent = null;
    }
508036
function( jsonConfig, callback, jQuery ) {
        if ( jsonConfig instanceof Array ) {
            jsonConfig = JSONconfig.make( jsonConfig );
        }

        // optional
        if ( jQuery ) {
            $ = jQuery;
        }

        this.tree = TreeStore.createTree( jsonConfig );
        this.tree.positionTree( callback );
    }
621611
function writeJson( row ){
    let targetDir = path.join(dataDir, wofIdToPath(row.id).join(path.sep));
    try {
      fs.ensureDirSync(targetDir);
      fs.writeFileSync( path.join(targetDir, `${row.id}.geojson`), row.body, 'utf8' );
    } catch( error ){
      if( error ){ console.error(`error making directory ${targetDir}`); }
    }
  }
763925
function(json) {
      
      var r = function(o) {
          Object.keys(o).forEach(function(v, i) {

              if (o[v] !== null && typeof o[v] === 'object' && o[v].hasOwnProperty('$date')) {                
                  o[v] = moment(o[v]['$date']).toDate();
                  return;
              }
              if (o[v] !== null && typeof o[v] === 'object') return r(o[v])
          })
       }

       r(json);

       return json;
  }
972962
function computeNodeValues(nodes) {
    zrUtil.each(nodes, function (node) {
        var value1 = sum(node.outEdges, getEdgeValue);
        var value2 = sum(node.inEdges, getEdgeValue);
        var value = Math.max(value1, value2);
        node.setLayout({value: value}, true);
    });
}
75173
static function json_parse($json = '', $assoc = false, $depth = 512)
    {

        $parsed = \json_decode($json, $assoc, $depth);

        //if (JSON_ERROR_NONE !== json_last_error()) {
        //    throw new \RuntimeException('JSON Error: Unable to parse into JSON: ' . json_last_error());
        //}

        $error = json_last_error();

        switch ($error) {
            case JSON_ERROR_NONE:
                break;
            case JSON_ERROR_DEPTH:
                throw new InvalidArgumentException('JSON Error: Maximum stack depth exceeded');
                break;
            case JSON_ERROR_CTRL_CHAR:
                throw new InvalidArgumentException('JSON Error: Unexpected control character found');
                break;
            case JSON_ERROR_SYNTAX:
                throw new InvalidArgumentException('JSON Error: Syntax error, malformed JSON');
                break;
            default:
                throw new InvalidArgumentException('JSON Error: Unknown error');
                break;
        }

        // This is a courtesy by PHP JSON parser to parse "null" into null, but this is an error situation
        if (empty($parsed)) {
            throw new InvalidArgumentException('JSON Error: Result is empty after parsing');
        }

        return $parsed;

    }
576586
public void loadFromJSONPlan(JSONObject jobj, Database db)  throws JSONException {
        if (jobj.has(Members.PLAN_NODES_LISTS)) {
            JSONArray jplanNodesArray = jobj.getJSONArray(Members.PLAN_NODES_LISTS);
            for (int i = 0; i < jplanNodesArray.length(); ++i) {
                JSONObject jplanNodesObj = jplanNodesArray.getJSONObject(i);
                JSONArray jplanNodes = jplanNodesObj.getJSONArray(Members.PLAN_NODES);
                int stmtId = jplanNodesObj.getInt(Members.STATEMENT_ID);
                loadPlanNodesFromJSONArrays(stmtId, jplanNodes, db);
            }
        }
        else {
            // There is only one statement in the plan. Its id is set to 0 by default
            int stmtId = 0;
            JSONArray jplanNodes = jobj.getJSONArray(Members.PLAN_NODES);
            loadPlanNodesFromJSONArrays(stmtId, jplanNodes, db);
        }

        // Connect the parent and child statements
        for (List<AbstractPlanNode> nextPlanNodes : m_planNodesListMap.values()) {
            for (AbstractPlanNode node : nextPlanNodes) {
                connectNodesIfNecessary(node);
            }
        }
    }
1358341
function toJSON(node) {
  node = node || this;

  var obj = {
    nodeType: node.nodeType
  };

  if (node.tagName) {
    obj.name = node.tagName.toLowerCase();
  } else if (node.nodeName) {
    obj.name = node.nodeName.toLowerCase();
  }
  if (node.nodeValue) {
    obj.nodeValue = node.nodeValue;
  }
  var attrs = node.attributes;

  if (attrs) {
    var length = attrs.length;

    obj.props = {};
    for (var i = 0; i < length; i++) {
      var attr = attrs[i];

      obj.props[attr.nodeName] = attr.nodeValue;
    }
  }
  var childNodes = node.childNodes;

  if (childNodes) {
    var _length = childNodes.length;

    obj.children = [];
    for (var _i = 0; _i < _length; _i++) {
      obj.children.push(toJSON(childNodes[_i]));
    }
  }
  return obj;
}
745092
function(json, indices) {
                            //                console.log("seperateProcessing:");
                            //                console.log("json = "+JSON.stringify(json));
                            for (var t=minTime; t<=maxTime; ) {
                                //                    console.log("t = "+t);
                                var nextTime = maxTime + 1; // break condition
                                var sum = 0; // for mean adjusted graphs
                                var hadValue = [];
                                for (var s=0; s<json.length; s++) {
                                    hadValue.push(false);
                                    if (indices[s] >= json[s].dps.length) {
                                        // skip this one
                                    }
                                    else if (json[s].dps[indices[s]][0] == t) {
                                        hadValue[s] = true;
                                        var val = json[s].dps[indices[s]][1];
                                        if (isNegativeSquashingEnabled(json[s]) && val < 0) {
                                            json[s].dps[indices[s]][1] = 0;
                                            val = 0;
                                        }
                                        indices[s]++;
                                        if (indices[s] < json[s].dps.length) {
                                            nextTime = Math.min(nextTime, json[s].dps[indices[s]][0]);
                                        }
                                        if (dygraphOptions.ratioGraph) {
                                            sum += Math.abs(val);
                                        }
                                        else if (dygraphOptions.meanAdjusted) {
                                            sum += val;
                                        }
                                    }
                                    else {
                                        nextTime = Math.min(nextTime, json[s].dps[indices[s]][0]);
                                    }
                                }
                                if (dygraphOptions.ratioGraph) {
                                    for (var s=0; s<json.length; s++) {
                                        if (hadValue[s] && json[s].dps[indices[s]-1][1]!=null && !isNaN(json[s].dps[indices[s]-1][1])) {
                                            json[s].dps[indices[s]-1][1] = (json[s].dps[indices[s]-1][1] * 100) / sum;
                                        }
                                    }
                                    ignoredBecause = "ratio graphs";
                                }
                                else if (dygraphOptions.meanAdjusted) {
                                    var mean = sum / json.length;
                                    for (var s=0; s<json.length; s++) {
                                        //                            console.log("s = "+s);
                                        //                            console.log("indices[s] = "+indices[s]);
                                        if (hadValue[s] && json[s].dps[indices[s]-1][1]!=null && !isNaN(json[s].dps[indices[s]-1][1])) {

                                            //                                console.log("val = "+json[s].dps[indices[s]-1][1]);
                                            //                                console.log("mean = "+mean);
                                            json[s].dps[indices[s]-1][1] -= mean;
                                        }
                                    }
                                    ignoredBecause = "mean adjustment";
                                }
                                else {
                                    if (dygraphOptions.y1AutoScale) {
                                        for (var s=0; s<json.length; s++) {
                                            if (isY1Axis(json[s].aardvark_query.graphOptions.axis)) {
                                                if (hadValue[s] && json[s].dps[indices[s]-1][1]!=null && !isNaN(json[s].dps[indices[s]-1][1])) {
                                                    json[s].dps[indices[s]-1][1] *= scaleMultiplierByMetricNameY1[json[s].metric];
                                                }
                                            }
                                        }
                                        ignoredBecause = "auto scaling";
                                    }
                                    if (dygraphOptions.y2AutoScale) {
                                        for (var s=0; s<json.length; s++) {
                                            if (isY2Axis(json[s].aardvark_query.graphOptions.axis)) {
                                                if (hadValue[s] && json[s].dps[indices[s]-1][1]!=null && !isNaN(json[s].dps[indices[s]-1][1])) {
                                                    json[s].dps[indices[s]-1][1] *= scaleMultiplierByMetricNameY2[json[s].metric];
                                                }
                                            }
                                        }
                                        ignoredBecause = "auto scaling";
                                    }
                                }
                                t = nextTime;
                            }
                        }
200664
private void loadPlanNodesFromJSONArrays(int stmtId, JSONArray jArray, Database db) {
        List<AbstractPlanNode> planNodes = new ArrayList<>();
        int size = jArray.length();

        try {
            for (int i = 0; i < size; i++) {
                JSONObject jobj = jArray.getJSONObject(i);
                String nodeTypeStr = jobj.getString("PLAN_NODE_TYPE");
                PlanNodeType nodeType = PlanNodeType.get(nodeTypeStr);
                AbstractPlanNode apn = nodeType.getPlanNodeClass().newInstance();
                apn.loadFromJSONObject(jobj, db);
                planNodes.add(apn);
            }

            //link children and parents
            for (int i = 0; i < size; i++) {
                JSONObject jobj = jArray.getJSONObject(i);
                if (jobj.has("CHILDREN_IDS")) {
                    AbstractPlanNode parent = planNodes.get(i);
                    JSONArray children = jobj.getJSONArray("CHILDREN_IDS");
                    for (int j = 0; j < children.length(); j++) {
                        AbstractPlanNode child = getNodeofId(children.getInt(j), planNodes);
                        parent.addAndLinkChild(child);
                    }
                }
            }
            m_planNodesListMap.put(stmtId,  planNodes);
        }
        catch (JSONException | InstantiationException | IllegalAccessException e) {
            System.err.println(e);
            e.printStackTrace();
        }
    }
552850
public void readJson(ConfigurationBuilderInfo builderInfo, String json) {
      readJson(builderInfo, "", Json.read(json));
   }
113836
function (json, lib) {

        // Create skeletons and joints
        util$1.each(json.skins, function (skinInfo, idx) {
            var skeleton = new Skeleton({
                name: skinInfo.name
            });
            for (var i = 0; i < skinInfo.joints.length; i++) {
                var nodeIdx = skinInfo.joints[i];
                var node = lib.nodes[nodeIdx];
                var joint = new Joint({
                    name: node.name,
                    node: node,
                    index: skeleton.joints.length
                });
                skeleton.joints.push(joint);
            }
            skeleton.relativeRootNode = lib.nodes[skinInfo.skeleton] || this.rootNode;
            if (skinInfo.inverseBindMatrices) {
                var IBMInfo = json.accessors[skinInfo.inverseBindMatrices];
                var buffer = lib.bufferViews[IBMInfo.bufferView];

                var offset = IBMInfo.byteOffset || 0;
                var size = IBMInfo.count * 16;

                var array = new vendor.Float32Array(buffer, offset, size);

                skeleton.setJointMatricesArray(array);
            }
            else {
                skeleton.updateJointMatrices();
            }
            lib.skeletons[idx] = skeleton;
        }, this);

        function enableSkinningForMesh(mesh, skeleton, jointIndices) {
            mesh.skeleton = skeleton;
            mesh.joints = jointIndices;

            if (!skeleton.boundingBox) {
                skeleton.updateJointsBoundingBoxes(mesh.geometry);
            }
        }

        function getJointIndex(joint) {
            return joint.index;
        }

        util$1.each(json.nodes, function (nodeInfo, nodeIdx) {
            if (nodeInfo.skin != null) {
                var skinIdx = nodeInfo.skin;
                var skeleton = lib.skeletons[skinIdx];

                var node = lib.nodes[nodeIdx];
                var jointIndices = skeleton.joints.map(getJointIndex);
                if (node instanceof Mesh) {
                    enableSkinningForMesh(node, skeleton, jointIndices);
                }
                else {
                    // Mesh have multiple primitives
                    var children = node.children();
                    for (var i = 0; i < children.length; i++) {
                        enableSkinningForMesh(children[i], skeleton, jointIndices);
                    }
                }
            }
        }, this);
    }