Skip to content

Commit d3b4d0d

Browse files
Atanas Nikolovdxcity
authored andcommitted
Pull request #6057: Feature/DXCF-6016 inconsistent decimals and negative values on scales
Merge in DXCHARTS/dxchart5 from feature/DXCF-6016-inconsistent-decimals-and-negative-values-on-scales-2 to master Squashed commit of the following: commit f224a7e7b73a83d95396553b23de730992bba67e Author: dxcity <[email protected]> Date: Fri Oct 24 12:43:51 2025 +0000 CI: update snapshots commit 2529766354b870f2970a5a60bdba9bd7a623bf32 Merge: 4623f80aad b2c33cbbbc Author: Atanas Nikolov <[email protected]> Date: Fri Oct 24 14:15:40 2025 +0300 Merge branch 'feature/DXCF-6016-inconsistent-decimals-and-negative-values-on-scales-2' of https://stash.in.devexperts.com/scm/dxcharts/dxchart5 into feature/DXCF-6016-inconsistent-decimals-and-negative-values-on-scales-2 commit 4623f80aadd9dcb319be3d336f1d7cf356849795 Author: Atanas Nikolov <[email protected]> Date: Fri Oct 24 14:14:32 2025 +0300 [DXCF-6016] Inconsistent decimals and negative values on scales // refactor naming commit b2c33cbbbcc0b499275d6ab0f90d182feaa17967 Author: dxcity <[email protected]> Date: Fri Oct 24 08:31:36 2025 +0000 CI: update snapshots commit b06d3a63e84dd135a7134aab93db3b618e2f53f9 Author: Atanas Nikolov <[email protected]> Date: Fri Oct 24 10:10:48 2025 +0300 [DXCF-6016] Inconsistent decimals and negative values on scales // refactor formatting commit 70f77a20f8d2c32e6989591deb3ec854f09f3ddc Author: Atanas Nikolov <[email protected]> Date: Fri Oct 24 00:41:53 2025 +0300 [DXCF-6016] Inconsistent decimals and negative values on scales // remove unused code commit 998ba762de2641a772700db26fa8ea4ff27af670 Author: Atanas Nikolov <[email protected]> Date: Fri Oct 24 00:39:04 2025 +0300 [DXCF-6016] Inconsistent decimals and negative values on scales GitOrigin-RevId: 05f7a010db81bf1b4261fcc7f1929a6f99fea69f
1 parent 531da73 commit d3b4d0d

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/chart/components/chart/price-formatters/price.formatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import { YAxisConfig } from '../../../chart.config';
77
import { DataSeriesModel } from '../../../model/data-series.model';
88
import { Unit, unitToPercent } from '../../../model/scaling/viewport.model';
9+
import { replaceMinusSign } from '../../../utils/math.utils';
910
import { PriceIncrementsUtils } from '../../../utils/price-increments.utils';
11+
import { MINUS_SIGN } from '../../../utils/symbol-constants';
1012
import { YExtentComponent } from '../../pane/extent/y-extent-component';
1113
import { YExtentFormatters } from '../../pane/pane.component';
1214
import { treasuryPriceFormatter } from './treasury-price.formatter';
@@ -46,8 +48,8 @@ export const createPercentFormatter =
4648
valueUnit = unitToPercent(value, series.getBaseline());
4749
}
4850
// always apply default precision for percent
49-
const formatted = valueUnit.toFixed(PriceIncrementsUtils.DEFAULT_PRECISION).replace('-', '−') + ' %';
50-
return formatted === '−0.00 %' ? '0.00 %' : formatted;
51+
const formatted = replaceMinusSign(valueUnit.toFixed(PriceIncrementsUtils.DEFAULT_PRECISION)) + ' %';
52+
return formatted === `${MINUS_SIGN}0.00 %` ? '0.00 %' : formatted;
5153
};
5254

