Skip to content

Commit 20c58f6

Browse files
authored
Firefly 1047 more chart func (#1254)
* FIREFLY-1047: add radians and degress into the list of supported functions used by chart * FIREFLY-1047: fix js test failing
1 parent b9c2b39 commit 20c58f6

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/firefly/js/charts/ui/ColumnOrExpression.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {ToolbarButton} from '../../ui/ToolbarButton.jsx';
1717

1818
const EXPRESSION_TTIPS = `
1919
Supported operators: *, /, +, -.
20-
Supported functions: abs(x), acos(x), asin(x), atan(x), atan2(x,y), ceil(x), cos(x), exp(x), floor(x), lg(x), ln(x), log10(x), log(x), power(x,y), round(x), sin(x), sqrt(x), tan(x).
20+
Supported functions: abs(x), acos(x), asin(x), atan(x), atan2(x,y), ceil(x), cos(x), degrees(x), exp(x), floor(x), lg(x), ln(x), log10(x), log(x), power(x,y), radians(x), round(x), sin(x), sqrt(x), tan(x).
2121
Example: sqrt(power(b,4) - 4*a*c) / (2*a), where a, b, c are column names.
2222
Non-alphanumeric column names should be quoted in expressions.`;
2323

src/firefly/js/util/__tests__/Expression-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ describe('A test suite for expr/Expression.js', function () {
3737
{e: 'atan(x)', r: Math.atan(x)},
3838
{e: 'ceil(x)', r: Math.ceil(x)},
3939
{e: 'cos(x)', r: Math.cos(x)},
40+
{e: 'degrees(x)', r: x * (180/Math.PI)},
4041
{e: 'exp(x)', r: Math.exp(x)},
4142
{e: 'floor(x)', r: Math.floor(x)},
4243
{e: 'lg(x)', r: Math.log10(x)},
4344
{e: 'log10(x)', r: Math.log10(x)},
4445
{e: 'log(x)', r: Math.log(x)},
4546
{e: 'ln(x)', r: Math.log(x)},
47+
{e: 'radians(x)', r: x * (Math.PI/180) },
4648
{e: 'round(x)', r: Math.round(x)},
4749
{e: 'sin(x)', r: Math.sin(x)},
4850
{e: 'sqrt(x)', r: Math.sqrt(x)},

src/firefly/js/util/expr/Expr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
/** Unary operator: natural log */ export const LN = 114;
4040
/** Unary operator: log 10 */ export const LOG10 = 115;
4141
/** Unary operator: log 10 */ export const LG = 116;
42+
/** Unary operator: degrees */ export const DEGREES = 117;
43+
/** Unary operator: radians */ export const RADIANS = 118;
4244

4345
// NVL2 - If <value expr 1> is not null, returns <value expr 2>, otherwise returns <value expr 3>. (HyperSQL)
4446
/** Ternary operator: if null */ export const NVL2 = 200;
@@ -175,6 +177,8 @@ class UnaryExpr {
175177
case SIN: return Math.sin(arg);
176178
case SQRT: return Math.sqrt(arg);
177179
case TAN: return Math.tan(arg);
180+
case DEGREES: return arg * (180/Math.PI);
181+
case RADIANS : return arg * (Math.PI/180) ;
178182
default: throw 'BUG: bad rator: '+this.rator;
179183
}
180184
}

src/firefly/js/util/expr/Parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ const rators0 = [
2727

2828
const procs1 = [
2929
'abs', 'acos', 'asin', 'atan',
30-
'ceil', 'cos', 'exp', 'floor',
31-
'log', 'ln', 'lg', 'log10', 'round', 'sin', 'sqrt',
30+
'ceil', 'cos', 'degrees', 'exp', 'floor',
31+
'log', 'ln', 'lg', 'log10', 'radians', 'round', 'sin', 'sqrt',
3232
'tan'
3333
];
3434

3535
const rators1 = [
3636
Expr.ABS, Expr.ACOS, Expr.ASIN, Expr.ATAN,
37-
Expr.CEIL, Expr.COS, Expr.EXP, Expr.FLOOR,
38-
Expr.LOG, Expr.LN, Expr.LG, Expr.LOG10, Expr.ROUND, Expr.SIN, Expr.SQRT,
37+
Expr.CEIL, Expr.COS, Expr.DEGREES ,Expr.EXP, Expr.FLOOR,
38+
Expr.LOG, Expr.LN, Expr.LG, Expr.LOG10, Expr.RADIANS, Expr.ROUND, Expr.SIN, Expr.SQRT,
3939
Expr.TAN
4040
];
4141

0 commit comments

Comments
 (0)