apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.91k stars 13.91k forks source link

[SIP] Proposal for HTML rendering in summary cells #30986

Open BaurArabov opened 2 days ago

BaurArabov commented 2 days ago

[SIP] Proposal for HTML rendering

Motivation

In Apache Superset, the ability to provide visually appealing and informative summaries is crucial for effective data visualization. The current implementation does not support HTML rendering in summary cells, which limits the ability to convey complex visual information. For instance, when summarizing a column that consists of custom div elements for percentage representation, the output is rendered as plain text, losing the intended visual context.

Proposed Change

The proposed change involves modifying the rendering logic for summary cells to allow HTML content.

path: superset-frontend\plugins\plugin-chart-table\src\TableChart.tsx

<td style={sharedStyle}>
  <strong dangerouslySetInnerHTML={{ __html: formatColumnValue(column, totals[key])[1] }} />
</td>

image

This change enables the summary cell to render HTML directly, allowing for the inclusion of styled elements that visually represent data. For example, if a column contains a div structure representing a percentage filled with color, this modification will ensure that the summary displays not just the numerical value but also retains the visual cues associated with it.

New or Changed Public Interfaces

This SIP introduces a new behavior in how summary cells are rendered within tables in Superset. The key changes include:

Result

Before: image

After: image

I recognize that there may be other approaches to achieve similar outcomes without modifying the core frontend code. If anyone has alternative methods or suggestions, please feel free to share your insights.