-
Notifications
You must be signed in to change notification settings - Fork 14
/
c3.min.js
1 lines (1 loc) · 3.04 KB
/
c3.min.js
1
(function(){function a(a){var b,c,d,e,f,g,h;c3.color=[];for(b=0;b<a.color.length;b+=3)c3.color[b/3]=d3.lab(a.color[b],a.color[b+1],a.color[b+2]);c=c3.color.length,c3.terms=a.terms,d=c3.terms.length,c3.T=e=[];for(var b=0;b<a.T.length;b+=2)e[a.T[b]]=a.T[b+1];c3.color.count=g=[];for(b=0;b<c;++b)g[b]=0;c3.terms.count=h=[];for(b=0;b<d;++b)h[b]=0;d3.keys(e).forEach(function(a){var b=Math.floor(a/d),c=Math.floor(a%d),f=e[a]||0;g[b]+=f,h[c]+=f}),c3.A=f=a.A}function b(){var a=c3.color.length,b=c3.terms.length,c=c3.T,d=c3.A,e=c3.color.count,f=c3.terms.count;c3.count=function(a,d){return c[a*b+d]||0},c3.terms.prob=function(a,d){return(c[d*b+a]||0)/f[a]},c3.terms.entropy=function(d){var e=0,g;for(var h=0;h<a;++h)g=(c[h*b+d]||0)/f[d],g>0&&(e+=g*Math.log(g)/Math.LN2);return e},c3.terms.perplexity=function(a){var b=c3.terms.entropy(a);return Math.pow(2,-b)},c3.terms.cosine=function(d,e){var f=0,g=0,h=0,i,j;for(var k=0;k<a;++k)i=c[k*b+d]||0,j=c[k*b+e]||0,f+=i*i,g+=j*j,h+=i*j;return h/Math.sqrt(f*g)},c3.color.prob=function(a,d){return(c[a*b+d]||0)/e[a]},c3.color.entropy=function(a){var d=0,f;for(var g=0;g<b;++g)f=(c[a*b+g]||0)/e[a],f>0&&(d+=f*Math.log(f)/Math.LN2);return d},c3.terms.hellinger=function(d,e){var g=0,h,i,j=Math.sqrt(f[d]*f[e]);for(var k=0;k<a;++k)h=c[k*b+d]||0,i=c[k*b+e]||0,g+=Math.sqrt(h*i);return Math.sqrt(1-g/j)},c3.color.perplexity=function(a){var b=c3.color.entropy(a);return Math.pow(2,-b)},c3.color.cosine=function(a,d){var e=0,f=0,g=0,h,i;for(var j=0;j<b;++j)h=c[a*b+j]||0,i=c[d*b+j]||0,e+=h*h,f+=i*i,g+=h*i;return g/Math.sqrt(e*f)},c3.color.hellinger=function(a,d){var f=0,g,h,i=Math.sqrt(e[a]*e[d]);for(var j=0;j<b;++j)g=c[a*b+j]||0,h=c[d*b+j]||0,f+=Math.sqrt(g*h);return Math.sqrt(1-f/i)},c3.terms.relatedTerms=function(a,c){var e=0,f=c3.terms.center[a],g=[];for(var h=0;h<b;++h)h!=a&&g.push({index:h,score:d[h*b+a]});return g.sort(function(a,b){var c,d,e,g,h,i,j,k,l=b.score-a.score;return Math.abs(l)<5e-5&&(c=c3.terms.center[a.index],d=c3.terms.center[b.index],l=c.de00(f)-d.de00(f)),l}),g.unshift({index:a,score:d[a*b+a]}),c?g.slice(0,c):g},c3.terms.relatedColors=function(d,f){var g=[];for(var h=0;h<a;++h){var i=(c[h*b+d]||0)/e[h];i>0&&g.push({index:h,score:i})}return g.sort(function(a,b){return b.score-a.score}),f?g.slice(0,f):g},c3.color.relatedTerms=function(a,d,e){var f=a*b,g=[],h=0,i,j=c3.terms.count;for(var k=0;k<b;++k)(i=c[f+k])!==undefined&&(g.push({index:k,score:i}),h+=i);return e&&(g=g.filter(function(a){return j[a.index]>e})),g.sort(function(a,b){return b.score-a.score}),g.forEach(function(a){a.score/=h}),d?g.slice(0,d):g},c3.terms.center=d3.range(b).map(function(a){var b=c3.terms.relatedColors(a,5).map(function(a){return c3.color[a.index]}),c=0,d=0,e=0,f=b.length;return b.forEach(function(a){c+=a.L,d+=a.a,e+=a.b}),d3.lab(Math.round(c/f),Math.round(d/f),Math.round(e/f))})}c3={version:"1.0.0"},c3.load=function(c,d){d=d||!1;var e=new XMLHttpRequest,f=function(){if(!d||e.readyState==4)e.status==200||e.status==0?(a(JSON.parse(e.responseText)),b()):alert("Error Loading C3 Data")};e.open("GET",c,!1),d&&(e.onreadystatechange=f),e.send(null),d||f()}})();