id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
8,400
node-inspector/node-inspector
front-end/ui/SplitView.js
function() { if (!this._totalSize) { this._totalSize = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight; this._totalSizeOtherDimension = this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth; } return this._totalSize * WebInspector.zoomManager.zoomFactor(); }
javascript
function() { if (!this._totalSize) { this._totalSize = this._isVertical ? this.contentElement.offsetWidth : this.contentElement.offsetHeight; this._totalSizeOtherDimension = this._isVertical ? this.contentElement.offsetHeight : this.contentElement.offsetWidth; } return this._totalSize * WebInspector.zoomManager.zoomFactor(); }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "_totalSize", ")", "{", "this", ".", "_totalSize", "=", "this", ".", "_isVertical", "?", "this", ".", "contentElement", ".", "offsetWidth", ":", "this", ".", "contentElement", ".", "offsetHeight", ";", "this", ".", "_totalSizeOtherDimension", "=", "this", ".", "_isVertical", "?", "this", ".", "contentElement", ".", "offsetHeight", ":", "this", ".", "contentElement", ".", "offsetWidth", ";", "}", "return", "this", ".", "_totalSize", "*", "WebInspector", ".", "zoomManager", ".", "zoomFactor", "(", ")", ";", "}" ]
Returns total size in DIP. @return {number}
[ "Returns", "total", "size", "in", "DIP", "." ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/front-end/ui/SplitView.js#L423-L430
8,401
node-inspector/node-inspector
front-end/toolbox/ResponsiveDesignView.js
function(dipWidth, dipHeight, scale) { this._scale = scale; this._dipWidth = dipWidth ? Math.max(dipWidth, 1) : 0; this._dipHeight = dipHeight ? Math.max(dipHeight, 1) : 0; this._updateUI(); }
javascript
function(dipWidth, dipHeight, scale) { this._scale = scale; this._dipWidth = dipWidth ? Math.max(dipWidth, 1) : 0; this._dipHeight = dipHeight ? Math.max(dipHeight, 1) : 0; this._updateUI(); }
[ "function", "(", "dipWidth", ",", "dipHeight", ",", "scale", ")", "{", "this", ".", "_scale", "=", "scale", ";", "this", ".", "_dipWidth", "=", "dipWidth", "?", "Math", ".", "max", "(", "dipWidth", ",", "1", ")", ":", "0", ";", "this", ".", "_dipHeight", "=", "dipHeight", "?", "Math", ".", "max", "(", "dipHeight", ",", "1", ")", ":", "0", ";", "this", ".", "_updateUI", "(", ")", ";", "}" ]
WebInspector.OverridesSupport.PageResizer override. @param {number} dipWidth @param {number} dipHeight @param {number} scale
[ "WebInspector", ".", "OverridesSupport", ".", "PageResizer", "override", "." ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/front-end/toolbox/ResponsiveDesignView.js#L167-L173
8,402
node-inspector/node-inspector
front-end/sources/NavigatorView.js
typeWeight
function typeWeight(treeElement) { var type = treeElement.type(); if (type === WebInspector.NavigatorTreeOutline.Types.Domain) { if (treeElement.titleText === WebInspector.targetManager.inspectedPageDomain()) return 1; return 2; } if (type === WebInspector.NavigatorTreeOutline.Types.FileSystem) return 3; if (type === WebInspector.NavigatorTreeOutline.Types.Folder) return 4; return 5; }
javascript
function typeWeight(treeElement) { var type = treeElement.type(); if (type === WebInspector.NavigatorTreeOutline.Types.Domain) { if (treeElement.titleText === WebInspector.targetManager.inspectedPageDomain()) return 1; return 2; } if (type === WebInspector.NavigatorTreeOutline.Types.FileSystem) return 3; if (type === WebInspector.NavigatorTreeOutline.Types.Folder) return 4; return 5; }
[ "function", "typeWeight", "(", "treeElement", ")", "{", "var", "type", "=", "treeElement", ".", "type", "(", ")", ";", "if", "(", "type", "===", "WebInspector", ".", "NavigatorTreeOutline", ".", "Types", ".", "Domain", ")", "{", "if", "(", "treeElement", ".", "titleText", "===", "WebInspector", ".", "targetManager", ".", "inspectedPageDomain", "(", ")", ")", "return", "1", ";", "return", "2", ";", "}", "if", "(", "type", "===", "WebInspector", ".", "NavigatorTreeOutline", ".", "Types", ".", "FileSystem", ")", "return", "3", ";", "if", "(", "type", "===", "WebInspector", ".", "NavigatorTreeOutline", ".", "Types", ".", "Folder", ")", "return", "4", ";", "return", "5", ";", "}" ]
Insert in the alphabetical order, first domains, then folders, then scripts.
[ "Insert", "in", "the", "alphabetical", "order", "first", "domains", "then", "folders", "then", "scripts", "." ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/front-end/sources/NavigatorView.js#L625-L638
8,403
node-inspector/node-inspector
index.js
buildInspectorUrl
function buildInspectorUrl(inspectorHost, inspectorPort, debugPort, isHttps) { var host = inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost; var port = inspectorPort; var protocol = isHttps ? 'https' : 'http'; var isUnixSocket = !/^\d+$/.test(port); if (isUnixSocket) { host = path.resolve(__dirname, inspectorPort); port = null; protocol = 'unix'; } var parts = { protocol: protocol, hostname: host, port: port, pathname: '/', search: '?port=' + debugPort }; return url.format(parts); }
javascript
function buildInspectorUrl(inspectorHost, inspectorPort, debugPort, isHttps) { var host = inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost; var port = inspectorPort; var protocol = isHttps ? 'https' : 'http'; var isUnixSocket = !/^\d+$/.test(port); if (isUnixSocket) { host = path.resolve(__dirname, inspectorPort); port = null; protocol = 'unix'; } var parts = { protocol: protocol, hostname: host, port: port, pathname: '/', search: '?port=' + debugPort }; return url.format(parts); }
[ "function", "buildInspectorUrl", "(", "inspectorHost", ",", "inspectorPort", ",", "debugPort", ",", "isHttps", ")", "{", "var", "host", "=", "inspectorHost", "==", "'0.0.0.0'", "?", "'127.0.0.1'", ":", "inspectorHost", ";", "var", "port", "=", "inspectorPort", ";", "var", "protocol", "=", "isHttps", "?", "'https'", ":", "'http'", ";", "var", "isUnixSocket", "=", "!", "/", "^\\d+$", "/", ".", "test", "(", "port", ")", ";", "if", "(", "isUnixSocket", ")", "{", "host", "=", "path", ".", "resolve", "(", "__dirname", ",", "inspectorPort", ")", ";", "port", "=", "null", ";", "protocol", "=", "'unix'", ";", "}", "var", "parts", "=", "{", "protocol", ":", "protocol", ",", "hostname", ":", "host", ",", "port", ":", "port", ",", "pathname", ":", "'/'", ",", "search", ":", "'?port='", "+", "debugPort", "}", ";", "return", "url", ".", "format", "(", "parts", ")", ";", "}" ]
Build a URL for loading inspector UI in the browser. @param {string|undefined} inspectorHost as configured via --web-host @param {number} inspectorPort as configured via --web-port @param {number} debugPort as configured via --debug in the debugged app @param {number} isHttps as configured via --ssl-cert and --ssl-key in the debugged app
[ "Build", "a", "URL", "for", "loading", "inspector", "UI", "in", "the", "browser", "." ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/index.js#L15-L36
8,404
node-inspector/node-inspector
index.js
buildWebSocketUrl
function buildWebSocketUrl(inspectorHost, inspectorPort, debugPort, isSecure) { var parts = { protocol: isSecure ? 'wss:' : 'ws:', hostname: inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost, port: inspectorPort, pathname: '/', search: '?port=' + debugPort, slashes: true }; return url.format(parts); }
javascript
function buildWebSocketUrl(inspectorHost, inspectorPort, debugPort, isSecure) { var parts = { protocol: isSecure ? 'wss:' : 'ws:', hostname: inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost, port: inspectorPort, pathname: '/', search: '?port=' + debugPort, slashes: true }; return url.format(parts); }
[ "function", "buildWebSocketUrl", "(", "inspectorHost", ",", "inspectorPort", ",", "debugPort", ",", "isSecure", ")", "{", "var", "parts", "=", "{", "protocol", ":", "isSecure", "?", "'wss:'", ":", "'ws:'", ",", "hostname", ":", "inspectorHost", "==", "'0.0.0.0'", "?", "'127.0.0.1'", ":", "inspectorHost", ",", "port", ":", "inspectorPort", ",", "pathname", ":", "'/'", ",", "search", ":", "'?port='", "+", "debugPort", ",", "slashes", ":", "true", "}", ";", "return", "url", ".", "format", "(", "parts", ")", ";", "}" ]
Build a URL for the WebSocket endpoint. @param {string|undefined} inspectorHost as configured via --web-host @param {number} inspectorPort as configured via --web-port @param {number} debugPort as configured via --debug in the debugged app @param {number} isHttps as configured via --ssl-cert and --ssl-key in the debugged app
[ "Build", "a", "URL", "for", "the", "WebSocket", "endpoint", "." ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/index.js#L45-L56
8,405
node-inspector/node-inspector
front-end/timeline/TimelinePanel.js
function() { if (!this._searchResults || !this._searchResults.length) return; var index = this._selectedSearchResult ? this._searchResults.indexOf(this._selectedSearchResult) : -1; this._jumpToSearchResult(index + 1); }
javascript
function() { if (!this._searchResults || !this._searchResults.length) return; var index = this._selectedSearchResult ? this._searchResults.indexOf(this._selectedSearchResult) : -1; this._jumpToSearchResult(index + 1); }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "_searchResults", "||", "!", "this", ".", "_searchResults", ".", "length", ")", "return", ";", "var", "index", "=", "this", ".", "_selectedSearchResult", "?", "this", ".", "_searchResults", ".", "indexOf", "(", "this", ".", "_selectedSearchResult", ")", ":", "-", "1", ";", "this", ".", "_jumpToSearchResult", "(", "index", "+", "1", ")", ";", "}" ]
WebInspector.Searchable implementation
[ "WebInspector", ".", "Searchable", "implementation" ]
79e01c049286374f86dd560742a614019c02402f
https://github.com/node-inspector/node-inspector/blob/79e01c049286374f86dd560742a614019c02402f/front-end/timeline/TimelinePanel.js#L829-L835
8,406
tempusdominus/bootstrap-4
build/js/tempusdominus-bootstrap-4.js
getSelectorFromElement
function getSelectorFromElement($element) { var selector = $element.data('target'), $selector = void 0; if (!selector) { selector = $element.attr('href') || ''; selector = /^#[a-z]/i.test(selector) ? selector : null; } $selector = $(selector); if ($selector.length === 0) { return $selector; } if (!$selector.data(DateTimePicker.DATA_KEY)) { $.extend({}, $selector.data(), $(this).data()); } return $selector; }
javascript
function getSelectorFromElement($element) { var selector = $element.data('target'), $selector = void 0; if (!selector) { selector = $element.attr('href') || ''; selector = /^#[a-z]/i.test(selector) ? selector : null; } $selector = $(selector); if ($selector.length === 0) { return $selector; } if (!$selector.data(DateTimePicker.DATA_KEY)) { $.extend({}, $selector.data(), $(this).data()); } return $selector; }
[ "function", "getSelectorFromElement", "(", "$element", ")", "{", "var", "selector", "=", "$element", ".", "data", "(", "'target'", ")", ",", "$selector", "=", "void", "0", ";", "if", "(", "!", "selector", ")", "{", "selector", "=", "$element", ".", "attr", "(", "'href'", ")", "||", "''", ";", "selector", "=", "/", "^#[a-z]", "/", "i", ".", "test", "(", "selector", ")", "?", "selector", ":", "null", ";", "}", "$selector", "=", "$", "(", "selector", ")", ";", "if", "(", "$selector", ".", "length", "===", "0", ")", "{", "return", "$selector", ";", "}", "if", "(", "!", "$selector", ".", "data", "(", "DateTimePicker", ".", "DATA_KEY", ")", ")", "{", "$", ".", "extend", "(", "{", "}", ",", "$selector", ".", "data", "(", ")", ",", "$", "(", "this", ")", ".", "data", "(", ")", ")", ";", "}", "return", "$selector", ";", "}" ]
eslint-disable-line no-unused-vars ReSharper disable once InconsistentNaming
[ "eslint", "-", "disable", "-", "line", "no", "-", "unused", "-", "vars", "ReSharper", "disable", "once", "InconsistentNaming" ]
540bfae18ca662bacfbea610e0ab8dcce6dd699e
https://github.com/tempusdominus/bootstrap-4/blob/540bfae18ca662bacfbea610e0ab8dcce6dd699e/build/js/tempusdominus-bootstrap-4.js#L1588-L1606
8,407
dagrejs/dagre
lib/position/bk.js
pass1
function pass1(elem) { xs[elem] = blockG.inEdges(elem).reduce(function(acc, e) { return Math.max(acc, xs[e.v] + blockG.edge(e)); }, 0); }
javascript
function pass1(elem) { xs[elem] = blockG.inEdges(elem).reduce(function(acc, e) { return Math.max(acc, xs[e.v] + blockG.edge(e)); }, 0); }
[ "function", "pass1", "(", "elem", ")", "{", "xs", "[", "elem", "]", "=", "blockG", ".", "inEdges", "(", "elem", ")", ".", "reduce", "(", "function", "(", "acc", ",", "e", ")", "{", "return", "Math", ".", "max", "(", "acc", ",", "xs", "[", "e", ".", "v", "]", "+", "blockG", ".", "edge", "(", "e", ")", ")", ";", "}", ",", "0", ")", ";", "}" ]
First pass, assign smallest coordinates
[ "First", "pass", "assign", "smallest", "coordinates" ]
ec3fd32a2ae9eb413aea5b8bd31fac652a9b6a5e
https://github.com/dagrejs/dagre/blob/ec3fd32a2ae9eb413aea5b8bd31fac652a9b6a5e/lib/position/bk.js#L235-L239
8,408
dagrejs/dagre
lib/position/bk.js
pass2
function pass2(elem) { var min = blockG.outEdges(elem).reduce(function(acc, e) { return Math.min(acc, xs[e.w] - blockG.edge(e)); }, Number.POSITIVE_INFINITY); var node = g.node(elem); if (min !== Number.POSITIVE_INFINITY && node.borderType !== borderType) { xs[elem] = Math.max(xs[elem], min); } }
javascript
function pass2(elem) { var min = blockG.outEdges(elem).reduce(function(acc, e) { return Math.min(acc, xs[e.w] - blockG.edge(e)); }, Number.POSITIVE_INFINITY); var node = g.node(elem); if (min !== Number.POSITIVE_INFINITY && node.borderType !== borderType) { xs[elem] = Math.max(xs[elem], min); } }
[ "function", "pass2", "(", "elem", ")", "{", "var", "min", "=", "blockG", ".", "outEdges", "(", "elem", ")", ".", "reduce", "(", "function", "(", "acc", ",", "e", ")", "{", "return", "Math", ".", "min", "(", "acc", ",", "xs", "[", "e", ".", "w", "]", "-", "blockG", ".", "edge", "(", "e", ")", ")", ";", "}", ",", "Number", ".", "POSITIVE_INFINITY", ")", ";", "var", "node", "=", "g", ".", "node", "(", "elem", ")", ";", "if", "(", "min", "!==", "Number", ".", "POSITIVE_INFINITY", "&&", "node", ".", "borderType", "!==", "borderType", ")", "{", "xs", "[", "elem", "]", "=", "Math", ".", "max", "(", "xs", "[", "elem", "]", ",", "min", ")", ";", "}", "}" ]
Second pass, assign greatest coordinates
[ "Second", "pass", "assign", "greatest", "coordinates" ]
ec3fd32a2ae9eb413aea5b8bd31fac652a9b6a5e
https://github.com/dagrejs/dagre/blob/ec3fd32a2ae9eb413aea5b8bd31fac652a9b6a5e/lib/position/bk.js#L242-L251
8,409
jakubpawlowicz/clean-css
docs/js/optimizer.js
function () { this.worker = new Worker('./js/optimizer-worker.js') this.worker.onmessage = function (event) { switch (event.data.command) { case 'optimized': Optimizer.oncomplete(event.data.id, event.data.output, event.data.saved) } } this.worker.onerror = function (event) { console.error(event) } }
javascript
function () { this.worker = new Worker('./js/optimizer-worker.js') this.worker.onmessage = function (event) { switch (event.data.command) { case 'optimized': Optimizer.oncomplete(event.data.id, event.data.output, event.data.saved) } } this.worker.onerror = function (event) { console.error(event) } }
[ "function", "(", ")", "{", "this", ".", "worker", "=", "new", "Worker", "(", "'./js/optimizer-worker.js'", ")", "this", ".", "worker", ".", "onmessage", "=", "function", "(", "event", ")", "{", "switch", "(", "event", ".", "data", ".", "command", ")", "{", "case", "'optimized'", ":", "Optimizer", ".", "oncomplete", "(", "event", ".", "data", ".", "id", ",", "event", ".", "data", ".", "output", ",", "event", ".", "data", ".", "saved", ")", "}", "}", "this", ".", "worker", ".", "onerror", "=", "function", "(", "event", ")", "{", "console", ".", "error", "(", "event", ")", "}", "}" ]
see setOptionsFrom in settings.js
[ "see", "setOptionsFrom", "in", "settings", ".", "js" ]
dc728a8167b7b6f62906115c560be2f5b530f9f6
https://github.com/jakubpawlowicz/clean-css/blob/dc728a8167b7b6f62906115c560be2f5b530f9f6/docs/js/optimizer.js#L4-L15
8,410
spite/ccapture.js
src/Whammy.js
checkFrames
function checkFrames(frames){ var width = frames[0].width, height = frames[0].height, duration = frames[0].duration; for(var i = 1; i < frames.length; i++){ if(frames[i].width != width) throw "Frame " + (i + 1) + " has a different width"; if(frames[i].height != height) throw "Frame " + (i + 1) + " has a different height"; if(frames[i].duration < 0 || frames[i].duration > 0x7fff) throw "Frame " + (i + 1) + " has a weird duration (must be between 0 and 32767)"; duration += frames[i].duration; } return { duration: duration, width: width, height: height }; }
javascript
function checkFrames(frames){ var width = frames[0].width, height = frames[0].height, duration = frames[0].duration; for(var i = 1; i < frames.length; i++){ if(frames[i].width != width) throw "Frame " + (i + 1) + " has a different width"; if(frames[i].height != height) throw "Frame " + (i + 1) + " has a different height"; if(frames[i].duration < 0 || frames[i].duration > 0x7fff) throw "Frame " + (i + 1) + " has a weird duration (must be between 0 and 32767)"; duration += frames[i].duration; } return { duration: duration, width: width, height: height }; }
[ "function", "checkFrames", "(", "frames", ")", "{", "var", "width", "=", "frames", "[", "0", "]", ".", "width", ",", "height", "=", "frames", "[", "0", "]", ".", "height", ",", "duration", "=", "frames", "[", "0", "]", ".", "duration", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<", "frames", ".", "length", ";", "i", "++", ")", "{", "if", "(", "frames", "[", "i", "]", ".", "width", "!=", "width", ")", "throw", "\"Frame \"", "+", "(", "i", "+", "1", ")", "+", "\" has a different width\"", ";", "if", "(", "frames", "[", "i", "]", ".", "height", "!=", "height", ")", "throw", "\"Frame \"", "+", "(", "i", "+", "1", ")", "+", "\" has a different height\"", ";", "if", "(", "frames", "[", "i", "]", ".", "duration", "<", "0", "||", "frames", "[", "i", "]", ".", "duration", ">", "0x7fff", ")", "throw", "\"Frame \"", "+", "(", "i", "+", "1", ")", "+", "\" has a weird duration (must be between 0 and 32767)\"", ";", "duration", "+=", "frames", "[", "i", "]", ".", "duration", ";", "}", "return", "{", "duration", ":", "duration", ",", "width", ":", "width", ",", "height", ":", "height", "}", ";", "}" ]
sums the lengths of all the frames and gets the duration, woo
[ "sums", "the", "lengths", "of", "all", "the", "frames", "and", "gets", "the", "duration", "woo" ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/Whammy.js#L231-L246
8,411
spite/ccapture.js
src/Whammy.js
parseWebP
function parseWebP(riff){ var VP8 = riff.RIFF[0].WEBP[0]; var frame_start = VP8.indexOf('\x9d\x01\x2a'); //A VP8 keyframe starts with the 0x9d012a header for(var i = 0, c = []; i < 4; i++) c[i] = VP8.charCodeAt(frame_start + 3 + i); var width, horizontal_scale, height, vertical_scale, tmp; //the code below is literally copied verbatim from the bitstream spec tmp = (c[1] << 8) | c[0]; width = tmp & 0x3FFF; horizontal_scale = tmp >> 14; tmp = (c[3] << 8) | c[2]; height = tmp & 0x3FFF; vertical_scale = tmp >> 14; return { width: width, height: height, data: VP8, riff: riff } }
javascript
function parseWebP(riff){ var VP8 = riff.RIFF[0].WEBP[0]; var frame_start = VP8.indexOf('\x9d\x01\x2a'); //A VP8 keyframe starts with the 0x9d012a header for(var i = 0, c = []; i < 4; i++) c[i] = VP8.charCodeAt(frame_start + 3 + i); var width, horizontal_scale, height, vertical_scale, tmp; //the code below is literally copied verbatim from the bitstream spec tmp = (c[1] << 8) | c[0]; width = tmp & 0x3FFF; horizontal_scale = tmp >> 14; tmp = (c[3] << 8) | c[2]; height = tmp & 0x3FFF; vertical_scale = tmp >> 14; return { width: width, height: height, data: VP8, riff: riff } }
[ "function", "parseWebP", "(", "riff", ")", "{", "var", "VP8", "=", "riff", ".", "RIFF", "[", "0", "]", ".", "WEBP", "[", "0", "]", ";", "var", "frame_start", "=", "VP8", ".", "indexOf", "(", "'\\x9d\\x01\\x2a'", ")", ";", "//A VP8 keyframe starts with the 0x9d012a header\r", "for", "(", "var", "i", "=", "0", ",", "c", "=", "[", "]", ";", "i", "<", "4", ";", "i", "++", ")", "c", "[", "i", "]", "=", "VP8", ".", "charCodeAt", "(", "frame_start", "+", "3", "+", "i", ")", ";", "var", "width", ",", "horizontal_scale", ",", "height", ",", "vertical_scale", ",", "tmp", ";", "//the code below is literally copied verbatim from the bitstream spec\r", "tmp", "=", "(", "c", "[", "1", "]", "<<", "8", ")", "|", "c", "[", "0", "]", ";", "width", "=", "tmp", "&", "0x3FFF", ";", "horizontal_scale", "=", "tmp", ">>", "14", ";", "tmp", "=", "(", "c", "[", "3", "]", "<<", "8", ")", "|", "c", "[", "2", "]", ";", "height", "=", "tmp", "&", "0x3FFF", ";", "vertical_scale", "=", "tmp", ">>", "14", ";", "return", "{", "width", ":", "width", ",", "height", ":", "height", ",", "data", ":", "VP8", ",", "riff", ":", "riff", "}", "}" ]
here's something else taken verbatim from weppy, awesome rite?
[ "here", "s", "something", "else", "taken", "verbatim", "from", "weppy", "awesome", "rite?" ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/Whammy.js#L428-L449
8,412
spite/ccapture.js
src/webm-writer-0.2.0.js
decodeBase64WebPDataURL
function decodeBase64WebPDataURL(url) { if (typeof url !== "string" || !url.match(/^data:image\/webp;base64,/i)) { return false; } return window.atob(url.substring("data:image\/webp;base64,".length)); }
javascript
function decodeBase64WebPDataURL(url) { if (typeof url !== "string" || !url.match(/^data:image\/webp;base64,/i)) { return false; } return window.atob(url.substring("data:image\/webp;base64,".length)); }
[ "function", "decodeBase64WebPDataURL", "(", "url", ")", "{", "if", "(", "typeof", "url", "!==", "\"string\"", "||", "!", "url", ".", "match", "(", "/", "^data:image\\/webp;base64,", "/", "i", ")", ")", "{", "return", "false", ";", "}", "return", "window", ".", "atob", "(", "url", ".", "substring", "(", "\"data:image\\/webp;base64,\"", ".", "length", ")", ")", ";", "}" ]
Decode a Base64 data URL into a binary string. Returns the binary string, or false if the URL could not be decoded.
[ "Decode", "a", "Base64", "data", "URL", "into", "a", "binary", "string", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L473-L479
8,413
spite/ccapture.js
src/webm-writer-0.2.0.js
renderAsWebP
function renderAsWebP(canvas, quality) { var frame = canvas.toDataURL('image/webp', {quality: quality}); return decodeBase64WebPDataURL(frame); }
javascript
function renderAsWebP(canvas, quality) { var frame = canvas.toDataURL('image/webp', {quality: quality}); return decodeBase64WebPDataURL(frame); }
[ "function", "renderAsWebP", "(", "canvas", ",", "quality", ")", "{", "var", "frame", "=", "canvas", ".", "toDataURL", "(", "'image/webp'", ",", "{", "quality", ":", "quality", "}", ")", ";", "return", "decodeBase64WebPDataURL", "(", "frame", ")", ";", "}" ]
Convert the given canvas to a WebP encoded image and return the image data as a string.
[ "Convert", "the", "given", "canvas", "to", "a", "WebP", "encoded", "image", "and", "return", "the", "image", "data", "as", "a", "string", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L499-L504
8,414
spite/ccapture.js
src/webm-writer-0.2.0.js
writeEBML
function writeEBML(buffer, bufferFileOffset, ebml) { // Is the ebml an array of sibling elements? if (Array.isArray(ebml)) { for (var i = 0; i < ebml.length; i++) { writeEBML(buffer, bufferFileOffset, ebml[i]); } // Is this some sort of raw data that we want to write directly? } else if (typeof ebml === "string") { buffer.writeString(ebml); } else if (ebml instanceof Uint8Array) { buffer.writeBytes(ebml); } else if (ebml.id){ // We're writing an EBML element ebml.offset = buffer.pos + bufferFileOffset; buffer.writeUnsignedIntBE(ebml.id); // ID field // Now we need to write the size field, so we must know the payload size: if (Array.isArray(ebml.data)) { // Writing an array of child elements. We won't try to measure the size of the children up-front var sizePos, dataBegin, dataEnd; if (ebml.size === -1) { // Write the reserved all-one-bits marker to note that the size of this element is unknown/unbounded buffer.writeByte(0xFF); } else { sizePos = buffer.pos; /* Write a dummy size field to overwrite later. 4 bytes allows an element maximum size of 256MB, * which should be plenty (we don't want to have to buffer that much data in memory at one time * anyway!) */ buffer.writeBytes([0, 0, 0, 0]); } dataBegin = buffer.pos; ebml.dataOffset = dataBegin + bufferFileOffset; writeEBML(buffer, bufferFileOffset, ebml.data); if (ebml.size !== -1) { dataEnd = buffer.pos; ebml.size = dataEnd - dataBegin; buffer.seek(sizePos); buffer.writeEBMLVarIntWidth(ebml.size, 4); // Size field buffer.seek(dataEnd); } } else if (typeof ebml.data === "string") { buffer.writeEBMLVarInt(ebml.data.length); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeString(ebml.data); } else if (typeof ebml.data === "number") { // Allow the caller to explicitly choose the size if they wish by supplying a size field if (!ebml.size) { ebml.size = buffer.measureUnsignedInt(ebml.data); } buffer.writeEBMLVarInt(ebml.size); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeUnsignedIntBE(ebml.data, ebml.size); } else if (ebml.data instanceof EBMLFloat64) { buffer.writeEBMLVarInt(8); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeDoubleBE(ebml.data.value); } else if (ebml.data instanceof EBMLFloat32) { buffer.writeEBMLVarInt(4); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeFloatBE(ebml.data.value); } else if (ebml.data instanceof Uint8Array) { buffer.writeEBMLVarInt(ebml.data.byteLength); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeBytes(ebml.data); } else { throw "Bad EBML datatype " + typeof ebml.data; } } else { throw "Bad EBML datatype " + typeof ebml.data; } }
javascript
function writeEBML(buffer, bufferFileOffset, ebml) { // Is the ebml an array of sibling elements? if (Array.isArray(ebml)) { for (var i = 0; i < ebml.length; i++) { writeEBML(buffer, bufferFileOffset, ebml[i]); } // Is this some sort of raw data that we want to write directly? } else if (typeof ebml === "string") { buffer.writeString(ebml); } else if (ebml instanceof Uint8Array) { buffer.writeBytes(ebml); } else if (ebml.id){ // We're writing an EBML element ebml.offset = buffer.pos + bufferFileOffset; buffer.writeUnsignedIntBE(ebml.id); // ID field // Now we need to write the size field, so we must know the payload size: if (Array.isArray(ebml.data)) { // Writing an array of child elements. We won't try to measure the size of the children up-front var sizePos, dataBegin, dataEnd; if (ebml.size === -1) { // Write the reserved all-one-bits marker to note that the size of this element is unknown/unbounded buffer.writeByte(0xFF); } else { sizePos = buffer.pos; /* Write a dummy size field to overwrite later. 4 bytes allows an element maximum size of 256MB, * which should be plenty (we don't want to have to buffer that much data in memory at one time * anyway!) */ buffer.writeBytes([0, 0, 0, 0]); } dataBegin = buffer.pos; ebml.dataOffset = dataBegin + bufferFileOffset; writeEBML(buffer, bufferFileOffset, ebml.data); if (ebml.size !== -1) { dataEnd = buffer.pos; ebml.size = dataEnd - dataBegin; buffer.seek(sizePos); buffer.writeEBMLVarIntWidth(ebml.size, 4); // Size field buffer.seek(dataEnd); } } else if (typeof ebml.data === "string") { buffer.writeEBMLVarInt(ebml.data.length); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeString(ebml.data); } else if (typeof ebml.data === "number") { // Allow the caller to explicitly choose the size if they wish by supplying a size field if (!ebml.size) { ebml.size = buffer.measureUnsignedInt(ebml.data); } buffer.writeEBMLVarInt(ebml.size); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeUnsignedIntBE(ebml.data, ebml.size); } else if (ebml.data instanceof EBMLFloat64) { buffer.writeEBMLVarInt(8); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeDoubleBE(ebml.data.value); } else if (ebml.data instanceof EBMLFloat32) { buffer.writeEBMLVarInt(4); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeFloatBE(ebml.data.value); } else if (ebml.data instanceof Uint8Array) { buffer.writeEBMLVarInt(ebml.data.byteLength); // Size field ebml.dataOffset = buffer.pos + bufferFileOffset; buffer.writeBytes(ebml.data); } else { throw "Bad EBML datatype " + typeof ebml.data; } } else { throw "Bad EBML datatype " + typeof ebml.data; } }
[ "function", "writeEBML", "(", "buffer", ",", "bufferFileOffset", ",", "ebml", ")", "{", "// Is the ebml an array of sibling elements?", "if", "(", "Array", ".", "isArray", "(", "ebml", ")", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "ebml", ".", "length", ";", "i", "++", ")", "{", "writeEBML", "(", "buffer", ",", "bufferFileOffset", ",", "ebml", "[", "i", "]", ")", ";", "}", "// Is this some sort of raw data that we want to write directly?", "}", "else", "if", "(", "typeof", "ebml", "===", "\"string\"", ")", "{", "buffer", ".", "writeString", "(", "ebml", ")", ";", "}", "else", "if", "(", "ebml", "instanceof", "Uint8Array", ")", "{", "buffer", ".", "writeBytes", "(", "ebml", ")", ";", "}", "else", "if", "(", "ebml", ".", "id", ")", "{", "// We're writing an EBML element", "ebml", ".", "offset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeUnsignedIntBE", "(", "ebml", ".", "id", ")", ";", "// ID field", "// Now we need to write the size field, so we must know the payload size:", "if", "(", "Array", ".", "isArray", "(", "ebml", ".", "data", ")", ")", "{", "// Writing an array of child elements. We won't try to measure the size of the children up-front", "var", "sizePos", ",", "dataBegin", ",", "dataEnd", ";", "if", "(", "ebml", ".", "size", "===", "-", "1", ")", "{", "// Write the reserved all-one-bits marker to note that the size of this element is unknown/unbounded", "buffer", ".", "writeByte", "(", "0xFF", ")", ";", "}", "else", "{", "sizePos", "=", "buffer", ".", "pos", ";", "/* Write a dummy size field to overwrite later. 4 bytes allows an element maximum size of 256MB,\n * which should be plenty (we don't want to have to buffer that much data in memory at one time\n * anyway!)\n */", "buffer", ".", "writeBytes", "(", "[", "0", ",", "0", ",", "0", ",", "0", "]", ")", ";", "}", "dataBegin", "=", "buffer", ".", "pos", ";", "ebml", ".", "dataOffset", "=", "dataBegin", "+", "bufferFileOffset", ";", "writeEBML", "(", "buffer", ",", "bufferFileOffset", ",", "ebml", ".", "data", ")", ";", "if", "(", "ebml", ".", "size", "!==", "-", "1", ")", "{", "dataEnd", "=", "buffer", ".", "pos", ";", "ebml", ".", "size", "=", "dataEnd", "-", "dataBegin", ";", "buffer", ".", "seek", "(", "sizePos", ")", ";", "buffer", ".", "writeEBMLVarIntWidth", "(", "ebml", ".", "size", ",", "4", ")", ";", "// Size field", "buffer", ".", "seek", "(", "dataEnd", ")", ";", "}", "}", "else", "if", "(", "typeof", "ebml", ".", "data", "===", "\"string\"", ")", "{", "buffer", ".", "writeEBMLVarInt", "(", "ebml", ".", "data", ".", "length", ")", ";", "// Size field", "ebml", ".", "dataOffset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeString", "(", "ebml", ".", "data", ")", ";", "}", "else", "if", "(", "typeof", "ebml", ".", "data", "===", "\"number\"", ")", "{", "// Allow the caller to explicitly choose the size if they wish by supplying a size field", "if", "(", "!", "ebml", ".", "size", ")", "{", "ebml", ".", "size", "=", "buffer", ".", "measureUnsignedInt", "(", "ebml", ".", "data", ")", ";", "}", "buffer", ".", "writeEBMLVarInt", "(", "ebml", ".", "size", ")", ";", "// Size field", "ebml", ".", "dataOffset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeUnsignedIntBE", "(", "ebml", ".", "data", ",", "ebml", ".", "size", ")", ";", "}", "else", "if", "(", "ebml", ".", "data", "instanceof", "EBMLFloat64", ")", "{", "buffer", ".", "writeEBMLVarInt", "(", "8", ")", ";", "// Size field", "ebml", ".", "dataOffset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeDoubleBE", "(", "ebml", ".", "data", ".", "value", ")", ";", "}", "else", "if", "(", "ebml", ".", "data", "instanceof", "EBMLFloat32", ")", "{", "buffer", ".", "writeEBMLVarInt", "(", "4", ")", ";", "// Size field", "ebml", ".", "dataOffset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeFloatBE", "(", "ebml", ".", "data", ".", "value", ")", ";", "}", "else", "if", "(", "ebml", ".", "data", "instanceof", "Uint8Array", ")", "{", "buffer", ".", "writeEBMLVarInt", "(", "ebml", ".", "data", ".", "byteLength", ")", ";", "// Size field", "ebml", ".", "dataOffset", "=", "buffer", ".", "pos", "+", "bufferFileOffset", ";", "buffer", ".", "writeBytes", "(", "ebml", ".", "data", ")", ";", "}", "else", "{", "throw", "\"Bad EBML datatype \"", "+", "typeof", "ebml", ".", "data", ";", "}", "}", "else", "{", "throw", "\"Bad EBML datatype \"", "+", "typeof", "ebml", ".", "data", ";", "}", "}" ]
Write the given EBML object to the provided ArrayBufferStream. The buffer's first byte is at bufferFileOffset inside the video file. This is used to complete offset and dataOffset fields in each EBML structure, indicating the file offset of the first byte of the EBML element and its data payload.
[ "Write", "the", "given", "EBML", "object", "to", "the", "provided", "ArrayBufferStream", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L537-L621
8,415
spite/ccapture.js
src/webm-writer-0.2.0.js
createSeekHead
function createSeekHead() { var seekPositionEBMLTemplate = { "id": 0x53AC, // SeekPosition "size": 5, // Allows for 32GB video files "data": 0 // We'll overwrite this when the file is complete }, result = { "id": 0x114D9B74, // SeekHead "data": [] }; for (var name in seekPoints) { var seekPoint = seekPoints[name]; seekPoint.positionEBML = Object.create(seekPositionEBMLTemplate); result.data.push({ "id": 0x4DBB, // Seek "data": [ { "id": 0x53AB, // SeekID "data": seekPoint.id }, seekPoint.positionEBML ] }); } return result; }
javascript
function createSeekHead() { var seekPositionEBMLTemplate = { "id": 0x53AC, // SeekPosition "size": 5, // Allows for 32GB video files "data": 0 // We'll overwrite this when the file is complete }, result = { "id": 0x114D9B74, // SeekHead "data": [] }; for (var name in seekPoints) { var seekPoint = seekPoints[name]; seekPoint.positionEBML = Object.create(seekPositionEBMLTemplate); result.data.push({ "id": 0x4DBB, // Seek "data": [ { "id": 0x53AB, // SeekID "data": seekPoint.id }, seekPoint.positionEBML ] }); } return result; }
[ "function", "createSeekHead", "(", ")", "{", "var", "seekPositionEBMLTemplate", "=", "{", "\"id\"", ":", "0x53AC", ",", "// SeekPosition", "\"size\"", ":", "5", ",", "// Allows for 32GB video files", "\"data\"", ":", "0", "// We'll overwrite this when the file is complete", "}", ",", "result", "=", "{", "\"id\"", ":", "0x114D9B74", ",", "// SeekHead", "\"data\"", ":", "[", "]", "}", ";", "for", "(", "var", "name", "in", "seekPoints", ")", "{", "var", "seekPoint", "=", "seekPoints", "[", "name", "]", ";", "seekPoint", ".", "positionEBML", "=", "Object", ".", "create", "(", "seekPositionEBMLTemplate", ")", ";", "result", ".", "data", ".", "push", "(", "{", "\"id\"", ":", "0x4DBB", ",", "// Seek", "\"data\"", ":", "[", "{", "\"id\"", ":", "0x53AB", ",", "// SeekID", "\"data\"", ":", "seekPoint", ".", "id", "}", ",", "seekPoint", ".", "positionEBML", "]", "}", ")", ";", "}", "return", "result", ";", "}" ]
Create a SeekHead element with descriptors for the points in the global seekPoints array. 5 bytes of position values are reserved for each node, which lie at the offset point.positionEBML.dataOffset, to be overwritten later.
[ "Create", "a", "SeekHead", "element", "with", "descriptors", "for", "the", "points", "in", "the", "global", "seekPoints", "array", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L673-L705
8,416
spite/ccapture.js
src/webm-writer-0.2.0.js
writeHeader
function writeHeader() { seekHead = createSeekHead(); var ebmlHeader = { "id": 0x1a45dfa3, // EBML "data": [ { "id": 0x4286, // EBMLVersion "data": 1 }, { "id": 0x42f7, // EBMLReadVersion "data": 1 }, { "id": 0x42f2, // EBMLMaxIDLength "data": 4 }, { "id": 0x42f3, // EBMLMaxSizeLength "data": 8 }, { "id": 0x4282, // DocType "data": "webm" }, { "id": 0x4287, // DocTypeVersion "data": 2 }, { "id": 0x4285, // DocTypeReadVersion "data": 2 } ] }, segmentInfo = { "id": 0x1549a966, // Info "data": [ { "id": 0x2ad7b1, // TimecodeScale "data": 1e6 // Times will be in miliseconds (1e6 nanoseconds per step = 1ms) }, { "id": 0x4d80, // MuxingApp "data": "webm-writer-js", }, { "id": 0x5741, // WritingApp "data": "webm-writer-js" }, segmentDuration // To be filled in later ] }, tracks = { "id": 0x1654ae6b, // Tracks "data": [ { "id": 0xae, // TrackEntry "data": [ { "id": 0xd7, // TrackNumber "data": DEFAULT_TRACK_NUMBER }, { "id": 0x73c5, // TrackUID "data": DEFAULT_TRACK_NUMBER }, { "id": 0x9c, // FlagLacing "data": 0 }, { "id": 0x22b59c, // Language "data": "und" }, { "id": 0x86, // CodecID "data": "V_VP8" }, { "id": 0x258688, // CodecName "data": "VP8" }, { "id": 0x83, // TrackType "data": 1 }, { "id": 0xe0, // Video "data": [ { "id": 0xb0, // PixelWidth "data": videoWidth }, { "id": 0xba, // PixelHeight "data": videoHeight } ] } ] } ] }; ebmlSegment = { "id": 0x18538067, // Segment "size": -1, // Unbounded size "data": [ seekHead, segmentInfo, tracks, ] }; var bufferStream = new ArrayBufferDataStream(256); writeEBML(bufferStream, blobBuffer.pos, [ebmlHeader, ebmlSegment]); blobBuffer.write(bufferStream.getAsDataArray()); // Now we know where these top-level elements lie in the file: seekPoints.SegmentInfo.positionEBML.data = fileOffsetToSegmentRelative(segmentInfo.offset); seekPoints.Tracks.positionEBML.data = fileOffsetToSegmentRelative(tracks.offset); }
javascript
function writeHeader() { seekHead = createSeekHead(); var ebmlHeader = { "id": 0x1a45dfa3, // EBML "data": [ { "id": 0x4286, // EBMLVersion "data": 1 }, { "id": 0x42f7, // EBMLReadVersion "data": 1 }, { "id": 0x42f2, // EBMLMaxIDLength "data": 4 }, { "id": 0x42f3, // EBMLMaxSizeLength "data": 8 }, { "id": 0x4282, // DocType "data": "webm" }, { "id": 0x4287, // DocTypeVersion "data": 2 }, { "id": 0x4285, // DocTypeReadVersion "data": 2 } ] }, segmentInfo = { "id": 0x1549a966, // Info "data": [ { "id": 0x2ad7b1, // TimecodeScale "data": 1e6 // Times will be in miliseconds (1e6 nanoseconds per step = 1ms) }, { "id": 0x4d80, // MuxingApp "data": "webm-writer-js", }, { "id": 0x5741, // WritingApp "data": "webm-writer-js" }, segmentDuration // To be filled in later ] }, tracks = { "id": 0x1654ae6b, // Tracks "data": [ { "id": 0xae, // TrackEntry "data": [ { "id": 0xd7, // TrackNumber "data": DEFAULT_TRACK_NUMBER }, { "id": 0x73c5, // TrackUID "data": DEFAULT_TRACK_NUMBER }, { "id": 0x9c, // FlagLacing "data": 0 }, { "id": 0x22b59c, // Language "data": "und" }, { "id": 0x86, // CodecID "data": "V_VP8" }, { "id": 0x258688, // CodecName "data": "VP8" }, { "id": 0x83, // TrackType "data": 1 }, { "id": 0xe0, // Video "data": [ { "id": 0xb0, // PixelWidth "data": videoWidth }, { "id": 0xba, // PixelHeight "data": videoHeight } ] } ] } ] }; ebmlSegment = { "id": 0x18538067, // Segment "size": -1, // Unbounded size "data": [ seekHead, segmentInfo, tracks, ] }; var bufferStream = new ArrayBufferDataStream(256); writeEBML(bufferStream, blobBuffer.pos, [ebmlHeader, ebmlSegment]); blobBuffer.write(bufferStream.getAsDataArray()); // Now we know where these top-level elements lie in the file: seekPoints.SegmentInfo.positionEBML.data = fileOffsetToSegmentRelative(segmentInfo.offset); seekPoints.Tracks.positionEBML.data = fileOffsetToSegmentRelative(tracks.offset); }
[ "function", "writeHeader", "(", ")", "{", "seekHead", "=", "createSeekHead", "(", ")", ";", "var", "ebmlHeader", "=", "{", "\"id\"", ":", "0x1a45dfa3", ",", "// EBML", "\"data\"", ":", "[", "{", "\"id\"", ":", "0x4286", ",", "// EBMLVersion", "\"data\"", ":", "1", "}", ",", "{", "\"id\"", ":", "0x42f7", ",", "// EBMLReadVersion", "\"data\"", ":", "1", "}", ",", "{", "\"id\"", ":", "0x42f2", ",", "// EBMLMaxIDLength", "\"data\"", ":", "4", "}", ",", "{", "\"id\"", ":", "0x42f3", ",", "// EBMLMaxSizeLength", "\"data\"", ":", "8", "}", ",", "{", "\"id\"", ":", "0x4282", ",", "// DocType", "\"data\"", ":", "\"webm\"", "}", ",", "{", "\"id\"", ":", "0x4287", ",", "// DocTypeVersion", "\"data\"", ":", "2", "}", ",", "{", "\"id\"", ":", "0x4285", ",", "// DocTypeReadVersion", "\"data\"", ":", "2", "}", "]", "}", ",", "segmentInfo", "=", "{", "\"id\"", ":", "0x1549a966", ",", "// Info", "\"data\"", ":", "[", "{", "\"id\"", ":", "0x2ad7b1", ",", "// TimecodeScale", "\"data\"", ":", "1e6", "// Times will be in miliseconds (1e6 nanoseconds per step = 1ms)", "}", ",", "{", "\"id\"", ":", "0x4d80", ",", "// MuxingApp", "\"data\"", ":", "\"webm-writer-js\"", ",", "}", ",", "{", "\"id\"", ":", "0x5741", ",", "// WritingApp", "\"data\"", ":", "\"webm-writer-js\"", "}", ",", "segmentDuration", "// To be filled in later", "]", "}", ",", "tracks", "=", "{", "\"id\"", ":", "0x1654ae6b", ",", "// Tracks", "\"data\"", ":", "[", "{", "\"id\"", ":", "0xae", ",", "// TrackEntry", "\"data\"", ":", "[", "{", "\"id\"", ":", "0xd7", ",", "// TrackNumber", "\"data\"", ":", "DEFAULT_TRACK_NUMBER", "}", ",", "{", "\"id\"", ":", "0x73c5", ",", "// TrackUID", "\"data\"", ":", "DEFAULT_TRACK_NUMBER", "}", ",", "{", "\"id\"", ":", "0x9c", ",", "// FlagLacing", "\"data\"", ":", "0", "}", ",", "{", "\"id\"", ":", "0x22b59c", ",", "// Language", "\"data\"", ":", "\"und\"", "}", ",", "{", "\"id\"", ":", "0x86", ",", "// CodecID", "\"data\"", ":", "\"V_VP8\"", "}", ",", "{", "\"id\"", ":", "0x258688", ",", "// CodecName", "\"data\"", ":", "\"VP8\"", "}", ",", "{", "\"id\"", ":", "0x83", ",", "// TrackType", "\"data\"", ":", "1", "}", ",", "{", "\"id\"", ":", "0xe0", ",", "// Video", "\"data\"", ":", "[", "{", "\"id\"", ":", "0xb0", ",", "// PixelWidth", "\"data\"", ":", "videoWidth", "}", ",", "{", "\"id\"", ":", "0xba", ",", "// PixelHeight", "\"data\"", ":", "videoHeight", "}", "]", "}", "]", "}", "]", "}", ";", "ebmlSegment", "=", "{", "\"id\"", ":", "0x18538067", ",", "// Segment", "\"size\"", ":", "-", "1", ",", "// Unbounded size", "\"data\"", ":", "[", "seekHead", ",", "segmentInfo", ",", "tracks", ",", "]", "}", ";", "var", "bufferStream", "=", "new", "ArrayBufferDataStream", "(", "256", ")", ";", "writeEBML", "(", "bufferStream", ",", "blobBuffer", ".", "pos", ",", "[", "ebmlHeader", ",", "ebmlSegment", "]", ")", ";", "blobBuffer", ".", "write", "(", "bufferStream", ".", "getAsDataArray", "(", ")", ")", ";", "// Now we know where these top-level elements lie in the file:", "seekPoints", ".", "SegmentInfo", ".", "positionEBML", ".", "data", "=", "fileOffsetToSegmentRelative", "(", "segmentInfo", ".", "offset", ")", ";", "seekPoints", ".", "Tracks", ".", "positionEBML", ".", "data", "=", "fileOffsetToSegmentRelative", "(", "tracks", ".", "offset", ")", ";", "}" ]
Write the WebM file header to the stream.
[ "Write", "the", "WebM", "file", "header", "to", "the", "stream", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L710-L838
8,417
spite/ccapture.js
src/webm-writer-0.2.0.js
flushClusterFrameBuffer
function flushClusterFrameBuffer() { if (clusterFrameBuffer.length == 0) { return; } // First work out how large of a buffer we need to hold the cluster data var rawImageSize = 0; for (var i = 0; i < clusterFrameBuffer.length; i++) { rawImageSize += clusterFrameBuffer[i].frame.length; } var buffer = new ArrayBufferDataStream(rawImageSize + clusterFrameBuffer.length * 32), // Estimate 32 bytes per SimpleBlock header cluster = createCluster({ timecode: Math.round(clusterStartTime), }); for (var i = 0; i < clusterFrameBuffer.length; i++) { cluster.data.push(createKeyframeBlock(clusterFrameBuffer[i])); } writeEBML(buffer, blobBuffer.pos, cluster); blobBuffer.write(buffer.getAsDataArray()); addCuePoint(DEFAULT_TRACK_NUMBER, Math.round(clusterStartTime), cluster.offset); clusterFrameBuffer = []; clusterStartTime += clusterDuration; clusterDuration = 0; }
javascript
function flushClusterFrameBuffer() { if (clusterFrameBuffer.length == 0) { return; } // First work out how large of a buffer we need to hold the cluster data var rawImageSize = 0; for (var i = 0; i < clusterFrameBuffer.length; i++) { rawImageSize += clusterFrameBuffer[i].frame.length; } var buffer = new ArrayBufferDataStream(rawImageSize + clusterFrameBuffer.length * 32), // Estimate 32 bytes per SimpleBlock header cluster = createCluster({ timecode: Math.round(clusterStartTime), }); for (var i = 0; i < clusterFrameBuffer.length; i++) { cluster.data.push(createKeyframeBlock(clusterFrameBuffer[i])); } writeEBML(buffer, blobBuffer.pos, cluster); blobBuffer.write(buffer.getAsDataArray()); addCuePoint(DEFAULT_TRACK_NUMBER, Math.round(clusterStartTime), cluster.offset); clusterFrameBuffer = []; clusterStartTime += clusterDuration; clusterDuration = 0; }
[ "function", "flushClusterFrameBuffer", "(", ")", "{", "if", "(", "clusterFrameBuffer", ".", "length", "==", "0", ")", "{", "return", ";", "}", "// First work out how large of a buffer we need to hold the cluster data", "var", "rawImageSize", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "clusterFrameBuffer", ".", "length", ";", "i", "++", ")", "{", "rawImageSize", "+=", "clusterFrameBuffer", "[", "i", "]", ".", "frame", ".", "length", ";", "}", "var", "buffer", "=", "new", "ArrayBufferDataStream", "(", "rawImageSize", "+", "clusterFrameBuffer", ".", "length", "*", "32", ")", ",", "// Estimate 32 bytes per SimpleBlock header", "cluster", "=", "createCluster", "(", "{", "timecode", ":", "Math", ".", "round", "(", "clusterStartTime", ")", ",", "}", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "clusterFrameBuffer", ".", "length", ";", "i", "++", ")", "{", "cluster", ".", "data", ".", "push", "(", "createKeyframeBlock", "(", "clusterFrameBuffer", "[", "i", "]", ")", ")", ";", "}", "writeEBML", "(", "buffer", ",", "blobBuffer", ".", "pos", ",", "cluster", ")", ";", "blobBuffer", ".", "write", "(", "buffer", ".", "getAsDataArray", "(", ")", ")", ";", "addCuePoint", "(", "DEFAULT_TRACK_NUMBER", ",", "Math", ".", "round", "(", "clusterStartTime", ")", ",", "cluster", ".", "offset", ")", ";", "clusterFrameBuffer", "=", "[", "]", ";", "clusterStartTime", "+=", "clusterDuration", ";", "clusterDuration", "=", "0", ";", "}" ]
Flush the frames in the current clusterFrameBuffer out to the stream as a Cluster.
[ "Flush", "the", "frames", "in", "the", "current", "clusterFrameBuffer", "out", "to", "the", "stream", "as", "a", "Cluster", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L940-L972
8,418
spite/ccapture.js
src/webm-writer-0.2.0.js
rewriteSeekHead
function rewriteSeekHead() { var seekHeadBuffer = new ArrayBufferDataStream(seekHead.size), oldPos = blobBuffer.pos; // Write the rewritten SeekHead element's data payload to the stream (don't need to update the id or size) writeEBML(seekHeadBuffer, seekHead.dataOffset, seekHead.data); // And write that through to the file blobBuffer.seek(seekHead.dataOffset); blobBuffer.write(seekHeadBuffer.getAsDataArray()); blobBuffer.seek(oldPos); }
javascript
function rewriteSeekHead() { var seekHeadBuffer = new ArrayBufferDataStream(seekHead.size), oldPos = blobBuffer.pos; // Write the rewritten SeekHead element's data payload to the stream (don't need to update the id or size) writeEBML(seekHeadBuffer, seekHead.dataOffset, seekHead.data); // And write that through to the file blobBuffer.seek(seekHead.dataOffset); blobBuffer.write(seekHeadBuffer.getAsDataArray()); blobBuffer.seek(oldPos); }
[ "function", "rewriteSeekHead", "(", ")", "{", "var", "seekHeadBuffer", "=", "new", "ArrayBufferDataStream", "(", "seekHead", ".", "size", ")", ",", "oldPos", "=", "blobBuffer", ".", "pos", ";", "// Write the rewritten SeekHead element's data payload to the stream (don't need to update the id or size)", "writeEBML", "(", "seekHeadBuffer", ",", "seekHead", ".", "dataOffset", ",", "seekHead", ".", "data", ")", ";", "// And write that through to the file", "blobBuffer", ".", "seek", "(", "seekHead", ".", "dataOffset", ")", ";", "blobBuffer", ".", "write", "(", "seekHeadBuffer", ".", "getAsDataArray", "(", ")", ")", ";", "blobBuffer", ".", "seek", "(", "oldPos", ")", ";", "}" ]
Rewrites the SeekHead element that was initially written to the stream with the offsets of top level elements. Call once writing is complete (so the offset of all top level elements is known).
[ "Rewrites", "the", "SeekHead", "element", "that", "was", "initially", "written", "to", "the", "stream", "with", "the", "offsets", "of", "top", "level", "elements", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L1005-L1018
8,419
spite/ccapture.js
src/webm-writer-0.2.0.js
rewriteDuration
function rewriteDuration() { var buffer = new ArrayBufferDataStream(8), oldPos = blobBuffer.pos; // Rewrite the data payload (don't need to update the id or size) buffer.writeDoubleBE(clusterStartTime); // And write that through to the file blobBuffer.seek(segmentDuration.dataOffset); blobBuffer.write(buffer.getAsDataArray()); blobBuffer.seek(oldPos); }
javascript
function rewriteDuration() { var buffer = new ArrayBufferDataStream(8), oldPos = blobBuffer.pos; // Rewrite the data payload (don't need to update the id or size) buffer.writeDoubleBE(clusterStartTime); // And write that through to the file blobBuffer.seek(segmentDuration.dataOffset); blobBuffer.write(buffer.getAsDataArray()); blobBuffer.seek(oldPos); }
[ "function", "rewriteDuration", "(", ")", "{", "var", "buffer", "=", "new", "ArrayBufferDataStream", "(", "8", ")", ",", "oldPos", "=", "blobBuffer", ".", "pos", ";", "// Rewrite the data payload (don't need to update the id or size)", "buffer", ".", "writeDoubleBE", "(", "clusterStartTime", ")", ";", "// And write that through to the file", "blobBuffer", ".", "seek", "(", "segmentDuration", ".", "dataOffset", ")", ";", "blobBuffer", ".", "write", "(", "buffer", ".", "getAsDataArray", "(", ")", ")", ";", "blobBuffer", ".", "seek", "(", "oldPos", ")", ";", "}" ]
Rewrite the Duration field of the Segment with the newly-discovered video duration.
[ "Rewrite", "the", "Duration", "field", "of", "the", "Segment", "with", "the", "newly", "-", "discovered", "video", "duration", "." ]
e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41
https://github.com/spite/ccapture.js/blob/e4bc8fccc1e10d69b79b1c02fd13f3c448a3fb41/src/webm-writer-0.2.0.js#L1023-L1036
8,420
apache/cordova-plugin-file-transfer
src/windows/FileTransferProxy.js
cordovaPathToNative
function cordovaPathToNative(path) { var cleanPath = String(path); // turn / into \\ cleanPath = cleanPath.replace(/\//g, '\\'); // turn \\ into \ cleanPath = cleanPath.replace(/\\\\/g, '\\'); // strip end \\ characters cleanPath = cleanPath.replace(/\\+$/g, ''); return cleanPath; }
javascript
function cordovaPathToNative(path) { var cleanPath = String(path); // turn / into \\ cleanPath = cleanPath.replace(/\//g, '\\'); // turn \\ into \ cleanPath = cleanPath.replace(/\\\\/g, '\\'); // strip end \\ characters cleanPath = cleanPath.replace(/\\+$/g, ''); return cleanPath; }
[ "function", "cordovaPathToNative", "(", "path", ")", "{", "var", "cleanPath", "=", "String", "(", "path", ")", ";", "// turn / into \\\\", "cleanPath", "=", "cleanPath", ".", "replace", "(", "/", "\\/", "/", "g", ",", "'\\\\'", ")", ";", "// turn \\\\ into \\", "cleanPath", "=", "cleanPath", ".", "replace", "(", "/", "\\\\\\\\", "/", "g", ",", "'\\\\'", ")", ";", "// strip end \\\\ characters", "cleanPath", "=", "cleanPath", ".", "replace", "(", "/", "\\\\+$", "/", "g", ",", "''", ")", ";", "return", "cleanPath", ";", "}" ]
Some private helper functions, hidden by the module
[ "Some", "private", "helper", "functions", "hidden", "by", "the", "module" ]
dc8fbd78a234bd88450ebe01835c60371bc2cf8e
https://github.com/apache/cordova-plugin-file-transfer/blob/dc8fbd78a234bd88450ebe01835c60371bc2cf8e/src/windows/FileTransferProxy.js#L40-L50
8,421
eventbrite/britecharts
src/charts/mini-tooltip.js
getMaxLengthLine
function getMaxLengthLine(...texts) { let textSizes = texts.filter(x => !!x) .map(x => x.node().getBBox().width); return d3Array.max(textSizes); }
javascript
function getMaxLengthLine(...texts) { let textSizes = texts.filter(x => !!x) .map(x => x.node().getBBox().width); return d3Array.max(textSizes); }
[ "function", "getMaxLengthLine", "(", "...", "texts", ")", "{", "let", "textSizes", "=", "texts", ".", "filter", "(", "x", "=>", "!", "!", "x", ")", ".", "map", "(", "x", "=>", "x", ".", "node", "(", ")", ".", "getBBox", "(", ")", ".", "width", ")", ";", "return", "d3Array", ".", "max", "(", "textSizes", ")", ";", "}" ]
Figures out the max length of the tooltip lines @param {D3Selection[]} texts List of svg elements of each line @return {Number} Max size of the lines
[ "Figures", "out", "the", "max", "length", "of", "the", "tooltip", "lines" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/mini-tooltip.js#L176-L181
8,422
eventbrite/britecharts
src/charts/mini-tooltip.js
updatePositionAndSize
function updatePositionAndSize(mousePosition, parentChartSize) { let [tooltipX, tooltipY] = getTooltipPosition(mousePosition, parentChartSize); svg.transition() .duration(mouseChaseDuration) .ease(ease) .attr('height', chartHeight + margin.top + margin.bottom) .attr('width', chartWidth + margin.left + margin.right) .attr('transform', `translate(${tooltipX},${tooltipY})`); tooltipBackground .attr('height', chartHeight + margin.top + margin.bottom) .attr('width', chartWidth + margin.left + margin.right); }
javascript
function updatePositionAndSize(mousePosition, parentChartSize) { let [tooltipX, tooltipY] = getTooltipPosition(mousePosition, parentChartSize); svg.transition() .duration(mouseChaseDuration) .ease(ease) .attr('height', chartHeight + margin.top + margin.bottom) .attr('width', chartWidth + margin.left + margin.right) .attr('transform', `translate(${tooltipX},${tooltipY})`); tooltipBackground .attr('height', chartHeight + margin.top + margin.bottom) .attr('width', chartWidth + margin.left + margin.right); }
[ "function", "updatePositionAndSize", "(", "mousePosition", ",", "parentChartSize", ")", "{", "let", "[", "tooltipX", ",", "tooltipY", "]", "=", "getTooltipPosition", "(", "mousePosition", ",", "parentChartSize", ")", ";", "svg", ".", "transition", "(", ")", ".", "duration", "(", "mouseChaseDuration", ")", ".", "ease", "(", "ease", ")", ".", "attr", "(", "'height'", ",", "chartHeight", "+", "margin", ".", "top", "+", "margin", ".", "bottom", ")", ".", "attr", "(", "'width'", ",", "chartWidth", "+", "margin", ".", "left", "+", "margin", ".", "right", ")", ".", "attr", "(", "'transform'", ",", "`", "${", "tooltipX", "}", "${", "tooltipY", "}", "`", ")", ";", "tooltipBackground", ".", "attr", "(", "'height'", ",", "chartHeight", "+", "margin", ".", "top", "+", "margin", ".", "bottom", ")", ".", "attr", "(", "'width'", ",", "chartWidth", "+", "margin", ".", "left", "+", "margin", ".", "right", ")", ";", "}" ]
Updates size and position of tooltip depending on the side of the chart we are in @param {Object} dataPoint DataPoint of the tooltip @return void
[ "Updates", "size", "and", "position", "of", "tooltip", "depending", "on", "the", "side", "of", "the", "chart", "we", "are", "in" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/mini-tooltip.js#L316-L329
8,423
eventbrite/britecharts
src/charts/step.js
cleanData
function cleanData(originalData) { return originalData.reduce((acc, d) => { d.value = +d[valueLabel]; d.key = String(d[nameLabel]); return [...acc, d]; }, []); }
javascript
function cleanData(originalData) { return originalData.reduce((acc, d) => { d.value = +d[valueLabel]; d.key = String(d[nameLabel]); return [...acc, d]; }, []); }
[ "function", "cleanData", "(", "originalData", ")", "{", "return", "originalData", ".", "reduce", "(", "(", "acc", ",", "d", ")", "=>", "{", "d", ".", "value", "=", "+", "d", "[", "valueLabel", "]", ";", "d", ".", "key", "=", "String", "(", "d", "[", "nameLabel", "]", ")", ";", "return", "[", "...", "acc", ",", "d", "]", ";", "}", ",", "[", "]", ")", ";", "}" ]
Cleaning data casting the values and keys to the proper type while keeping the rest of properties on the data @param {StepChartData} originalData Data as provided on the container @private
[ "Cleaning", "data", "casting", "the", "values", "and", "keys", "to", "the", "proper", "type", "while", "keeping", "the", "rest", "of", "properties", "on", "the", "data" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/step.js#L215-L222
8,424
eventbrite/britecharts
src/charts/step.js
drawSteps
function drawSteps(){ let steps = svg.select('.chart-group').selectAll('.step').data(data); // Enter steps.enter() .append('rect') .classed('step', true) .attr('x', chartWidth) // Initially drawing the steps at the end of Y axis .attr('y', ({value}) => yScale(value)) .attr('width', xScale.bandwidth()) .attr('height', (d) => (chartHeight - yScale(d.value))) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .merge(steps) .transition() .ease(ease) .attr('x', ({key}) => xScale(key)) .attr('y', function(d) { return yScale(d.value); }) .attr('width', xScale.bandwidth()) .attr('height', function(d) { return chartHeight - yScale(d.value); }); // Exit steps.exit() .transition() .style('opacity', 0) .remove(); }
javascript
function drawSteps(){ let steps = svg.select('.chart-group').selectAll('.step').data(data); // Enter steps.enter() .append('rect') .classed('step', true) .attr('x', chartWidth) // Initially drawing the steps at the end of Y axis .attr('y', ({value}) => yScale(value)) .attr('width', xScale.bandwidth()) .attr('height', (d) => (chartHeight - yScale(d.value))) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .merge(steps) .transition() .ease(ease) .attr('x', ({key}) => xScale(key)) .attr('y', function(d) { return yScale(d.value); }) .attr('width', xScale.bandwidth()) .attr('height', function(d) { return chartHeight - yScale(d.value); }); // Exit steps.exit() .transition() .style('opacity', 0) .remove(); }
[ "function", "drawSteps", "(", ")", "{", "let", "steps", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "selectAll", "(", "'.step'", ")", ".", "data", "(", "data", ")", ";", "// Enter", "steps", ".", "enter", "(", ")", ".", "append", "(", "'rect'", ")", ".", "classed", "(", "'step'", ",", "true", ")", ".", "attr", "(", "'x'", ",", "chartWidth", ")", "// Initially drawing the steps at the end of Y axis", ".", "attr", "(", "'y'", ",", "(", "{", "value", "}", ")", "=>", "yScale", "(", "value", ")", ")", ".", "attr", "(", "'width'", ",", "xScale", ".", "bandwidth", "(", ")", ")", ".", "attr", "(", "'height'", ",", "(", "d", ")", "=>", "(", "chartHeight", "-", "yScale", "(", "d", ".", "value", ")", ")", ")", ".", "on", "(", "'mouseover'", ",", "function", "(", "d", ")", "{", "handleMouseOver", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mousemove'", ",", "function", "(", "d", ")", "{", "handleMouseMove", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mouseout'", ",", "function", "(", "d", ")", "{", "handleMouseOut", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "merge", "(", "steps", ")", ".", "transition", "(", ")", ".", "ease", "(", "ease", ")", ".", "attr", "(", "'x'", ",", "(", "{", "key", "}", ")", "=>", "xScale", "(", "key", ")", ")", ".", "attr", "(", "'y'", ",", "function", "(", "d", ")", "{", "return", "yScale", "(", "d", ".", "value", ")", ";", "}", ")", ".", "attr", "(", "'width'", ",", "xScale", ".", "bandwidth", "(", ")", ")", ".", "attr", "(", "'height'", ",", "function", "(", "d", ")", "{", "return", "chartHeight", "-", "yScale", "(", "d", ".", "value", ")", ";", "}", ")", ";", "// Exit", "steps", ".", "exit", "(", ")", ".", "transition", "(", ")", ".", "style", "(", "'opacity'", ",", "0", ")", ".", "remove", "(", ")", ";", "}" ]
Draws the step elements within the chart group @private
[ "Draws", "the", "step", "elements", "within", "the", "chart", "group" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/step.js#L273-L310
8,425
eventbrite/britecharts
src/charts/brush.js
buildAxis
function buildAxis(){ let minor, major; if (xAxisFormat === 'custom' && typeof xAxisCustomFormat === 'string') { minor = { tick: xTicks, format: d3TimeFormat.timeFormat(xAxisCustomFormat) }; } else { ({minor, major} = timeAxisHelper.getTimeSeriesAxis(data, width, xAxisFormat)); } xAxis = d3Axis.axisBottom(xScale) .ticks(minor.tick) .tickSize(10, 0) .tickPadding([tickPadding]) .tickFormat(minor.format); }
javascript
function buildAxis(){ let minor, major; if (xAxisFormat === 'custom' && typeof xAxisCustomFormat === 'string') { minor = { tick: xTicks, format: d3TimeFormat.timeFormat(xAxisCustomFormat) }; } else { ({minor, major} = timeAxisHelper.getTimeSeriesAxis(data, width, xAxisFormat)); } xAxis = d3Axis.axisBottom(xScale) .ticks(minor.tick) .tickSize(10, 0) .tickPadding([tickPadding]) .tickFormat(minor.format); }
[ "function", "buildAxis", "(", ")", "{", "let", "minor", ",", "major", ";", "if", "(", "xAxisFormat", "===", "'custom'", "&&", "typeof", "xAxisCustomFormat", "===", "'string'", ")", "{", "minor", "=", "{", "tick", ":", "xTicks", ",", "format", ":", "d3TimeFormat", ".", "timeFormat", "(", "xAxisCustomFormat", ")", "}", ";", "}", "else", "{", "(", "{", "minor", ",", "major", "}", "=", "timeAxisHelper", ".", "getTimeSeriesAxis", "(", "data", ",", "width", ",", "xAxisFormat", ")", ")", ";", "}", "xAxis", "=", "d3Axis", ".", "axisBottom", "(", "xScale", ")", ".", "ticks", "(", "minor", ".", "tick", ")", ".", "tickSize", "(", "10", ",", "0", ")", ".", "tickPadding", "(", "[", "tickPadding", "]", ")", ".", "tickFormat", "(", "minor", ".", "format", ")", ";", "}" ]
Creates the d3 x axis, setting orientation @private
[ "Creates", "the", "d3", "x", "axis", "setting", "orientation" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L154-L171
8,426
eventbrite/britecharts
src/charts/brush.js
buildBrush
function buildBrush() { brush = d3Brush.brushX() .extent([[0, 0], [chartWidth, chartHeight]]) .on('brush', handleBrushStart) .on('end', handleBrushEnd); }
javascript
function buildBrush() { brush = d3Brush.brushX() .extent([[0, 0], [chartWidth, chartHeight]]) .on('brush', handleBrushStart) .on('end', handleBrushEnd); }
[ "function", "buildBrush", "(", ")", "{", "brush", "=", "d3Brush", ".", "brushX", "(", ")", ".", "extent", "(", "[", "[", "0", ",", "0", "]", ",", "[", "chartWidth", ",", "chartHeight", "]", "]", ")", ".", "on", "(", "'brush'", ",", "handleBrushStart", ")", ".", "on", "(", "'end'", ",", "handleBrushEnd", ")", ";", "}" ]
Creates the brush element and attaches a listener @return {void}
[ "Creates", "the", "brush", "element", "and", "attaches", "a", "listener" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L177-L182
8,427
eventbrite/britecharts
src/charts/brush.js
buildGradient
function buildGradient() { if (!chartGradientEl) { chartGradientEl = svg.select('.metadata-group') .append('linearGradient') .attr('id', gradientId) .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: gradient[0]}, {offset: '100%', color: gradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); } }
javascript
function buildGradient() { if (!chartGradientEl) { chartGradientEl = svg.select('.metadata-group') .append('linearGradient') .attr('id', gradientId) .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: gradient[0]}, {offset: '100%', color: gradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); } }
[ "function", "buildGradient", "(", ")", "{", "if", "(", "!", "chartGradientEl", ")", "{", "chartGradientEl", "=", "svg", ".", "select", "(", "'.metadata-group'", ")", ".", "append", "(", "'linearGradient'", ")", ".", "attr", "(", "'id'", ",", "gradientId", ")", ".", "attr", "(", "'gradientUnits'", ",", "'userSpaceOnUse'", ")", ".", "attr", "(", "'x1'", ",", "0", ")", ".", "attr", "(", "'x2'", ",", "xScale", "(", "data", "[", "data", ".", "length", "-", "1", "]", ".", "date", ")", ")", ".", "attr", "(", "'y1'", ",", "0", ")", ".", "attr", "(", "'y2'", ",", "0", ")", ".", "selectAll", "(", "'stop'", ")", ".", "data", "(", "[", "{", "offset", ":", "'0%'", ",", "color", ":", "gradient", "[", "0", "]", "}", ",", "{", "offset", ":", "'100%'", ",", "color", ":", "gradient", "[", "1", "]", "}", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'stop'", ")", ".", "attr", "(", "'offset'", ",", "(", "{", "offset", "}", ")", "=>", "offset", ")", ".", "attr", "(", "'stop-color'", ",", "(", "{", "color", "}", ")", "=>", "color", ")", ";", "}", "}" ]
Creates the gradient on the area @return {void}
[ "Creates", "the", "gradient", "on", "the", "area" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L215-L234
8,428
eventbrite/britecharts
src/charts/brush.js
drawArea
function drawArea() { if (brushArea) { svg.selectAll('.brush-area').remove(); } // Create and configure the area generator brushArea = d3Shape.area() .x(({date}) => xScale(date)) .y0(chartHeight) .y1(({value}) => yScale(value)) .curve(d3Shape.curveBasis); // Create the area path svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'brush-area') .attr('d', brushArea); }
javascript
function drawArea() { if (brushArea) { svg.selectAll('.brush-area').remove(); } // Create and configure the area generator brushArea = d3Shape.area() .x(({date}) => xScale(date)) .y0(chartHeight) .y1(({value}) => yScale(value)) .curve(d3Shape.curveBasis); // Create the area path svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'brush-area') .attr('d', brushArea); }
[ "function", "drawArea", "(", ")", "{", "if", "(", "brushArea", ")", "{", "svg", ".", "selectAll", "(", "'.brush-area'", ")", ".", "remove", "(", ")", ";", "}", "// Create and configure the area generator", "brushArea", "=", "d3Shape", ".", "area", "(", ")", ".", "x", "(", "(", "{", "date", "}", ")", "=>", "xScale", "(", "date", ")", ")", ".", "y0", "(", "chartHeight", ")", ".", "y1", "(", "(", "{", "value", "}", ")", "=>", "yScale", "(", "value", ")", ")", ".", "curve", "(", "d3Shape", ".", "curveBasis", ")", ";", "// Create the area path", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "append", "(", "'path'", ")", ".", "datum", "(", "data", ")", ".", "attr", "(", "'class'", ",", "'brush-area'", ")", ".", "attr", "(", "'d'", ",", "brushArea", ")", ";", "}" ]
Draws the area that is going to represent the data @return {void}
[ "Draws", "the", "area", "that", "is", "going", "to", "represent", "the", "data" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L310-L328
8,429
eventbrite/britecharts
src/charts/brush.js
drawBrush
function drawBrush() { chartBrush = svg.select('.brush-group') .call(brush); // Update the height of the brushing rectangle chartBrush.selectAll('rect') .classed('brush-rect', true) .attr('height', chartHeight); chartBrush.selectAll('.selection') .attr('fill', `url(#${gradientId})`); }
javascript
function drawBrush() { chartBrush = svg.select('.brush-group') .call(brush); // Update the height of the brushing rectangle chartBrush.selectAll('rect') .classed('brush-rect', true) .attr('height', chartHeight); chartBrush.selectAll('.selection') .attr('fill', `url(#${gradientId})`); }
[ "function", "drawBrush", "(", ")", "{", "chartBrush", "=", "svg", ".", "select", "(", "'.brush-group'", ")", ".", "call", "(", "brush", ")", ";", "// Update the height of the brushing rectangle", "chartBrush", ".", "selectAll", "(", "'rect'", ")", ".", "classed", "(", "'brush-rect'", ",", "true", ")", ".", "attr", "(", "'height'", ",", "chartHeight", ")", ";", "chartBrush", ".", "selectAll", "(", "'.selection'", ")", ".", "attr", "(", "'fill'", ",", "`", "${", "gradientId", "}", "`", ")", ";", "}" ]
Draws the Brush components on its group @return {void}
[ "Draws", "the", "Brush", "components", "on", "its", "group" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L334-L345
8,430
eventbrite/britecharts
src/charts/brush.js
drawHandles
function drawHandles() { let handleFillColor = colorHelper.colorSchemasHuman.grey[1]; // Styling handle = chartBrush .selectAll('.handle.brush-rect') .style('fill', handleFillColor); }
javascript
function drawHandles() { let handleFillColor = colorHelper.colorSchemasHuman.grey[1]; // Styling handle = chartBrush .selectAll('.handle.brush-rect') .style('fill', handleFillColor); }
[ "function", "drawHandles", "(", ")", "{", "let", "handleFillColor", "=", "colorHelper", ".", "colorSchemasHuman", ".", "grey", "[", "1", "]", ";", "// Styling", "handle", "=", "chartBrush", ".", "selectAll", "(", "'.handle.brush-rect'", ")", ".", "style", "(", "'fill'", ",", "handleFillColor", ")", ";", "}" ]
Draws a handle for the Brush section @return {void}
[ "Draws", "a", "handle", "for", "the", "Brush", "section" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L351-L358
8,431
eventbrite/britecharts
src/charts/brush.js
handleBrushStart
function handleBrushStart() { const selection = d3Selection.event.selection; if (!selection) { return; } dispatcher.call('customBrushStart', this, selection.map(xScale.invert)); }
javascript
function handleBrushStart() { const selection = d3Selection.event.selection; if (!selection) { return; } dispatcher.call('customBrushStart', this, selection.map(xScale.invert)); }
[ "function", "handleBrushStart", "(", ")", "{", "const", "selection", "=", "d3Selection", ".", "event", ".", "selection", ";", "if", "(", "!", "selection", ")", "{", "return", ";", "}", "dispatcher", ".", "call", "(", "'customBrushStart'", ",", "this", ",", "selection", ".", "map", "(", "xScale", ".", "invert", ")", ")", ";", "}" ]
When a brush event starts, we can extract info from the extension of the brush. @return {void}
[ "When", "a", "brush", "event", "starts", "we", "can", "extract", "info", "from", "the", "extension", "of", "the", "brush", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L366-L374
8,432
eventbrite/britecharts
src/charts/brush.js
setBrushByDates
function setBrushByDates(dateA, dateB) { let selection = null; if (dateA !== null) { selection = [ xScale(new Date(dateA)), xScale(new Date(dateB)) ]; } brush.move(chartBrush, selection); }
javascript
function setBrushByDates(dateA, dateB) { let selection = null; if (dateA !== null) { selection = [ xScale(new Date(dateA)), xScale(new Date(dateB)) ]; } brush.move(chartBrush, selection); }
[ "function", "setBrushByDates", "(", "dateA", ",", "dateB", ")", "{", "let", "selection", "=", "null", ";", "if", "(", "dateA", "!==", "null", ")", "{", "selection", "=", "[", "xScale", "(", "new", "Date", "(", "dateA", ")", ")", ",", "xScale", "(", "new", "Date", "(", "dateB", ")", ")", "]", ";", "}", "brush", ".", "move", "(", "chartBrush", ",", "selection", ")", ";", "}" ]
Sets a new brush extent within the passed dates @param {String | Date} dateA Initial Date @param {String | Date} dateB End Date
[ "Sets", "a", "new", "brush", "extent", "within", "the", "passed", "dates" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/brush.js#L414-L425
8,433
eventbrite/britecharts
src/charts/sparkline.js
createGradients
function createGradients() { let metadataGroup = svg.select('.metadata-group'); if (areaGradientEl || lineGradientEl) { svg.selectAll(`#${areaGradientId}`).remove(); svg.selectAll(`#${lineGradientId}`).remove(); } areaGradientEl = metadataGroup.append('linearGradient') .attr('id', areaGradientId) .attr('class', 'area-gradient') .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: areaGradient[0]}, {offset: '100%', color: areaGradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); lineGradientEl = metadataGroup.append('linearGradient') .attr('id', lineGradientId) .attr('class', 'line-gradient') .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: lineGradient[0]}, {offset: '100%', color: lineGradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); }
javascript
function createGradients() { let metadataGroup = svg.select('.metadata-group'); if (areaGradientEl || lineGradientEl) { svg.selectAll(`#${areaGradientId}`).remove(); svg.selectAll(`#${lineGradientId}`).remove(); } areaGradientEl = metadataGroup.append('linearGradient') .attr('id', areaGradientId) .attr('class', 'area-gradient') .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: areaGradient[0]}, {offset: '100%', color: areaGradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); lineGradientEl = metadataGroup.append('linearGradient') .attr('id', lineGradientId) .attr('class', 'line-gradient') .attr('gradientUnits', 'userSpaceOnUse') .attr('x1', 0) .attr('x2', xScale(data[data.length - 1].date)) .attr('y1', 0) .attr('y2', 0) .selectAll('stop') .data([ {offset: '0%', color: lineGradient[0]}, {offset: '100%', color: lineGradient[1]} ]) .enter().append('stop') .attr('offset', ({offset}) => offset) .attr('stop-color', ({color}) => color); }
[ "function", "createGradients", "(", ")", "{", "let", "metadataGroup", "=", "svg", ".", "select", "(", "'.metadata-group'", ")", ";", "if", "(", "areaGradientEl", "||", "lineGradientEl", ")", "{", "svg", ".", "selectAll", "(", "`", "${", "areaGradientId", "}", "`", ")", ".", "remove", "(", ")", ";", "svg", ".", "selectAll", "(", "`", "${", "lineGradientId", "}", "`", ")", ".", "remove", "(", ")", ";", "}", "areaGradientEl", "=", "metadataGroup", ".", "append", "(", "'linearGradient'", ")", ".", "attr", "(", "'id'", ",", "areaGradientId", ")", ".", "attr", "(", "'class'", ",", "'area-gradient'", ")", ".", "attr", "(", "'gradientUnits'", ",", "'userSpaceOnUse'", ")", ".", "attr", "(", "'x1'", ",", "0", ")", ".", "attr", "(", "'x2'", ",", "xScale", "(", "data", "[", "data", ".", "length", "-", "1", "]", ".", "date", ")", ")", ".", "attr", "(", "'y1'", ",", "0", ")", ".", "attr", "(", "'y2'", ",", "0", ")", ".", "selectAll", "(", "'stop'", ")", ".", "data", "(", "[", "{", "offset", ":", "'0%'", ",", "color", ":", "areaGradient", "[", "0", "]", "}", ",", "{", "offset", ":", "'100%'", ",", "color", ":", "areaGradient", "[", "1", "]", "}", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'stop'", ")", ".", "attr", "(", "'offset'", ",", "(", "{", "offset", "}", ")", "=>", "offset", ")", ".", "attr", "(", "'stop-color'", ",", "(", "{", "color", "}", ")", "=>", "color", ")", ";", "lineGradientEl", "=", "metadataGroup", ".", "append", "(", "'linearGradient'", ")", ".", "attr", "(", "'id'", ",", "lineGradientId", ")", ".", "attr", "(", "'class'", ",", "'line-gradient'", ")", ".", "attr", "(", "'gradientUnits'", ",", "'userSpaceOnUse'", ")", ".", "attr", "(", "'x1'", ",", "0", ")", ".", "attr", "(", "'x2'", ",", "xScale", "(", "data", "[", "data", ".", "length", "-", "1", "]", ".", "date", ")", ")", ".", "attr", "(", "'y1'", ",", "0", ")", ".", "attr", "(", "'y2'", ",", "0", ")", ".", "selectAll", "(", "'stop'", ")", ".", "data", "(", "[", "{", "offset", ":", "'0%'", ",", "color", ":", "lineGradient", "[", "0", "]", "}", ",", "{", "offset", ":", "'100%'", ",", "color", ":", "lineGradient", "[", "1", "]", "}", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'stop'", ")", ".", "attr", "(", "'offset'", ",", "(", "{", "offset", "}", ")", "=>", "offset", ")", ".", "attr", "(", "'stop-color'", ",", "(", "{", "color", "}", ")", "=>", "color", ")", ";", "}" ]
Creates the gradient on the area below the line @return {void}
[ "Creates", "the", "gradient", "on", "the", "area", "below", "the", "line" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/sparkline.js#L215-L256
8,434
eventbrite/britecharts
src/charts/sparkline.js
drawArea
function drawArea(){ if (area) { svg.selectAll('.sparkline-area').remove(); } area = d3Shape.area() .x(({date}) => xScale(date)) .y0(() => yScale(0) + lineStrokeWidth / 2) .y1(({value}) => yScale(value)) .curve(d3Shape.curveBasis); svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'sparkline-area') .attr('fill', `url(#${areaGradientId})`) .attr('d', area) .attr('clip-path', `url(#${maskingClipId})`); }
javascript
function drawArea(){ if (area) { svg.selectAll('.sparkline-area').remove(); } area = d3Shape.area() .x(({date}) => xScale(date)) .y0(() => yScale(0) + lineStrokeWidth / 2) .y1(({value}) => yScale(value)) .curve(d3Shape.curveBasis); svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'sparkline-area') .attr('fill', `url(#${areaGradientId})`) .attr('d', area) .attr('clip-path', `url(#${maskingClipId})`); }
[ "function", "drawArea", "(", ")", "{", "if", "(", "area", ")", "{", "svg", ".", "selectAll", "(", "'.sparkline-area'", ")", ".", "remove", "(", ")", ";", "}", "area", "=", "d3Shape", ".", "area", "(", ")", ".", "x", "(", "(", "{", "date", "}", ")", "=>", "xScale", "(", "date", ")", ")", ".", "y0", "(", "(", ")", "=>", "yScale", "(", "0", ")", "+", "lineStrokeWidth", "/", "2", ")", ".", "y1", "(", "(", "{", "value", "}", ")", "=>", "yScale", "(", "value", ")", ")", ".", "curve", "(", "d3Shape", ".", "curveBasis", ")", ";", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "append", "(", "'path'", ")", ".", "datum", "(", "data", ")", ".", "attr", "(", "'class'", ",", "'sparkline-area'", ")", ".", "attr", "(", "'fill'", ",", "`", "${", "areaGradientId", "}", "`", ")", ".", "attr", "(", "'d'", ",", "area", ")", ".", "attr", "(", "'clip-path'", ",", "`", "${", "maskingClipId", "}", "`", ")", ";", "}" ]
Draws the area that will be placed below the line @private
[ "Draws", "the", "area", "that", "will", "be", "placed", "below", "the", "line" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/sparkline.js#L290-L308
8,435
eventbrite/britecharts
src/charts/sparkline.js
drawLine
function drawLine(){ if (topLine) { svg.selectAll('.line').remove(); } topLine = d3Shape.line() .curve(d3Shape.curveBasis) .x(({date}) => xScale(date)) .y(({value}) => yScale(value)); svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'line') .attr('stroke', `url(#${lineGradientId})`) .attr('d', topLine) .attr('clip-path', `url(#${maskingClipId})`); }
javascript
function drawLine(){ if (topLine) { svg.selectAll('.line').remove(); } topLine = d3Shape.line() .curve(d3Shape.curveBasis) .x(({date}) => xScale(date)) .y(({value}) => yScale(value)); svg.select('.chart-group') .append('path') .datum(data) .attr('class', 'line') .attr('stroke', `url(#${lineGradientId})`) .attr('d', topLine) .attr('clip-path', `url(#${maskingClipId})`); }
[ "function", "drawLine", "(", ")", "{", "if", "(", "topLine", ")", "{", "svg", ".", "selectAll", "(", "'.line'", ")", ".", "remove", "(", ")", ";", "}", "topLine", "=", "d3Shape", ".", "line", "(", ")", ".", "curve", "(", "d3Shape", ".", "curveBasis", ")", ".", "x", "(", "(", "{", "date", "}", ")", "=>", "xScale", "(", "date", ")", ")", ".", "y", "(", "(", "{", "value", "}", ")", "=>", "yScale", "(", "value", ")", ")", ";", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "append", "(", "'path'", ")", ".", "datum", "(", "data", ")", ".", "attr", "(", "'class'", ",", "'line'", ")", ".", "attr", "(", "'stroke'", ",", "`", "${", "lineGradientId", "}", "`", ")", ".", "attr", "(", "'d'", ",", "topLine", ")", ".", "attr", "(", "'clip-path'", ",", "`", "${", "maskingClipId", "}", "`", ")", ";", "}" ]
Draws the line element within the chart group @private
[ "Draws", "the", "line", "element", "within", "the", "chart", "group" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/sparkline.js#L314-L331
8,436
eventbrite/britecharts
src/charts/sparkline.js
drawSparklineTitle
function drawSparklineTitle() { if (titleEl) { svg.selectAll('.sparkline-text').remove(); } titleEl = svg.selectAll('.text-group') .append('text') .attr('x', chartWidth / 2) .attr('y', chartHeight / 6) .attr('text-anchor', 'middle') .attr('class', 'sparkline-text') .style('font-size', titleTextStyle['font-size'] || DEFAULT_TITLE_TEXT_STYLE['font-size']) .style('fill', titleTextStyle['fill'] || lineGradient[0]) .style('font-family', titleTextStyle['font-family'] || DEFAULT_TITLE_TEXT_STYLE['font-family']) .style('font-weight', titleTextStyle['font-weight'] || DEFAULT_TITLE_TEXT_STYLE['font-weight']) .style('font-style', titleTextStyle['font-style'] || DEFAULT_TITLE_TEXT_STYLE['font-style']) .text(titleText) }
javascript
function drawSparklineTitle() { if (titleEl) { svg.selectAll('.sparkline-text').remove(); } titleEl = svg.selectAll('.text-group') .append('text') .attr('x', chartWidth / 2) .attr('y', chartHeight / 6) .attr('text-anchor', 'middle') .attr('class', 'sparkline-text') .style('font-size', titleTextStyle['font-size'] || DEFAULT_TITLE_TEXT_STYLE['font-size']) .style('fill', titleTextStyle['fill'] || lineGradient[0]) .style('font-family', titleTextStyle['font-family'] || DEFAULT_TITLE_TEXT_STYLE['font-family']) .style('font-weight', titleTextStyle['font-weight'] || DEFAULT_TITLE_TEXT_STYLE['font-weight']) .style('font-style', titleTextStyle['font-style'] || DEFAULT_TITLE_TEXT_STYLE['font-style']) .text(titleText) }
[ "function", "drawSparklineTitle", "(", ")", "{", "if", "(", "titleEl", ")", "{", "svg", ".", "selectAll", "(", "'.sparkline-text'", ")", ".", "remove", "(", ")", ";", "}", "titleEl", "=", "svg", ".", "selectAll", "(", "'.text-group'", ")", ".", "append", "(", "'text'", ")", ".", "attr", "(", "'x'", ",", "chartWidth", "/", "2", ")", ".", "attr", "(", "'y'", ",", "chartHeight", "/", "6", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ".", "attr", "(", "'class'", ",", "'sparkline-text'", ")", ".", "style", "(", "'font-size'", ",", "titleTextStyle", "[", "'font-size'", "]", "||", "DEFAULT_TITLE_TEXT_STYLE", "[", "'font-size'", "]", ")", ".", "style", "(", "'fill'", ",", "titleTextStyle", "[", "'fill'", "]", "||", "lineGradient", "[", "0", "]", ")", ".", "style", "(", "'font-family'", ",", "titleTextStyle", "[", "'font-family'", "]", "||", "DEFAULT_TITLE_TEXT_STYLE", "[", "'font-family'", "]", ")", ".", "style", "(", "'font-weight'", ",", "titleTextStyle", "[", "'font-weight'", "]", "||", "DEFAULT_TITLE_TEXT_STYLE", "[", "'font-weight'", "]", ")", ".", "style", "(", "'font-style'", ",", "titleTextStyle", "[", "'font-style'", "]", "||", "DEFAULT_TITLE_TEXT_STYLE", "[", "'font-style'", "]", ")", ".", "text", "(", "titleText", ")", "}" ]
Draws the text element within the text group Is displayed at the top of sparked area @private
[ "Draws", "the", "text", "element", "within", "the", "text", "group", "Is", "displayed", "at", "the", "top", "of", "sparked", "area" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/sparkline.js#L338-L355
8,437
eventbrite/britecharts
src/charts/sparkline.js
drawEndMarker
function drawEndMarker(){ if (circle) { svg.selectAll('.sparkline-circle').remove(); } circle = svg.selectAll('.chart-group') .append('circle') .attr('class', 'sparkline-circle') .attr('cx', xScale(data[data.length - 1].date)) .attr('cy', yScale(data[data.length - 1].value)) .attr('r', markerSize); }
javascript
function drawEndMarker(){ if (circle) { svg.selectAll('.sparkline-circle').remove(); } circle = svg.selectAll('.chart-group') .append('circle') .attr('class', 'sparkline-circle') .attr('cx', xScale(data[data.length - 1].date)) .attr('cy', yScale(data[data.length - 1].value)) .attr('r', markerSize); }
[ "function", "drawEndMarker", "(", ")", "{", "if", "(", "circle", ")", "{", "svg", ".", "selectAll", "(", "'.sparkline-circle'", ")", ".", "remove", "(", ")", ";", "}", "circle", "=", "svg", ".", "selectAll", "(", "'.chart-group'", ")", ".", "append", "(", "'circle'", ")", ".", "attr", "(", "'class'", ",", "'sparkline-circle'", ")", ".", "attr", "(", "'cx'", ",", "xScale", "(", "data", "[", "data", ".", "length", "-", "1", "]", ".", "date", ")", ")", ".", "attr", "(", "'cy'", ",", "yScale", "(", "data", "[", "data", ".", "length", "-", "1", "]", ".", "value", ")", ")", ".", "attr", "(", "'r'", ",", "markerSize", ")", ";", "}" ]
Draws a marker at the end of the sparkline
[ "Draws", "a", "marker", "at", "the", "end", "of", "the", "sparkline" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/sparkline.js#L360-L371
8,438
eventbrite/britecharts
sandbox/sandbox.js
main
function main() { loadDependencies(); setInitialData(); domHelpers.initDomElements(); setDataInInputField(); setConfigInInputField(); setChartSelectorType(); setNewChart(); setHandlers(); }
javascript
function main() { loadDependencies(); setInitialData(); domHelpers.initDomElements(); setDataInInputField(); setConfigInInputField(); setChartSelectorType(); setNewChart(); setHandlers(); }
[ "function", "main", "(", ")", "{", "loadDependencies", "(", ")", ";", "setInitialData", "(", ")", ";", "domHelpers", ".", "initDomElements", "(", ")", ";", "setDataInInputField", "(", ")", ";", "setConfigInInputField", "(", ")", ";", "setChartSelectorType", "(", ")", ";", "setNewChart", "(", ")", ";", "setHandlers", "(", ")", ";", "}" ]
Main function to run the sandbox
[ "Main", "function", "to", "run", "the", "sandbox" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L75-L85
8,439
eventbrite/britecharts
sandbox/sandbox.js
setHandlers
function setHandlers() { d3.select(`.${chartSelectorClass}`).on('change', _handleChartSelectorChange); d3.select(`.${dataSelectorClass}`).on('change', _handleDataSelectorChange); d3.select(`.${dataSubmitButtonClass}`).on('click', _handleDataUpdate); d3.select(`.${dataResetButtonClass}`).on('click', _handleDataReset); d3.select(`.${dataInputSizeToggleClass}`).on('click', _handleDataSizeToggle); d3.select(`.${configSubmitButtonClass}`).on('click', _handleConfigUpdate); d3.select(`.${configResetButtonClass}`).on('click', _handleConfigReset); d3.select(`.${configAddTooltipClass}`).on('click', _handleAddTooltip.bind(null, tooltipTypes.basic)) d3.select(`.${configAddMiniTooltipClass}`).on('click', _handleAddTooltip.bind(null, tooltipTypes.mini)) }
javascript
function setHandlers() { d3.select(`.${chartSelectorClass}`).on('change', _handleChartSelectorChange); d3.select(`.${dataSelectorClass}`).on('change', _handleDataSelectorChange); d3.select(`.${dataSubmitButtonClass}`).on('click', _handleDataUpdate); d3.select(`.${dataResetButtonClass}`).on('click', _handleDataReset); d3.select(`.${dataInputSizeToggleClass}`).on('click', _handleDataSizeToggle); d3.select(`.${configSubmitButtonClass}`).on('click', _handleConfigUpdate); d3.select(`.${configResetButtonClass}`).on('click', _handleConfigReset); d3.select(`.${configAddTooltipClass}`).on('click', _handleAddTooltip.bind(null, tooltipTypes.basic)) d3.select(`.${configAddMiniTooltipClass}`).on('click', _handleAddTooltip.bind(null, tooltipTypes.mini)) }
[ "function", "setHandlers", "(", ")", "{", "d3", ".", "select", "(", "`", "${", "chartSelectorClass", "}", "`", ")", ".", "on", "(", "'change'", ",", "_handleChartSelectorChange", ")", ";", "d3", ".", "select", "(", "`", "${", "dataSelectorClass", "}", "`", ")", ".", "on", "(", "'change'", ",", "_handleDataSelectorChange", ")", ";", "d3", ".", "select", "(", "`", "${", "dataSubmitButtonClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleDataUpdate", ")", ";", "d3", ".", "select", "(", "`", "${", "dataResetButtonClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleDataReset", ")", ";", "d3", ".", "select", "(", "`", "${", "dataInputSizeToggleClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleDataSizeToggle", ")", ";", "d3", ".", "select", "(", "`", "${", "configSubmitButtonClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleConfigUpdate", ")", ";", "d3", ".", "select", "(", "`", "${", "configResetButtonClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleConfigReset", ")", ";", "d3", ".", "select", "(", "`", "${", "configAddTooltipClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleAddTooltip", ".", "bind", "(", "null", ",", "tooltipTypes", ".", "basic", ")", ")", "d3", ".", "select", "(", "`", "${", "configAddMiniTooltipClass", "}", "`", ")", ".", "on", "(", "'click'", ",", "_handleAddTooltip", ".", "bind", "(", "null", ",", "tooltipTypes", ".", "mini", ")", ")", "}" ]
Sets handlers on all of our input fields on the sandbox dom
[ "Sets", "handlers", "on", "all", "of", "our", "input", "fields", "on", "the", "sandbox", "dom" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L98-L111
8,440
eventbrite/britecharts
sandbox/sandbox.js
setNewDataTypes
function setNewDataTypes() { let chartType = getCurrentType(); let dataTypes = Object.keys(defaultData[chartType]); let dataSelector = d3.select(`.${dataSelectorClass}`) .selectAll('option') .data(dataTypes); dataSelector.enter().append('option') .merge(dataSelector) .attr('value', (d) => d) .text((d) => d); dataSelector.exit().remove(); }
javascript
function setNewDataTypes() { let chartType = getCurrentType(); let dataTypes = Object.keys(defaultData[chartType]); let dataSelector = d3.select(`.${dataSelectorClass}`) .selectAll('option') .data(dataTypes); dataSelector.enter().append('option') .merge(dataSelector) .attr('value', (d) => d) .text((d) => d); dataSelector.exit().remove(); }
[ "function", "setNewDataTypes", "(", ")", "{", "let", "chartType", "=", "getCurrentType", "(", ")", ";", "let", "dataTypes", "=", "Object", ".", "keys", "(", "defaultData", "[", "chartType", "]", ")", ";", "let", "dataSelector", "=", "d3", ".", "select", "(", "`", "${", "dataSelectorClass", "}", "`", ")", ".", "selectAll", "(", "'option'", ")", ".", "data", "(", "dataTypes", ")", ";", "dataSelector", ".", "enter", "(", ")", ".", "append", "(", "'option'", ")", ".", "merge", "(", "dataSelector", ")", ".", "attr", "(", "'value'", ",", "(", "d", ")", "=>", "d", ")", ".", "text", "(", "(", "d", ")", "=>", "d", ")", ";", "dataSelector", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Reads from the constants file to fill the data type selelctor with the data types of that chart
[ "Reads", "from", "the", "constants", "file", "to", "fill", "the", "data", "type", "selelctor", "with", "the", "data", "types", "of", "that", "chart" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L176-L190
8,441
eventbrite/britecharts
sandbox/sandbox.js
getCurrentData
function getCurrentData() { let currentData = storage.getDataByKey(savedDataKey); if (!currentData) { let chartType = getCurrentType(); let {initialDataType} = defaultConfig[chartType]; currentData = defaultData[chartType][initialDataType]; storage.setDataByKey(savedDataKey, currentData); } return currentData; }
javascript
function getCurrentData() { let currentData = storage.getDataByKey(savedDataKey); if (!currentData) { let chartType = getCurrentType(); let {initialDataType} = defaultConfig[chartType]; currentData = defaultData[chartType][initialDataType]; storage.setDataByKey(savedDataKey, currentData); } return currentData; }
[ "function", "getCurrentData", "(", ")", "{", "let", "currentData", "=", "storage", ".", "getDataByKey", "(", "savedDataKey", ")", ";", "if", "(", "!", "currentData", ")", "{", "let", "chartType", "=", "getCurrentType", "(", ")", ";", "let", "{", "initialDataType", "}", "=", "defaultConfig", "[", "chartType", "]", ";", "currentData", "=", "defaultData", "[", "chartType", "]", "[", "initialDataType", "]", ";", "storage", ".", "setDataByKey", "(", "savedDataKey", ",", "currentData", ")", ";", "}", "return", "currentData", ";", "}" ]
Gets the current data either from the store or from the data file. If no data is found on the store, one is set from the data file. @return {Object} Data object [data is parsed before it is set]
[ "Gets", "the", "current", "data", "either", "from", "the", "store", "or", "from", "the", "data", "file", ".", "If", "no", "data", "is", "found", "on", "the", "store", "one", "is", "set", "from", "the", "data", "file", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L197-L210
8,442
eventbrite/britecharts
sandbox/sandbox.js
getCurrentConfig
function getCurrentConfig() { let initString = storage.getDataByKey(savedConfigKey); if (!initString) { let chartType = getCurrentType(); let {chartConfig} = defaultConfig[chartType]; initString = formatParamsIntoChartInitString(chartConfig); storage.setDataByKey(savedConfigKey, initString); } return initString; }
javascript
function getCurrentConfig() { let initString = storage.getDataByKey(savedConfigKey); if (!initString) { let chartType = getCurrentType(); let {chartConfig} = defaultConfig[chartType]; initString = formatParamsIntoChartInitString(chartConfig); storage.setDataByKey(savedConfigKey, initString); } return initString; }
[ "function", "getCurrentConfig", "(", ")", "{", "let", "initString", "=", "storage", ".", "getDataByKey", "(", "savedConfigKey", ")", ";", "if", "(", "!", "initString", ")", "{", "let", "chartType", "=", "getCurrentType", "(", ")", ";", "let", "{", "chartConfig", "}", "=", "defaultConfig", "[", "chartType", "]", ";", "initString", "=", "formatParamsIntoChartInitString", "(", "chartConfig", ")", ";", "storage", ".", "setDataByKey", "(", "savedConfigKey", ",", "initString", ")", ";", "}", "return", "initString", ";", "}" ]
Gets teh current chart configuration either from the store or from the constants file. If no configuraiton is found on the store, one is set from the constants. @return {String} config string
[ "Gets", "teh", "current", "chart", "configuration", "either", "from", "the", "store", "or", "from", "the", "constants", "file", ".", "If", "no", "configuraiton", "is", "found", "on", "the", "store", "one", "is", "set", "from", "the", "constants", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L217-L230
8,443
eventbrite/britecharts
sandbox/sandbox.js
getCurrentType
function getCurrentType() { let currentType = storage.getDataByKey(savedChartTypeKey); if (!currentType) { currentType = charts[0]; storage.setDataByKey(savedChartTypeKey, currentType); } return currentType; }
javascript
function getCurrentType() { let currentType = storage.getDataByKey(savedChartTypeKey); if (!currentType) { currentType = charts[0]; storage.setDataByKey(savedChartTypeKey, currentType); } return currentType; }
[ "function", "getCurrentType", "(", ")", "{", "let", "currentType", "=", "storage", ".", "getDataByKey", "(", "savedChartTypeKey", ")", ";", "if", "(", "!", "currentType", ")", "{", "currentType", "=", "charts", "[", "0", "]", ";", "storage", ".", "setDataByKey", "(", "savedChartTypeKey", ",", "currentType", ")", ";", "}", "return", "currentType", ";", "}" ]
Gets the current chart type either from the store or from the constants file If no chart type is found in the store, one is set from the constants. @return {String} chart type
[ "Gets", "the", "current", "chart", "type", "either", "from", "the", "store", "or", "from", "the", "constants", "file", "If", "no", "chart", "type", "is", "found", "in", "the", "store", "one", "is", "set", "from", "the", "constants", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L237-L246
8,444
eventbrite/britecharts
sandbox/sandbox.js
_handleAddTooltip
function _handleAddTooltip(tooltipType) { let initString = getCurrentConfig(); let tooltipInitString = tooltipConfigs[tooltipType].initString; initString = initString.concat(tooltipInitString); configEditor.setValue(prettifyInitString(initString)); setNewChart(); }
javascript
function _handleAddTooltip(tooltipType) { let initString = getCurrentConfig(); let tooltipInitString = tooltipConfigs[tooltipType].initString; initString = initString.concat(tooltipInitString); configEditor.setValue(prettifyInitString(initString)); setNewChart(); }
[ "function", "_handleAddTooltip", "(", "tooltipType", ")", "{", "let", "initString", "=", "getCurrentConfig", "(", ")", ";", "let", "tooltipInitString", "=", "tooltipConfigs", "[", "tooltipType", "]", ".", "initString", ";", "initString", "=", "initString", ".", "concat", "(", "tooltipInitString", ")", ";", "configEditor", ".", "setValue", "(", "prettifyInitString", "(", "initString", ")", ")", ";", "setNewChart", "(", ")", ";", "}" ]
Adds tooltip code to the editor @param {string} tooltipType Constant from constant file
[ "Adds", "tooltip", "code", "to", "the", "editor" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L252-L258
8,445
eventbrite/britecharts
sandbox/sandbox.js
_handleDataSelectorChange
function _handleDataSelectorChange () { let chartType = getCurrentType(); let dataType = d3.select(`.${dataSelectorClass}`).property('value'); let currentData = defaultData[chartType][dataType]; storage.setDataByKey(savedDataKey, currentData); updateAllComponents(); }
javascript
function _handleDataSelectorChange () { let chartType = getCurrentType(); let dataType = d3.select(`.${dataSelectorClass}`).property('value'); let currentData = defaultData[chartType][dataType]; storage.setDataByKey(savedDataKey, currentData); updateAllComponents(); }
[ "function", "_handleDataSelectorChange", "(", ")", "{", "let", "chartType", "=", "getCurrentType", "(", ")", ";", "let", "dataType", "=", "d3", ".", "select", "(", "`", "${", "dataSelectorClass", "}", "`", ")", ".", "property", "(", "'value'", ")", ";", "let", "currentData", "=", "defaultData", "[", "chartType", "]", "[", "dataType", "]", ";", "storage", ".", "setDataByKey", "(", "savedDataKey", ",", "currentData", ")", ";", "updateAllComponents", "(", ")", ";", "}" ]
Handles data selection change, updates the data on the store and then updates all components
[ "Handles", "data", "selection", "change", "updates", "the", "data", "on", "the", "store", "and", "then", "updates", "all", "components" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L263-L270
8,446
eventbrite/britecharts
sandbox/sandbox.js
_handleDataUpdate
function _handleDataUpdate() { const rawData = dataEditor.getValue(); let freshData = null; try { freshData = evalDataString(rawData); } catch(e) { errors.push(new Error('Could not parse the data from the input field', rawData)); } storage.setDataByKey(savedDataKey, freshData); if (freshData) { setNewChart(); } }
javascript
function _handleDataUpdate() { const rawData = dataEditor.getValue(); let freshData = null; try { freshData = evalDataString(rawData); } catch(e) { errors.push(new Error('Could not parse the data from the input field', rawData)); } storage.setDataByKey(savedDataKey, freshData); if (freshData) { setNewChart(); } }
[ "function", "_handleDataUpdate", "(", ")", "{", "const", "rawData", "=", "dataEditor", ".", "getValue", "(", ")", ";", "let", "freshData", "=", "null", ";", "try", "{", "freshData", "=", "evalDataString", "(", "rawData", ")", ";", "}", "catch", "(", "e", ")", "{", "errors", ".", "push", "(", "new", "Error", "(", "'Could not parse the data from the input field'", ",", "rawData", ")", ")", ";", "}", "storage", ".", "setDataByKey", "(", "savedDataKey", ",", "freshData", ")", ";", "if", "(", "freshData", ")", "{", "setNewChart", "(", ")", ";", "}", "}" ]
Updates the data for the chart on the store, then sets a new chart so the new data is displayed @return {[type]} [description]
[ "Updates", "the", "data", "for", "the", "chart", "on", "the", "store", "then", "sets", "a", "new", "chart", "so", "the", "new", "data", "is", "displayed" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L288-L303
8,447
eventbrite/britecharts
sandbox/sandbox.js
_handleDataReset
function _handleDataReset() { storage.removeDataByKey(savedDataKey); let data = getCurrentData(); dataEditor.setValue(prettifyJson(data)); }
javascript
function _handleDataReset() { storage.removeDataByKey(savedDataKey); let data = getCurrentData(); dataEditor.setValue(prettifyJson(data)); }
[ "function", "_handleDataReset", "(", ")", "{", "storage", ".", "removeDataByKey", "(", "savedDataKey", ")", ";", "let", "data", "=", "getCurrentData", "(", ")", ";", "dataEditor", ".", "setValue", "(", "prettifyJson", "(", "data", ")", ")", ";", "}" ]
Resets the data to its default state
[ "Resets", "the", "data", "to", "its", "default", "state" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L308-L314
8,448
eventbrite/britecharts
sandbox/sandbox.js
_handleConfigReset
function _handleConfigReset() { storage.removeDataByKey(savedConfigKey); let initString = getCurrentConfig(); configEditor.setValue(prettifyInitString(initString)); }
javascript
function _handleConfigReset() { storage.removeDataByKey(savedConfigKey); let initString = getCurrentConfig(); configEditor.setValue(prettifyInitString(initString)); }
[ "function", "_handleConfigReset", "(", ")", "{", "storage", ".", "removeDataByKey", "(", "savedConfigKey", ")", ";", "let", "initString", "=", "getCurrentConfig", "(", ")", ";", "configEditor", ".", "setValue", "(", "prettifyInitString", "(", "initString", ")", ")", ";", "}" ]
Resets the chart config to its default state
[ "Resets", "the", "chart", "config", "to", "its", "default", "state" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L329-L335
8,449
eventbrite/britecharts
sandbox/sandbox.js
_handleChartSelectorChange
function _handleChartSelectorChange() { storage.clear(); let chartType = d3.select(`.${chartSelectorClass}`).property('value'); storage.setDataByKey(savedChartTypeKey, chartType); updateAllComponents(); }
javascript
function _handleChartSelectorChange() { storage.clear(); let chartType = d3.select(`.${chartSelectorClass}`).property('value'); storage.setDataByKey(savedChartTypeKey, chartType); updateAllComponents(); }
[ "function", "_handleChartSelectorChange", "(", ")", "{", "storage", ".", "clear", "(", ")", ";", "let", "chartType", "=", "d3", ".", "select", "(", "`", "${", "chartSelectorClass", "}", "`", ")", ".", "property", "(", "'value'", ")", ";", "storage", ".", "setDataByKey", "(", "savedChartTypeKey", ",", "chartType", ")", ";", "updateAllComponents", "(", ")", ";", "}" ]
Updates the chart type when the chart selector is changed
[ "Updates", "the", "chart", "type", "when", "the", "chart", "selector", "is", "changed" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L341-L348
8,450
eventbrite/britecharts
sandbox/sandbox.js
_safeLoadDependency
function _safeLoadDependency(name) { try { window[name.split('/').pop()] = require(`../src/charts/${name}`); } catch(e) { errors.push({ error: e, filePath: name }); } }
javascript
function _safeLoadDependency(name) { try { window[name.split('/').pop()] = require(`../src/charts/${name}`); } catch(e) { errors.push({ error: e, filePath: name }); } }
[ "function", "_safeLoadDependency", "(", "name", ")", "{", "try", "{", "window", "[", "name", ".", "split", "(", "'/'", ")", ".", "pop", "(", ")", "]", "=", "require", "(", "`", "${", "name", "}", "`", ")", ";", "}", "catch", "(", "e", ")", "{", "errors", ".", "push", "(", "{", "error", ":", "e", ",", "filePath", ":", "name", "}", ")", ";", "}", "}" ]
Safe load dependency. If there is an error, it loads the error to be displayed in the notification bar @param {file name} name name of fiel at src/charts. probably could refactor to take full path
[ "Safe", "load", "dependency", ".", "If", "there", "is", "an", "error", "it", "loads", "the", "error", "to", "be", "displayed", "in", "the", "notification", "bar" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/sandbox/sandbox.js#L354-L363
8,451
eventbrite/britecharts
src/charts/scatter-plot.js
buildAxis
function buildAxis() { xAxis = d3Axis.axisBottom(xScale) .ticks(xTicks) .tickPadding(tickPadding) .tickFormat(d3Format.format(xAxisFormat)); yAxis = d3Axis.axisLeft(yScale) .ticks(yTicks) .tickPadding(tickPadding) .tickFormat(d3Format.format(yAxisFormat)); }
javascript
function buildAxis() { xAxis = d3Axis.axisBottom(xScale) .ticks(xTicks) .tickPadding(tickPadding) .tickFormat(d3Format.format(xAxisFormat)); yAxis = d3Axis.axisLeft(yScale) .ticks(yTicks) .tickPadding(tickPadding) .tickFormat(d3Format.format(yAxisFormat)); }
[ "function", "buildAxis", "(", ")", "{", "xAxis", "=", "d3Axis", ".", "axisBottom", "(", "xScale", ")", ".", "ticks", "(", "xTicks", ")", ".", "tickPadding", "(", "tickPadding", ")", ".", "tickFormat", "(", "d3Format", ".", "format", "(", "xAxisFormat", ")", ")", ";", "yAxis", "=", "d3Axis", ".", "axisLeft", "(", "yScale", ")", ".", "ticks", "(", "yTicks", ")", ".", "tickPadding", "(", "tickPadding", ")", ".", "tickFormat", "(", "d3Format", ".", "format", "(", "yAxisFormat", ")", ")", ";", "}" ]
Creates the x-axis and y-axis with proper orientations @return {void} @private
[ "Creates", "the", "x", "-", "axis", "and", "y", "-", "axis", "with", "proper", "orientations" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L241-L251
8,452
eventbrite/britecharts
src/charts/scatter-plot.js
buildVoronoi
function buildVoronoi() { voronoi = d3Voronoi.voronoi() .x((d) => xScale(d.x)) .y((d) => yScale(d.y)) .extent([ [0, 0], [chartWidth, chartHeight] ])(dataPoints); }
javascript
function buildVoronoi() { voronoi = d3Voronoi.voronoi() .x((d) => xScale(d.x)) .y((d) => yScale(d.y)) .extent([ [0, 0], [chartWidth, chartHeight] ])(dataPoints); }
[ "function", "buildVoronoi", "(", ")", "{", "voronoi", "=", "d3Voronoi", ".", "voronoi", "(", ")", ".", "x", "(", "(", "d", ")", "=>", "xScale", "(", "d", ".", "x", ")", ")", ".", "y", "(", "(", "d", ")", "=>", "yScale", "(", "d", ".", "y", ")", ")", ".", "extent", "(", "[", "[", "0", ",", "0", "]", ",", "[", "chartWidth", ",", "chartHeight", "]", "]", ")", "(", "dataPoints", ")", ";", "}" ]
Draws the voronoi component in the chart. @return {void} @private
[ "Draws", "the", "voronoi", "component", "in", "the", "chart", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L286-L294
8,453
eventbrite/britecharts
src/charts/scatter-plot.js
buildScales
function buildScales() { const [minX, minY] = [d3Array.min(dataPoints, ({ x }) => x), d3Array.min(dataPoints, ({ y }) => y)]; const [maxX, maxY] = [d3Array.max(dataPoints, ({ x }) => x), d3Array.max(dataPoints, ({ y }) => y)]; const yScaleBottomValue = Math.abs(minY) < 0 ? Math.abs(minY) : 0; xScale = d3Scale.scaleLinear() .domain([minX, maxX]) .rangeRound([0, chartWidth]) .nice(); yScale = d3Scale.scaleLinear() .domain([yScaleBottomValue, maxY]) .rangeRound([chartHeight, 0]) .nice(); colorScale = d3Scale.scaleOrdinal() .domain(dataPoints.map(getName)) .range(colorSchema); areaScale = d3Scale.scaleSqrt() .domain([yScaleBottomValue, maxY]) .range([0, maxCircleArea]); const colorRange = colorScale.range(); /** * Maps data point category name to * each color of the given color scheme * { * name1: 'color1', * name2: 'color2', * name3: 'color3', * ... * } * @private */ nameColorMap = colorScale.domain().reduce((accum, item, i) => { accum[item] = colorRange[i]; return accum; }, {}); }
javascript
function buildScales() { const [minX, minY] = [d3Array.min(dataPoints, ({ x }) => x), d3Array.min(dataPoints, ({ y }) => y)]; const [maxX, maxY] = [d3Array.max(dataPoints, ({ x }) => x), d3Array.max(dataPoints, ({ y }) => y)]; const yScaleBottomValue = Math.abs(minY) < 0 ? Math.abs(minY) : 0; xScale = d3Scale.scaleLinear() .domain([minX, maxX]) .rangeRound([0, chartWidth]) .nice(); yScale = d3Scale.scaleLinear() .domain([yScaleBottomValue, maxY]) .rangeRound([chartHeight, 0]) .nice(); colorScale = d3Scale.scaleOrdinal() .domain(dataPoints.map(getName)) .range(colorSchema); areaScale = d3Scale.scaleSqrt() .domain([yScaleBottomValue, maxY]) .range([0, maxCircleArea]); const colorRange = colorScale.range(); /** * Maps data point category name to * each color of the given color scheme * { * name1: 'color1', * name2: 'color2', * name3: 'color3', * ... * } * @private */ nameColorMap = colorScale.domain().reduce((accum, item, i) => { accum[item] = colorRange[i]; return accum; }, {}); }
[ "function", "buildScales", "(", ")", "{", "const", "[", "minX", ",", "minY", "]", "=", "[", "d3Array", ".", "min", "(", "dataPoints", ",", "(", "{", "x", "}", ")", "=>", "x", ")", ",", "d3Array", ".", "min", "(", "dataPoints", ",", "(", "{", "y", "}", ")", "=>", "y", ")", "]", ";", "const", "[", "maxX", ",", "maxY", "]", "=", "[", "d3Array", ".", "max", "(", "dataPoints", ",", "(", "{", "x", "}", ")", "=>", "x", ")", ",", "d3Array", ".", "max", "(", "dataPoints", ",", "(", "{", "y", "}", ")", "=>", "y", ")", "]", ";", "const", "yScaleBottomValue", "=", "Math", ".", "abs", "(", "minY", ")", "<", "0", "?", "Math", ".", "abs", "(", "minY", ")", ":", "0", ";", "xScale", "=", "d3Scale", ".", "scaleLinear", "(", ")", ".", "domain", "(", "[", "minX", ",", "maxX", "]", ")", ".", "rangeRound", "(", "[", "0", ",", "chartWidth", "]", ")", ".", "nice", "(", ")", ";", "yScale", "=", "d3Scale", ".", "scaleLinear", "(", ")", ".", "domain", "(", "[", "yScaleBottomValue", ",", "maxY", "]", ")", ".", "rangeRound", "(", "[", "chartHeight", ",", "0", "]", ")", ".", "nice", "(", ")", ";", "colorScale", "=", "d3Scale", ".", "scaleOrdinal", "(", ")", ".", "domain", "(", "dataPoints", ".", "map", "(", "getName", ")", ")", ".", "range", "(", "colorSchema", ")", ";", "areaScale", "=", "d3Scale", ".", "scaleSqrt", "(", ")", ".", "domain", "(", "[", "yScaleBottomValue", ",", "maxY", "]", ")", ".", "range", "(", "[", "0", ",", "maxCircleArea", "]", ")", ";", "const", "colorRange", "=", "colorScale", ".", "range", "(", ")", ";", "/**\n * Maps data point category name to\n * each color of the given color scheme\n * {\n * name1: 'color1',\n * name2: 'color2',\n * name3: 'color3',\n * ...\n * }\n * @private\n */", "nameColorMap", "=", "colorScale", ".", "domain", "(", ")", ".", "reduce", "(", "(", "accum", ",", "item", ",", "i", ")", "=>", "{", "accum", "[", "item", "]", "=", "colorRange", "[", "i", "]", ";", "return", "accum", ";", "}", ",", "{", "}", ")", ";", "}" ]
Creates the x and y scales of the chart @return {void} @private
[ "Creates", "the", "x", "and", "y", "scales", "of", "the", "chart" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L301-L342
8,454
eventbrite/britecharts
src/charts/scatter-plot.js
cleanData
function cleanData(originalData) { return originalData.reduce((acc, d) => { d.name = String(d[nameKey]); d.x = d[xKey]; d.y = d[yKey]; return [...acc, d]; }, []); }
javascript
function cleanData(originalData) { return originalData.reduce((acc, d) => { d.name = String(d[nameKey]); d.x = d[xKey]; d.y = d[yKey]; return [...acc, d]; }, []); }
[ "function", "cleanData", "(", "originalData", ")", "{", "return", "originalData", ".", "reduce", "(", "(", "acc", ",", "d", ")", "=>", "{", "d", ".", "name", "=", "String", "(", "d", "[", "nameKey", "]", ")", ";", "d", ".", "x", "=", "d", "[", "xKey", "]", ";", "d", ".", "y", "=", "d", "[", "yKey", "]", ";", "return", "[", "...", "acc", ",", "d", "]", ";", "}", ",", "[", "]", ")", ";", "}" ]
Cleaning data casting the values and names to the proper type while keeping the rest of properties on the data @param {ScatterPlotData} originalData Raw data as passed to the container @return {ScatterPlotData} Clean data @private
[ "Cleaning", "data", "casting", "the", "values", "and", "names", "to", "the", "proper", "type", "while", "keeping", "the", "rest", "of", "properties", "on", "the", "data" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L372-L380
8,455
eventbrite/britecharts
src/charts/scatter-plot.js
drawAxisLabels
function drawAxisLabels() { // If y-axis label is given, draw it if (yAxisLabel) { if (yAxisLabelEl) { svg.selectAll('.y-axis-label-text').remove(); } yAxisLabelEl = svg.select('.axis-labels-group') .append('g') .attr('class', 'y-axis-label') .append('text') .classed('y-axis-label-text', true) .attr('x', -chartHeight / 2) .attr('y', yAxisLabelOffset - xAxisPadding.left) .attr('text-anchor', 'middle') .attr('transform', 'rotate(270 0 0)') .text(yAxisLabel) } // If x-axis label is given, draw it if (xAxisLabel) { if (xAxisLabelEl) { svg.selectAll('.x-axis-label-text').remove(); } xAxisLabelEl = svg.selectAll('.axis-labels-group') .append('g') .attr('class', 'x-axis-label') .append('text') .classed('x-axis-label-text', true) .attr('x', chartWidth / 2) .attr('y', chartHeight - xAxisLabelOffset) .attr('text-anchor', 'middle') .text(xAxisLabel); } }
javascript
function drawAxisLabels() { // If y-axis label is given, draw it if (yAxisLabel) { if (yAxisLabelEl) { svg.selectAll('.y-axis-label-text').remove(); } yAxisLabelEl = svg.select('.axis-labels-group') .append('g') .attr('class', 'y-axis-label') .append('text') .classed('y-axis-label-text', true) .attr('x', -chartHeight / 2) .attr('y', yAxisLabelOffset - xAxisPadding.left) .attr('text-anchor', 'middle') .attr('transform', 'rotate(270 0 0)') .text(yAxisLabel) } // If x-axis label is given, draw it if (xAxisLabel) { if (xAxisLabelEl) { svg.selectAll('.x-axis-label-text').remove(); } xAxisLabelEl = svg.selectAll('.axis-labels-group') .append('g') .attr('class', 'x-axis-label') .append('text') .classed('x-axis-label-text', true) .attr('x', chartWidth / 2) .attr('y', chartHeight - xAxisLabelOffset) .attr('text-anchor', 'middle') .text(xAxisLabel); } }
[ "function", "drawAxisLabels", "(", ")", "{", "// If y-axis label is given, draw it", "if", "(", "yAxisLabel", ")", "{", "if", "(", "yAxisLabelEl", ")", "{", "svg", ".", "selectAll", "(", "'.y-axis-label-text'", ")", ".", "remove", "(", ")", ";", "}", "yAxisLabelEl", "=", "svg", ".", "select", "(", "'.axis-labels-group'", ")", ".", "append", "(", "'g'", ")", ".", "attr", "(", "'class'", ",", "'y-axis-label'", ")", ".", "append", "(", "'text'", ")", ".", "classed", "(", "'y-axis-label-text'", ",", "true", ")", ".", "attr", "(", "'x'", ",", "-", "chartHeight", "/", "2", ")", ".", "attr", "(", "'y'", ",", "yAxisLabelOffset", "-", "xAxisPadding", ".", "left", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ".", "attr", "(", "'transform'", ",", "'rotate(270 0 0)'", ")", ".", "text", "(", "yAxisLabel", ")", "}", "// If x-axis label is given, draw it", "if", "(", "xAxisLabel", ")", "{", "if", "(", "xAxisLabelEl", ")", "{", "svg", ".", "selectAll", "(", "'.x-axis-label-text'", ")", ".", "remove", "(", ")", ";", "}", "xAxisLabelEl", "=", "svg", ".", "selectAll", "(", "'.axis-labels-group'", ")", ".", "append", "(", "'g'", ")", ".", "attr", "(", "'class'", ",", "'x-axis-label'", ")", ".", "append", "(", "'text'", ")", ".", "classed", "(", "'x-axis-label-text'", ",", "true", ")", ".", "attr", "(", "'x'", ",", "chartWidth", "/", "2", ")", ".", "attr", "(", "'y'", ",", "chartHeight", "-", "xAxisLabelOffset", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ".", "text", "(", "xAxisLabel", ")", ";", "}", "}" ]
Draws axis labels next to x and y axis to represent data value labels on the chart @return {void} @private
[ "Draws", "axis", "labels", "next", "to", "x", "and", "y", "axis", "to", "represent", "data", "value", "labels", "on", "the", "chart" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L405-L440
8,456
eventbrite/britecharts
src/charts/scatter-plot.js
drawTrendline
function drawTrendline(linearData) { if (trendLinePath) { trendLinePath.remove(); } const params = [ {x: linearData.x1, y: linearData.y1}, {x: linearData.x2, y: linearData.y2} ]; let line = d3Shape.line() .curve(trendLineCurve) .x(({x}) => xScale(x)) .y(({y}) => yScale(y)); trendLinePath = svg.selectAll('.chart-group') .append('path') .attr('class', 'scatter-trendline') .attr('d', line(params)) .attr('stroke', colorSchema[0]) .attr('stroke-width', trendLineStrokWidth) .attr('fill', 'none'); const totalLength = trendLinePath.node().getTotalLength(); trendLinePath .attr('stroke-dasharray', `${totalLength} ${totalLength}`) .attr('stroke-dashoffset', totalLength) .transition() .delay(trendLineDelay) .duration(trendLineDuration) .ease(ease) .attr('stroke-dashoffset', 0); }
javascript
function drawTrendline(linearData) { if (trendLinePath) { trendLinePath.remove(); } const params = [ {x: linearData.x1, y: linearData.y1}, {x: linearData.x2, y: linearData.y2} ]; let line = d3Shape.line() .curve(trendLineCurve) .x(({x}) => xScale(x)) .y(({y}) => yScale(y)); trendLinePath = svg.selectAll('.chart-group') .append('path') .attr('class', 'scatter-trendline') .attr('d', line(params)) .attr('stroke', colorSchema[0]) .attr('stroke-width', trendLineStrokWidth) .attr('fill', 'none'); const totalLength = trendLinePath.node().getTotalLength(); trendLinePath .attr('stroke-dasharray', `${totalLength} ${totalLength}`) .attr('stroke-dashoffset', totalLength) .transition() .delay(trendLineDelay) .duration(trendLineDuration) .ease(ease) .attr('stroke-dashoffset', 0); }
[ "function", "drawTrendline", "(", "linearData", ")", "{", "if", "(", "trendLinePath", ")", "{", "trendLinePath", ".", "remove", "(", ")", ";", "}", "const", "params", "=", "[", "{", "x", ":", "linearData", ".", "x1", ",", "y", ":", "linearData", ".", "y1", "}", ",", "{", "x", ":", "linearData", ".", "x2", ",", "y", ":", "linearData", ".", "y2", "}", "]", ";", "let", "line", "=", "d3Shape", ".", "line", "(", ")", ".", "curve", "(", "trendLineCurve", ")", ".", "x", "(", "(", "{", "x", "}", ")", "=>", "xScale", "(", "x", ")", ")", ".", "y", "(", "(", "{", "y", "}", ")", "=>", "yScale", "(", "y", ")", ")", ";", "trendLinePath", "=", "svg", ".", "selectAll", "(", "'.chart-group'", ")", ".", "append", "(", "'path'", ")", ".", "attr", "(", "'class'", ",", "'scatter-trendline'", ")", ".", "attr", "(", "'d'", ",", "line", "(", "params", ")", ")", ".", "attr", "(", "'stroke'", ",", "colorSchema", "[", "0", "]", ")", ".", "attr", "(", "'stroke-width'", ",", "trendLineStrokWidth", ")", ".", "attr", "(", "'fill'", ",", "'none'", ")", ";", "const", "totalLength", "=", "trendLinePath", ".", "node", "(", ")", ".", "getTotalLength", "(", ")", ";", "trendLinePath", ".", "attr", "(", "'stroke-dasharray'", ",", "`", "${", "totalLength", "}", "${", "totalLength", "}", "`", ")", ".", "attr", "(", "'stroke-dashoffset'", ",", "totalLength", ")", ".", "transition", "(", ")", ".", "delay", "(", "trendLineDelay", ")", ".", "duration", "(", "trendLineDuration", ")", ".", "ease", "(", "ease", ")", ".", "attr", "(", "'stroke-dashoffset'", ",", "0", ")", ";", "}" ]
Draws a trend line given the data that contains and y params from calculated y-intercept and slope using linear regression formula. @param {Object} linearData @returns {void} @private
[ "Draws", "a", "trend", "line", "given", "the", "data", "that", "contains", "and", "y", "params", "from", "calculated", "y", "-", "intercept", "and", "slope", "using", "linear", "regression", "formula", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L468-L501
8,457
eventbrite/britecharts
src/charts/scatter-plot.js
drawVerticalGridLines
function drawVerticalGridLines() { maskGridLines = svg.select('.grid-lines-group') .selectAll('line.vertical-grid-line') .data(xScale.ticks(xTicks)) .enter() .append('line') .attr('class', 'vertical-grid-line') .attr('y1', (xAxisPadding.left)) .attr('y2', chartHeight) .attr('x1', (d) => xScale(d)) .attr('x2', (d) => xScale(d)); }
javascript
function drawVerticalGridLines() { maskGridLines = svg.select('.grid-lines-group') .selectAll('line.vertical-grid-line') .data(xScale.ticks(xTicks)) .enter() .append('line') .attr('class', 'vertical-grid-line') .attr('y1', (xAxisPadding.left)) .attr('y2', chartHeight) .attr('x1', (d) => xScale(d)) .attr('x2', (d) => xScale(d)); }
[ "function", "drawVerticalGridLines", "(", ")", "{", "maskGridLines", "=", "svg", ".", "select", "(", "'.grid-lines-group'", ")", ".", "selectAll", "(", "'line.vertical-grid-line'", ")", ".", "data", "(", "xScale", ".", "ticks", "(", "xTicks", ")", ")", ".", "enter", "(", ")", ".", "append", "(", "'line'", ")", ".", "attr", "(", "'class'", ",", "'vertical-grid-line'", ")", ".", "attr", "(", "'y1'", ",", "(", "xAxisPadding", ".", "left", ")", ")", ".", "attr", "(", "'y2'", ",", "chartHeight", ")", ".", "attr", "(", "'x1'", ",", "(", "d", ")", "=>", "xScale", "(", "d", ")", ")", ".", "attr", "(", "'x2'", ",", "(", "d", ")", "=>", "xScale", "(", "d", ")", ")", ";", "}" ]
Draws vertical gridlines of the chart These gridlines are parallel to y-axis @return {void} @private
[ "Draws", "vertical", "gridlines", "of", "the", "chart", "These", "gridlines", "are", "parallel", "to", "y", "-", "axis" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L509-L520
8,458
eventbrite/britecharts
src/charts/scatter-plot.js
drawDataPoints
function drawDataPoints() { let circles = svg.select('.chart-group') .attr('clip-path', `url(#${maskingRectangleId})`) .selectAll('circle') .data(dataPoints) .enter(); if (isAnimated) { circles .append('circle') .attr('class', 'data-point data-point-highlighter') .transition() .delay(delay) .duration(duration) .ease(ease) .style('stroke', (d) => nameColorMap[d.name]) .attr('fill', (d) => ( hasHollowCircles ? hollowColor : nameColorMap[d.name] )) .attr('fill-opacity', circleOpacity) .attr('r', (d) => areaScale(d.y)) .attr('cx', (d) => xScale(d.x)) .attr('cy', (d) => yScale(d.y)) .style('cursor', 'pointer'); } else { circles .append('circle') .attr('class', 'point') .attr('class', 'data-point-highlighter') .style('stroke', (d) => nameColorMap[d.name]) .attr('fill', (d) => ( hasHollowCircles ? hollowColor : nameColorMap[d.name] )) .attr('fill-opacity', circleOpacity) .attr('r', (d) => areaScale(d.y)) .attr('cx', (d) => xScale(d.x)) .attr('cy', (d) => yScale(d.y)) .style('cursor', 'pointer'); } }
javascript
function drawDataPoints() { let circles = svg.select('.chart-group') .attr('clip-path', `url(#${maskingRectangleId})`) .selectAll('circle') .data(dataPoints) .enter(); if (isAnimated) { circles .append('circle') .attr('class', 'data-point data-point-highlighter') .transition() .delay(delay) .duration(duration) .ease(ease) .style('stroke', (d) => nameColorMap[d.name]) .attr('fill', (d) => ( hasHollowCircles ? hollowColor : nameColorMap[d.name] )) .attr('fill-opacity', circleOpacity) .attr('r', (d) => areaScale(d.y)) .attr('cx', (d) => xScale(d.x)) .attr('cy', (d) => yScale(d.y)) .style('cursor', 'pointer'); } else { circles .append('circle') .attr('class', 'point') .attr('class', 'data-point-highlighter') .style('stroke', (d) => nameColorMap[d.name]) .attr('fill', (d) => ( hasHollowCircles ? hollowColor : nameColorMap[d.name] )) .attr('fill-opacity', circleOpacity) .attr('r', (d) => areaScale(d.y)) .attr('cx', (d) => xScale(d.x)) .attr('cy', (d) => yScale(d.y)) .style('cursor', 'pointer'); } }
[ "function", "drawDataPoints", "(", ")", "{", "let", "circles", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "attr", "(", "'clip-path'", ",", "`", "${", "maskingRectangleId", "}", "`", ")", ".", "selectAll", "(", "'circle'", ")", ".", "data", "(", "dataPoints", ")", ".", "enter", "(", ")", ";", "if", "(", "isAnimated", ")", "{", "circles", ".", "append", "(", "'circle'", ")", ".", "attr", "(", "'class'", ",", "'data-point data-point-highlighter'", ")", ".", "transition", "(", ")", ".", "delay", "(", "delay", ")", ".", "duration", "(", "duration", ")", ".", "ease", "(", "ease", ")", ".", "style", "(", "'stroke'", ",", "(", "d", ")", "=>", "nameColorMap", "[", "d", ".", "name", "]", ")", ".", "attr", "(", "'fill'", ",", "(", "d", ")", "=>", "(", "hasHollowCircles", "?", "hollowColor", ":", "nameColorMap", "[", "d", ".", "name", "]", ")", ")", ".", "attr", "(", "'fill-opacity'", ",", "circleOpacity", ")", ".", "attr", "(", "'r'", ",", "(", "d", ")", "=>", "areaScale", "(", "d", ".", "y", ")", ")", ".", "attr", "(", "'cx'", ",", "(", "d", ")", "=>", "xScale", "(", "d", ".", "x", ")", ")", ".", "attr", "(", "'cy'", ",", "(", "d", ")", "=>", "yScale", "(", "d", ".", "y", ")", ")", ".", "style", "(", "'cursor'", ",", "'pointer'", ")", ";", "}", "else", "{", "circles", ".", "append", "(", "'circle'", ")", ".", "attr", "(", "'class'", ",", "'point'", ")", ".", "attr", "(", "'class'", ",", "'data-point-highlighter'", ")", ".", "style", "(", "'stroke'", ",", "(", "d", ")", "=>", "nameColorMap", "[", "d", ".", "name", "]", ")", ".", "attr", "(", "'fill'", ",", "(", "d", ")", "=>", "(", "hasHollowCircles", "?", "hollowColor", ":", "nameColorMap", "[", "d", ".", "name", "]", ")", ")", ".", "attr", "(", "'fill-opacity'", ",", "circleOpacity", ")", ".", "attr", "(", "'r'", ",", "(", "d", ")", "=>", "areaScale", "(", "d", ".", "y", ")", ")", ".", "attr", "(", "'cx'", ",", "(", "d", ")", "=>", "xScale", "(", "d", ".", "x", ")", ")", ".", "attr", "(", "'cy'", ",", "(", "d", ")", "=>", "yScale", "(", "d", ".", "y", ")", ")", ".", "style", "(", "'cursor'", ",", "'pointer'", ")", ";", "}", "}" ]
Draws the points for each data element on the chart group @return {void} @private
[ "Draws", "the", "points", "for", "each", "data", "element", "on", "the", "chart", "group" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L527-L566
8,459
eventbrite/britecharts
src/charts/scatter-plot.js
drawDataPointsValueHighlights
function drawDataPointsValueHighlights(data) { showCrossHairComponentsWithLabels(true); // Draw line perpendicular to y-axis highlightCrossHairContainer.selectAll('line.highlight-y-line') .attr('stroke', nameColorMap[data.name]) .attr('class', 'highlight-y-line') .attr('x1', (xScale(data.x) - areaScale(data.y))) .attr('x2', 0) .attr('y1', yScale(data.y)) .attr('y2', yScale(data.y)); // Draw line perpendicular to x-axis highlightCrossHairContainer.selectAll('line.highlight-x-line') .attr('stroke', nameColorMap[data.name]) .attr('class', 'highlight-x-line') .attr('x1', xScale(data.x)) .attr('x2', xScale(data.x)) .attr('y1', (yScale(data.y) + areaScale(data.y))) .attr('y2', chartHeight); // Draw data label for y value highlightCrossHairLabelsContainer.selectAll('text.highlight-y-legend') .attr('text-anchor', 'middle') .attr('fill', nameColorMap[data.name]) .attr('class', 'highlight-y-legend') .attr('y', (yScale(data.y) + (areaScale(data.y) / 2))) .attr('x', highlightTextLegendOffset) .text(`${d3Format.format(yAxisFormat)(data.y)}`); // Draw data label for x value highlightCrossHairLabelsContainer.selectAll('text.highlight-x-legend') .attr('text-anchor', 'middle') .attr('fill', nameColorMap[data.name]) .attr('class', 'highlight-x-legend') .attr('transform', `translate(0, ${chartHeight - highlightTextLegendOffset})`) .attr('x', (xScale(data.x) - (areaScale(data.y) / 2))) .text(`${d3Format.format(xAxisFormat)(data.x)}`); }
javascript
function drawDataPointsValueHighlights(data) { showCrossHairComponentsWithLabels(true); // Draw line perpendicular to y-axis highlightCrossHairContainer.selectAll('line.highlight-y-line') .attr('stroke', nameColorMap[data.name]) .attr('class', 'highlight-y-line') .attr('x1', (xScale(data.x) - areaScale(data.y))) .attr('x2', 0) .attr('y1', yScale(data.y)) .attr('y2', yScale(data.y)); // Draw line perpendicular to x-axis highlightCrossHairContainer.selectAll('line.highlight-x-line') .attr('stroke', nameColorMap[data.name]) .attr('class', 'highlight-x-line') .attr('x1', xScale(data.x)) .attr('x2', xScale(data.x)) .attr('y1', (yScale(data.y) + areaScale(data.y))) .attr('y2', chartHeight); // Draw data label for y value highlightCrossHairLabelsContainer.selectAll('text.highlight-y-legend') .attr('text-anchor', 'middle') .attr('fill', nameColorMap[data.name]) .attr('class', 'highlight-y-legend') .attr('y', (yScale(data.y) + (areaScale(data.y) / 2))) .attr('x', highlightTextLegendOffset) .text(`${d3Format.format(yAxisFormat)(data.y)}`); // Draw data label for x value highlightCrossHairLabelsContainer.selectAll('text.highlight-x-legend') .attr('text-anchor', 'middle') .attr('fill', nameColorMap[data.name]) .attr('class', 'highlight-x-legend') .attr('transform', `translate(0, ${chartHeight - highlightTextLegendOffset})`) .attr('x', (xScale(data.x) - (areaScale(data.y) / 2))) .text(`${d3Format.format(xAxisFormat)(data.x)}`); }
[ "function", "drawDataPointsValueHighlights", "(", "data", ")", "{", "showCrossHairComponentsWithLabels", "(", "true", ")", ";", "// Draw line perpendicular to y-axis", "highlightCrossHairContainer", ".", "selectAll", "(", "'line.highlight-y-line'", ")", ".", "attr", "(", "'stroke'", ",", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'class'", ",", "'highlight-y-line'", ")", ".", "attr", "(", "'x1'", ",", "(", "xScale", "(", "data", ".", "x", ")", "-", "areaScale", "(", "data", ".", "y", ")", ")", ")", ".", "attr", "(", "'x2'", ",", "0", ")", ".", "attr", "(", "'y1'", ",", "yScale", "(", "data", ".", "y", ")", ")", ".", "attr", "(", "'y2'", ",", "yScale", "(", "data", ".", "y", ")", ")", ";", "// Draw line perpendicular to x-axis", "highlightCrossHairContainer", ".", "selectAll", "(", "'line.highlight-x-line'", ")", ".", "attr", "(", "'stroke'", ",", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'class'", ",", "'highlight-x-line'", ")", ".", "attr", "(", "'x1'", ",", "xScale", "(", "data", ".", "x", ")", ")", ".", "attr", "(", "'x2'", ",", "xScale", "(", "data", ".", "x", ")", ")", ".", "attr", "(", "'y1'", ",", "(", "yScale", "(", "data", ".", "y", ")", "+", "areaScale", "(", "data", ".", "y", ")", ")", ")", ".", "attr", "(", "'y2'", ",", "chartHeight", ")", ";", "// Draw data label for y value", "highlightCrossHairLabelsContainer", ".", "selectAll", "(", "'text.highlight-y-legend'", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ".", "attr", "(", "'fill'", ",", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'class'", ",", "'highlight-y-legend'", ")", ".", "attr", "(", "'y'", ",", "(", "yScale", "(", "data", ".", "y", ")", "+", "(", "areaScale", "(", "data", ".", "y", ")", "/", "2", ")", ")", ")", ".", "attr", "(", "'x'", ",", "highlightTextLegendOffset", ")", ".", "text", "(", "`", "${", "d3Format", ".", "format", "(", "yAxisFormat", ")", "(", "data", ".", "y", ")", "}", "`", ")", ";", "// Draw data label for x value", "highlightCrossHairLabelsContainer", ".", "selectAll", "(", "'text.highlight-x-legend'", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ".", "attr", "(", "'fill'", ",", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'class'", ",", "'highlight-x-legend'", ")", ".", "attr", "(", "'transform'", ",", "`", "${", "chartHeight", "-", "highlightTextLegendOffset", "}", "`", ")", ".", "attr", "(", "'x'", ",", "(", "xScale", "(", "data", ".", "x", ")", "-", "(", "areaScale", "(", "data", ".", "y", ")", "/", "2", ")", ")", ")", ".", "text", "(", "`", "${", "d3Format", ".", "format", "(", "xAxisFormat", ")", "(", "data", ".", "x", ")", "}", "`", ")", ";", "}" ]
Draws the crosshair lines and label components given the coordinates and name of the data point @param {Object} dataPoint @return {void} @private
[ "Draws", "the", "crosshair", "lines", "and", "label", "components", "given", "the", "coordinates", "and", "name", "of", "the", "data", "point" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L575-L614
8,460
eventbrite/britecharts
src/charts/scatter-plot.js
drawHorizontalGridLines
function drawHorizontalGridLines() { maskGridLines = svg.select('.grid-lines-group') .selectAll('line.horizontal-grid-line') .data(yScale.ticks(yTicks)) .enter() .append('line') .attr('class', 'horizontal-grid-line') .attr('x1', xAxisPadding.left) .attr('x2', chartWidth) .attr('y1', (d) => yScale(d)) .attr('y2', (d) => yScale(d)); }
javascript
function drawHorizontalGridLines() { maskGridLines = svg.select('.grid-lines-group') .selectAll('line.horizontal-grid-line') .data(yScale.ticks(yTicks)) .enter() .append('line') .attr('class', 'horizontal-grid-line') .attr('x1', xAxisPadding.left) .attr('x2', chartWidth) .attr('y1', (d) => yScale(d)) .attr('y2', (d) => yScale(d)); }
[ "function", "drawHorizontalGridLines", "(", ")", "{", "maskGridLines", "=", "svg", ".", "select", "(", "'.grid-lines-group'", ")", ".", "selectAll", "(", "'line.horizontal-grid-line'", ")", ".", "data", "(", "yScale", ".", "ticks", "(", "yTicks", ")", ")", ".", "enter", "(", ")", ".", "append", "(", "'line'", ")", ".", "attr", "(", "'class'", ",", "'horizontal-grid-line'", ")", ".", "attr", "(", "'x1'", ",", "xAxisPadding", ".", "left", ")", ".", "attr", "(", "'x2'", ",", "chartWidth", ")", ".", "attr", "(", "'y1'", ",", "(", "d", ")", "=>", "yScale", "(", "d", ")", ")", ".", "attr", "(", "'y2'", ",", "(", "d", ")", "=>", "yScale", "(", "d", ")", ")", ";", "}" ]
Draw horizontal gridles of the chart These gridlines are parallel to x-axis @return {void} @private
[ "Draw", "horizontal", "gridles", "of", "the", "chart", "These", "gridlines", "are", "parallel", "to", "x", "-", "axis" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L661-L672
8,461
eventbrite/britecharts
src/charts/scatter-plot.js
calcLinearRegression
function calcLinearRegression() { let n = dataPoints.length, x = 0, y = 0, xy = 0, x2 = 0, y2 = 0; dataPoints.forEach(d => { x += d.x; y += d.y; xy += d.x * d.y; x2 += d.x * d.x; y2 += d.y * d.y; }); const denominator = (n * x2) - (x * x); const intercept = ((y * x2) - (x * xy)) / denominator; const slope = ((n * xy) - (x * y)) / denominator; const minX = d3Array.min(dataPoints, ({ x }) => x); const maxX = d3Array.max(dataPoints, ({ x }) => x); return { x1: minX, y1: slope * n + intercept, x2: maxX, y2: slope * maxX + intercept } }
javascript
function calcLinearRegression() { let n = dataPoints.length, x = 0, y = 0, xy = 0, x2 = 0, y2 = 0; dataPoints.forEach(d => { x += d.x; y += d.y; xy += d.x * d.y; x2 += d.x * d.x; y2 += d.y * d.y; }); const denominator = (n * x2) - (x * x); const intercept = ((y * x2) - (x * xy)) / denominator; const slope = ((n * xy) - (x * y)) / denominator; const minX = d3Array.min(dataPoints, ({ x }) => x); const maxX = d3Array.max(dataPoints, ({ x }) => x); return { x1: minX, y1: slope * n + intercept, x2: maxX, y2: slope * maxX + intercept } }
[ "function", "calcLinearRegression", "(", ")", "{", "let", "n", "=", "dataPoints", ".", "length", ",", "x", "=", "0", ",", "y", "=", "0", ",", "xy", "=", "0", ",", "x2", "=", "0", ",", "y2", "=", "0", ";", "dataPoints", ".", "forEach", "(", "d", "=>", "{", "x", "+=", "d", ".", "x", ";", "y", "+=", "d", ".", "y", ";", "xy", "+=", "d", ".", "x", "*", "d", ".", "y", ";", "x2", "+=", "d", ".", "x", "*", "d", ".", "x", ";", "y2", "+=", "d", ".", "y", "*", "d", ".", "y", ";", "}", ")", ";", "const", "denominator", "=", "(", "n", "*", "x2", ")", "-", "(", "x", "*", "x", ")", ";", "const", "intercept", "=", "(", "(", "y", "*", "x2", ")", "-", "(", "x", "*", "xy", ")", ")", "/", "denominator", ";", "const", "slope", "=", "(", "(", "n", "*", "xy", ")", "-", "(", "x", "*", "y", ")", ")", "/", "denominator", ";", "const", "minX", "=", "d3Array", ".", "min", "(", "dataPoints", ",", "(", "{", "x", "}", ")", "=>", "x", ")", ";", "const", "maxX", "=", "d3Array", ".", "max", "(", "dataPoints", ",", "(", "{", "x", "}", ")", "=>", "x", ")", ";", "return", "{", "x1", ":", "minX", ",", "y1", ":", "slope", "*", "n", "+", "intercept", ",", "x2", ":", "maxX", ",", "y2", ":", "slope", "*", "maxX", "+", "intercept", "}", "}" ]
Returns an object that contains necessary coordinates for drawing the trendline. The calculation of slope and y-intercept uses basic accumulative linear regression formula. @return {Object} @private
[ "Returns", "an", "object", "that", "contains", "necessary", "coordinates", "for", "drawing", "the", "trendline", ".", "The", "calculation", "of", "slope", "and", "y", "-", "intercept", "uses", "basic", "accumulative", "linear", "regression", "formula", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L682-L710
8,462
eventbrite/britecharts
src/charts/scatter-plot.js
getPointProps
function getPointProps(svg) { let mousePos = d3Selection.mouse(svg); mousePos[0] -= margin.left; mousePos[1] -= margin.top; return { closestPoint: voronoi.find(mousePos[0], mousePos[1]), mousePos }; }
javascript
function getPointProps(svg) { let mousePos = d3Selection.mouse(svg); mousePos[0] -= margin.left; mousePos[1] -= margin.top; return { closestPoint: voronoi.find(mousePos[0], mousePos[1]), mousePos }; }
[ "function", "getPointProps", "(", "svg", ")", "{", "let", "mousePos", "=", "d3Selection", ".", "mouse", "(", "svg", ")", ";", "mousePos", "[", "0", "]", "-=", "margin", ".", "left", ";", "mousePos", "[", "1", "]", "-=", "margin", ".", "top", ";", "return", "{", "closestPoint", ":", "voronoi", ".", "find", "(", "mousePos", "[", "0", "]", ",", "mousePos", "[", "1", "]", ")", ",", "mousePos", "}", ";", "}" ]
Calculates and returns @param {*} svg @return {Object} @private
[ "Calculates", "and", "returns" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L718-L728
8,463
eventbrite/britecharts
src/charts/scatter-plot.js
handleMouseMove
function handleMouseMove(e) { let { mousePos, closestPoint } = getPointProps(e); let pointData = getPointData(closestPoint); if (hasCrossHairs) { drawDataPointsValueHighlights(pointData); } highlightDataPoint(pointData); dispatcher.call('customMouseMove', e, pointData, d3Selection.mouse(e), [chartWidth, chartHeight]); }
javascript
function handleMouseMove(e) { let { mousePos, closestPoint } = getPointProps(e); let pointData = getPointData(closestPoint); if (hasCrossHairs) { drawDataPointsValueHighlights(pointData); } highlightDataPoint(pointData); dispatcher.call('customMouseMove', e, pointData, d3Selection.mouse(e), [chartWidth, chartHeight]); }
[ "function", "handleMouseMove", "(", "e", ")", "{", "let", "{", "mousePos", ",", "closestPoint", "}", "=", "getPointProps", "(", "e", ")", ";", "let", "pointData", "=", "getPointData", "(", "closestPoint", ")", ";", "if", "(", "hasCrossHairs", ")", "{", "drawDataPointsValueHighlights", "(", "pointData", ")", ";", "}", "highlightDataPoint", "(", "pointData", ")", ";", "dispatcher", ".", "call", "(", "'customMouseMove'", ",", "e", ",", "pointData", ",", "d3Selection", ".", "mouse", "(", "e", ")", ",", "[", "chartWidth", ",", "chartHeight", "]", ")", ";", "}" ]
Handler called on mousemove event @return {void} @private
[ "Handler", "called", "on", "mousemove", "event" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L735-L746
8,464
eventbrite/britecharts
src/charts/scatter-plot.js
handleMouseOver
function handleMouseOver (e, d) { dispatcher.call('customMouseOver', e, d, d3Selection.mouse(e)); }
javascript
function handleMouseOver (e, d) { dispatcher.call('customMouseOver', e, d, d3Selection.mouse(e)); }
[ "function", "handleMouseOver", "(", "e", ",", "d", ")", "{", "dispatcher", ".", "call", "(", "'customMouseOver'", ",", "e", ",", "d", ",", "d3Selection", ".", "mouse", "(", "e", ")", ")", ";", "}" ]
Handler called on mouseover event @return {void} @private
[ "Handler", "called", "on", "mouseover", "event" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L753-L755
8,465
eventbrite/britecharts
src/charts/scatter-plot.js
handleMouseOut
function handleMouseOut(e, d) { removePointHighlight(); if (hasCrossHairs) { showCrossHairComponentsWithLabels(false); } dispatcher.call('customMouseOut', e, d, d3Selection.mouse(e)); }
javascript
function handleMouseOut(e, d) { removePointHighlight(); if (hasCrossHairs) { showCrossHairComponentsWithLabels(false); } dispatcher.call('customMouseOut', e, d, d3Selection.mouse(e)); }
[ "function", "handleMouseOut", "(", "e", ",", "d", ")", "{", "removePointHighlight", "(", ")", ";", "if", "(", "hasCrossHairs", ")", "{", "showCrossHairComponentsWithLabels", "(", "false", ")", ";", "}", "dispatcher", ".", "call", "(", "'customMouseOut'", ",", "e", ",", "d", ",", "d3Selection", ".", "mouse", "(", "e", ")", ")", ";", "}" ]
Handler called on mouseout event @return {void} @private
[ "Handler", "called", "on", "mouseout", "event" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L762-L769
8,466
eventbrite/britecharts
src/charts/scatter-plot.js
handleClick
function handleClick(e) { let { closestPoint } = getPointProps(e); let d = getPointData(closestPoint); handleClickAnimation(d); dispatcher.call('customClick', e, d, d3Selection.mouse(e), [chartWidth, chartHeight]); }
javascript
function handleClick(e) { let { closestPoint } = getPointProps(e); let d = getPointData(closestPoint); handleClickAnimation(d); dispatcher.call('customClick', e, d, d3Selection.mouse(e), [chartWidth, chartHeight]); }
[ "function", "handleClick", "(", "e", ")", "{", "let", "{", "closestPoint", "}", "=", "getPointProps", "(", "e", ")", ";", "let", "d", "=", "getPointData", "(", "closestPoint", ")", ";", "handleClickAnimation", "(", "d", ")", ";", "dispatcher", ".", "call", "(", "'customClick'", ",", "e", ",", "d", ",", "d3Selection", ".", "mouse", "(", "e", ")", ",", "[", "chartWidth", ",", "chartHeight", "]", ")", ";", "}" ]
Custom onClick event handler @return {void} @private
[ "Custom", "onClick", "event", "handler" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L776-L783
8,467
eventbrite/britecharts
src/charts/scatter-plot.js
handleClickAnimation
function handleClickAnimation(dataPoint) { bounceCircleHighlight( highlightCircle, ease, areaScale(dataPoint.y), areaScale(dataPoint.y * 2) ); }
javascript
function handleClickAnimation(dataPoint) { bounceCircleHighlight( highlightCircle, ease, areaScale(dataPoint.y), areaScale(dataPoint.y * 2) ); }
[ "function", "handleClickAnimation", "(", "dataPoint", ")", "{", "bounceCircleHighlight", "(", "highlightCircle", ",", "ease", ",", "areaScale", "(", "dataPoint", ".", "y", ")", ",", "areaScale", "(", "dataPoint", ".", "y", "*", "2", ")", ")", ";", "}" ]
Applies animation on data point click @param {Object} dataPoint @return {void} @private
[ "Applies", "animation", "on", "data", "point", "click" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L791-L798
8,468
eventbrite/britecharts
src/charts/scatter-plot.js
highlightDataPoint
function highlightDataPoint(data) { removePointHighlight(); if (!highlightFilter) { highlightFilter = createFilterContainer(svg.select('.metadata-group')); highlightFilterId = createGlowWithMatrix(highlightFilter); } highlightCircle .attr('opacity', 1) .attr('stroke', () => nameColorMap[data.name]) .attr('fill', () => nameColorMap[data.name]) .attr('fill-opacity', circleOpacity) .attr('cx', () => xScale(data.x)) .attr('cy', () => yScale(data.y)) .attr('r', () => areaScale(data.y)) .style('stroke-width', highlightStrokeWidth) .style('stroke-opacity', highlightCircleOpacity); // apply glow container overlay highlightCircle .attr('filter', `url(#${highlightFilterId})`); }
javascript
function highlightDataPoint(data) { removePointHighlight(); if (!highlightFilter) { highlightFilter = createFilterContainer(svg.select('.metadata-group')); highlightFilterId = createGlowWithMatrix(highlightFilter); } highlightCircle .attr('opacity', 1) .attr('stroke', () => nameColorMap[data.name]) .attr('fill', () => nameColorMap[data.name]) .attr('fill-opacity', circleOpacity) .attr('cx', () => xScale(data.x)) .attr('cy', () => yScale(data.y)) .attr('r', () => areaScale(data.y)) .style('stroke-width', highlightStrokeWidth) .style('stroke-opacity', highlightCircleOpacity); // apply glow container overlay highlightCircle .attr('filter', `url(#${highlightFilterId})`); }
[ "function", "highlightDataPoint", "(", "data", ")", "{", "removePointHighlight", "(", ")", ";", "if", "(", "!", "highlightFilter", ")", "{", "highlightFilter", "=", "createFilterContainer", "(", "svg", ".", "select", "(", "'.metadata-group'", ")", ")", ";", "highlightFilterId", "=", "createGlowWithMatrix", "(", "highlightFilter", ")", ";", "}", "highlightCircle", ".", "attr", "(", "'opacity'", ",", "1", ")", ".", "attr", "(", "'stroke'", ",", "(", ")", "=>", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'fill'", ",", "(", ")", "=>", "nameColorMap", "[", "data", ".", "name", "]", ")", ".", "attr", "(", "'fill-opacity'", ",", "circleOpacity", ")", ".", "attr", "(", "'cx'", ",", "(", ")", "=>", "xScale", "(", "data", ".", "x", ")", ")", ".", "attr", "(", "'cy'", ",", "(", ")", "=>", "yScale", "(", "data", ".", "y", ")", ")", ".", "attr", "(", "'r'", ",", "(", ")", "=>", "areaScale", "(", "data", ".", "y", ")", ")", ".", "style", "(", "'stroke-width'", ",", "highlightStrokeWidth", ")", ".", "style", "(", "'stroke-opacity'", ",", "highlightCircleOpacity", ")", ";", "// apply glow container overlay", "highlightCircle", ".", "attr", "(", "'filter'", ",", "`", "${", "highlightFilterId", "}", "`", ")", ";", "}" ]
Applies glow to hovered data point @return {void} @private
[ "Applies", "glow", "to", "hovered", "data", "point" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L805-L827
8,469
eventbrite/britecharts
src/charts/scatter-plot.js
initHighlightComponents
function initHighlightComponents() { highlightCircle = svg.select('.metadata-group') .selectAll('circle.highlight-circle') .data([1]) .enter() .append('circle') .attr('class', 'highlight-circle') .attr('cursor', 'pointer'); if (hasCrossHairs) { // initialize cross hair lines container highlightCrossHairContainer = svg.select('.chart-group') .append('g') .attr('class', 'crosshair-lines-container'); // initialize corss hair labels container highlightCrossHairLabelsContainer = svg.select('.metadata-group') .append('g') .attr('class', 'crosshair-labels-container'); highlightCrossHairContainer.selectAll('line.highlight-y-line') .data([1]) .enter() .append('line') .attr('class', 'highlight-y-line'); highlightCrossHairContainer.selectAll('line.highlight-x-line') .data([1]) .enter() .append('line') .attr('class', 'highlight-x-line'); highlightCrossHairLabelsContainer.selectAll('text.highlight-y-legend') .data([1]) .enter() .append('text') .attr('class', 'highlight-y-legend'); highlightCrossHairLabelsContainer.selectAll('text.highlight-x-legend') .data([1]) .enter() .append('text') .attr('class', 'highlight-x-legend'); } }
javascript
function initHighlightComponents() { highlightCircle = svg.select('.metadata-group') .selectAll('circle.highlight-circle') .data([1]) .enter() .append('circle') .attr('class', 'highlight-circle') .attr('cursor', 'pointer'); if (hasCrossHairs) { // initialize cross hair lines container highlightCrossHairContainer = svg.select('.chart-group') .append('g') .attr('class', 'crosshair-lines-container'); // initialize corss hair labels container highlightCrossHairLabelsContainer = svg.select('.metadata-group') .append('g') .attr('class', 'crosshair-labels-container'); highlightCrossHairContainer.selectAll('line.highlight-y-line') .data([1]) .enter() .append('line') .attr('class', 'highlight-y-line'); highlightCrossHairContainer.selectAll('line.highlight-x-line') .data([1]) .enter() .append('line') .attr('class', 'highlight-x-line'); highlightCrossHairLabelsContainer.selectAll('text.highlight-y-legend') .data([1]) .enter() .append('text') .attr('class', 'highlight-y-legend'); highlightCrossHairLabelsContainer.selectAll('text.highlight-x-legend') .data([1]) .enter() .append('text') .attr('class', 'highlight-x-legend'); } }
[ "function", "initHighlightComponents", "(", ")", "{", "highlightCircle", "=", "svg", ".", "select", "(", "'.metadata-group'", ")", ".", "selectAll", "(", "'circle.highlight-circle'", ")", ".", "data", "(", "[", "1", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'circle'", ")", ".", "attr", "(", "'class'", ",", "'highlight-circle'", ")", ".", "attr", "(", "'cursor'", ",", "'pointer'", ")", ";", "if", "(", "hasCrossHairs", ")", "{", "// initialize cross hair lines container", "highlightCrossHairContainer", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "append", "(", "'g'", ")", ".", "attr", "(", "'class'", ",", "'crosshair-lines-container'", ")", ";", "// initialize corss hair labels container", "highlightCrossHairLabelsContainer", "=", "svg", ".", "select", "(", "'.metadata-group'", ")", ".", "append", "(", "'g'", ")", ".", "attr", "(", "'class'", ",", "'crosshair-labels-container'", ")", ";", "highlightCrossHairContainer", ".", "selectAll", "(", "'line.highlight-y-line'", ")", ".", "data", "(", "[", "1", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'line'", ")", ".", "attr", "(", "'class'", ",", "'highlight-y-line'", ")", ";", "highlightCrossHairContainer", ".", "selectAll", "(", "'line.highlight-x-line'", ")", ".", "data", "(", "[", "1", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'line'", ")", ".", "attr", "(", "'class'", ",", "'highlight-x-line'", ")", ";", "highlightCrossHairLabelsContainer", ".", "selectAll", "(", "'text.highlight-y-legend'", ")", ".", "data", "(", "[", "1", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'text'", ")", ".", "attr", "(", "'class'", ",", "'highlight-y-legend'", ")", ";", "highlightCrossHairLabelsContainer", ".", "selectAll", "(", "'text.highlight-x-legend'", ")", ".", "data", "(", "[", "1", "]", ")", ".", "enter", "(", ")", ".", "append", "(", "'text'", ")", ".", "attr", "(", "'class'", ",", "'highlight-x-legend'", ")", ";", "}", "}" ]
Places the highlighter point to the DOM to be used once one of the data points is highlighted @return {void} @private
[ "Places", "the", "highlighter", "point", "to", "the", "DOM", "to", "be", "used", "once", "one", "of", "the", "data", "points", "is", "highlighted" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L836-L880
8,470
eventbrite/britecharts
src/charts/scatter-plot.js
showCrossHairComponentsWithLabels
function showCrossHairComponentsWithLabels(status = false) { const opacityIndex = status ? 1 : 0; highlightCrossHairContainer.attr('opacity', opacityIndex); highlightCrossHairLabelsContainer.attr('opacity', opacityIndex); }
javascript
function showCrossHairComponentsWithLabels(status = false) { const opacityIndex = status ? 1 : 0; highlightCrossHairContainer.attr('opacity', opacityIndex); highlightCrossHairLabelsContainer.attr('opacity', opacityIndex); }
[ "function", "showCrossHairComponentsWithLabels", "(", "status", "=", "false", ")", "{", "const", "opacityIndex", "=", "status", "?", "1", ":", "0", ";", "highlightCrossHairContainer", ".", "attr", "(", "'opacity'", ",", "opacityIndex", ")", ";", "highlightCrossHairLabelsContainer", ".", "attr", "(", "'opacity'", ",", "opacityIndex", ")", ";", "}" ]
Sets the visibility of cross hair lines if 1, it sets lines to visible, if 0, it hides lines @param {boolean} @return {void} @private
[ "Sets", "the", "visibility", "of", "cross", "hair", "lines", "if", "1", "it", "sets", "lines", "to", "visible", "if", "0", "it", "hides", "lines" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/scatter-plot.js#L899-L904
8,471
eventbrite/britecharts
src/charts/helpers/export.js
exportChart
function exportChart(d3svg, filename, title) { if (isIE) { console.error(IE_ERROR_MSG); return false; } let img = createImage(convertSvgToHtml.call(this, d3svg, title)); img.onload = handleImageLoad.bind( img, createCanvas(this.width(), this.height()), filename ); }
javascript
function exportChart(d3svg, filename, title) { if (isIE) { console.error(IE_ERROR_MSG); return false; } let img = createImage(convertSvgToHtml.call(this, d3svg, title)); img.onload = handleImageLoad.bind( img, createCanvas(this.width(), this.height()), filename ); }
[ "function", "exportChart", "(", "d3svg", ",", "filename", ",", "title", ")", "{", "if", "(", "isIE", ")", "{", "console", ".", "error", "(", "IE_ERROR_MSG", ")", ";", "return", "false", ";", "}", "let", "img", "=", "createImage", "(", "convertSvgToHtml", ".", "call", "(", "this", ",", "d3svg", ",", "title", ")", ")", ";", "img", ".", "onload", "=", "handleImageLoad", ".", "bind", "(", "img", ",", "createCanvas", "(", "this", ".", "width", "(", ")", ",", "this", ".", "height", "(", ")", ")", ",", "filename", ")", ";", "}" ]
Main function to be used as a method by chart instances to export charts to png @param {array} svgs (or an svg element) pass in both chart & legend as array or just chart as svg or in array @param {string} filename [download to be called <filename>.png] @param {string} title Title for the image
[ "Main", "function", "to", "be", "used", "as", "a", "method", "by", "chart", "instances", "to", "export", "charts", "to", "png" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/helpers/export.js#L45-L59
8,472
eventbrite/britecharts
src/charts/helpers/export.js
convertSvgToHtml
function convertSvgToHtml (d3svg, title) { if (!d3svg) { return; } d3svg.attr('version', 1.1) .attr('xmlns', 'http://www.w3.org/2000/svg'); let serializer = serializeWithStyles.initializeSerializer(); let html = serializer(d3svg.node()); html = formatHtmlByBrowser(html); html = prependTitle.call(this, html, title, parseInt(d3svg.attr('width'), 10)); html = addBackground(html); return html; }
javascript
function convertSvgToHtml (d3svg, title) { if (!d3svg) { return; } d3svg.attr('version', 1.1) .attr('xmlns', 'http://www.w3.org/2000/svg'); let serializer = serializeWithStyles.initializeSerializer(); let html = serializer(d3svg.node()); html = formatHtmlByBrowser(html); html = prependTitle.call(this, html, title, parseInt(d3svg.attr('width'), 10)); html = addBackground(html); return html; }
[ "function", "convertSvgToHtml", "(", "d3svg", ",", "title", ")", "{", "if", "(", "!", "d3svg", ")", "{", "return", ";", "}", "d3svg", ".", "attr", "(", "'version'", ",", "1.1", ")", ".", "attr", "(", "'xmlns'", ",", "'http://www.w3.org/2000/svg'", ")", ";", "let", "serializer", "=", "serializeWithStyles", ".", "initializeSerializer", "(", ")", ";", "let", "html", "=", "serializer", "(", "d3svg", ".", "node", "(", ")", ")", ";", "html", "=", "formatHtmlByBrowser", "(", "html", ")", ";", "html", "=", "prependTitle", ".", "call", "(", "this", ",", "html", ",", "title", ",", "parseInt", "(", "d3svg", ".", "attr", "(", "'width'", ")", ",", "10", ")", ")", ";", "html", "=", "addBackground", "(", "html", ")", ";", "return", "html", ";", "}" ]
Takes the D3 SVG element, adds proper SVG tags, adds inline styles from stylesheets, adds white background and returns string @param {SVGElement} d3svg TYPE d3 svg element @return {String} String of passed d3
[ "Takes", "the", "D3", "SVG", "element", "adds", "proper", "SVG", "tags", "adds", "inline", "styles", "from", "stylesheets", "adds", "white", "background", "and", "returns", "string" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/helpers/export.js#L75-L90
8,473
eventbrite/britecharts
src/charts/helpers/export.js
handleImageLoad
function handleImageLoad(canvas, filename, e) { e.preventDefault(); downloadCanvas(drawImageOnCanvas(this, canvas), filename); }
javascript
function handleImageLoad(canvas, filename, e) { e.preventDefault(); downloadCanvas(drawImageOnCanvas(this, canvas), filename); }
[ "function", "handleImageLoad", "(", "canvas", ",", "filename", ",", "e", ")", "{", "e", ".", "preventDefault", "(", ")", ";", "downloadCanvas", "(", "drawImageOnCanvas", "(", "this", ",", "canvas", ")", ",", "filename", ")", ";", "}" ]
Handles on load event fired by img.onload, this=img @param {object} canvas TYPE: el <canvas> @param {string} filename @param {object} e
[ "Handles", "on", "load", "event", "fired", "by", "img", ".", "onload", "this", "=", "img" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/helpers/export.js#L169-L173
8,474
eventbrite/britecharts
src/charts/helpers/export.js
prependTitle
function prependTitle(html, title, svgWidth) { if (!title || !svgWidth) { return html; } let {grey} = colorSchemas; html = html.replace(/<g/,`<text x="${this.margin().left}" y="${config.titleTopOffset}" font-family="${config.titleFontFamily}" font-size="${config.titleFontSize}" fill="${grey[6]}"> ${title} </text><g `); return html; }
javascript
function prependTitle(html, title, svgWidth) { if (!title || !svgWidth) { return html; } let {grey} = colorSchemas; html = html.replace(/<g/,`<text x="${this.margin().left}" y="${config.titleTopOffset}" font-family="${config.titleFontFamily}" font-size="${config.titleFontSize}" fill="${grey[6]}"> ${title} </text><g `); return html; }
[ "function", "prependTitle", "(", "html", ",", "title", ",", "svgWidth", ")", "{", "if", "(", "!", "title", "||", "!", "svgWidth", ")", "{", "return", "html", ";", "}", "let", "{", "grey", "}", "=", "colorSchemas", ";", "html", "=", "html", ".", "replace", "(", "/", "<g", "/", ",", "`", "${", "this", ".", "margin", "(", ")", ".", "left", "}", "${", "config", ".", "titleTopOffset", "}", "${", "config", ".", "titleFontFamily", "}", "${", "config", ".", "titleFontSize", "}", "${", "grey", "[", "6", "]", "}", "${", "title", "}", "`", ")", ";", "return", "html", ";", "}" ]
if passed, append title to the raw html to appear on graph @param {string} html raw html string @param {string} title title of the graph @param {number} svgWidth width of graph container @return {string} raw html with title prepended
[ "if", "passed", "append", "title", "to", "the", "raw", "html", "to", "appear", "on", "graph" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/helpers/export.js#L182-L191
8,475
eventbrite/britecharts
src/charts/donut.js
buildContainerGroups
function buildContainerGroups() { let container = svg .append('g') .classed('container-group', true); container .append('g') .classed('chart-group', true); container .append('g') .classed('legend-group', true); }
javascript
function buildContainerGroups() { let container = svg .append('g') .classed('container-group', true); container .append('g') .classed('chart-group', true); container .append('g') .classed('legend-group', true); }
[ "function", "buildContainerGroups", "(", ")", "{", "let", "container", "=", "svg", ".", "append", "(", "'g'", ")", ".", "classed", "(", "'container-group'", ",", "true", ")", ";", "container", ".", "append", "(", "'g'", ")", ".", "classed", "(", "'chart-group'", ",", "true", ")", ";", "container", ".", "append", "(", "'g'", ")", ".", "classed", "(", "'legend-group'", ",", "true", ")", ";", "}" ]
Builds containers for the chart, the legend and a wrapper for all of them @private
[ "Builds", "containers", "for", "the", "chart", "the", "legend", "and", "a", "wrapper", "for", "all", "of", "them" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L183-L194
8,476
eventbrite/britecharts
src/charts/donut.js
buildLayout
function buildLayout() { layout = d3Shape.pie() .padAngle(paddingAngle) .value(getQuantity) .sort(orderingFunction); }
javascript
function buildLayout() { layout = d3Shape.pie() .padAngle(paddingAngle) .value(getQuantity) .sort(orderingFunction); }
[ "function", "buildLayout", "(", ")", "{", "layout", "=", "d3Shape", ".", "pie", "(", ")", ".", "padAngle", "(", "paddingAngle", ")", ".", "value", "(", "getQuantity", ")", ".", "sort", "(", "orderingFunction", ")", ";", "}" ]
Builds the pie layout that will produce data ready to draw @private
[ "Builds", "the", "pie", "layout", "that", "will", "produce", "data", "ready", "to", "draw" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L200-L205
8,477
eventbrite/britecharts
src/charts/donut.js
cleanData
function cleanData(data) { let dataWithPercentages; let cleanData = data.reduce((acc, d) => { // Skip data without quantity if (d[quantityLabel] === undefined || d[quantityLabel] === null) { return acc; } d.quantity = +d[quantityLabel]; d.name = String(d[nameLabel]); d.percentage = d[percentageLabel] || null; return [...acc, d]; }, []); let totalQuantity = sumValues(cleanData); if (totalQuantity === 0 && emptyDataConfig.showEmptySlice) { isEmpty = true; } dataWithPercentages = cleanData.map((d) => { d.percentage = String(d.percentage || calculatePercent(d[quantityLabel], totalQuantity, percentageFormat)); return d; }); return dataWithPercentages; }
javascript
function cleanData(data) { let dataWithPercentages; let cleanData = data.reduce((acc, d) => { // Skip data without quantity if (d[quantityLabel] === undefined || d[quantityLabel] === null) { return acc; } d.quantity = +d[quantityLabel]; d.name = String(d[nameLabel]); d.percentage = d[percentageLabel] || null; return [...acc, d]; }, []); let totalQuantity = sumValues(cleanData); if (totalQuantity === 0 && emptyDataConfig.showEmptySlice) { isEmpty = true; } dataWithPercentages = cleanData.map((d) => { d.percentage = String(d.percentage || calculatePercent(d[quantityLabel], totalQuantity, percentageFormat)); return d; }); return dataWithPercentages; }
[ "function", "cleanData", "(", "data", ")", "{", "let", "dataWithPercentages", ";", "let", "cleanData", "=", "data", ".", "reduce", "(", "(", "acc", ",", "d", ")", "=>", "{", "// Skip data without quantity", "if", "(", "d", "[", "quantityLabel", "]", "===", "undefined", "||", "d", "[", "quantityLabel", "]", "===", "null", ")", "{", "return", "acc", ";", "}", "d", ".", "quantity", "=", "+", "d", "[", "quantityLabel", "]", ";", "d", ".", "name", "=", "String", "(", "d", "[", "nameLabel", "]", ")", ";", "d", ".", "percentage", "=", "d", "[", "percentageLabel", "]", "||", "null", ";", "return", "[", "...", "acc", ",", "d", "]", ";", "}", ",", "[", "]", ")", ";", "let", "totalQuantity", "=", "sumValues", "(", "cleanData", ")", ";", "if", "(", "totalQuantity", "===", "0", "&&", "emptyDataConfig", ".", "showEmptySlice", ")", "{", "isEmpty", "=", "true", ";", "}", "dataWithPercentages", "=", "cleanData", ".", "map", "(", "(", "d", ")", "=>", "{", "d", ".", "percentage", "=", "String", "(", "d", ".", "percentage", "||", "calculatePercent", "(", "d", "[", "quantityLabel", "]", ",", "totalQuantity", ",", "percentageFormat", ")", ")", ";", "return", "d", ";", "}", ")", ";", "return", "dataWithPercentages", ";", "}" ]
Cleaning data casting the quantities, names and percentages to the proper type while keeping the rest of properties on the data. It also calculates the percentages if not present. @param {DonutChartData} data Data as passed to the container @return {DonutChartData} Clean data with percentages @private
[ "Cleaning", "data", "casting", "the", "quantities", "names", "and", "percentages", "to", "the", "proper", "type", "while", "keeping", "the", "rest", "of", "properties", "on", "the", "data", ".", "It", "also", "calculates", "the", "percentages", "if", "not", "present", "." ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L250-L279
8,478
eventbrite/britecharts
src/charts/donut.js
drawEmptySlice
function drawEmptySlice() { if (slices) { svg.selectAll('g.arc').remove(); } slices = svg.select('.chart-group') .selectAll('g.arc') .data(layout(emptyDonutData)); let newSlices = slices.enter() .append('g') .each(storeAngle) .each(reduceOuterRadius) .classed('arc', true) .append('path'); newSlices.merge(slices) .attr('fill', emptyDataConfig.emptySliceColor) .attr('d', shape) .transition() .ease(ease) .duration(pieDrawingTransitionDuration) .attrTween('d', tweenLoading); slices.exit().remove(); }
javascript
function drawEmptySlice() { if (slices) { svg.selectAll('g.arc').remove(); } slices = svg.select('.chart-group') .selectAll('g.arc') .data(layout(emptyDonutData)); let newSlices = slices.enter() .append('g') .each(storeAngle) .each(reduceOuterRadius) .classed('arc', true) .append('path'); newSlices.merge(slices) .attr('fill', emptyDataConfig.emptySliceColor) .attr('d', shape) .transition() .ease(ease) .duration(pieDrawingTransitionDuration) .attrTween('d', tweenLoading); slices.exit().remove(); }
[ "function", "drawEmptySlice", "(", ")", "{", "if", "(", "slices", ")", "{", "svg", ".", "selectAll", "(", "'g.arc'", ")", ".", "remove", "(", ")", ";", "}", "slices", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "selectAll", "(", "'g.arc'", ")", ".", "data", "(", "layout", "(", "emptyDonutData", ")", ")", ";", "let", "newSlices", "=", "slices", ".", "enter", "(", ")", ".", "append", "(", "'g'", ")", ".", "each", "(", "storeAngle", ")", ".", "each", "(", "reduceOuterRadius", ")", ".", "classed", "(", "'arc'", ",", "true", ")", ".", "append", "(", "'path'", ")", ";", "newSlices", ".", "merge", "(", "slices", ")", ".", "attr", "(", "'fill'", ",", "emptyDataConfig", ".", "emptySliceColor", ")", ".", "attr", "(", "'d'", ",", "shape", ")", ".", "transition", "(", ")", ".", "ease", "(", "ease", ")", ".", "duration", "(", "pieDrawingTransitionDuration", ")", ".", "attrTween", "(", "'d'", ",", "tweenLoading", ")", ";", "slices", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Draw an empty slice @private
[ "Draw", "an", "empty", "slice" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L293-L318
8,479
eventbrite/britecharts
src/charts/donut.js
drawLegend
function drawLegend(obj) { if (obj.data) { svg.select('.donut-text') .text(() => centeredTextFunction(obj.data)) .attr('dy', '.2em') .attr('text-anchor', 'middle'); svg.select('.donut-text').call(wrapText, legendWidth); } }
javascript
function drawLegend(obj) { if (obj.data) { svg.select('.donut-text') .text(() => centeredTextFunction(obj.data)) .attr('dy', '.2em') .attr('text-anchor', 'middle'); svg.select('.donut-text').call(wrapText, legendWidth); } }
[ "function", "drawLegend", "(", "obj", ")", "{", "if", "(", "obj", ".", "data", ")", "{", "svg", ".", "select", "(", "'.donut-text'", ")", ".", "text", "(", "(", ")", "=>", "centeredTextFunction", "(", "obj", ".", "data", ")", ")", ".", "attr", "(", "'dy'", ",", "'.2em'", ")", ".", "attr", "(", "'text-anchor'", ",", "'middle'", ")", ";", "svg", ".", "select", "(", "'.donut-text'", ")", ".", "call", "(", "wrapText", ",", "legendWidth", ")", ";", "}", "}" ]
Draws the values on the donut slice inside the text element @param {Object} obj Data object @private
[ "Draws", "the", "values", "on", "the", "donut", "slice", "inside", "the", "text", "element" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L326-L336
8,480
eventbrite/britecharts
src/charts/donut.js
drawSlices
function drawSlices() { // Not ideal, we need to figure out how to call exit for nested elements if (slices) { svg.selectAll('g.arc').remove(); } slices = svg.select('.chart-group') .selectAll('g.arc') .data(layout(data)); let newSlices = slices.enter() .append('g') .each(storeAngle) .each(reduceOuterRadius) .classed('arc', true) .append('path'); if (isAnimated) { newSlices.merge(slices) .attr('fill', getSliceFill) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .on('click', function(d) { handleClick(this, d, chartWidth, chartHeight); }) .transition() .ease(ease) .duration(pieDrawingTransitionDuration) .attrTween('d', tweenLoading); } else { newSlices.merge(slices) .attr('fill', getSliceFill) .attr('d', shape) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .on('click', function(d) { handleClick(this, d, chartWidth, chartHeight); }); } slices.exit().remove(); }
javascript
function drawSlices() { // Not ideal, we need to figure out how to call exit for nested elements if (slices) { svg.selectAll('g.arc').remove(); } slices = svg.select('.chart-group') .selectAll('g.arc') .data(layout(data)); let newSlices = slices.enter() .append('g') .each(storeAngle) .each(reduceOuterRadius) .classed('arc', true) .append('path'); if (isAnimated) { newSlices.merge(slices) .attr('fill', getSliceFill) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .on('click', function(d) { handleClick(this, d, chartWidth, chartHeight); }) .transition() .ease(ease) .duration(pieDrawingTransitionDuration) .attrTween('d', tweenLoading); } else { newSlices.merge(slices) .attr('fill', getSliceFill) .attr('d', shape) .on('mouseover', function(d) { handleMouseOver(this, d, chartWidth, chartHeight); }) .on('mousemove', function(d) { handleMouseMove(this, d, chartWidth, chartHeight); }) .on('mouseout', function(d) { handleMouseOut(this, d, chartWidth, chartHeight); }) .on('click', function(d) { handleClick(this, d, chartWidth, chartHeight); }); } slices.exit().remove(); }
[ "function", "drawSlices", "(", ")", "{", "// Not ideal, we need to figure out how to call exit for nested elements", "if", "(", "slices", ")", "{", "svg", ".", "selectAll", "(", "'g.arc'", ")", ".", "remove", "(", ")", ";", "}", "slices", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "selectAll", "(", "'g.arc'", ")", ".", "data", "(", "layout", "(", "data", ")", ")", ";", "let", "newSlices", "=", "slices", ".", "enter", "(", ")", ".", "append", "(", "'g'", ")", ".", "each", "(", "storeAngle", ")", ".", "each", "(", "reduceOuterRadius", ")", ".", "classed", "(", "'arc'", ",", "true", ")", ".", "append", "(", "'path'", ")", ";", "if", "(", "isAnimated", ")", "{", "newSlices", ".", "merge", "(", "slices", ")", ".", "attr", "(", "'fill'", ",", "getSliceFill", ")", ".", "on", "(", "'mouseover'", ",", "function", "(", "d", ")", "{", "handleMouseOver", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mousemove'", ",", "function", "(", "d", ")", "{", "handleMouseMove", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mouseout'", ",", "function", "(", "d", ")", "{", "handleMouseOut", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'click'", ",", "function", "(", "d", ")", "{", "handleClick", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "transition", "(", ")", ".", "ease", "(", "ease", ")", ".", "duration", "(", "pieDrawingTransitionDuration", ")", ".", "attrTween", "(", "'d'", ",", "tweenLoading", ")", ";", "}", "else", "{", "newSlices", ".", "merge", "(", "slices", ")", ".", "attr", "(", "'fill'", ",", "getSliceFill", ")", ".", "attr", "(", "'d'", ",", "shape", ")", ".", "on", "(", "'mouseover'", ",", "function", "(", "d", ")", "{", "handleMouseOver", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mousemove'", ",", "function", "(", "d", ")", "{", "handleMouseMove", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'mouseout'", ",", "function", "(", "d", ")", "{", "handleMouseOut", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ".", "on", "(", "'click'", ",", "function", "(", "d", ")", "{", "handleClick", "(", "this", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", ";", "}", ")", ";", "}", "slices", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Draws the slices of the donut @private
[ "Draws", "the", "slices", "of", "the", "donut" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L342-L397
8,481
eventbrite/britecharts
src/charts/donut.js
handleMouseOver
function handleMouseOver(el, d, chartWidth, chartHeight) { drawLegend(d); dispatcher.call('customMouseOver', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); if (hasHoverAnimation) { // if the hovered slice is not the same as the last slice hovered // after mouseout event, then shrink the last slice that was highlighted if (lastHighlightedSlice && el !== lastHighlightedSlice) { tweenGrowth(lastHighlightedSlice, externalRadius - radiusHoverOffset, pieHoverTransitionDuration); } if (highlightedSlice && el !== highlightedSlice) { tweenGrowth(highlightedSlice, externalRadius - radiusHoverOffset); } tweenGrowth(el, externalRadius); } }
javascript
function handleMouseOver(el, d, chartWidth, chartHeight) { drawLegend(d); dispatcher.call('customMouseOver', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); if (hasHoverAnimation) { // if the hovered slice is not the same as the last slice hovered // after mouseout event, then shrink the last slice that was highlighted if (lastHighlightedSlice && el !== lastHighlightedSlice) { tweenGrowth(lastHighlightedSlice, externalRadius - radiusHoverOffset, pieHoverTransitionDuration); } if (highlightedSlice && el !== highlightedSlice) { tweenGrowth(highlightedSlice, externalRadius - radiusHoverOffset); } tweenGrowth(el, externalRadius); } }
[ "function", "handleMouseOver", "(", "el", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", "{", "drawLegend", "(", "d", ")", ";", "dispatcher", ".", "call", "(", "'customMouseOver'", ",", "el", ",", "d", ",", "d3Selection", ".", "mouse", "(", "el", ")", ",", "[", "chartWidth", ",", "chartHeight", "]", ")", ";", "if", "(", "hasHoverAnimation", ")", "{", "// if the hovered slice is not the same as the last slice hovered", "// after mouseout event, then shrink the last slice that was highlighted", "if", "(", "lastHighlightedSlice", "&&", "el", "!==", "lastHighlightedSlice", ")", "{", "tweenGrowth", "(", "lastHighlightedSlice", ",", "externalRadius", "-", "radiusHoverOffset", ",", "pieHoverTransitionDuration", ")", ";", "}", "if", "(", "highlightedSlice", "&&", "el", "!==", "highlightedSlice", ")", "{", "tweenGrowth", "(", "highlightedSlice", ",", "externalRadius", "-", "radiusHoverOffset", ")", ";", "}", "tweenGrowth", "(", "el", ",", "externalRadius", ")", ";", "}", "}" ]
Handles a path mouse over @return {void} @private
[ "Handles", "a", "path", "mouse", "over" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L416-L432
8,482
eventbrite/britecharts
src/charts/donut.js
handleMouseMove
function handleMouseMove(el, d, chartWidth, chartHeight) { dispatcher.call('customMouseMove', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); }
javascript
function handleMouseMove(el, d, chartWidth, chartHeight) { dispatcher.call('customMouseMove', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); }
[ "function", "handleMouseMove", "(", "el", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", "{", "dispatcher", ".", "call", "(", "'customMouseMove'", ",", "el", ",", "d", ",", "d3Selection", ".", "mouse", "(", "el", ")", ",", "[", "chartWidth", ",", "chartHeight", "]", ")", ";", "}" ]
Handles a path mouse move @return {void} @private
[ "Handles", "a", "path", "mouse", "move" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L439-L441
8,483
eventbrite/britecharts
src/charts/donut.js
handleMouseOut
function handleMouseOut(el, d, chartWidth, chartHeight) { cleanLegend(); // When there is a fixed highlighted slice, // we will always highlight it and render legend if (highlightedSlice && hasFixedHighlightedSlice && !hasLastHoverSliceHighlighted) { drawLegend(highlightedSlice.__data__); tweenGrowth(highlightedSlice, externalRadius); } // When the current slice is not the highlighted, or there isn't a fixed highlighted slice and it is the highlighted // we will shrink the slice if (el !== highlightedSlice || (!hasFixedHighlightedSlice && el === highlightedSlice) ) { tweenGrowth(el, externalRadius - radiusHoverOffset, pieHoverTransitionDuration); } if (hasLastHoverSliceHighlighted) { drawLegend(el.__data__); tweenGrowth(el, externalRadius); lastHighlightedSlice = el; } dispatcher.call('customMouseOut', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); }
javascript
function handleMouseOut(el, d, chartWidth, chartHeight) { cleanLegend(); // When there is a fixed highlighted slice, // we will always highlight it and render legend if (highlightedSlice && hasFixedHighlightedSlice && !hasLastHoverSliceHighlighted) { drawLegend(highlightedSlice.__data__); tweenGrowth(highlightedSlice, externalRadius); } // When the current slice is not the highlighted, or there isn't a fixed highlighted slice and it is the highlighted // we will shrink the slice if (el !== highlightedSlice || (!hasFixedHighlightedSlice && el === highlightedSlice) ) { tweenGrowth(el, externalRadius - radiusHoverOffset, pieHoverTransitionDuration); } if (hasLastHoverSliceHighlighted) { drawLegend(el.__data__); tweenGrowth(el, externalRadius); lastHighlightedSlice = el; } dispatcher.call('customMouseOut', el, d, d3Selection.mouse(el), [chartWidth, chartHeight]); }
[ "function", "handleMouseOut", "(", "el", ",", "d", ",", "chartWidth", ",", "chartHeight", ")", "{", "cleanLegend", "(", ")", ";", "// When there is a fixed highlighted slice,", "// we will always highlight it and render legend", "if", "(", "highlightedSlice", "&&", "hasFixedHighlightedSlice", "&&", "!", "hasLastHoverSliceHighlighted", ")", "{", "drawLegend", "(", "highlightedSlice", ".", "__data__", ")", ";", "tweenGrowth", "(", "highlightedSlice", ",", "externalRadius", ")", ";", "}", "// When the current slice is not the highlighted, or there isn't a fixed highlighted slice and it is the highlighted", "// we will shrink the slice", "if", "(", "el", "!==", "highlightedSlice", "||", "(", "!", "hasFixedHighlightedSlice", "&&", "el", "===", "highlightedSlice", ")", ")", "{", "tweenGrowth", "(", "el", ",", "externalRadius", "-", "radiusHoverOffset", ",", "pieHoverTransitionDuration", ")", ";", "}", "if", "(", "hasLastHoverSliceHighlighted", ")", "{", "drawLegend", "(", "el", ".", "__data__", ")", ";", "tweenGrowth", "(", "el", ",", "externalRadius", ")", ";", "lastHighlightedSlice", "=", "el", ";", "}", "dispatcher", ".", "call", "(", "'customMouseOut'", ",", "el", ",", "d", ",", "d3Selection", ".", "mouse", "(", "el", ")", ",", "[", "chartWidth", ",", "chartHeight", "]", ")", ";", "}" ]
Handles a path mouse out @return {void} @private
[ "Handles", "a", "path", "mouse", "out" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L448-L471
8,484
eventbrite/britecharts
src/charts/donut.js
initHighlightSlice
function initHighlightSlice() { highlightedSlice = svg.selectAll('.chart-group .arc path') .select(filterHighlightedSlice).node(); if (highlightedSlice) { drawLegend(highlightedSlice.__data__); tweenGrowth(highlightedSlice, externalRadius, pieDrawingTransitionDuration); } }
javascript
function initHighlightSlice() { highlightedSlice = svg.selectAll('.chart-group .arc path') .select(filterHighlightedSlice).node(); if (highlightedSlice) { drawLegend(highlightedSlice.__data__); tweenGrowth(highlightedSlice, externalRadius, pieDrawingTransitionDuration); } }
[ "function", "initHighlightSlice", "(", ")", "{", "highlightedSlice", "=", "svg", ".", "selectAll", "(", "'.chart-group .arc path'", ")", ".", "select", "(", "filterHighlightedSlice", ")", ".", "node", "(", ")", ";", "if", "(", "highlightedSlice", ")", "{", "drawLegend", "(", "highlightedSlice", ".", "__data__", ")", ";", "tweenGrowth", "(", "highlightedSlice", ",", "externalRadius", ",", "pieDrawingTransitionDuration", ")", ";", "}", "}" ]
Find the slice by id and growth it if needed @private
[ "Find", "the", "slice", "by", "id", "and", "growth", "it", "if", "needed" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L486-L494
8,485
eventbrite/britecharts
src/charts/donut.js
tweenGrowth
function tweenGrowth(slice, outerRadius, delay = 0) { d3Selection.select(slice) .transition() .delay(delay) .attrTween('d', function(d) { let i = d3Interpolate.interpolate(d.outerRadius, outerRadius); return (t) => { d.outerRadius = i(t); return shape(d); }; }); }
javascript
function tweenGrowth(slice, outerRadius, delay = 0) { d3Selection.select(slice) .transition() .delay(delay) .attrTween('d', function(d) { let i = d3Interpolate.interpolate(d.outerRadius, outerRadius); return (t) => { d.outerRadius = i(t); return shape(d); }; }); }
[ "function", "tweenGrowth", "(", "slice", ",", "outerRadius", ",", "delay", "=", "0", ")", "{", "d3Selection", ".", "select", "(", "slice", ")", ".", "transition", "(", ")", ".", "delay", "(", "delay", ")", ".", "attrTween", "(", "'d'", ",", "function", "(", "d", ")", "{", "let", "i", "=", "d3Interpolate", ".", "interpolate", "(", "d", ".", "outerRadius", ",", "outerRadius", ")", ";", "return", "(", "t", ")", "=>", "{", "d", ".", "outerRadius", "=", "i", "(", "t", ")", ";", "return", "shape", "(", "d", ")", ";", "}", ";", "}", ")", ";", "}" ]
Animate slice with tweens depending on the attributes given @param {DOMElement} slice Slice to growth @param {Number} outerRadius Final outer radius value @param {Number} delay Delay of animation @private
[ "Animate", "slice", "with", "tweens", "depending", "on", "the", "attributes", "given" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L531-L544
8,486
eventbrite/britecharts
src/charts/donut.js
wrapText
function wrapText(text, legendWidth) { let fontSize = externalRadius / 5; textHelper.wrapText.call(null, 0, fontSize, legendWidth, text.node()); }
javascript
function wrapText(text, legendWidth) { let fontSize = externalRadius / 5; textHelper.wrapText.call(null, 0, fontSize, legendWidth, text.node()); }
[ "function", "wrapText", "(", "text", ",", "legendWidth", ")", "{", "let", "fontSize", "=", "externalRadius", "/", "5", ";", "textHelper", ".", "wrapText", ".", "call", "(", "null", ",", "0", ",", "fontSize", ",", "legendWidth", ",", "text", ".", "node", "(", ")", ")", ";", "}" ]
Utility function that wraps a text into the given width @param {D3Selection} text Text to write @param {Number} legendWidth Width of the container @private
[ "Utility", "function", "that", "wraps", "a", "text", "into", "the", "given", "width" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/donut.js#L570-L574
8,487
eventbrite/britecharts
src/charts/tooltip.js
getValueText
function getValueText(data) { let value = data[valueLabel]; let valueText; if (data.missingValue) { valueText = '-'; } else { valueText = getFormattedValue(value).toString(); } return valueText; }
javascript
function getValueText(data) { let value = data[valueLabel]; let valueText; if (data.missingValue) { valueText = '-'; } else { valueText = getFormattedValue(value).toString(); } return valueText; }
[ "function", "getValueText", "(", "data", ")", "{", "let", "value", "=", "data", "[", "valueLabel", "]", ";", "let", "valueText", ";", "if", "(", "data", ".", "missingValue", ")", "{", "valueText", "=", "'-'", ";", "}", "else", "{", "valueText", "=", "getFormattedValue", "(", "value", ")", ".", "toString", "(", ")", ";", "}", "return", "valueText", ";", "}" ]
Extracts the value from the data object @param {Object} data Data value containing the info @return {String} Value to show
[ "Extracts", "the", "value", "from", "the", "data", "object" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L296-L307
8,488
eventbrite/britecharts
src/charts/tooltip.js
updateTitle
function updateTitle(dataPoint) { let tTitle = title; let formattedDate = formatDate(new Date(dataPoint[dateLabel])); if (tTitle.length) { if (shouldShowDateInTitle) { tTitle = `${tTitle} - ${formattedDate}`; } } else { tTitle = formattedDate; } tooltipTitle.text(tTitle); }
javascript
function updateTitle(dataPoint) { let tTitle = title; let formattedDate = formatDate(new Date(dataPoint[dateLabel])); if (tTitle.length) { if (shouldShowDateInTitle) { tTitle = `${tTitle} - ${formattedDate}`; } } else { tTitle = formattedDate; } tooltipTitle.text(tTitle); }
[ "function", "updateTitle", "(", "dataPoint", ")", "{", "let", "tTitle", "=", "title", ";", "let", "formattedDate", "=", "formatDate", "(", "new", "Date", "(", "dataPoint", "[", "dateLabel", "]", ")", ")", ";", "if", "(", "tTitle", ".", "length", ")", "{", "if", "(", "shouldShowDateInTitle", ")", "{", "tTitle", "=", "`", "${", "tTitle", "}", "${", "formattedDate", "}", "`", ";", "}", "}", "else", "{", "tTitle", "=", "formattedDate", ";", "}", "tooltipTitle", ".", "text", "(", "tTitle", ")", ";", "}" ]
Updates value of tooltipTitle with the data meaning and the date @param {Object} dataPoint Point of data to use as source @return void @private
[ "Updates", "value", "of", "tooltipTitle", "with", "the", "data", "meaning", "and", "the", "date" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L409-L422
8,489
eventbrite/britecharts
src/charts/tooltip.js
formatDate
function formatDate(date) { let settings = dateFormat || defaultAxisSettings; let format = null; let localeOptions = {month:'short', day:'numeric'}; if (settings === axisTimeCombinations.DAY_MONTH || settings === axisTimeCombinations.MONTH_YEAR) { format = monthDayYearFormat; localeOptions.year = 'numeric'; } else if (settings === axisTimeCombinations.HOUR_DAY || settings === axisTimeCombinations.MINUTE_HOUR) { format = monthDayHourFormat; localeOptions.hour = 'numeric'; } else if (settings === axisTimeCombinations.CUSTOM && typeof dateCustomFormat === 'string') { format = d3TimeFormat.timeFormat(dateCustomFormat); } if (locale && ((typeof Intl !== 'undefined') && (typeof Intl === 'object' && Intl.DateTimeFormat))) { let f = Intl.DateTimeFormat(locale, localeOptions); return f.format(date); } return format(date); }
javascript
function formatDate(date) { let settings = dateFormat || defaultAxisSettings; let format = null; let localeOptions = {month:'short', day:'numeric'}; if (settings === axisTimeCombinations.DAY_MONTH || settings === axisTimeCombinations.MONTH_YEAR) { format = monthDayYearFormat; localeOptions.year = 'numeric'; } else if (settings === axisTimeCombinations.HOUR_DAY || settings === axisTimeCombinations.MINUTE_HOUR) { format = monthDayHourFormat; localeOptions.hour = 'numeric'; } else if (settings === axisTimeCombinations.CUSTOM && typeof dateCustomFormat === 'string') { format = d3TimeFormat.timeFormat(dateCustomFormat); } if (locale && ((typeof Intl !== 'undefined') && (typeof Intl === 'object' && Intl.DateTimeFormat))) { let f = Intl.DateTimeFormat(locale, localeOptions); return f.format(date); } return format(date); }
[ "function", "formatDate", "(", "date", ")", "{", "let", "settings", "=", "dateFormat", "||", "defaultAxisSettings", ";", "let", "format", "=", "null", ";", "let", "localeOptions", "=", "{", "month", ":", "'short'", ",", "day", ":", "'numeric'", "}", ";", "if", "(", "settings", "===", "axisTimeCombinations", ".", "DAY_MONTH", "||", "settings", "===", "axisTimeCombinations", ".", "MONTH_YEAR", ")", "{", "format", "=", "monthDayYearFormat", ";", "localeOptions", ".", "year", "=", "'numeric'", ";", "}", "else", "if", "(", "settings", "===", "axisTimeCombinations", ".", "HOUR_DAY", "||", "settings", "===", "axisTimeCombinations", ".", "MINUTE_HOUR", ")", "{", "format", "=", "monthDayHourFormat", ";", "localeOptions", ".", "hour", "=", "'numeric'", ";", "}", "else", "if", "(", "settings", "===", "axisTimeCombinations", ".", "CUSTOM", "&&", "typeof", "dateCustomFormat", "===", "'string'", ")", "{", "format", "=", "d3TimeFormat", ".", "timeFormat", "(", "dateCustomFormat", ")", ";", "}", "if", "(", "locale", "&&", "(", "(", "typeof", "Intl", "!==", "'undefined'", ")", "&&", "(", "typeof", "Intl", "===", "'object'", "&&", "Intl", ".", "DateTimeFormat", ")", ")", ")", "{", "let", "f", "=", "Intl", ".", "DateTimeFormat", "(", "locale", ",", "localeOptions", ")", ";", "return", "f", ".", "format", "(", "date", ")", ";", "}", "return", "format", "(", "date", ")", ";", "}" ]
Figures out which date format to use when showing the date of the current data entry @param {Date} date Date object to format @return {Function} The proper date formatting function @private
[ "Figures", "out", "which", "date", "format", "to", "use", "when", "showing", "the", "date", "of", "the", "current", "data", "entry" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L430-L452
8,490
eventbrite/britecharts
src/charts/tooltip.js
_sortByTopicsOrder
function _sortByTopicsOrder(topics, order=topicsOrder) { return order.map((orderName) => topics.filter(({name}) => name === orderName)[0]); }
javascript
function _sortByTopicsOrder(topics, order=topicsOrder) { return order.map((orderName) => topics.filter(({name}) => name === orderName)[0]); }
[ "function", "_sortByTopicsOrder", "(", "topics", ",", "order", "=", "topicsOrder", ")", "{", "return", "order", ".", "map", "(", "(", "orderName", ")", "=>", "topics", ".", "filter", "(", "(", "{", "name", "}", ")", "=>", "name", "===", "orderName", ")", "[", "0", "]", ")", ";", "}" ]
Helper method to sort the passed topics array by the names passed int he order arary @param {Object[]} topics Topics data, retrieved from datapoint passed by line chart @param {Object[]} order Array of names in the order to sort topics by @return {Object[]} sorted topics object @private
[ "Helper", "method", "to", "sort", "the", "passed", "topics", "array", "by", "the", "names", "passed", "int", "he", "order", "arary" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L461-L463
8,491
eventbrite/britecharts
src/charts/tooltip.js
_sortByAlpha
function _sortByAlpha(topics) { return topics .map(d => d) .sort((a, b) => { if (a.name > b.name) return 1; if (a.name === b.name) return 0; return -1; }); let otherIndex = topics.map(({ name }) => name).indexOf('Other'); if (otherIndex >= 0) { let other = topics.splice(otherIndex, 1); topics = topics.concat(other); } }
javascript
function _sortByAlpha(topics) { return topics .map(d => d) .sort((a, b) => { if (a.name > b.name) return 1; if (a.name === b.name) return 0; return -1; }); let otherIndex = topics.map(({ name }) => name).indexOf('Other'); if (otherIndex >= 0) { let other = topics.splice(otherIndex, 1); topics = topics.concat(other); } }
[ "function", "_sortByAlpha", "(", "topics", ")", "{", "return", "topics", ".", "map", "(", "d", "=>", "d", ")", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "{", "if", "(", "a", ".", "name", ">", "b", ".", "name", ")", "return", "1", ";", "if", "(", "a", ".", "name", "===", "b", ".", "name", ")", "return", "0", ";", "return", "-", "1", ";", "}", ")", ";", "let", "otherIndex", "=", "topics", ".", "map", "(", "(", "{", "name", "}", ")", "=>", "name", ")", ".", "indexOf", "(", "'Other'", ")", ";", "if", "(", "otherIndex", ">=", "0", ")", "{", "let", "other", "=", "topics", ".", "splice", "(", "otherIndex", ",", "1", ")", ";", "topics", "=", "topics", ".", "concat", "(", "other", ")", ";", "}", "}" ]
Sorts topic by alphabetical order for arrays of objects with a name proeprty @param {Array} topics List of topic objects @return {Array} List of topic name strings @private
[ "Sorts", "topic", "by", "alphabetical", "order", "for", "arrays", "of", "objects", "with", "a", "name", "proeprty" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L471-L488
8,492
eventbrite/britecharts
src/charts/tooltip.js
updateContent
function updateContent(dataPoint){ var topics = dataPoint[topicLabel]; // sort order by topicsOrder array if passed if (topicsOrder.length) { topics = _sortByTopicsOrder(topics); } else if (topics.length && topics[0].name) { topics = _sortByAlpha(topics); } cleanContent(); updateTitle(dataPoint); resetSizeAndPositionPointers(); topics.forEach(updateTopicContent); }
javascript
function updateContent(dataPoint){ var topics = dataPoint[topicLabel]; // sort order by topicsOrder array if passed if (topicsOrder.length) { topics = _sortByTopicsOrder(topics); } else if (topics.length && topics[0].name) { topics = _sortByAlpha(topics); } cleanContent(); updateTitle(dataPoint); resetSizeAndPositionPointers(); topics.forEach(updateTopicContent); }
[ "function", "updateContent", "(", "dataPoint", ")", "{", "var", "topics", "=", "dataPoint", "[", "topicLabel", "]", ";", "// sort order by topicsOrder array if passed", "if", "(", "topicsOrder", ".", "length", ")", "{", "topics", "=", "_sortByTopicsOrder", "(", "topics", ")", ";", "}", "else", "if", "(", "topics", ".", "length", "&&", "topics", "[", "0", "]", ".", "name", ")", "{", "topics", "=", "_sortByAlpha", "(", "topics", ")", ";", "}", "cleanContent", "(", ")", ";", "updateTitle", "(", "dataPoint", ")", ";", "resetSizeAndPositionPointers", "(", ")", ";", "topics", ".", "forEach", "(", "updateTopicContent", ")", ";", "}" ]
Draws the data entries inside the tooltip @param {Object} dataPoint Data entry from to take the info @return void @private
[ "Draws", "the", "data", "entries", "inside", "the", "tooltip" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L557-L571
8,493
eventbrite/britecharts
src/charts/tooltip.js
updateTooltip
function updateTooltip(dataPoint, xPosition, yPosition) { updateContent(dataPoint); updatePositionAndSize(dataPoint, xPosition, yPosition); }
javascript
function updateTooltip(dataPoint, xPosition, yPosition) { updateContent(dataPoint); updatePositionAndSize(dataPoint, xPosition, yPosition); }
[ "function", "updateTooltip", "(", "dataPoint", ",", "xPosition", ",", "yPosition", ")", "{", "updateContent", "(", "dataPoint", ")", ";", "updatePositionAndSize", "(", "dataPoint", ",", "xPosition", ",", "yPosition", ")", ";", "}" ]
Updates tooltip title, content, size and position sorts by alphatical name order if not forced order given @param {lineChartPointByDate} dataPoint Current datapoint to show info about @param {Number} xPosition Position of the mouse on the X axis @return void @private
[ "Updates", "tooltip", "title", "content", "size", "and", "position", "sorts", "by", "alphatical", "name", "order", "if", "not", "forced", "order", "given" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/tooltip.js#L582-L585
8,494
eventbrite/britecharts
src/charts/helpers/text.js
function(text, fontSize = defaultTextSize, fontFace = defaultFontFace) { let a = document.createElement('canvas'), b = a.getContext('2d'); b.font = fontSize + 'px ' + fontFace; return b.measureText(text).width; }
javascript
function(text, fontSize = defaultTextSize, fontFace = defaultFontFace) { let a = document.createElement('canvas'), b = a.getContext('2d'); b.font = fontSize + 'px ' + fontFace; return b.measureText(text).width; }
[ "function", "(", "text", ",", "fontSize", "=", "defaultTextSize", ",", "fontFace", "=", "defaultFontFace", ")", "{", "let", "a", "=", "document", ".", "createElement", "(", "'canvas'", ")", ",", "b", "=", "a", ".", "getContext", "(", "'2d'", ")", ";", "b", ".", "font", "=", "fontSize", "+", "'px '", "+", "fontFace", ";", "return", "b", ".", "measureText", "(", "text", ")", ".", "width", ";", "}" ]
Figures out an approximate of the text width by using a canvas element This avoids having to actually render the text to measure it from the DOM itself @param {String} text Text to measure @param {Number} [fontSize=12] Font size (or default) @param {String} [fontFace='Arial'] Font family to use in the calculation (or default) @return {String} Approximated width of the text
[ "Figures", "out", "an", "approximate", "of", "the", "text", "width", "by", "using", "a", "canvas", "element", "This", "avoids", "having", "to", "actually", "render", "the", "text", "to", "measure", "it", "from", "the", "DOM", "itself" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/helpers/text.js#L144-L151
8,495
eventbrite/britecharts
src/charts/heatmap.js
buildScales
function buildScales() { colorScale = d3Scale.scaleLinear() .range([colorSchema[0], colorSchema[colorSchema.length - 1]]) .domain(d3Array.extent(data, getValue)) .interpolate(d3Interpolate.interpolateHcl); }
javascript
function buildScales() { colorScale = d3Scale.scaleLinear() .range([colorSchema[0], colorSchema[colorSchema.length - 1]]) .domain(d3Array.extent(data, getValue)) .interpolate(d3Interpolate.interpolateHcl); }
[ "function", "buildScales", "(", ")", "{", "colorScale", "=", "d3Scale", ".", "scaleLinear", "(", ")", ".", "range", "(", "[", "colorSchema", "[", "0", "]", ",", "colorSchema", "[", "colorSchema", ".", "length", "-", "1", "]", "]", ")", ".", "domain", "(", "d3Array", ".", "extent", "(", "data", ",", "getValue", ")", ")", ".", "interpolate", "(", "d3Interpolate", ".", "interpolateHcl", ")", ";", "}" ]
Creates the scales for the heatmap chart @return void
[ "Creates", "the", "scales", "for", "the", "heatmap", "chart" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/heatmap.js#L183-L188
8,496
eventbrite/britecharts
src/charts/heatmap.js
drawBoxes
function drawBoxes() { boxes = svg.select('.chart-group').selectAll('.box').data(data); boxes.enter() .append('rect') .classed('box', true) .attr('width', boxSize) .attr('height', boxSize) .attr('x', ({hour}) => hour * boxSize) .attr('y', ({day}) => day * boxSize) .style('opacity', boxInitialOpacity) .style('fill', boxInitialColor) .style('stroke', boxBorderColor) .style('stroke-width', boxBorderSize) .transition() .duration(animationDuration) .style('fill', ({value}) => colorScale(value)) .style('opacity', boxFinalOpacity); boxes.exit().remove(); }
javascript
function drawBoxes() { boxes = svg.select('.chart-group').selectAll('.box').data(data); boxes.enter() .append('rect') .classed('box', true) .attr('width', boxSize) .attr('height', boxSize) .attr('x', ({hour}) => hour * boxSize) .attr('y', ({day}) => day * boxSize) .style('opacity', boxInitialOpacity) .style('fill', boxInitialColor) .style('stroke', boxBorderColor) .style('stroke-width', boxBorderSize) .transition() .duration(animationDuration) .style('fill', ({value}) => colorScale(value)) .style('opacity', boxFinalOpacity); boxes.exit().remove(); }
[ "function", "drawBoxes", "(", ")", "{", "boxes", "=", "svg", ".", "select", "(", "'.chart-group'", ")", ".", "selectAll", "(", "'.box'", ")", ".", "data", "(", "data", ")", ";", "boxes", ".", "enter", "(", ")", ".", "append", "(", "'rect'", ")", ".", "classed", "(", "'box'", ",", "true", ")", ".", "attr", "(", "'width'", ",", "boxSize", ")", ".", "attr", "(", "'height'", ",", "boxSize", ")", ".", "attr", "(", "'x'", ",", "(", "{", "hour", "}", ")", "=>", "hour", "*", "boxSize", ")", ".", "attr", "(", "'y'", ",", "(", "{", "day", "}", ")", "=>", "day", "*", "boxSize", ")", ".", "style", "(", "'opacity'", ",", "boxInitialOpacity", ")", ".", "style", "(", "'fill'", ",", "boxInitialColor", ")", ".", "style", "(", "'stroke'", ",", "boxBorderColor", ")", ".", "style", "(", "'stroke-width'", ",", "boxBorderSize", ")", ".", "transition", "(", ")", ".", "duration", "(", "animationDuration", ")", ".", "style", "(", "'fill'", ",", "(", "{", "value", "}", ")", "=>", "colorScale", "(", "value", ")", ")", ".", "style", "(", "'opacity'", ",", "boxFinalOpacity", ")", ";", "boxes", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Draws the boxes of the heatmap
[ "Draws", "the", "boxes", "of", "the", "heatmap" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/heatmap.js#L193-L213
8,497
eventbrite/britecharts
src/charts/heatmap.js
drawDayLabels
function drawDayLabels() { let dayLabelsGroup = svg.select('.day-labels-group'); dayLabels = svg.select('.day-labels-group').selectAll('.day-label') .data(daysHuman); dayLabels.enter() .append('text') .text((label) => label) .attr('x', 0) .attr('y', (d, i) => i * boxSize) .style('text-anchor', 'start') .style('dominant-baseline', 'central') .attr('class', 'day-label'); dayLabelsGroup.attr('transform', `translate(-${dayLabelWidth}, ${boxSize / 2})`); }
javascript
function drawDayLabels() { let dayLabelsGroup = svg.select('.day-labels-group'); dayLabels = svg.select('.day-labels-group').selectAll('.day-label') .data(daysHuman); dayLabels.enter() .append('text') .text((label) => label) .attr('x', 0) .attr('y', (d, i) => i * boxSize) .style('text-anchor', 'start') .style('dominant-baseline', 'central') .attr('class', 'day-label'); dayLabelsGroup.attr('transform', `translate(-${dayLabelWidth}, ${boxSize / 2})`); }
[ "function", "drawDayLabels", "(", ")", "{", "let", "dayLabelsGroup", "=", "svg", ".", "select", "(", "'.day-labels-group'", ")", ";", "dayLabels", "=", "svg", ".", "select", "(", "'.day-labels-group'", ")", ".", "selectAll", "(", "'.day-label'", ")", ".", "data", "(", "daysHuman", ")", ";", "dayLabels", ".", "enter", "(", ")", ".", "append", "(", "'text'", ")", ".", "text", "(", "(", "label", ")", "=>", "label", ")", ".", "attr", "(", "'x'", ",", "0", ")", ".", "attr", "(", "'y'", ",", "(", "d", ",", "i", ")", "=>", "i", "*", "boxSize", ")", ".", "style", "(", "'text-anchor'", ",", "'start'", ")", ".", "style", "(", "'dominant-baseline'", ",", "'central'", ")", ".", "attr", "(", "'class'", ",", "'day-label'", ")", ";", "dayLabelsGroup", ".", "attr", "(", "'transform'", ",", "`", "${", "dayLabelWidth", "}", "${", "boxSize", "/", "2", "}", "`", ")", ";", "}" ]
Draws the day labels
[ "Draws", "the", "day", "labels" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/heatmap.js#L218-L234
8,498
eventbrite/britecharts
src/charts/heatmap.js
drawHourLabels
function drawHourLabels() { let hourLabelsGroup = svg.select('.hour-labels-group'); hourLabels = svg.select('.hour-labels-group').selectAll('.hour-label') .data(hoursHuman); hourLabels.enter() .append('text') .text((label) => label) .attr('y', 0) .attr('x', (d, i) => i * boxSize) .style('text-anchor', 'middle') .style('dominant-baseline', 'central') .attr('class', 'hour-label'); hourLabelsGroup.attr('transform', `translate(${boxSize / 2}, -${hourLabelHeight})`); }
javascript
function drawHourLabels() { let hourLabelsGroup = svg.select('.hour-labels-group'); hourLabels = svg.select('.hour-labels-group').selectAll('.hour-label') .data(hoursHuman); hourLabels.enter() .append('text') .text((label) => label) .attr('y', 0) .attr('x', (d, i) => i * boxSize) .style('text-anchor', 'middle') .style('dominant-baseline', 'central') .attr('class', 'hour-label'); hourLabelsGroup.attr('transform', `translate(${boxSize / 2}, -${hourLabelHeight})`); }
[ "function", "drawHourLabels", "(", ")", "{", "let", "hourLabelsGroup", "=", "svg", ".", "select", "(", "'.hour-labels-group'", ")", ";", "hourLabels", "=", "svg", ".", "select", "(", "'.hour-labels-group'", ")", ".", "selectAll", "(", "'.hour-label'", ")", ".", "data", "(", "hoursHuman", ")", ";", "hourLabels", ".", "enter", "(", ")", ".", "append", "(", "'text'", ")", ".", "text", "(", "(", "label", ")", "=>", "label", ")", ".", "attr", "(", "'y'", ",", "0", ")", ".", "attr", "(", "'x'", ",", "(", "d", ",", "i", ")", "=>", "i", "*", "boxSize", ")", ".", "style", "(", "'text-anchor'", ",", "'middle'", ")", ".", "style", "(", "'dominant-baseline'", ",", "'central'", ")", ".", "attr", "(", "'class'", ",", "'hour-label'", ")", ";", "hourLabelsGroup", ".", "attr", "(", "'transform'", ",", "`", "${", "boxSize", "/", "2", "}", "${", "hourLabelHeight", "}", "`", ")", ";", "}" ]
Draws the hour labels
[ "Draws", "the", "hour", "labels" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/heatmap.js#L239-L255
8,499
eventbrite/britecharts
src/charts/stacked-area.js
addGlowFilter
function addGlowFilter(el) { if (!highlightFilter) { highlightFilter = createFilterContainer(svg.select('.metadata-group')); highlightFilterId = createGlowWithMatrix(highlightFilter); } let glowEl = d3Selection.select(el); glowEl .style('stroke-width', highlightCircleActiveStrokeWidth) .style('stroke-opacity', highlightCircleActiveStrokeOpacity) .attr('filter', `url(#${highlightFilterId})`); bounceCircleHighlight( glowEl, ease, highlightCircleActiveRadius ); }
javascript
function addGlowFilter(el) { if (!highlightFilter) { highlightFilter = createFilterContainer(svg.select('.metadata-group')); highlightFilterId = createGlowWithMatrix(highlightFilter); } let glowEl = d3Selection.select(el); glowEl .style('stroke-width', highlightCircleActiveStrokeWidth) .style('stroke-opacity', highlightCircleActiveStrokeOpacity) .attr('filter', `url(#${highlightFilterId})`); bounceCircleHighlight( glowEl, ease, highlightCircleActiveRadius ); }
[ "function", "addGlowFilter", "(", "el", ")", "{", "if", "(", "!", "highlightFilter", ")", "{", "highlightFilter", "=", "createFilterContainer", "(", "svg", ".", "select", "(", "'.metadata-group'", ")", ")", ";", "highlightFilterId", "=", "createGlowWithMatrix", "(", "highlightFilter", ")", ";", "}", "let", "glowEl", "=", "d3Selection", ".", "select", "(", "el", ")", ";", "glowEl", ".", "style", "(", "'stroke-width'", ",", "highlightCircleActiveStrokeWidth", ")", ".", "style", "(", "'stroke-opacity'", ",", "highlightCircleActiveStrokeOpacity", ")", ".", "attr", "(", "'filter'", ",", "`", "${", "highlightFilterId", "}", "`", ")", ";", "bounceCircleHighlight", "(", "glowEl", ",", "ease", ",", "highlightCircleActiveRadius", ")", ";", "}" ]
Adds a filter to the element @param {DOMElement} el @private
[ "Adds", "a", "filter", "to", "the", "element" ]
0767051287e9e7211e610b1b13244da71e8e355e
https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/stacked-area.js#L241-L259