Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kildefelt lagt til highmaps part #2564

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/resources/site/content-types/highmap/highmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@
</input>
</items>
</field-set>

<field-set>
<label>Kilder</label>
<items>
<item-set name="sourceList">
<occurrences minimum="0" maximum="0"/>
<items>
<input name="sourceText" type="TextArea">
<label>Kildetekst</label>
<default>Statistisk sentralbyrå</default>
</input>
<input name="sourceHref" type="TextLine">
<label>Kilde-URL</label>
<default>https://www.ssb.no</default>
</input>
</items>
</item-set>
</items>
</field-set>

<field-set>
<label>Fotnoter</label>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/site/parts/highmap/Highmap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ function Highmap(props) {
},
}

function renderHighchartsSource(sourceLink, index) {
return (
<div key={index} className='mt-3'>
<a className='ssb-link stand-alone' href={sourceLink.sourceHref}>
{props.phrases.source}: {sourceLink.sourceText}
</a>
</div>
)
}

return (
<section className='xp-part highchart-wrapper'>
<Row>
Expand All @@ -176,6 +186,7 @@ function Highmap(props) {
{footnote && <Text>{footnote}</Text>}
</Col>
))}
{props.sourceList && props.sourceList.map(renderHighchartsSource)}
</Col>
</Row>
</section>
Expand All @@ -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,
Expand Down
93 changes: 44 additions & 49 deletions src/main/resources/site/parts/highmap/highmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapFeatures>
}

interface HighmapTable {
table: {
tbody: {
tr: Array<RowData>
}
}
}

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<HighmapFormattedTableData>
thresholdValues: Array<ThresholdValues>
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<XP.PartComponent.Highmap>()?.config
Expand Down Expand Up @@ -169,11 +121,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
Expand Down Expand Up @@ -256,3 +208,46 @@ function getDataClass(formattedThresholdValues: Array<number>): Array<ThresholdV

return dataClasses
}
interface MapFeatures {
properties: {
name?: string
capitalName?: string
}
}
interface MapResult {
features: Array<MapFeatures>
}
interface HighmapTable {
table: {
tbody: {
tr: Array<RowData>
}
}
}
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<HighmapFormattedTableData>
thresholdValues: Array<ThresholdValues>
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
}
Loading