Commit e6dfeddf authored by Matthias Eurich's avatar Matthias Eurich

Add WordCloud to welcome page

parent b3426a04
......@@ -32,6 +32,9 @@ if (Meteor.isServer) {
});
}
});
Meteor.publish("tags", function () {
return Cardsets.find({}, {fields: {_id: 1, name: 1, quantity: 1, kind: 1}});
});
}
const CardsetsSchema = new SimpleSchema({
......
import {Meteor} from "meteor/meteor";
import {Mongo} from "meteor/mongo";
export const Cloud = new Mongo.Collection("wordcloud");
if (Meteor.isServer) {
Meteor.publish("wordcloud", function () {
return Cloud.find({}, {fields: {_id: 1, list: 1}});
});
}
......@@ -193,4 +193,5 @@ Meteor.startup(function () {
}
cronScheduler.startCron();
cronScheduler.startWordCron();
});
......@@ -8,7 +8,9 @@
class="pull-left lmargin">Share.</h2>
</span>
</div>
<div id="tag-cloud-container">
<canvas id="tag-cloud-canvas"></canvas>
</div>
<div class="panel-footer" id="login">
<h5>{{_ "intro.choose"}}</h5>
</div>
......
......@@ -2,8 +2,60 @@
import {Meteor} from "meteor/meteor";
import {Template} from "meteor/templating";
import WordCloud from "wordcloud";
import {Cloud} from "../../api/cloud.js";
import "./welcome.html";
Meteor.subscribe("wordcloud");
function createTagCloud() {
var cloud = Cloud.find({}).fetch();
var list = [];
if (cloud.length > 0) {
list = cloud[0].list;
} else {
return;
}
document.getElementById('tag-cloud-canvas').width = document.getElementById('tag-cloud-container').offsetWidth;// 750;
let width = document.getElementById('tag-cloud-canvas').width;
let gridSize = 20;
let weightFactor = 1;
if (width < 300) {
gridSize = 10;
weightFactor = 0.6;
} else if (width < 500) {
gridSize = 15;
weightFactor = 0.8;
}
document.getElementById('tag-cloud-canvas').height = width / 3.125;
WordCloud(document.getElementById('tag-cloud-canvas'),
{
list: list,
gridSize: gridSize,
weightFactor: weightFactor,
fontFamily: 'Finger Paint, cursive, sans-serif',
color: function (word) {
for (var i = 0; i < list.length; i++) {
if (word == list[i][0]) {
return list[i][2];
}
}
},
hover: window.drawBox,
backgroundColor: '#FFFFFF',
drawOutOfBound: false,
rotateRatio: 0.1,
minRotation: 0,
maxRotation: 0
});
}
//------------------------ LOGIN EVENT
Template.welcome.events({
......@@ -55,6 +107,15 @@ Template.welcome.events({
}
});
Template.welcome.onCreated(function () {
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function () {
createTagCloud();
}, false);
});
Template.welcome.onRendered(function () {
if (Meteor.settings.public.displayLoginButtons.displayFacebook) {
$('.panel-footer').append('<a id="facebook" href=""><img src="img/social_facebook_box_white.png" alt="login using facebook"/></a>');
......@@ -74,4 +135,8 @@ Template.welcome.onRendered(function () {
$('.panel-footer').append('<a id="BackdoorLogin" href=""><img src="img/social_backdoor_box_white.png" /></a>');
$('.panel-footer').append('<input id="TestingBackdoorUsername" name="username" placeholder="username">');
}
this.autorun(() => {
createTagCloud();
});
});
......@@ -39,6 +39,7 @@ $color_fuscous_gray_approx: rgb(85, 85, 84);
.panel-footer {
border-top: 0;
margin-top: 0px;
}
}
......
......@@ -10,7 +10,8 @@
"ink-docstrap": "~1.3.0",
"meteor-node-stubs": "~0.2.0",
"react": "^15.0.2",
"web-push": "^3.2.2"
"web-push": "^3.2.2",
"wordcloud": "^1.0.6"
},
"version": "1.0.0",
"main": "index.js",
......
......@@ -17,4 +17,15 @@ export class CronScheduler {
});
SyncedCron.start();
}
startWordCron() {
SyncedCron.add({
name: "wordCron",
schedule: function (parser) {
return parser.recur().on('02:00:00').time();
},
job: function () {
Meteor.call("updateWordsForWordcloud");
}
});
}
}
......@@ -6,6 +6,7 @@ import "../imports/api/cardsets.js";
import "../imports/api/cards.js";
import "../imports/api/learned.js";
import "./leitner.js";
import "./wordcloud.js";
import "../imports/api/badges.js";
import "../imports/api/experience.js";
import "../imports/api/ratings.js";
......
import {Meteor} from "meteor/meteor";
import {Cardsets} from "../imports/api/cardsets.js";
import {Cloud} from "../imports/api/cloud.js";
Meteor.methods({
updateWordsForWordcloud: function () {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
var cardsets = Cardsets.find({}, {fields: {_id: 1, name: 1, quantity: 1, kind: 1}});
var list = [];
// find biggest cardset for normalization
var biggestCardsetSize = 0;
cardsets.forEach(function (cardset) {
if (cardset.quantity > biggestCardsetSize) {
biggestCardsetSize = cardset.quantity;
}
});
// load cardset name
cardsets.forEach(function (cardset) {
var name = cardset.name;
if (name.length > 30) {
name = name.substring(0, 30) + "";
}
var colors = ["#003bd1", "#80ba24", "#ffb300"];
var color = colors[0];
switch (cardset.kind) {
case "free":
color = colors[0];
break;
case "edu":
color = colors[1];
break;
case "pro":
color = colors[2];
break;
}
var quantitiy = cardset.quantity / biggestCardsetSize * 40;
list.push([name, quantitiy, color]);
});
// sort list
list.sort(function (a, b) { return (b[0].length * b[1]) - (a[0].length * a[1]); });
if (list.length > 0) {
Cloud.remove({});
Cloud.insert({'list': list});
}
}
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment