12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- var d3 = require("d3"),
- patterns = require("./patterns.js"),
- textWrapper = require("./text-wrapper.js");
-
- module.exports = function(t) {
-
- var renderer = {},
- backgroundImage,
- wrapText,
- theme;
-
- renderer.backgroundImage = function(_) {
- if (!arguments.length) return backgroundImage;
- backgroundImage = _;
- return this;
- };
-
- renderer.theme = function(_) {
- if (!arguments.length) return theme;
-
- theme = _;
-
- // Default colors
- theme.backgroundColor = theme.backgroundColor || "#fff";
- theme.waveColor = theme.waveColor || theme.foregroundColor || "#000";
- theme.captionColor = theme.captionColor || theme.foregroundColor || "#000";
-
- // Default wave dimensions
- if (typeof theme.waveTop !== "number") theme.waveTop = 0;
- if (typeof theme.waveBottom !== "number") theme.waveBottom = theme.height;
- if (typeof theme.waveLeft !== "number") theme.waveLeft = 0;
- if (typeof theme.waveRight !== "number") theme.waveRight = theme.width;
-
- wrapText = textWrapper(theme);
-
- return this;
- };
-
- // Draw the frame
- renderer.drawFrame = function(context, options){
-
- context.patternQuality = "best";
-
- // Draw the background image and/or background color
- context.clearRect(0, 0, theme.width, theme.height);
-
- context.fillStyle = theme.backgroundColor;
- context.fillRect(0, 0, theme.width, theme.height);
-
- if (backgroundImage) {
- context.drawImage(backgroundImage, 0, 0, theme.width, theme.height);
- }
-
- patterns[theme.pattern || "wave"](context, options.waveform, theme);
-
- // Write the caption
- if (options.caption) {
- wrapText(context, options.caption, 'caption');
- }
-
- // Write the citation
- if (options.citation) {
- wrapText(context, options.citation, 'citation');
- }
-
- // Write the label
- if (options.label) {
- wrapText(context, options.label, 'label');
- }
-
- return this;
-
- };
-
- if (t) {
- renderer.theme(t);
- }
-
- return renderer;
-
- }
|