When streamlit app is in dark mode, the tooltip of the nivo Pie chart displays white text on white background instead of black (or any discernible color) on white or white text on dark background.
- How to edit the tooltip?
- How to add a custom tooltip? (I saw How to create a custom tooltip to be used with Nivo charts · Issue #4 · okld/streamlit-gallery · GitHub but it’s still unanswered)
What I tried
- I tried to add a tooltip by examining the live nivo Pie chart react code but I couldn’t implement it. (look for tooltip/custom tooltip example)
- I tried using the CSS hack injected through
st.markdown()
but it doesn’t work in case of aniframe
, which is the case for streamlit-elements nivo pie chart, its not possible to reach the element by class or id to affect the text color.
Preview
Code
import streamlit as st
from streamlit_elements import elements, mui, html
from streamlit_elements import nivo
with elements("nivo_pie_chart"):
DATA = [
{ "id": "css", "label": "css", "value": 58, "color": "hsl(309, 70%, 50%)" },
{ "id": "php", "label": "php", "value": 582, "color": "hsl(229, 70%, 50%)" },
{ "id": "ruby", "label": "ruby", "value": 491, "color": "hsl(78, 70%, 50%)" },
{ "id": "scala", "label": "scala", "value": 254, "color": "hsl(278, 70%, 50%)" },
{ "id": "stylus", "label": "stylus", "value": 598, "color": "hsl(273, 70%, 50%)" }
]
with mui.Box(sx={"height": 500}):
nivo.Pie(
data=DATA,
margin={"top": 100, "right": 100, "bottom": 100, "left": 100},
innerRadius=0.5,
padAngle=0.7,
cornerRadius=3,
activeOuterRadiusOffset=8,
borderWidth=1,
borderColor={"from": "color", "modifiers": [["darker", 0.8]]},
arcLinkLabelsSkipAngle=10,
arcLinkLabelsTextColor="grey",
arcLinkLabelsThickness=2,
arcLinkLabelsColor={"from": "color"},
arcLabelsSkipAngle=10,
arcLabelsTextColor={"from": "color", "modifiers": [["darker", 4]]},
defs=[
{
"id": "dots",
"type": "patternDots",
"background": "inherit",
"color": "rgba(255, 255, 255, 0.3)",
"size": 4,
"padding": 1,
"stagger": True,
},
{
"id": "lines",
"type": "patternLines",
"background": "inherit",
"color": "rgba(255, 255, 255, 0.3)",
"rotation": -45,
"lineWidth": 6,
"spacing": 10,
},
],
fill=[
{"match": {"id": "ruby"}, "id": "dots"},
{"match": {"id": "php"}, "id": "dots"},
{"match": {"id": "scala"}, "id": "lines"},
{"match": {"id": "css"}, "id": "dots"},
{"match": {"id": "stylus"}, "id": "lines"},
],
legends=[
{
"anchor": "bottom",
"direction": "row",
"justify": False,
"translateX": 0,
"translateY": 56,
"itemsSpacing": 0,
"itemWidth": 100,
"itemHeight": 18,
"itemTextColor": "#999",
"itemDirection": "left-to-right",
"itemOpacity": 1,
"symbolSize": 18,
"symbolShape": "circle",
"effects": [
{"on": "hover", "style": {"itemTextColor": "#000"}}
],
}
],
)
Config
- Streamlit 1.27.2
- Streamlit-elements 0.1.0
- Python 3.10.2