Skip to content

Commit dc54870

Browse files
authored
Merge pull request #428 from sokumon/show-values-over-bar
fix: better UX for valuesOverPoints
2 parents d8ae43f + b73bd1e commit dc54870

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frappe-charts",
3-
"version": "2.0.0-rc26",
3+
"version": "2.0.0-rc27",
44
"main": "dist/frappe-charts.esm.js",
55
"module": "dist/frappe-charts.esm.js",
66
"browser": "dist/frappe-charts.umd.js",

src/js/charts/AxisChart.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getTopOffset, getLeftOffset, MIN_BAR_PERCENT_HEIGHT, BAR_CHART_SPACE_RATIO,
1010
LINE_CHART_DOT_SIZE
1111
} from '../utils/constants';
12+
import { shortenLargeNumber } from '../utils/draw-utils';
1213

1314
export default class AxisChart extends BaseChart {
1415
constructor(parent, args) {
@@ -270,7 +271,7 @@ export default class AxisChart extends BaseChart {
270271
if (stacked && d.index === s.datasets.length - 1) {
271272
labels = d.cumulativeYs;
272273
} else {
273-
labels = d.values;
274+
labels = d.values.map(v => shortenLargeNumber(v));
274275
}
275276
}
276277

@@ -403,16 +404,18 @@ export default class AxisChart extends BaseChart {
403404
let relX = e.pageX - o.left - getLeftOffset(m);
404405
let relY = e.pageY - o.top;
405406

406-
if (relY < this.height + getTopOffset(m)
407+
if (!this.config.valuesOverPoints && relY < this.height + getTopOffset(m)
407408
&& relY > getTopOffset(m)) {
408409
this.mapTooltipXPosition(relX);
409-
} else {
410+
} else if (this.config.valuesOverPoints && e.target.getAttribute("class") == "data-point-value"){
411+
this.mapTooltipXPosition(relX, -20)
412+
}else {
410413
this.tip.hideTip();
411414
}
412415
});
413416
}
414417

415-
mapTooltipXPosition(relX) {
418+
mapTooltipXPosition(relX, y=0) {
416419
let s = this.state;
417420
if (!s.yExtremes) return;
418421

@@ -422,7 +425,7 @@ export default class AxisChart extends BaseChart {
422425

423426
this.tip.setValues(
424427
dbi.xPos + this.tip.offset.x,
425-
dbi.yExtreme + this.tip.offset.y,
428+
dbi.yExtreme + this.tip.offset.y + y,
426429
{ name: dbi.formattedLabel, value: '' },
427430
dbi.values,
428431
index

0 commit comments

Comments
 (0)