Skip to content

Commit

Permalink
Merge pull request #282 from gisce/feature/add_thousand_separator_gra…
Browse files Browse the repository at this point in the history
…phs_tooltip

Add thousand separator to graphs tooltip
  • Loading branch information
mguellsegarra authored Apr 14, 2023
2 parents abd4ca9 + cd1cd39 commit 92fa326
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/react-ooui",
"version": "1.1.36",
"version": "1.1.37",
"files": [
"dist",
"src",
Expand Down
19 changes: 19 additions & 0 deletions src/widgets/views/Graph/GraphDefaults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const formatter = (graphType: "pie" | "default" | "barGrouped") => {
return (object: any) => {
const formattedValue = object.value.toLocaleString("es-ES", {
useGrouping: true,
});
const name = graphType === "pie" ? object.x : object.type;
return { name, value: formattedValue };
};
};

const DefaultGraphOptions = {
default: {
padding: "auto",
Expand All @@ -8,6 +18,9 @@ const DefaultGraphOptions = {
maxWidthRatio: 0.5,
maxItemWidth: 1000,
},
tooltip: {
formatter: formatter("default"),
},
},
pie: {
appendPadding: 10,
Expand All @@ -25,6 +38,9 @@ const DefaultGraphOptions = {
maxWidthRatio: 0.5,
maxItemWidth: 1000,
},
tooltip: {
formatter: formatter("pie"),
},
interactions: [
{
type: "element-active",
Expand All @@ -37,6 +53,9 @@ const DefaultGraphOptions = {
maxWidthRatio: 0.5,
maxItemWidth: 1000,
},
tooltip: {
formatter: formatter("barGrouped"),
},
label: {
position: "middle",
layout: [
Expand Down
20 changes: 17 additions & 3 deletions src/widgets/views/Graph/GraphIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ function CommonIndicator({
? minFontSize
: height * fontGrowFactor;

let finalValue = total ? `${value}/${total}` : `${value}`;
const localeValue = value?.toLocaleString("es-ES", {
useGrouping: true,
});

let finalValue = total ? `${localeValue}/${total}` : `${localeValue}`;

if (suffix) {
finalValue += " " + suffix;
Expand Down Expand Up @@ -342,13 +346,23 @@ function PercentageIndicator({
? minFontSize
: twoLinesHeight * fontGrowFactor;

let finalValue = total ? `${value}/${total}` : `${value}`;
const localeValue = value?.toLocaleString("es-ES", {
useGrouping: true,
});

let finalValue = total
? `${localeValue}/${total?.toLocaleString("es-ES", {
useGrouping: true,
})}`
: `${localeValue}`;

if (suffix) {
finalValue += " " + suffix;
}

const percentValue = `${percent}%`;
const percentValue = `${percent?.toLocaleString("es-ES", {
useGrouping: true,
})}%`;

let tw = getTextWidth(
percentValue,
Expand Down

0 comments on commit 92fa326

Please sign in to comment.