w2v-server: generate tsne-map from js variables
diff --git a/templates/index.html.ep b/templates/index.html.ep
index 59514fd..f4765a2 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -753,8 +753,21 @@
% use Mojo::ByteStream 'b';
% my $urlprefix = url_with->query([word=>'']);
$(window).load(function() {
- var vecs = <%= b(Mojo::JSON::to_json($lists->[0])) %>;
- showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => $urlprefix})); %>);
+ var result = <%= b(Mojo::JSON::to_json($lists)) %>;
+ var nvecs = [],
+ nwords = [],
+ nranks = [],
+ nmarked = [];
+ for(var i = 0; i < result.length; i++) {
+ nwords = nwords.concat(result[i].map(function(a){return a.word;}));
+ nvecs = nvecs.concat(result[i].map(function(a){return a.vector;}));
+ nranks = nranks.concat(result[i].map(function(a){return a.rank;}));
+ nmarked = nmarked.concat(result[i].map(function(a){return a.marked;}));
+ }
+ var urlprefix = new URLSearchParams(window.location.search);
+ urlprefix.set("word","");
+ showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked, urlprefix: "?"+urlprefix} );
+ // showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => "?"+$urlprefix})); %>);
});
</script>
<div id="second">