(values, offset, valueIndex, mode = 'unit')
| 191 | |
| 192 | // Values |
| 193 | const offsetValues: OffsetValues = (values, offset, valueIndex, mode = 'unit') => { |
| 194 | const nextValues = values.map<number>(formatValue); |
| 195 | const originValue = nextValues[valueIndex]; |
| 196 | const nextValue = offsetValue(nextValues, offset, valueIndex, mode); |
| 197 | nextValues[valueIndex] = nextValue; |
| 198 | |
| 199 | if (allowCross === false) { |
| 200 | // >>>>> Allow Cross |
| 201 | const pushNum = pushable || 0; |
| 202 | |
| 203 | // ============ AllowCross =============== |
| 204 | if (valueIndex > 0 && nextValues[valueIndex - 1] !== originValue) { |
| 205 | nextValues[valueIndex] = Math.max( |
| 206 | nextValues[valueIndex], |
| 207 | nextValues[valueIndex - 1] + pushNum, |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | if (valueIndex < nextValues.length - 1 && nextValues[valueIndex + 1] !== originValue) { |
| 212 | nextValues[valueIndex] = Math.min( |
| 213 | nextValues[valueIndex], |
| 214 | nextValues[valueIndex + 1] - pushNum, |
| 215 | ); |
| 216 | } |
| 217 | } else if (typeof pushable === 'number' || pushable === null) { |
| 218 | // >>>>> Pushable |
| 219 | // =============== Push ================== |
| 220 | |
| 221 | // >>>>>> Basic push |
| 222 | // End values |
| 223 | for (let i = valueIndex + 1; i < nextValues.length; i += 1) { |
| 224 | let changed = true; |
| 225 | while (needPush(nextValues[i] - nextValues[i - 1]) && changed) { |
| 226 | ({ value: nextValues[i], changed } = offsetChangedValue(nextValues, 1, i)); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // Start values |
| 231 | for (let i = valueIndex; i > 0; i -= 1) { |
| 232 | let changed = true; |
| 233 | while (needPush(nextValues[i] - nextValues[i - 1]) && changed) { |
| 234 | ({ value: nextValues[i - 1], changed } = offsetChangedValue(nextValues, -1, i - 1)); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // >>>>> Revert back to safe push range |
| 239 | // End to Start |
| 240 | for (let i = nextValues.length - 1; i > 0; i -= 1) { |
| 241 | let changed = true; |
| 242 | while (needPush(nextValues[i] - nextValues[i - 1]) && changed) { |
| 243 | ({ value: nextValues[i - 1], changed } = offsetChangedValue(nextValues, -1, i - 1)); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Start to End |
| 248 | for (let i = 0; i < nextValues.length - 1; i += 1) { |
| 249 | let changed = true; |
| 250 | while (needPush(nextValues[i + 1] - nextValues[i]) && changed) { |
no test coverage detected