Skip to content

Commit

Permalink
fix(plugin-chart-pivot-table): color weight of Conditional formatting…
Browse files Browse the repository at this point in the history
… metrics not work
  • Loading branch information
stephenLYZ committed Jun 15, 2022
1 parent c3fdd52 commit bc503d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import memoizeOne from 'memoize-one';
import { DataRecord } from '@superset-ui/core';
import { addAlpha, DataRecord } from '@superset-ui/core';
import {
ColorFormatters,
COMPARATOR,
Expand All @@ -28,9 +28,6 @@ import {
export const round = (num: number, precision = 0) =>
Number(`${Math.round(Number(`${num}e+${precision}`))}e-${precision}`);

export const rgbToRgba = (rgb: string, alpha: number) =>
rgb.replace(/rgb/i, 'rgba').replace(/\)/i, `,${alpha})`);

const MIN_OPACITY_BOUNDED = 0.05;
const MIN_OPACITY_UNBOUNDED = 0;
const MAX_OPACITY = 1;
Expand Down Expand Up @@ -174,7 +171,7 @@ export const getColorFunction = (
const compareResult = comparatorFunction(value, columnValues);
if (compareResult === false) return undefined;
const { cutoffValue, extremeValue } = compareResult;
return rgbToRgba(
return addAlpha(
colorScheme,
getOpacity(value, cutoffValue, extremeValue, minOpacity, maxOpacity),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { configure } from '@superset-ui/core';
import {
COMPARATOR,
getOpacity,
rgbToRgba,
round,
getColorFormatters,
getColorFunction,
Expand Down Expand Up @@ -54,12 +53,6 @@ describe('getOpacity', () => {
});
});

describe('rgba', () => {
it('returns correct rgba value', () => {
expect(rgbToRgba('rgb(255,0,0)', 0.5)).toEqual('rgba(255,0,0,0.5)');
});
});

describe('getColorFunction()', () => {
it('getColorFunction GREATER_THAN', () => {
const colorFunction = getColorFunction(
Expand Down

0 comments on commit bc503d3

Please sign in to comment.