) {
const search = queryString.parse(location.search);
for (const key in args) {
search[key] = args[key];
}
location.search = queryString.stringify(search);
navigate(location);
}
/**
* Called when the user clicks an individual box in the chart.
* Updates the browser URL.
*/
function onSelection(selection: IndiInfo) {
// Don't allow selecting WikiTree private profiles.
if (selection.id.startsWith(PRIVATE_ID_PREFIX)) {
return;
}
analyticsEvent('selection_changed');
updateUrl({
indi: selection.id,
gen: String(selection.generation),
});
}
/**
* Called when the user shift+clicks an individual box in the chart.
* Shows the individual in the details pane.
*/
function onDetailSelection(selection: IndiInfo) {
setDetailIndi(selection.id);
}
function onPrint() {
analyticsEvent('print');
printChart();
}
function displayErrorPopup(message: string) {
setShowErrorPopup(true);
setError(message);
}
async function onDownloadPdf() {
analyticsEvent('download_pdf');
try {
await downloadPdf();
} catch (e) {
displayErrorPopup(
intl.formatMessage({
id: 'error.failed_pdf',
defaultMessage:
'Failed to generate PDF file.' +
' Please try with a smaller diagram or download an SVG file.',
}),
);
}
}
async function onDownloadPng() {
analyticsEvent('download_png');
try {
await downloadPng();
} catch (e) {
displayErrorPopup(
intl.formatMessage({
id: 'error.failed_png',
defaultMessage:
'Failed to generate PNG file.' +
' Please try with a smaller diagram or download an SVG file.',
}),
);
}
}
function onDownloadSvg() {
analyticsEvent('download_svg');
downloadSvg();
}
function onDismissErrorPopup() {
setShowErrorPopup(false);
}
function renderChart(selection: IndiInfo) {
if (!data) {
return null;
}
if (chartType === ChartType.Donatso) {
return (
);
}
return (
);
}
function renderMainArea() {
switch (state) {
case AppState.SHOWING_CHART:
case AppState.LOADING_MORE: {
if (!data) {
return null;
}
const updatedSelection = getSelection(data.chartData, selection);
return (
{state === AppState.LOADING_MORE ? (
) : null}
{
setConfig(config);
updateChartWithConfig(config, data);
updateUrl(configToArgs(config));
}}
/>
{renderChart(updatedSelection)}
);
}
case AppState.ERROR:
return ;
case AppState.INITIAL:
case AppState.LOADING:
return ;
}
}
return (
<>
{staticUrl ? (
} />
) : (
} />
} />
)}
>
);
}