MCPcopy Index your code
hub / github.com/microsoft/SandDance / cloud

Function cloud

docs/app/js/sanddance-app.js:140717–140872  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140715// Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf
140716var cloudRadians = Math.PI / 180, cw = 64, ch = 2048;
140717function cloud() {
140718 var size = [
140719 256,
140720 256
140721 ], text, font, fontSize, fontStyle, fontWeight, rotate, padding, spiral = archimedeanSpiral, words = [], random = Math.random, cloud1 = {};
140722 cloud1.layout = function() {
140723 var contextAndRatio = getContext((0, _vegaCanvas.canvas)()), board = zeroArray((size[0] >> 5) * size[1]), bounds = null, n = words.length, i = -1, tags = [], data = words.map((d)=>({
140724 text: text(d),
140725 font: font(d),
140726 style: fontStyle(d),
140727 weight: fontWeight(d),
140728 rotate: rotate(d),
140729 size: ~~(fontSize(d) + 1e-14),
140730 padding: padding(d),
140731 xoff: 0,
140732 yoff: 0,
140733 x1: 0,
140734 y1: 0,
140735 x0: 0,
140736 y0: 0,
140737 hasText: false,
140738 sprite: null,
140739 datum: d
140740 })).sort((a, b)=>b.size - a.size);
140741 while(++i < n){
140742 var d1 = data[i];
140743 d1.x = size[0] * (random() + .5) >> 1;
140744 d1.y = size[1] * (random() + .5) >> 1;
140745 cloudSprite(contextAndRatio, d1, data, i);
140746 if (d1.hasText && place(board, d1, bounds)) {
140747 tags.push(d1);
140748 if (bounds) cloudBounds(bounds, d1);
140749 else bounds = [
140750 {
140751 x: d1.x + d1.x0,
140752 y: d1.y + d1.y0
140753 },
140754 {
140755 x: d1.x + d1.x1,
140756 y: d1.y + d1.y1
140757 }
140758 ]; // Temporary hack
140759 d1.x -= size[0] >> 1;
140760 d1.y -= size[1] >> 1;
140761 }
140762 }
140763 return tags;
140764 };
140765 function getContext(canvas) {
140766 canvas.width = canvas.height = 1;
140767 var ratio = Math.sqrt(canvas.getContext("2d").getImageData(0, 0, 1, 1).data.length >> 2);
140768 canvas.width = (cw << 5) / ratio;
140769 canvas.height = ch / ratio;
140770 var context = canvas.getContext("2d");
140771 context.fillStyle = context.strokeStyle = "red";
140772 context.textAlign = "center";
140773 return {
140774 context: context,

Callers 1

WordcloudFunction · 0.70

Calls 12

getContextFunction · 0.70
zeroArrayFunction · 0.70
textFunction · 0.70
fontFunction · 0.70
rotateFunction · 0.70
fontSizeFunction · 0.70
paddingFunction · 0.70
randomFunction · 0.70
cloudSpriteFunction · 0.70
placeFunction · 0.70
cloudBoundsFunction · 0.70
functorFunction · 0.70

Tested by

no test coverage detected