rusackas commented on code in PR #21482:
URL: https://github.com/apache/superset/pull/21482#discussion_r974874470
##########
superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:
##########
@@ -80,44 +82,67 @@ function getSortTypeByDataType(dataType: GenericDataType):
DefaultSortTypes {
}
/**
- * Cell background to render columns as horizontal bar chart
+ * Cell background width calculation for horizontal bar chart
*/
-function cellBar({
+function cellWidth({
value,
valueRange,
- colorPositiveNegative = false,
alignPositiveNegative,
}: {
value: number;
valueRange: ValueRange;
- colorPositiveNegative: boolean;
alignPositiveNegative: boolean;
}) {
const [minValue, maxValue] = valueRange;
- const r = colorPositiveNegative && value < 0 ? 150 : 0;
if (alignPositiveNegative) {
const perc = Math.abs(Math.round((value / maxValue) * 100));
- // The 0.01 to 0.001 is a workaround for what appears to be a
- // CSS rendering bug on flat, transparent colors
- return (
- `linear-gradient(to right, rgba(${r},0,0,0.2), rgba(${r},0,0,0.2)
${perc}%, ` +
- `rgba(0,0,0,0.01) ${perc}%, rgba(0,0,0,0.001) 100%)`
- );
+ return perc;
}
const posExtent = Math.abs(Math.max(maxValue, 0));
const negExtent = Math.abs(Math.min(minValue, 0));
const tot = posExtent + negExtent;
+ const perc2 = Math.round((Math.abs(value) / tot) * 100);
+ return perc2;
+}
+
+/**
+ * Cell left margin (offset) calculation for horizontal bar chart elements
+ * when alignPositiveNegative is not set
+ */
+function cellOffset({
+ value,
+ valueRange,
+ alignPositiveNegative,
+}: {
+ value: number;
+ valueRange: ValueRange;
+ alignPositiveNegative: boolean;
+}) {
+ if (alignPositiveNegative) {
+ return 0;
+ }
+ const [minValue, maxValue] = valueRange;
+ const posExtent = Math.abs(Math.max(maxValue, 0));
+ const negExtent = Math.abs(Math.min(minValue, 0));
+ const tot = posExtent + negExtent;
const perc1 = Math.round(
(Math.min(negExtent + value, negExtent) / tot) * 100,
);
- const perc2 = Math.round((Math.abs(value) / tot) * 100);
- // The 0.01 to 0.001 is a workaround for what appears to be a
- // CSS rendering bug on flat, transparent colors
- return (
- `linear-gradient(to right, rgba(0,0,0,0.01), rgba(0,0,0,0.001) ${perc1}%,
` +
- `rgba(${r},0,0,0.2) ${perc1}%, rgba(${r},0,0,0.2) ${perc1 + perc2}%, ` +
- `rgba(0,0,0,0.01) ${perc1 + perc2}%, rgba(0,0,0,0.001) 100%)`
- );
+ return perc1;
Review Comment:
It's a vestige of recycled code, but I liked the readability. You're right
though, returning the value is straightforward enough. Done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]