Skip to content

Commit

Permalink
Merge pull request #579 from Vizzuality/fix/new-nrc-fixes
Browse files Browse the repository at this point in the history
Fix/new-nrc-fixes
  • Loading branch information
anamontiaga authored Jan 13, 2023
2 parents 8467883 + 24c7dad commit 066b7e1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
26 changes: 15 additions & 11 deletions src/assets/icons/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/components/charts/area-chart/area-chart-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
YAxis,
Tooltip as RechartsTooltip,
ResponsiveContainer,
ReferenceDot,
Label,
} from 'recharts';

import styles from './area-chart-styles.module.scss';
Expand All @@ -23,6 +25,32 @@ function AreaChartComponent({
pdf = false,
}) {
const tickStroke = variant === 'light' ? 'white' : variant;
const labelColor = variant === 'light' ? 'white' : variant;

const lastData =
(area1.label || area2.label) && data && data[data.length - 1];

const renderLabel = (area) => {
const lastAreaY =
lastData && area.key && lastData[area.key] && lastData[area.key][0];
if (!lastAreaY && lastAreaY !== 0) return null;
return (
<ReferenceDot
y={lastAreaY}
x={2020}
stroke="transparent"
fill="transparent"
>
<Label
className={styles.label}
value={area.label}
position="insideTop"
offset={-5}
fill={labelColor}
/>
</ReferenceDot>
);
};

const renderAreaChart = () => (
<AreaChart
Expand Down Expand Up @@ -51,6 +79,7 @@ function AreaChartComponent({

<YAxis
axisLine={{ stroke: '#0F2B3B' }}
domain={[0, 100]}
fontSize={9}
tick={{ stroke: tickStroke, strokeWidth: 0.4 }}
tickCount={3}
Expand All @@ -71,6 +100,8 @@ function AreaChartComponent({
stroke={area1.stroke}
strokeWidth={area1.strokeWidth}
/>
{area1.label && renderLabel(area1)}
{area2.label && renderLabel(area2)}
<Area
type="monotone"
dataKey={area2.key}
Expand Down
11 changes: 11 additions & 0 deletions src/components/charts/area-chart/area-chart-styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
@import 'styles/settings';

.areaChart {
display: block;
position: relative;
margin: 0;
}

.label {
font-size: 10px;
text-anchor: end;
font-family: $font-family-1;

// Readjust text. TODO: Improve positioning
transform: translate(18px, 0);
}
6 changes: 4 additions & 2 deletions src/components/nrc-content/nrc-content-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ function NrcContent({
style={{
backgroundImage: getBarStyles(
COLORS['high-modification'],
65,
hm_vh,
COLORS['some-modification'],
70
hm
),
}}
/>
Expand Down Expand Up @@ -426,12 +426,14 @@ function NrcContent({
key: 'spi',
stroke: COLORS.white,
strokeWidth: 0.5,
label: 'SPI',
}}
area2={{
key: 'protected',
stroke: COLORS.white,
strokeWidth: 0.7,
strokeDasharray: '3 3 3 3',
label: '% Protected areas',
}}
data={land ? landData : marineData}
height={240}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ function NationalReportPdf({
style={{
backgroundImage: getBarStyles(
COLORS['high-modification'],
65,
hm_vh,
COLORS['some-modification'],
70
hm
),
}}
/>
Expand Down Expand Up @@ -285,12 +285,14 @@ function NationalReportPdf({
key: 'spi',
stroke: COLORS['dark-text'],
strokeWidth: 0.5,
label: 'SPI',
}}
area2={{
key: 'protected',
stroke: COLORS['dark-text'],
strokeWidth: 0.7,
strokeDasharray: '3 3 3 3',
label: '% Protected areas',
}}
data={selectedLandMarineOption.slug === 'land' ? landData : marineData}
variant="dark"
Expand Down

0 comments on commit 066b7e1

Please sign in to comment.