MCPcopy Index your code
hub / github.com/chartbrew/chartbrew / SharedChart

Function SharedChart

client/src/containers/SharedChart.jsx:43–453  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41 This container is used for embedding charts in other websites
42*/
43function SharedChart() {
44 const [loading, setLoading] = useState(false);
45 const [chart, setChart] = useState({});
46 const [error, setError] = useState(false);
47 const [conditions, setConditions] = useState([]);
48 const [dataLoading, setDataLoading] = useState(false);
49 const [redraw, setRedraw] = useState(true);
50 const [isSnapshot, setIsSnapshot] = useState(false);
51 const [showChart, setShowChart] = useState(false);
52 const [exportLoading, setExportLoading] = useState(false);
53
54 const params = useParams();
55 const dispatch = useDispatch();
56 const { setTheme } = useTheme();
57 const [searchParams] = useSearchParams();
58 const filterRef = useRef(null);
59 const chartSize = useChartSize(chart?.layout);
60
61 useInterval(() => {
62 setDataLoading(true);
63
64 // Extract all query parameters to pass to the backend
65 const allQueryParams = {};
66 searchParams.forEach((value, key) => {
67 allQueryParams[key] = value;
68 });
69
70 // We pass all query parameters so the backend can process variables based on the share policy
71 dispatch(getSharedChart({
72 share_string: params.share_string,
73 token: searchParams.get("token"),
74 queryParams: allQueryParams
75 }))
76 .then((chart) => {
77 if (chart?.error) {
78 setError(true);
79 setChart({ error: "no chart" });
80 } else {
81 setChart(chart.payload);
82 }
83
84 setDataLoading(false);
85 })
86 .catch(() => {
87 setError(true);
88 setChart({ error: "no chart" });
89 setDataLoading(false);
90 });
91 }, chart?.autoUpdate > 0 && chart.autoUpdate < 600 ? chart.autoUpdate * 1000 : 600000);
92
93 useEffect(() => {
94 // change the background color to transparent
95 document.body.style.backgroundColor = "transparent";
96
97 const urlParams = new URLSearchParams(document.location.search);
98
99 setIsSnapshot(urlParams.has("isSnapshot"));
100

Callers

nothing calls this directly

Calls 7

useThemeFunction · 0.90
useChartSizeFunction · 0.85
_getUpdatedTimeFunction · 0.70
_checkIfFiltersFunction · 0.70
_onPublicExportFunction · 0.70
dispatchFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected