From 992fa850e976e0ea22c4e5c96c747f2c140a684b Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:26:56 +0100 Subject: [PATCH 1/3] kildefelt lagt til highmaps part --- .../site/content-types/highmap/highmap.xml | 19 ++++ .../resources/site/parts/highmap/Highmap.jsx | 14 ++- .../resources/site/parts/highmap/highmap.ts | 103 +++++++++--------- 3 files changed, 85 insertions(+), 51 deletions(-) diff --git a/src/main/resources/site/content-types/highmap/highmap.xml b/src/main/resources/site/content-types/highmap/highmap.xml index 0c801e977..54d247a8a 100644 --- a/src/main/resources/site/content-types/highmap/highmap.xml +++ b/src/main/resources/site/content-types/highmap/highmap.xml @@ -103,6 +103,25 @@ + + + + + + + + + + Statistisk sentralbyrå + + + + https://www.ssb.no + + + + + diff --git a/src/main/resources/site/parts/highmap/Highmap.jsx b/src/main/resources/site/parts/highmap/Highmap.jsx index 68962b00c..1014fb850 100644 --- a/src/main/resources/site/parts/highmap/Highmap.jsx +++ b/src/main/resources/site/parts/highmap/Highmap.jsx @@ -49,7 +49,7 @@ function Highmap(props) { fontSize: '14px', fontWeight: 'normal', fontFamily: '"Open Sans Regular", "Arial", "DejaVu Sans", sans-serif', - } + }, }, accessibility: { enabled: true, @@ -161,6 +161,16 @@ function Highmap(props) { }, } + function renderHighchartsSource(sourceLink, index) { + return ( +
+ + {props.phrases.source}: {sourceLink.sourceText} + +
+ ) + } + return (
@@ -176,6 +186,7 @@ function Highmap(props) { {footnote && {footnote}} ))} + {props.sourceList && props.sourceList.map(renderHighchartsSource)}
@@ -197,6 +208,7 @@ Highmap.propTypes = { seriesTitle: PropTypes.string, legendTitle: PropTypes.string, legendAlign: PropTypes.string, + sourceList: PropTypes.array, footnoteText: PropTypes.array, phrases: PropTypes.object, language: PropTypes.string, diff --git a/src/main/resources/site/parts/highmap/highmap.ts b/src/main/resources/site/parts/highmap/highmap.ts index b55860c36..a07824a17 100644 --- a/src/main/resources/site/parts/highmap/highmap.ts +++ b/src/main/resources/site/parts/highmap/highmap.ts @@ -14,54 +14,6 @@ import { type Highmap } from '/site/content-types' const xmlParser: XmlParser = __.newBean('no.ssb.xp.xmlparser.XmlParser') -interface MapFeatures { - properties: { - name?: string - capitalName?: string - } -} - -interface MapResult { - features: Array -} - -interface HighmapTable { - table: { - tbody: { - tr: Array - } - } -} - -interface HighmapFormattedTableData { - capitalName: string - value: number -} - -interface ThresholdValues { - to: number | undefined - from: number | undefined -} - -interface HighmapProps { - title: string - subtitle: Highmap['subtitle'] - description: Highmap['description'] - mapFile: object - tableData: Array - thresholdValues: Array - hideTitle: Highmap['hideTitle'] - colorPalette: Highmap['colorPalette'] - numberDecimals: number | undefined - heightAspectRatio: Highmap['heightAspectRatio'] - seriesTitle: Highmap['seriesTitle'] - legendTitle: Highmap['legendTitle'] - legendAlign: Highmap['legendAlign'] - footnoteText: Highmap['footnoteText'] - phrases: Phrases | undefined - language: string | undefined -} - export function get(req: XP.Request): XP.Response { try { const config = getComponent()?.config @@ -106,6 +58,7 @@ function renderPart(req: XP.Request, highmapId: string | undefined): XP.Response }) : null + const mapFile: Content | null = highmapContent && highmapContent.data.mapFile ? getContentByKey({ @@ -155,6 +108,8 @@ function renderPart(req: XP.Request, highmapId: string | undefined): XP.Response ? util.data.forceArray(highmapContent.data.thresholdValues) : [] + + const props: HighmapProps = { title: highmapContent.displayName, subtitle: highmapContent.data.subtitle, @@ -169,12 +124,11 @@ function renderPart(req: XP.Request, highmapId: string | undefined): XP.Response seriesTitle: highmapContent.data.seriesTitle, legendTitle: highmapContent.data.legendTitle, legendAlign: highmapContent.data.legendAlign, + sourceList: highmapContent.data.sourceList ? util.data.forceArray(highmapContent.data.sourceList) : undefined, footnoteText: highmapContent.data.footnoteText ? util.data.forceArray(highmapContent.data.footnoteText) : [], phrases: getPhrases(page), language: page.language, } - - // R4xp disables hydration in edit mode, but highmap need hydration to show // we sneaky swap mode since we want a render of highmap in edit mode // Works good for highmap macro, not so much when part @@ -257,3 +211,52 @@ function getDataClass(formattedThresholdValues: Array): Array +} + +interface HighmapTable { + table: { + tbody: { + tr: Array + } + } +} + +interface HighmapFormattedTableData { + capitalName: string + value: number +} + +interface ThresholdValues { + to: number | undefined + from: number | undefined +} + +interface HighmapProps { + title: string + subtitle: Highmap['subtitle'] + description: Highmap['description'] + mapFile: object + tableData: Array + thresholdValues: Array + hideTitle: Highmap['hideTitle'] + colorPalette: Highmap['colorPalette'] + numberDecimals: number | undefined + heightAspectRatio: Highmap['heightAspectRatio'] + seriesTitle: Highmap['seriesTitle'] + legendTitle: Highmap['legendTitle'] + legendAlign: Highmap['legendAlign'] + sourceList?: Highmap['sourceList'] + footnoteText: Highmap['footnoteText'] + phrases: Phrases | undefined + language: string | undefined +} From ce1f6790fa140a5451f22457efae5835ec52edd1 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:52:53 +0100 Subject: [PATCH 2/3] highmap.ts spaces clean-up --- src/main/resources/site/parts/highmap/highmap.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/resources/site/parts/highmap/highmap.ts b/src/main/resources/site/parts/highmap/highmap.ts index a07824a17..6d79d5a4b 100644 --- a/src/main/resources/site/parts/highmap/highmap.ts +++ b/src/main/resources/site/parts/highmap/highmap.ts @@ -58,7 +58,6 @@ function renderPart(req: XP.Request, highmapId: string | undefined): XP.Response }) : null - const mapFile: Content | null = highmapContent && highmapContent.data.mapFile ? getContentByKey({ @@ -108,8 +107,6 @@ function renderPart(req: XP.Request, highmapId: string | undefined): XP.Response ? util.data.forceArray(highmapContent.data.thresholdValues) : [] - - const props: HighmapProps = { title: highmapContent.displayName, subtitle: highmapContent.data.subtitle, @@ -211,18 +208,15 @@ function getDataClass(formattedThresholdValues: Array): Array } - interface HighmapTable { table: { tbody: { @@ -230,17 +224,14 @@ interface HighmapTable { } } } - interface HighmapFormattedTableData { capitalName: string value: number } - interface ThresholdValues { to: number | undefined from: number | undefined } - interface HighmapProps { title: string subtitle: Highmap['subtitle'] From 48ea300fe016b941090df25836c3810142f1b820 Mon Sep 17 00:00:00 2001 From: Carl-OW <142233642+Carl-OW@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:52:30 +0100 Subject: [PATCH 3/3] Changed a to Link --- src/main/resources/site/parts/highmap/Highmap.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/site/parts/highmap/Highmap.jsx b/src/main/resources/site/parts/highmap/Highmap.jsx index 1014fb850..629b03486 100644 --- a/src/main/resources/site/parts/highmap/Highmap.jsx +++ b/src/main/resources/site/parts/highmap/Highmap.jsx @@ -2,7 +2,7 @@ import React, { useEffect } from 'react' import Highcharts from 'highcharts' import HighchartsReact from 'highcharts-react-official' import PropTypes from 'prop-types' -import { Text } from '@statisticsnorway/ssb-component-library' +import { Link, Text } from '@statisticsnorway/ssb-component-library' import { Col, Row } from 'react-bootstrap' import { useMediaQuery } from 'react-responsive' @@ -164,9 +164,9 @@ function Highmap(props) { function renderHighchartsSource(sourceLink, index) { return ( ) }