Created
February 12, 2017 02:38
-
-
Save kinlane/c1fdae328e0fd1b317790a297c4af837 to your computer and use it in GitHub Desktop.
APIs.json Tag Cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/jscript"> | |
var $apiurl = ""; | |
var $Pallette = {}; | |
var $FullCount = 0; | |
var $tagsforcloud = {}; | |
$tagsforcloud['tags'] = []; | |
function processAPIsJSONTagCloud($apisjsonURL) | |
{ | |
$apiHumanURL = ""; | |
$FullCount = $FullCount + 1; | |
var loadIt = $.getJSON($apisjsonURL, function(apisJSON) { | |
$masterName = apisJSON['name']; | |
$masterDesc = apisJSON['description']; | |
$masterLogo = apisJSON['image']; | |
$masterURL = apisJSON['url']; | |
$masterTags = apisJSON['tags']; | |
$masterIncludes = apisJSON['include']; | |
$.each($masterIncludes, function(masterKey, masterValue) { | |
$includeName = masterValue['name']; | |
$includeRootUrl = masterValue['url']; | |
$FullCount = $FullCount + 1; | |
var loadIt2 = $.getJSON($includeRootUrl, function(apisJSON) { | |
$singleName = apisJSON['name']; | |
//console.log($singleName); | |
$singleDesc = apisJSON['description']; | |
$singleLogo = apisJSON['image']; | |
$singleURL = apisJSON['url']; | |
$singleTags = apisJSON['tags']; | |
$singleAPIs = apisJSON['apis']; | |
$.each($singleAPIs, function(apiKey, apiVal) { | |
$apiName = apiVal['name']; | |
$apiDesc = apiVal['description']; | |
$apiLogo = apiVal['image']; | |
$apiHumanURL = apiVal['humanURL']; | |
$apiBaseURL = apiVal['baseURL']; | |
$apiProperties = apiVal['properties']; | |
$.each($apiProperties, function(propertyKey, propertyValue) { | |
$type = propertyValue['type']; | |
$url = propertyValue['url']; | |
if($type=='x-openapi-spec') | |
{ | |
$FullCount = $FullCount + 1; | |
var loadIt3 = $.getJSON($url, function($openapispec) { | |
$paths = $openapispec['paths']; | |
$title = $openapispec['info']['title']; | |
$apiSlug = $title.replace(/ /g,"-"); | |
$apiSlug = $apiSlug.toLowerCase(); | |
// show the unique host | |
$host = $openapispec['host']; | |
$.each($paths, function(pathKey, pathValue) { | |
$path_name = pathKey; | |
$.each(pathValue, function(methodKey, methodValue) { | |
$method = methodKey; | |
$method_summary = methodValue['summary']; | |
$tags = methodValue['tags']; | |
$.each($tags, function($tagKey, $tagValue) { | |
$tag = $tagValue; | |
$tagslug = $tag.replace(/ /g,"-"); | |
$tagslug = $tagslug.toLowerCase(); | |
$tag = $tag.charAt(0).toUpperCase() + $tag.slice(1); | |
if(!Array.isArray($Pallette[$tag])) | |
{ | |
$Pallette[$tag] = []; | |
} | |
$T = {}; | |
$T['summary'] = $method_summary; | |
$T['method'] = $method.toUpperCase(); | |
$T['path'] = $path_name; | |
$T['url'] = $url; | |
$T['host'] = $host; | |
$Pallette[$tag].push($T); | |
$M = {}; | |
$M['tag'] = $tag; | |
$M['name'] = $tag; | |
$M['slug'] = $tagslug; | |
$M['count'] = 1; | |
$M['percentage'] = 0; | |
$TagExist = 0; | |
$.each($tagsforcloud['tags'], function(key, value) { | |
if(value['tag'] == $tag) | |
{ | |
$TagExist = 1; | |
$verbcount = $tagsforcloud['tags'][key]['count']; | |
$verbcount = $verbcount + 1; | |
$tagsforcloud['tags'][key]['count'] = $verbcount ; | |
} | |
}); | |
// Add It Because It Doesn't Exist | |
if($TagExist==0) | |
{ | |
$tagsforcloud['tags'].push($M); | |
} | |
}); | |
}); | |
}); | |
}); | |
loadIt3.complete(function() { | |
$FullCount = $FullCount - 1; | |
if($FullCount==0){ | |
//$viewer = JSON.stringify($Pallette, null, 4); | |
//document.getElementById("jsonViewerDetails").value = $viewer; | |
//sortPage(); | |
// Let's get max | |
$Max = 0; | |
$.each($tagsforcloud['tags'], function(key, val) { | |
$tagcount = val['count']; | |
if($tagcount > $Max){ $Max = $tagcount; } | |
}); | |
// Set percentages | |
$.each($tagsforcloud['tags'], function(key, val) { | |
$tagcount = val['count']; | |
//$percentage = (($tagcount - 1) / ($Max - 1)); | |
$percentage = ($tagcount / $Max) * 100; | |
//$percentage = ($percentage / 10) * 100; | |
$percentage = Math.round($percentage); | |
$tagsforcloud['tags'][key]['percentage'] = $percentage; | |
}); | |
$.each($tagsforcloud['tags'], function(key, val) { | |
$tag = val['tag']; | |
$name = val['name']; | |
$slug = val['slug']; | |
$tagcount = val['count']; | |
$tagpercentage = val['percentage']; | |
//console.log("count/perc: " + $tagcount + "/" + $tagpercentage); | |
//html = '<span style="padding: 5px; text-align: center;"><a href="#" title="used ' + $tagcount + ' times">' + $name + '</a> (' + $tagcount + ' times)</span>'; | |
//$('#stack-toc').append(html); | |
html = '<span data-weight="' + $tagpercentage + '"><a href="#" name="' + $name + '">' + $name + '</a></span>'; | |
$('#stack-cloud').append(html); | |
}); | |
$("#stack-cloud").awesomeCloud({ | |
"size" : { | |
"grid" : 35, | |
"factor" : 10 | |
}, | |
"options" : { | |
"color" : "random-dark", | |
"rotationRatio" : 0 | |
}, | |
"font" : "'Times New Roman', Times, serif", | |
"shape" : "square" | |
}); | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
loadIt2.complete(function() { | |
$FullCount = $FullCount - 1; | |
}); | |
}); | |
}); | |
loadIt.complete(function() { | |
$FullCount = $FullCount - 1; | |
}); | |
} | |
$apisjsonURL = "https://raw.githubusercontent.com/gsa-data/index/master/_data/apis.json"; | |
//console.log("loading..." + $apisjsonURL); | |
processAPIsJSONTagCloud($apisjsonURL); | |
</script> | |
<div id="stack-cloud-wrapper" style="width 75%; border: 0px solid #000; margin-left: 0px; margin-right: 0px;"> | |
<div id="stack-toc" style="text-align: center; width=100%; border: 0px solid #000;"></div> | |
<div id="stack-cloud" class="wordcloud" style="height: 400px;"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment