import React from "react"; import { Trans, useTranslation } from "react-i18next"; import { ClassTable, Collapse, ReportError, ResultsCard, SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, Metric, MetricGroup, ReportResult, SketchProperties, flattenBySketchAllClass, metricsWithSketchId, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; /** * OverlapCard component * * @param props - geographyId * @returns A react component which displays an overlap report */ export const OverlapCard: React.FunctionComponent = (props) => { const { t } = useTranslation(); const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); // Metrics const metricGroup = project.getMetricGroup("overlapFunction", t); const precalcMetrics = project.getPrecalcMetrics( metricGroup, "sum", curGeography.geographyId, ); // Labels const titleLabel = t("OverlapCard"); const mapLabel = t("Map"); const withinLabel = t("Within Plan"); const percWithinLabel = t("% Within Plan"); const unitsLabel = t("units"); return ( {(data: ReportResult) => { const percMetricIdName = `${metricGroup.metricId}Perc`; const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, }); const metrics = [...valueMetrics, ...percentMetrics]; const objectives = (() => { const objectives = project.getMetricGroupObjectives(metricGroup, t); if (objectives.length) { return objectives; } else { return; } })(); return (

This report summarizes this plan's overlap with the data.

{isCollection && childProperties && ( {genSketchTable( data, metricGroup, precalcMetrics, childProperties, )} )}

â„šī¸ Overview:

đŸŽ¯ Planning Objective:

đŸ—ēī¸ Source Data:

📈 Report: This report calculates the total value of each feature within the plan. This value is divided by the total value of each feature to obtain the % contained within the plan. If the plan includes multiple areas that overlap, the overlap is only counted once.

); }}
); }; const genSketchTable = ( data: ReportResult, metricGroup: MetricGroup, precalcMetrics: Metric[], childProperties: SketchProperties[], ) => { const childSketchIds = childProperties ? childProperties.map((skp) => skp.id) : []; // Build agg metric objects for each child sketch in collection with percValue for each class const childSketchMetrics = toPercentMetric( metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), childSketchIds, ), precalcMetrics, ); const sketchRows = flattenBySketchAllClass( childSketchMetrics, metricGroup.classes, childProperties, ); return ( ); };