5355
export const createYExtentFormatters = (extent: YExtentComponent, config: YAxisConfig): YExtentFormatters => ({

src/chart/components/labels_generator/numeric-axis-labels.generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Observable, Subject } from 'rxjs';
77
import { Percent, Pixel, Unit, logValueToUnit, percentToUnit, calcLogValue } from '../../model/scaling/viewport.model';
88
import { AnimationFrameCache } from '../../utils/performance/animation-frame-cache.utils';
99
import { identity } from '../../utils/function.utils';
10-
import { MathUtils } from '../../utils/math.utils';
10+
import { replaceMinusSign, MathUtils } from '../../utils/math.utils';
1111
import { PriceIncrementsUtils } from '../../utils/price-increments.utils';
1212
import { TREASURY_32ND } from '../chart/price-formatters/treasury-price.formatter';
1313
import { YAxisConfig, YAxisConfigTreasuryFormat } from '../../chart.config';
@@ -68,7 +68,7 @@ export class NumericAxisLabelsGenerator implements LabelsGenerator {
6868
while (value < max) {
6969
// Adjust value to increment
7070
const adjustedValue = MathUtils.roundToNearest(value, singleLabelHeightValue);
71-
const labelText = this.valueFormatter(adjustedValue);
71+
const labelText = replaceMinusSign(this.valueFormatter(adjustedValue));
7272
newLabels.push({
7373
value: adjustedValue,
7474
text: labelText,
@@ -87,7 +87,7 @@ export class NumericAxisLabelsGenerator implements LabelsGenerator {
8787
// Adjust value to increment
8888
const adjustedValue = MathUtils.roundToNearest(value, singleLabelHeightValue);
8989
const valueUnit = percentToUnit(adjustedValue, baseLine);
90-
const labelText = this.valueFormatter(valueUnit);
90+
const labelText = replaceMinusSign(this.valueFormatter(valueUnit));
9191
newLabels.push({
9292
value: adjustedValue,
9393
text: labelText,

src/chart/components/y_axis/price_labels/price-label.drawer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { redrawBackgroundArea } from '../../../drawers/chart-background.drawer';
1616
import { Bounds } from '../../../model/bounds.model';
1717
import { avoidAntialiasing, drawLine } from '../../../utils/canvas/canvas-drawing-functions.utils';
1818
import { calculateSymbolHeight, calculateTextWidth } from '../../../utils/canvas/canvas-font-measure-tool.utils';
19-
import { floor } from '../../../utils/math.utils';
19+
import { floor, replaceMinusSign } from '../../../utils/math.utils';
2020
import { drawBadgeLabel, drawPlainLabel, drawRectLabel, checkLabelInBoundaries } from '../y-axis-labels.drawer';
2121
import { VisualYAxisLabel, YAxisVisualLabelType } from './y-axis-labels.model';
2222

@@ -97,7 +97,7 @@ export function drawLabel(
9797
const lineY = visualLabel.lineY ?? visualLabel.y;
9898
const _drawLine = () =>
9999
showLine && avoidAntialiasing(ctx, () => drawLine(ctx, lineXStart, lineY, lineXEnd, lineY, 1));
100-
const _drawLabel = () => drawLabel(ctx, bounds, text, centralY, visualLabel, config, colors.yAxis, false);
100+
const _drawLabel = () => drawLabel(ctx, bounds, replaceMinusSign(text), centralY, visualLabel, config, colors.yAxis, false);
101101

102102
const drawLineLabel = () => {
103103
_drawLine();

src/chart/utils/math.utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66
import { StringTMap } from './object.utils';
7+
import { MINUS_SIGN, TRUE_MINUS_SIGN } from './symbol-constants';
78

89
const MAX_DECIMAL_DIGITS = 14;
910
// Array of powers of 10. Used in roundDecimal to walk through mantissa.
@@ -174,3 +175,7 @@ export function countDecimalPlaces(number: number): number {
174175
return 0; // No decimal places
175176
}
176177
}
178+
179+
export const replaceMinusSign = (stringValue: string) => {
180+
return stringValue.replace(TRUE_MINUS_SIGN, MINUS_SIGN);
181+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const MINUS_SIGN = '−';
2+
export const TRUE_MINUS_SIGN = '-';

0 commit comments

Comments
 (0)