Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3049c75
Optional toggle for showing last updated info based on content dimens…
sakari-malkki Oct 28, 2025
e6f09b8
Add test coverage, fix sonar complaint about too many parameters
sakari-malkki Oct 28, 2025
c34e91c
Assume GB English locale for date formatting if not explicitly stated…
sakari-malkki Oct 28, 2025
7aab6fc
Correct minor version raise, handle chart spacing and credits text po…
sakari-malkki Oct 28, 2025
9318e51
Update snapshots
sakari-malkki Oct 28, 2025
0d19c41
Update src/core/conversion/viewUtils.ts
sakari-malkki Oct 28, 2025
20e4a5f
Update src/core/highcharts/drawChart.ts
sakari-malkki Oct 28, 2025
3bb085c
Update src/react/components/chart/chart.test.tsx
sakari-malkki Oct 28, 2025
9d16ac9
Fix inconsistent indentation
sakari-malkki Oct 28, 2025
99d7caf
Copilot nitpick fix
sakari-malkki Oct 28, 2025
9580ed8
Fix undefined return type for getLastUpdate function
sakari-malkki Oct 28, 2025
833efbc
Combine tableOptions and chartOptions. Fix some indentations
sakari-malkki Oct 29, 2025
010d57d
Builds date objects before comparison
sakari-malkki Oct 29, 2025
dabe2c2
Merge pull request #125 from StatisticsFinland/feature/lastupdated
sakari-malkki Oct 29, 2025
cd5c75e
Rename showTitle parameter back to showTitles to fix discrepancy betw…
sakari-malkki Oct 31, 2025
bc87f05
Merge pull request #128 from StatisticsFinland/bugfix/chart-parameter…
sakari-malkki Nov 3, 2025
47bb054
Merge pull request #127 from StatisticsFinland/dev
sakari-malkki Nov 3, 2025
6ac4df4
Replaces credits field with more responsive caption field
sakari-malkki Nov 5, 2025
1cda828
Move html table title out of the table caption to a separate element
sakari-malkki Nov 5, 2025
b393f22
Adjust burgermenu and chart container padding based on visualization …
sakari-malkki Nov 6, 2025
6f62f9d
Added test coverage
sakari-malkki Nov 6, 2025
2d0bf40
Copilot feedback fixes
sakari-malkki Nov 6, 2025
e0a7bf8
Merge pull request #129 from StatisticsFinland/bugfix/fix-credits-field
sakari-malkki Nov 7, 2025
fcaf93c
Merge pull request #130 from StatisticsFinland/bugfix/fix-table-title
sakari-malkki Nov 7, 2025
f97fb62
Merge pull request #132 from StatisticsFinland/dev
sakari-malkki Nov 7, 2025
f86407d
Update changelog to reflect recent changes
sakari-malkki Nov 10, 2025
f0fd4fa
Update Changelog.md
sakari-malkki Nov 10, 2025
65e05f1
Merge pull request #134 from StatisticsFinland/feature/changelog-update
sakari-malkki Nov 10, 2025
2cbb9a6
Merge pull request #135 from StatisticsFinland/dev
sakari-malkki Nov 10, 2025
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
36 changes: 34 additions & 2 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,43 @@ const preview: Preview = {
name: 'Website',
styles: {
width: '766px',
height: '600px',
height: '635px',
},
type: 'desktop',
},
small: {
name: 'Small screen',
styles: {
width: '383px',
height: '300px',
},
type: 'desktop',
},
large: {
name: 'Large screen',
styles: {
width: '1150px',
height: '900px'
},
type: 'desktop',
},
},
mobile: {
name: 'Mobile',
styles: {
width: '540px',
height: '960px',
},
type: 'mobile',
},
tablet: {
name: 'Tablet',
styles: {
width: '900px',
height: '600px',
},
type: 'tablet',
},
}
},
},
tags: ['autodocs']
Expand Down
9 changes: 8 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
v1.3.0 (24 September 2025):
- <Chart> component optional property 'showTableTitles' renamed to 'showTitles' as it now applies to both chart and table titles. Default value is true.
- Chart component optional property 'showTableTitles' renamed to 'showTitles' as it now applies to both chart and table titles. Default value is true.

