UNPKG

@elastic/eui

Version:

Elastic UI Component Library

26 lines (24 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateThumbPosition = exports.EUI_THUMB_SIZE = void 0; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ var EUI_THUMB_SIZE = exports.EUI_THUMB_SIZE = 16; var calculateThumbPosition = exports.calculateThumbPosition = function calculateThumbPosition(value, min, max, trackWidth) { var thumbSize = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : EUI_THUMB_SIZE; // Calculate the left position based on value var decimal = (value - min) / (max - min); // Must be between 0-100% var valuePosition = decimal <= 1 ? decimal : 1; valuePosition = valuePosition >= 0 ? valuePosition : 0; var thumbToTrackRatio = thumbSize / trackWidth; var trackPositionScale = (1 - thumbToTrackRatio) * 100; return valuePosition * trackPositionScale; };