|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>JSDoc: Source: Color.js</title> |
| 6 | + |
| 7 | + <script src="scripts/prettify/prettify.js"> </script> |
| 8 | + <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | + <!--[if lt IE 9]> |
| 10 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | + <![endif]--> |
| 12 | + <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | + <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> |
| 14 | +</head> |
| 15 | + |
| 16 | +<body> |
| 17 | + |
| 18 | +<div id="main"> |
| 19 | + |
| 20 | + <h1 class="page-title">Source: Color.js</h1> |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + <section> |
| 28 | + <article> |
| 29 | + <pre class="prettyprint source linenums"><code>/** @module Color */ |
| 30 | + |
| 31 | +const $ = require('jquery'); |
| 32 | + |
| 33 | +/** |
| 34 | + * Set a highlight by a different grouping. Either staff, syllable, or neume. |
| 35 | + * @param {string} grouping - The grouping name. |
| 36 | + */ |
| 37 | +export function setGroupingHighlight (grouping) { |
| 38 | + unsetGroupingHighlight(); |
| 39 | + if (grouping === 'staff') { |
| 40 | + setStaffHighlight(); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + let groups = Array.from($('.' + grouping)); |
| 45 | + for (var i = 0; i < groups.length; i++) { |
| 46 | + let groupColor = ColorPalette[i % ColorPalette.length]; |
| 47 | + if (!$(groups[i]).parents('.selected').length && !$(groups[i]).hasClass('selected')) { |
| 48 | + groups[i].setAttribute('fill', groupColor); |
| 49 | + $(groups[i]).addClass('highlighted'); |
| 50 | + } else { |
| 51 | + if (!$(groups[i]).hasClass('selected')) { |
| 52 | + groups[i].setAttribute('fill', null); |
| 53 | + } else { |
| 54 | + groups[i].setAttribute('fill', '#d00'); |
| 55 | + } |
| 56 | + $(groups[i]).removeClass('highlighted'); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * Unset highlight for all grouping types |
| 63 | + */ |
| 64 | +export function unsetGroupingHighlight () { |
| 65 | + unsetStaffHighlight(); |
| 66 | + let highlighted = Array.from($('.highlighted').filter((index, elem) => { return !$(elem.parentElement).hasClass('selected'); })); |
| 67 | + highlighted.forEach(elem => { |
| 68 | + elem.setAttribute('fill', null); |
| 69 | + $(elem).removeClass('highlighted'); |
| 70 | + }); |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * Highlight each staff a different color. |
| 75 | + */ |
| 76 | +export function setStaffHighlight () { |
| 77 | + let staves = Array.from(document.getElementsByClassName('staff')); |
| 78 | + for (var i = 0; i < staves.length; i++) { |
| 79 | + let staffColor = ColorPalette[i % ColorPalette.length]; |
| 80 | + highlight(staves[i], staffColor); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * Remove the highlight from each staff. |
| 86 | + */ |
| 87 | +export function unsetStaffHighlight () { |
| 88 | + unhighlight('.staff'); |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * Highlight a staff a certain color. |
| 93 | + * @param {SVGSVGElement} staff - The staff's SVG element. |
| 94 | + * @param {string} color - The color to highlight the staff. |
| 95 | + */ |
| 96 | +export function highlight (staff, color) { |
| 97 | + let children = Array.from($('#' + staff.id).children()); |
| 98 | + children.forEach(child => { |
| 99 | + if (child.tagName === 'path') { |
| 100 | + child.setAttribute('stroke', color); |
| 101 | + } else { |
| 102 | + child.setAttribute('fill', color); |
| 103 | + } |
| 104 | + $(child).addClass('highlighted'); |
| 105 | + }); |
| 106 | +} |
| 107 | + |
| 108 | +/** |
| 109 | + * Remove the highlight from a staff. |
| 110 | + * @param {(SVGSVGElement|string)} staff - The staff's SVG element or a JQuery selector. |
| 111 | + */ |
| 112 | +export function unhighlight (staff) { |
| 113 | + let children = Array.from($(staff).filter(':not(.selected)').children('.highlighted')); |
| 114 | + children.forEach(elem => { |
| 115 | + if (elem.tagName === 'path') { |
| 116 | + elem.setAttribute('stroke', '#000000'); |
| 117 | + } else { |
| 118 | + elem.removeAttribute('fill'); |
| 119 | + } |
| 120 | + }); |
| 121 | + $(staff).filter(':not(.selected)').children('.highlighted').removeClass('highlighted'); |
| 122 | +} |
| 123 | + |
| 124 | +/** |
| 125 | + * Color palette from Figure 2 (Colors optimized for color-blind |
| 126 | + * individuals) from |
| 127 | + * ["Points of view: Color blindness" by Bang Wong published in Nature Methods volume 8 on 27 May 2011]{@link https://www.nature.com/articles/nmeth.1618?WT.ec_id=NMETH-201106} |
| 128 | + * @type {string[]} |
| 129 | + */ |
| 130 | +const ColorPalette = [ |
| 131 | +// "rgb(0,0,0)", |
| 132 | + 'rgb(230, 159, 0)', |
| 133 | + 'rgb(86, 180, 233)', |
| 134 | + 'rgb(0, 158, 115)', |
| 135 | + 'rgb(240, 228, 66)', |
| 136 | + 'rgb(0, 114, 178)', |
| 137 | + 'rgb(213, 94, 0)', |
| 138 | + 'rgb(204, 121, 167)' |
| 139 | +]; |
| 140 | +</code></pre> |
| 141 | + </article> |
| 142 | + </section> |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +</div> |
| 148 | + |
| 149 | +<nav> |
| 150 | + <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Color.html">Color</a></li><li><a href="module-Compatibility.html">Compatibility</a></li><li><a href="module-Contents.html">Contents</a></li><li><a href="module-Controls.html">Controls</a></li><li><a href="module-Cursor.html">Cursor</a></li><li><a href="module-Grouping.html">Grouping</a></li><li><a href="module-Notification.html">Notification</a></li><li><a href="module-ResizeStaff.html">ResizeStaff</a></li><li><a href="module-Select.html">Select</a></li><li><a href="module-SelectOptions.html">SelectOptions</a></li><li><a href="module-Text.html">Text</a></li><li><a href="module-Warnings.html">Warnings</a></li><li><a href="module-Zoom.html">Zoom</a></li></ul><h3>Classes</h3><ul><li><a href="DragHandler.html">DragHandler</a></li><li><a href="EditMode.html">EditMode</a></li><li><a href="InfoBox.html">InfoBox</a></li><li><a href="InsertHandler.html">InsertHandler</a></li><li><a href="module-Notification-Notification.html">Notification</a></li><li><a href="module-ResizeStaff-Resize.html">Resize</a></li><li><a href="module-Select.ClickSelect.html">ClickSelect</a></li><li><a href="module-Select.DragSelect.html">DragSelect</a></li><li><a href="module-Zoom.ViewBox.html">ViewBox</a></li><li><a href="module-Zoom-ZoomHandler.html">ZoomHandler</a></li><li><a href="NeonCore.html">NeonCore</a></li><li><a href="NeonView.html">NeonView</a></li><li><a href="SplitHandler.html">SplitHandler</a></li></ul> |
| 151 | +</nav> |
| 152 | + |
| 153 | +<br class="clear"> |
| 154 | + |
| 155 | +<footer> |
| 156 | + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Apr 25 2019 17:27:40 GMT-0400 (GMT-04:00) |
| 157 | +</footer> |
| 158 | + |
| 159 | +<script> prettyPrint(); </script> |
| 160 | +<script src="scripts/linenumber.js"> </script> |
| 161 | +</body> |
| 162 | +</html> |
0 commit comments