|
239 | 239 | var numericValue = toNumber(value, 0); |
240 | 240 | var percentage = numericValue / this.options.max; |
241 | 241 |
|
242 | | - // Interpolate between red (0) and green (100) |
243 | | - // Red: #d82e28, Orange: #f07f46, Yellow: #f5c46b, Yellow-green: #b7e276, Green: #2db034 |
244 | | - var r, g, b; |
245 | | - if (percentage <= 0.2) { |
246 | | - // Red to orange (0-20) |
247 | | - var t = percentage * 5; |
248 | | - r = Math.round(216 * (1 - t) + 240 * t); |
249 | | - g = Math.round(46 * (1 - t) + 127 * t); |
250 | | - b = Math.round(40 * (1 - t) + 70 * t); |
251 | | - } else if (percentage <= 0.4) { |
252 | | - // Orange to yellow (20-40) |
253 | | - var t = (percentage - 0.2) * 5; |
254 | | - r = Math.round(240 * (1 - t) + 245 * t); |
255 | | - g = Math.round(127 * (1 - t) + 196 * t); |
256 | | - b = Math.round(70 * (1 - t) + 107 * t); |
257 | | - } else if (percentage <= 0.6) { |
258 | | - // Yellow to yellow-green (40-60) |
259 | | - var t = (percentage - 0.4) * 5; |
260 | | - r = Math.round(245 * (1 - t) + 183 * t); |
261 | | - g = Math.round(196 * (1 - t) + 226 * t); |
262 | | - b = Math.round(107 * (1 - t) + 118 * t); |
263 | | - } else { |
264 | | - // Yellow-green to green (60-100) |
265 | | - var t = (percentage - 0.6) * 2.5; |
266 | | - r = Math.round(183 * (1 - t) + 45 * t); |
267 | | - g = Math.round(226 * (1 - t) + 176 * t); |
268 | | - b = Math.round(118 * (1 - t) + 52 * t); |
269 | | - } |
| 242 | + // Color stops from CSS quality-option-1 through quality-option-10 |
| 243 | + // Each represents 10% of the scale (0-9, 10-19, ..., 90-100) |
| 244 | + var colorStops = [ |
| 245 | + {r: 216, g: 46, b: 40}, // #d82e28 - option-1 (0-9) |
| 246 | + {r: 225, g: 104, b: 75}, // #e1684b - option-2 (10-19) |
| 247 | + {r: 240, g: 127, b: 70}, // #f07f46 - option-3 (20-29) |
| 248 | + {r: 240, g: 173, b: 78}, // #f0ad4e - option-4 (30-39) |
| 249 | + {r: 245, g: 196, b: 107}, // #f5c46b - option-5 (40-49) |
| 250 | + {r: 211, g: 231, b: 98}, // #d3e762 - option-6 (50-59) |
| 251 | + {r: 183, g: 226, b: 118}, // #b7e276 - option-7 (60-69) |
| 252 | + {r: 142, g: 220, b: 141}, // #8edc8d - option-8 (70-79) |
| 253 | + {r: 94, g: 191, b: 100}, // #5ebf64 - option-9 (80-89) |
| 254 | + {r: 45, g: 176, b: 52} // #2db034 - option-10 (90-100) |
| 255 | + ]; |
| 256 | + |
| 257 | + // Find which segment we're in (0-9) |
| 258 | + var segment = Math.min(Math.floor(percentage * 10), 9); |
| 259 | + var nextSegment = Math.min(segment + 1, 9); |
| 260 | + |
| 261 | + // Calculate position within the segment (0.0 to 1.0) |
| 262 | + var segmentPosition = (percentage * 10) - segment; |
| 263 | + |
| 264 | + // Interpolate between the two color stops |
| 265 | + var color1 = colorStops[segment]; |
| 266 | + var color2 = colorStops[nextSegment]; |
| 267 | + |
| 268 | + var r = Math.round(color1.r * (1 - segmentPosition) + color2.r * segmentPosition); |
| 269 | + var g = Math.round(color1.g * (1 - segmentPosition) + color2.g * segmentPosition); |
| 270 | + var b = Math.round(color1.b * (1 - segmentPosition) + color2.b * segmentPosition); |
270 | 271 |
|
271 | 272 | var color = 'rgb(' + r + ',' + g + ',' + b + ')'; |
272 | | - var textColor = percentage < 0.3 || percentage > 0.85 ? '#fff' : '#2f3b11'; |
| 273 | + |
| 274 | + // Determine text color based on segment for better readability |
| 275 | + var textColor = '#2f3b11'; |
| 276 | + if (segment === 0 || segment === 1) { |
| 277 | + textColor = '#fff'; // White text for dark red/orange |
| 278 | + } else if (segment === 9) { |
| 279 | + textColor = '#fff'; // White text for dark green |
| 280 | + } else if (segment === 8) { |
| 281 | + textColor = '#14351a'; // Darker text for lighter green |
| 282 | + } |
273 | 283 |
|
274 | 284 | this.$range.css({'background': color, 'background-color': color}); |
275 | 285 | this.$handle.css({'background': color, 'background-color': color, 'border-color': color, 'color': textColor}); |
|
0 commit comments