v1.4.0 (10 November 2025):
- Chart component's optional properties' default values updated:
- 'showTitles' default changed to true.
- 'showSources' default changed to true.
- NEW: showLastUpdated defaults to false.
- Chart component's new optional property 'showLastUpdated' (boolean) added to control the visibility of the last updated information above the source information.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statisticsfinland/pxvisualizer",
"version": "1.3.2",
"version": "1.4.0",
"description": "Component library for visualizing PxGraf data",
"main": "./dist/pxv.cjs",
"jestSonar": {
Expand Down
29 changes: 28 additions & 1 deletion src/core/chartOptions/Utility/formatters.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataLabelsOptions, Point, Tooltip } from "highcharts";
import { formatLocale, getDataFormattedForChartType, getDataLabelFormatterFunction, getLineChartToolTipFormatterFunction, getToolTipFormatterFunction, parseScreenReaderFriendlyTimePeriods, shortenStringValue } from "./formatters";
import { formatLocale, getDataFormattedForChartType, getDataLabelFormatterFunction, getLineChartToolTipFormatterFunction, getToolTipFormatterFunction, parseScreenReaderFriendlyTimePeriods, shortenStringValue, getFormattedLastUpdatedText } from "./formatters";
import { combinationValuesLinechartViewFixture, multiselectableLineChartViewFixture, simpleQuarterLinechartViewFixture } from "./fixtures/linechartViews";
import { simpleHorizontalBarchartViewFixture } from "./fixtures/horizontalbarchartViews";
import { simpleGroupHorizontalBarchartViewFixture } from "./fixtures/grouphorizontalbarchartViews";
Expand Down Expand Up @@ -421,4 +421,31 @@ describe('getDataFormattedForChartType tests', () => {
const result: string = getDataFormattedForChartType(view, point, 'en', 2);
expect(result).toBe('12.0% (123.46 kg)');
});
});

describe('getFormattedLastUpdatedText tests', () => {
it('should format last updated text correctly for Finnish locale', () => {
const result = getFormattedLastUpdatedText('2025-09-23', 'fi');
expect(result).toBe('Päivitetty: 23.9.2025');
});

it('should format last updated text correctly for Swedish locale', () => {
const result = getFormattedLastUpdatedText('2025-09-23', 'sv');
expect(result).toBe('Uppdaterad: 2025-09-23');
});

it('should format last updated text correctly for English locale to British English', () => {
const result = getFormattedLastUpdatedText('2025-09-23', 'en');
expect(result).toBe('Updated: 23/09/2025');
});

it('should return undefined for undefined input', () => {
const result = getFormattedLastUpdatedText(undefined, 'fi');
expect(result).toBeUndefined();
});

it('should return undefined for invalid date', () => {
const result = getFormattedLastUpdatedText('invalid-date', 'fi');
expect(result).toBeUndefined();
});
});
23 changes: 23 additions & 0 deletions src/core/chartOptions/Utility/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,27 @@ function parsePlacementSuffix(value: string, locale: string) {
} else {
return `${value}.`;
}
}

/**
* Formats the last updated text based on the provided date string and locale.
* @param lastUpdated Date string representing the last updated date.
* @param locale Locale string for formatting the date.
* @returns Formatted last updated text or undefined if input is invalid.
*/
export function getFormattedLastUpdatedText(lastUpdated: string | undefined, locale: string): string | undefined {
if (!lastUpdated) return undefined;

try {
const date = new Date(lastUpdated);
if (Number.isNaN(date.getTime())) return undefined;

const dateLocale = locale === 'en' ? 'en-GB' : locale; // Use en-GB for English to get DD/MM/YYYY format if not specified
const formattedDate: string = Intl.DateTimeFormat(dateLocale).format(date);

return `${Translations.lastUpdated[locale]}: ${formattedDate}`;
} catch (error) {
console.error('Error formatting date:', error);
return undefined;
}
}
26 changes: 21 additions & 5 deletions src/core/chartOptions/chartOptions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import { LegendOptions, Options, PlotSeriesDataLabelsOptions, YAxisOptions } from 'highcharts';
import { View } from "../types/view";
import { getAxisLabelShorteningFunction, getFormattedUnits, getToolTipFormatterFunction, getScreenReaderFormatterCallbackFunction, getDataLabelFormatterFunction } from './Utility/formatters';
import { Translations } from '../conversion/translations';
import { getAxisLabelShorteningFunction, getFormattedUnits, getToolTipFormatterFunction, getScreenReaderFormatterCallbackFunction, getDataLabelFormatterFunction, getFormattedLastUpdatedText } from './Utility/formatters';
import { getXAxisOptions } from './Utility/timeIntervals';
import { getLinearAxisTickPositionerFunction } from './Utility/tickPositioners';
import { IChartOptions } from '../types/chartOptions';
import { buildBarChartSeries, buildColumnChartSeries } from './Utility/seriesDataBuilder';
import { Translations } from "../conversion/translations";

