(scaleType, e, position)
| 218 | } |
| 219 | |
| 220 | function addScaleKeyColor(scaleType, e, position) { |
| 221 | let smoothWrapper = document.getElementById(`${scaleType}_smoothWrapper`); |
| 222 | let smooth = document.getElementById(`${scaleType}_smooth`); |
| 223 | let thisId = e.target.id; |
| 224 | let parentId = thisId.replace('_addKeyColor', ''); |
| 225 | |
| 226 | let currentColor = scaleType === 'sequential' ? _sequentialScale : _divergingScale; // TODO: replace with _diverging when available |
| 227 | let currentKeys = scaleType === 'sequential' ? currentColor.colorKeys : position === 'start' ? currentColor.startKeys : currentColor.endKeys; |
| 228 | |
| 229 | let lastIndex = currentKeys.length; |
| 230 | if (!lastIndex) lastIndex = 0; |
| 231 | let lastColor = lastIndex > 0 ? chroma(currentKeys[lastIndex - 1]).hsluv() : chroma(currentKeys[0]).hsluv(); |
| 232 | let lastColorLightness = lastColor[2]; |
| 233 | let fCtintHalf = (100 - lastColorLightness) / 3 + lastColorLightness; |
| 234 | let fCshadeHalf = lastColorLightness / 2; |
| 235 | |
| 236 | let c = lastColorLightness >= 50 ? chroma.hsluv(lastColor[0], lastColor[1], fCshadeHalf) : chroma.hsluv(lastColor[0], lastColor[1], fCtintHalf); |
| 237 | c = c.hex(); |
| 238 | currentKeys.push(c); |
| 239 | |
| 240 | // Update color class arguments via the theme class |
| 241 | if (scaleType === 'sequential') { |
| 242 | currentColor.colorKeys = currentKeys; |
| 243 | |
| 244 | removeElementsByClass(`keyColor-${scaleType}`); |
| 245 | } else { |
| 246 | if (position === 'start') { |
| 247 | currentColor.startKeys = currentKeys; |
| 248 | // only remove respective inputs |
| 249 | let parentDest = document.getElementById('diverging_startKeyColors'); |
| 250 | removeElementsByClass(`keyColor-${scaleType}`, parentDest); |
| 251 | } else { |
| 252 | currentColor.endKeys = currentKeys; |
| 253 | // only remove respective inputs |
| 254 | let parentDest = document.getElementById('diverging_endKeyColors'); |
| 255 | removeElementsByClass(`keyColor-${scaleType}`, parentDest); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | if (scaleType === 'sequential') { |
| 260 | currentColor.colorKeys.forEach((key, i) => { |
| 261 | addScaleKeyColorInput(key, thisId, scaleType, i, position); |
| 262 | }); |
| 263 | } else { |
| 264 | if (position === 'start') { |
| 265 | currentColor.startKeys.forEach((key, i) => { |
| 266 | addScaleKeyColorInput(key, thisId, scaleType, i, position); |
| 267 | }); |
| 268 | } else { |
| 269 | currentColor.endKeys.forEach((key, i) => { |
| 270 | addScaleKeyColorInput(key, thisId, scaleType, i, position); |
| 271 | }); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // Update gradient |
| 276 | updateRamps(currentColor, parentId, scaleType); |
| 277 |
no test coverage detected