= ({
max={max || rangeMax}
lowerValue={min || rangeMin}
upperValue={max || rangeMax}
- background={background}
+ background={gradient}
compressed={compressed}
/>
{
+ if (a.stop < b.stop) {
+ return -1;
+ }
+ if (a.stop > b.stop) {
+ return 1;
+ }
+ return 0;
+ });
+ return colorStops;
};
export const addStop = (
@@ -125,7 +135,7 @@ export const getPositionFromStop = (
return parseFloat(
(
((stop - min) / (max - min)) *
- calculateScale(ref ? ref.clientWidth : 100)
+ calculateScale(ref && ref.clientWidth > 0 ? ref.clientWidth : 100)
).toFixed(1)
);
};
diff --git a/src/components/form/range/range_highlight.tsx b/src/components/form/range/range_highlight.tsx
index ee67271f43f..adbc70e3512 100644
--- a/src/components/form/range/range_highlight.tsx
+++ b/src/components/form/range/range_highlight.tsx
@@ -49,6 +49,7 @@ export const EuiRangeHighlight: FunctionComponent = ({
// const rangeWidth = (value - min) / (max - min);
const leftPosition = (lowerValue - min) / (max - min);
const rangeWidth = (upperValue - lowerValue) / (max - min);
+
const rangeWidthStyle = {
background,
marginLeft: `${leftPosition * 100}%`,
diff --git a/src/services/color/index.ts b/src/services/color/index.ts
index 391d185bfab..f12247056fb 100644
--- a/src/services/color/index.ts
+++ b/src/services/color/index.ts
@@ -49,3 +49,4 @@ export {
euiPaletteGray,
} from './eui_palettes';
export { rgbDef, HSV, RGB } from './color_types';
+export { getSteppedGradient } from './stepped_gradient';
diff --git a/src/services/color/stepped_gradient.ts b/src/services/color/stepped_gradient.ts
new file mode 100644
index 00000000000..0dbaa8ec996
--- /dev/null
+++ b/src/services/color/stepped_gradient.ts
@@ -0,0 +1,32 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import chroma from 'chroma-js';
+import { ColorStop } from '../../components/color_picker/color_stops';
+
+export const getSteppedGradient = function (
+ colors: ColorStop[],
+ steps: number
+) {
+ const range = colors[colors.length - 1].stop - colors[0].stop;
+ const offset = colors[0].stop;
+ const finalStops = [...colors.map((item) => (item.stop - offset) / range)];
+ const color = [...colors.map((item) => item.color)];
+ return chroma.scale(color).domain(finalStops).colors(steps);
+};
diff --git a/src/services/index.ts b/src/services/index.ts
index 51239389444..9b7e56f545d 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -70,6 +70,7 @@ export {
euiPaletteWarm,
euiPaletteGray,
HSV,
+ getSteppedGradient,
} from './color';
export { useColorPickerState, useColorStopsState } from './color_picker';