mirror of
https://github.com/apache/superset.git
synced 2026-07-11 17:25:31 +00:00
Co-authored-by: Enzo Martellucci <52219496+EnxDev@users.noreply.github.com> Co-authored-by: Enzo Martellucci <enzomartellucci@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
116 lines
3.4 KiB
TypeScript
116 lines
3.4 KiB
TypeScript
/**
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF 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 {
|
|
ColorFormatters,
|
|
getTextColorForBackground,
|
|
ObjectFormattingEnum,
|
|
} from '@superset-ui/chart-controls';
|
|
import { CellClassParams } from '@superset-ui/core/components/ThemedAgGridReact';
|
|
import { BasicColorFormatterType, InputColumn } from '../types';
|
|
import getRowBasicColorFormatter from './getRowBasicColorFormatter';
|
|
|
|
type CellStyleParams = CellClassParams & {
|
|
hasColumnColorFormatters: boolean | undefined;
|
|
columnColorFormatters: ColorFormatters;
|
|
hasBasicColorFormatters: boolean | undefined;
|
|
basicColorFormatters?: {
|
|
[Key: string]: BasicColorFormatterType;
|
|
}[];
|
|
col: InputColumn;
|
|
cellSurfaceColor: string;
|
|
hoverCellSurfaceColor: string;
|
|
};
|
|
|
|
const getCellStyle = (params: CellStyleParams) => {
|
|
const {
|
|
value,
|
|
colDef,
|
|
rowIndex,
|
|
hasBasicColorFormatters,
|
|
basicColorFormatters,
|
|
hasColumnColorFormatters,
|
|
columnColorFormatters,
|
|
col,
|
|
node,
|
|
cellSurfaceColor,
|
|
hoverCellSurfaceColor,
|
|
} = params;
|
|
let backgroundColor;
|
|
let color;
|
|
if (hasColumnColorFormatters) {
|
|
columnColorFormatters!
|
|
.filter(formatter => {
|
|
const colTitle = formatter?.column?.includes('Main')
|
|
? formatter?.column?.replace('Main', '').trim()
|
|
: formatter?.column;
|
|
return colTitle === colDef.field;
|
|
})
|
|
.forEach(formatter => {
|
|
const formatterResult =
|
|
value || value === 0 ? formatter.getColorFromValue(value) : false;
|
|
if (formatterResult) {
|
|
if (
|
|
formatter.objectFormatting === ObjectFormattingEnum.TEXT_COLOR ||
|
|
formatter.toTextColor
|
|
) {
|
|
color = formatterResult;
|
|
} else if (
|
|
formatter.objectFormatting !== ObjectFormattingEnum.CELL_BAR
|
|
) {
|
|
backgroundColor = formatterResult;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if (
|
|
hasBasicColorFormatters &&
|
|
col?.metricName &&
|
|
node?.rowPinned !== 'bottom'
|
|
) {
|
|
backgroundColor = getRowBasicColorFormatter(
|
|
node,
|
|
rowIndex,
|
|
basicColorFormatters,
|
|
)?.[col.metricName]?.backgroundColor;
|
|
}
|
|
|
|
const textAlign =
|
|
col?.config?.horizontalAlign || (col?.isNumeric ? 'right' : 'left');
|
|
const resolvedTextColor = getTextColorForBackground(
|
|
{ backgroundColor, color },
|
|
cellSurfaceColor,
|
|
);
|
|
const hoverResolvedTextColor = getTextColorForBackground(
|
|
{ backgroundColor, color },
|
|
hoverCellSurfaceColor,
|
|
);
|
|
|
|
return {
|
|
backgroundColor: backgroundColor || '',
|
|
color: '',
|
|
'--ag-cell-value-color': resolvedTextColor || '',
|
|
'--ag-cell-value-hover-color': hoverResolvedTextColor || '',
|
|
textAlign,
|
|
};
|
|
};
|
|
|
|
export default getCellStyle;
|