export const commonChartOptions = (view: View, locale: string, options?: IChartOptions): Options => {
const showTitle: boolean = options?.showTitle ?? true;
const showTitles: boolean = options?.showTitles ?? true;

const sourceText = Translations.source[locale];
let creditsText = `${sourceText}: ${view.sources.map(s => s[locale]).join(', ')}`;
const hasLastUpdated = options?.showLastUpdated && view.lastUpdated;

if (hasLastUpdated) {
const lastUpdatedText = getFormattedLastUpdatedText(view.lastUpdated, locale);
if (lastUpdatedText) {
creditsText = `${lastUpdatedText}<br>${sourceText}: ${view.sources.map(s => s[locale]).join(', ')}`;
}
}

return {
chart: {
spacingBottom: hasLastUpdated ? 50 : 30 // Conditional spacing based on lastUpdated presence
},
accessibility: {
point: {
descriptionFormatter: getScreenReaderFormatterCallbackFunction(view, locale)
}
},
title: { text: showTitle ? view.header[locale] : undefined },
title: { text: showTitles ? view.header[locale] : undefined },
subtitle: { text: view.subheaderValues.map(sv => sv[locale]).join(' | ') },
credits: { text: `${Translations.source[locale]}: ${view.sources.map(s => s[locale]).join(', ')}` },
credits: { enabled: false },
caption: { text: creditsText },
tooltip: {
formatter: getToolTipFormatterFunction(view, locale)
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/chartOptions/pieChartOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { buildPatternObject } from './Utility/patternFill';

export const pieChartOptions = (view: View, locale: string, options?: IChartOptions): Options => {
return {
...commonChartOptions(view, locale),
...commonChartOptions(view, locale, options),
chart: { type: 'pie' },
plotOptions: {
pie: {
Expand Down
2 changes: 2 additions & 0 deletions src/core/conversion/fixtures/percentHorizontalBarChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const PERCENT_HORIZONTAL_BAR_CHART_VIEW: View = {
"sv": "Antal, Enrumslägenhet 2022Q4 efter Område, Finansieringssätt",
"en": "Number, One-room flat 2022Q4 by Region, Type of funding"
},
lastUpdated: "2023-01-19T06:00:00Z",
subheaderValues: [],
units: [
{
Expand Down Expand Up @@ -595,6 +596,7 @@ export const PERCENT_HORIZONTAL_BAR_CHART_WITH_SELECTABLES_VIEW: View = {
"sv": "Antal 2022Q4 efter Område, Antal rum, Finansieringssätt",
"en": "Number 2022Q4 by Region, Number of rooms, Type of funding"
},
"lastUpdated": "2023-01-19T06:00:00Z",
subheaderValues: [
{
"fi": "Kaksiot",
Expand Down
3 changes: 3 additions & 0 deletions src/core/conversion/fixtures/percentVerticalBarChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export const PERCENT_VERTICAL_BAR_CHART_VIEW: View = {
"sv": "Antal, Helsingfors, Fri finansierad 2021Q2-2022Q4 efter Antal rum",
"en": "Number, Helsinki, Non subsidised 2021Q2-2022Q4 by Number of rooms"
},
lastUpdated: "2023-01-19T06:00:00Z",
subheaderValues: [],
units: [{
name: {
Expand Down Expand Up @@ -843,6 +844,7 @@ export const PERCENT_VERTICAL_BAR_CHART_WITH_SELECTABLES_VIEW: View = {
"sv": "Antal 2021Q4 efter Område, Antal rum, Finansieringssätt",
"en": "Number 2021Q4 by Region, Number of rooms, Type of funding"
},
lastUpdated: "2023-01-19T06:00:00Z",
subheaderValues: [
{
"fi": "2022Q1",
Expand Down Expand Up @@ -1241,6 +1243,7 @@ export const PERCENT_VERTICAL_BAR_CHART_PIVOTED_WITH_SELECTABLES_VIEW: View = {
"sv": "Antal 2022Q4 efter Område, Antal rum, Finansieringssätt",
"en": "Number 2022Q4 by Region, Number of rooms, Type of funding"
},
lastUpdated: "2023-01-19T06:00:00Z",
subheaderValues: [
{
"fi": "Vapaarahoitteinen",
Expand Down
Loading