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

Add support for big number in the card and chart components #85

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b407083
fix: update valueOrPercentage function to operate with GxBigNumber
OrlandoP97 May 2, 2024
9d2b48c
make some experimental changes
OrlandoP97 May 2, 2024
62383d1
fix errors operating with bigNumbers
OrlandoP97 May 2, 2024
c409144
chore: Update @genexus/web-standard-functions dependency to version ^…
OrlandoP97 May 3, 2024
c127fed
Merge remote-tracking branch 'upstream/main' into feature/gxBigNumber
OrlandoP97 May 3, 2024
5e29cd9
use commonJS for @genexus/web-standar-functions imports, card-utils v…
OrlandoP97 May 3, 2024
6b97cee
test: valueOrPercentage test functions with long decimal values
OrlandoP97 May 3, 2024
fd57f77
test: pass the big number with decimals as strings in valueOrPercenta…
OrlandoP97 May 3, 2024
214a9f5
labels/tooltips
ehrivero May 8, 2024
8ec9519
Merge pull request #1 from ehrivero/chart
OrlandoP97 May 13, 2024
15022ce
pass right number through label
OrlandoP97 May 13, 2024
87758d6
Merge branch 'feature/gxBigNumber' of https://github.com/OrlandoP97/r…
OrlandoP97 May 13, 2024
4caf10c
make quantityValues a gxBigNumber
OrlandoP97 May 15, 2024
e52a41c
fix error with timeline tooltip
OrlandoP97 May 15, 2024
0b6a4ef
add condition to fix console error
OrlandoP97 May 22, 2024
c1c8485
Create tests for functions affected by changes
OrlandoP97 May 30, 2024
3fe31b4
Merge branch 'main' into feature/gxBigNumber
OrlandoP97 Jun 3, 2024
af78794
chore: Update npm dependencies for @genexus/web-controls-library and …
OrlandoP97 Jun 3, 2024
861ce6c
support bigNumbers in card when isFormula
OrlandoP97 Jun 4, 2024
949c278
Merge branch 'main' into feature/gxBigNumber
OrlandoP97 Jun 4, 2024
d905d37
fix calculate function to respect operations order, test when is formula
OrlandoP97 Jun 5, 2024
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
}
}
58 changes: 58 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"dependencies": {
"@genexus/reporting-api": "~3.1.0",
"@genexus/web-controls-library": "2.3.0",
"@genexus/web-standard-functions": "file:///C:/PROJECTS/genexus/web-standard-functions/dist/lib-esm",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a peer dependency to not force the version in this repo. Also, this should point to @genexus/web-standard-functions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I did this because I understood that could be necesary to modify some web-standard-function code before start working, but actually it wasn't so I will remove that. Thanks!

"date-fns": "^2.30.0",
"highcharts": "^11.1.0",
"jquery": "^3.7.1",
Expand Down
14 changes: 10 additions & 4 deletions src/components/query-viewer-card/controller/card-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
QueryViewerTrendPeriod
} from "@genexus/reporting-api";
import { fromDateToString, fromStringToDateISO } from "../../../utils/date";
import { GxBigNumber } from "@genexus/web-standard-functions/types/gxbignumber";
import { divide } from "@genexus/web-standard-functions/math/divide";
import { toStringBigNumber } from "@genexus/web-standard-functions/bigNumber/toString";
import { multiply } from "@genexus/web-standard-functions/math/multiply";

