Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from newsdev/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
blumysden committed Jan 23, 2020
2 parents 52d78aa + 331461c commit 8e524b2
Show file tree
Hide file tree
Showing 81 changed files with 11,974 additions and 132 deletions.
46 changes: 20 additions & 26 deletions audiogram/draw-frames.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var fs = require("fs"),
path = require("path"),
Canvas = require("canvas"),
queue = require("d3").queue;
path = require("path"),
Canvas = require("../vendor/canvas"),
queue = require("d3").queue;

function drawFrames(renderer, options, cb) {

var frameQueue = queue(10),
canvases = [];
canvases = [];

for (var i = 0; i < 10; i++) {
canvases.push(new Canvas(options.width, options.height));
Expand All @@ -19,9 +18,8 @@ function drawFrames(renderer, options, cb) {
frameQueue.awaitAll(cb);

function drawFrame(frameNumber, frameCallback) {

var canvas = canvases.pop(),
context = canvas.getContext("2d");
context = canvas.getContext("2d");

renderer.drawFrame(context, {
caption: options.caption,
Expand All @@ -31,44 +29,40 @@ function drawFrames(renderer, options, cb) {
frame: frameNumber
});

canvas.toBuffer(function(err, buf){

canvas.toBuffer(function(err, buf) {
if (err) {
return cb(err);
}

fs.writeFile(path.join(options.frameDir, zeropad(frameNumber + 1, 6) + ".png"), buf, function(writeErr) {

if (writeErr) {
return frameCallback(writeErr);
}

if (options.tick) {
options.tick();
}
fs.writeFile(
path.join(options.frameDir, zeropad(frameNumber + 1, 6) + ".png"),
buf,
function(writeErr) {
if (writeErr) {
return frameCallback(writeErr);
}

canvases.push(canvas);
if (options.tick) {
options.tick();
}

return frameCallback(null);

});
canvases.push(canvas);

return frameCallback(null);
}
);
});

}

}

function zeropad(str, len) {

str = str.toString();

while (str.length < len) {
str = "0" + str;
}

return str;

}

module.exports = drawFrames;
39 changes: 22 additions & 17 deletions audiogram/initialize-canvas.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var fs = require("fs"),
path = require("path"),
Canvas = require("canvas"),
getRenderer = require("../renderer/");
path = require("path"),
Canvas = require("../vendor/canvas"),
getRenderer = require("../renderer/");

function initializeCanvas(theme, cb) {

// Fonts pre-registered in bin/worker
var renderer = getRenderer(theme);

Expand All @@ -13,20 +12,26 @@ function initializeCanvas(theme, cb) {
}

// Load background image from file (done separately so renderer code can work in browser too)
fs.readFile(path.join(__dirname, "..", "settings", "backgrounds", theme.backgroundImage), function(err, raw){

if (err) {
return cb(err);
fs.readFile(
path.join(
__dirname,
"..",
"settings",
"backgrounds",
theme.backgroundImage
),
function(err, raw) {
if (err) {
return cb(err);
}

var bg = new Canvas.Image();
bg.src = raw;
renderer.backgroundImage(bg);

return cb(null, renderer);
}

var bg = new Canvas.Image;
bg.src = raw;
renderer.backgroundImage(bg);

return cb(null, renderer);

});

);
}

module.exports = initializeCanvas;
6 changes: 4 additions & 2 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ function timestamp () {
+ addZero(d.getSeconds()) + '_';
}

var pre_pro = window.location.protocol,
pre_host = window.location.host;

d3.json("/settings/labels.json", function(err, labels){
d3.json(pre_pro + "//" + pre_host + "/settings/labels.json", function(err, labels){

// Populate labels menu
d3.select("#input-label")
Expand All @@ -45,7 +47,7 @@ d3.json("/settings/labels.json", function(err, labels){

}); // end label ingestion

d3.json("/settings/themes.json", function(err, themes){
d3.json(pre_pro + "//" + pre_host + "/settings/themes.json", function(err, themes){

var errorMessage;

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- "./settings:/usr/src/app/settings/"
- "./lib:/usr/src/app/lib/"
- "./server:/usr/src/app/server/"
- "./vendor:/usr/src/app/vendor/"
6 changes: 3 additions & 3 deletions lib/register-fonts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var fonts = require("./settings/").fonts,
_ = require("underscore"),
Canvas = require("canvas");
_ = require("underscore"),
Canvas = require("../vendor/canvas");

// Register custom fonts one time
if (Array.isArray(fonts)) {
fonts.forEach(function(font){
fonts.forEach(function(font) {
Canvas.registerFont(font.file, _.pick(font, "family", "weight", "style"));
});
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"dependencies": {
"aws-sdk": "^2.2.39",
"browserify": "^13.0.0",
"canvas": "git+https://github.com/chearon/node-canvas.git#12971f64a66b",
"compression": "^1.6.1",
"d3": "^4.1.1",
"dotenv": "^2.0.0",
Expand Down
15 changes: 2 additions & 13 deletions renderer/text-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ module.exports = function(theme) {
wrap_width = right - left,
max_width = 0,
words = smartquotes(txt + "").trim().replace(/\s\s+/g, " \n").split(/ /g),
indent;

if (type === 'caption') {
// negative indentation for opening quotes
indent = 20;
}
else if (type === 'citation') {
// negative indentation for opening em dash
indent = 50;
}
indent = 20;

if (bottom === null && top === null) {
top = 0;
Expand All @@ -53,8 +44,6 @@ module.exports = function(theme) {

} else {

// automatically prepend em dash to citation
word = (type === 'citation' && i === 0) ? '— ' + word : word;
lines[lines.length - 1].push(word);

}
Expand Down Expand Up @@ -97,7 +86,7 @@ module.exports = function(theme) {
lines.forEach(function(line, i){

if (/caption|citation/.test(type)) {
if (i === 0 && /^“|^—/.test(line[0])) {
if (i === 0 && /^“/.test(line[0])) {
context.fillText(line.join(" "), x, y + i * (theme[type + 'LineHeight'] + theme[type + 'LineSpacing']));
}
else {
Expand Down
Binary file added settings/backgrounds/t_logo_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added settings/backgrounds/t_logo_dearsugars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added settings/backgrounds/the-choice.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion settings/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"None",
"The Daily",
"Still Processing",
"Dear Sugars",
"Popcast",
"Modern Love",
"The Book Review",
"- Other:"
"The Argument"
]
}
18 changes: 18 additions & 0 deletions settings/themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@
"labelColor": "#fff",
"labelText": "The Daily"
},
"Dear Sugars": {
"waveColor": "rgba(255, 255, 255, 0.35)",
"foregroundColor": "rgba(0, 0, 0, 0.9)",
"citationColor": "rgba(0, 0, 0, 0.9)",
"backgroundColor": "#91d2d2",
"backgroundImage": "t_logo_dearsugars.png",
"labelColor": "rgba(0, 0, 0, 0.9)",
"labelText": "Dear Sugars"
},
"The Choice": {
"waveColor": "rgba(255, 255, 255, 0.50)",
"foregroundColor": "#fff",
"citationColor": "#fff",
"backgroundColor": "#f4d7b9",
"backgroundImage": "the-choice.jpg",
"labelColor": "#fff",
"labelText": "The Choice"
},
"Science": {
"waveColor": "#d9d9d9",
"foregroundColor": "#000",
Expand Down
Loading

0 comments on commit 8e524b2

Please sign in to comment.