export type RegressionSeries = {
LinearRegression: {
Expand Down Expand Up @@ -302,13 +306,15 @@ const showDataAsMapping: {
// @todo Complete the implementation of this function by comparing it to the Web implementation
export function valueOrPercentage(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[valueOrPercentage] It would be nice to add some tests using this utility with different values to validates the new behavior.

showDataAs: QueryViewerShowDataAs,
value: number,
value: GxBigNumber,
datum: QueryViewerServiceMetaDataData
) {
const percentage = (value * 100) / datum.targetValue;
const multiplication = multiply(value, 100);
const percentage = divide(multiplication, datum.targetValue);

return showDataAsMapping[showDataAs]({
value: value.toFixed(2),
percentage: percentage.toFixed(2) + "%"
value: toStringBigNumber(value, new GxBigNumber(), new GxBigNumber()),
percentage:
toStringBigNumber(percentage, new GxBigNumber(), new GxBigNumber()) + "%"
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "@genexus/reporting-api";
import { aggregateData } from "../../../utils/general";
import { analyzeSeries, valueOrPercentage } from "./card-utils";
import { GxBigNumber } from "@genexus/web-standard-functions/types/gxbignumber";

type CardInformation = {
title: string;
Expand Down Expand Up @@ -225,7 +226,7 @@ export class QueryViewerCard {

cardInformation["value"] = valueOrPercentage(
this.showDataAs,
parseFloat(lastRow[datum.dataField]),
new GxBigNumber(lastRow[datum.dataField]),
datum
);

Expand Down Expand Up @@ -279,14 +280,14 @@ export class QueryViewerCard {
// MinValue @todo Update the implementation of the minValue using the Web implementation
cardInformation["minValue"] = valueOrPercentage(
this.showDataAs,
data.MinValue,
new GxBigNumber(data.MinValue),
datum
);

// MaxValue @todo Update the implementation of the maxValue using the Web implementation
cardInformation["maxValue"] = valueOrPercentage(
this.showDataAs,
data.MaxValue,
new GxBigNumber(data.MaxValue),
datum
);
}
Expand Down
18 changes: 13 additions & 5 deletions src/components/query-viewer-chart/controller/highcharts-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import {
PaneOptions,
PlotOptions,
PointMarkerOptionsObject,
SeriesLineOptions
SeriesLineOptions,
// ExtremesObject,
// SeriesLineOptions
,
SeriesOptionsType,
SubtitleOptions,
TooltipFormatterContextObject,
Expand Down Expand Up @@ -53,6 +52,7 @@ import {
getChartGroup
} from "./chart-utils";
import { ChartMetadataAndData, XAxisDataType } from "./processDataAndMetadata";
import { GxBigNumber } from "@genexus/web-standard-functions/types/gxbignumber";

const DEFAULT_CHART_SPACING = 10;
export const HOURS_PER_DAY = 24;
Expand Down Expand Up @@ -1524,7 +1524,7 @@ function groupPoints(
dateStr: null,
name: null
};
let pointAdd: { x: string; y: number; name: string };
let pointAdd: { x: string; y: GxBigNumber; name: string };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[groupPoints] It would be nice to add some tests using this utility with different values to validates the new behavior.

let currentYValues: number[] = [];
let currentYQuantities: number[] = [];
const points = [];
Expand Down Expand Up @@ -1566,7 +1566,11 @@ function groupPoints(
} else {
pointAdd = {
x: lastStartPoint.dateStr,
y: aggregate(aggregation, currentYValues, currentYQuantities),
y: aggregate(
aggregation,
currentYValues.map(value => new GxBigNumber(value)),
currentYQuantities
),
name: lastStartPoint.name
};
points.push(pointAdd);
Expand All @@ -1578,7 +1582,11 @@ function groupPoints(
if (currentYValues.length > 0 && currentYQuantities.length > 0) {
pointAdd = {
x: lastStartPoint.dateStr,
y: aggregate(aggregation, currentYValues, currentYQuantities),
y: aggregate(
aggregation,
currentYValues.map(value => new GxBigNumber(value)),
currentYQuantities
),
name: lastStartPoint.name
};
points.push(pointAdd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
parseNumericPicture
} from "../../../utils/general";
import { ChartTypes, IS_CHART_TYPE, isDatetimeXAxis } from "./chart-types";
import { GxBigNumber } from "@genexus/web-standard-functions/types/gxbignumber";

export type ChartMetadataAndData = {
Categories: QueryViewerChartCategories;
Expand Down Expand Up @@ -512,7 +513,7 @@ function aggregatePoints(chartSerie: QueryViewerChartSerie) {
});
const value = aggregate(
chartSerie.Aggregation,
currentYValues,
currentYValues.map(val => new GxBigNumber(val)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[aggregatePoints] It would be nice to add some tests using this utility with different values to validates the new behavior.

currentYQuantities
).toString();
chartSerie.Points = [{ Value: value, Value_N: value, Value_D: "1" }];
Expand Down
Loading