Skip to content

Commit

Permalink
[Heatmap] Localize Tooltip Dates
Browse files Browse the repository at this point in the history
  • Loading branch information
kimili committed Apr 22, 2018
1 parent 8630548 commit 750be23
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 30 deletions.
15 changes: 6 additions & 9 deletions dist/frappe-charts.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ class SvgTip {
}
}

/**
* Returns the value of a number upto 2 decimal places.
* @param {Number} d Any number
*/
function floatTwo(d) {
return parseFloat(d.toFixed(2));
}
Expand Down Expand Up @@ -2704,6 +2700,7 @@ class Heatmap extends BaseChart {
this.type = 'heatmap';

this.countLabel = options.countLabel || '';
this.dateFormat = options.dateFormat || { year: 'numeric', month: 'short', day: 'numeric' };

let validStarts = ['Sunday', 'Monday'];
let startSubDomain = validStarts.includes(options.startSubDomain)
Expand Down Expand Up @@ -2838,17 +2835,18 @@ class Heatmap extends BaseChart {
if(daySquares.includes(daySquare)) {

let count = daySquare.getAttribute('data-value');
let dateParts = daySquare.getAttribute('data-date').split('-');

let month = getMonthName(parseInt(dateParts[1])-1, true);
let date = new Date(daySquare.getAttribute('data-date'));

let gOff = this.container.getBoundingClientRect(), pOff = daySquare.getBoundingClientRect();

let width = parseInt(e.target.getAttribute('width'));
let x = pOff.left - gOff.left + width/2;
let y = pOff.top - gOff.top;
let value = count + ' ' + this.countLabel;
let name = ' on ' + month + ' ' + dateParts[0] + ', ' + dateParts[2];
let name = ' on ' + date.toLocaleDateString(
window.navigator.location || 'en-US',
this.dateFormat
);

this.tip.setValues(x, y, {name: name, value: value, valueFirst: 1}, []);
this.tip.showTip();
Expand Down Expand Up @@ -3677,7 +3675,6 @@ class AxisChart extends BaseChart {
// removeDataPoint(index = 0) {}
}

// import MultiAxisChart from './charts/MultiAxisChart';
const chartTypes = {
bar: AxisChart,
line: AxisChart,
Expand Down
2 changes: 1 addition & 1 deletion dist/frappe-charts.min.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.iife.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/frappe-charts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/frappe-charts.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ let heatmapArgs = {
discreteDomains: 1,
countLabel: 'Level',
colors: HEATMAP_COLORS_BLUE,
dateFormat: { month: 'numeric', day: '2-digit' },
legendScale: [0, 1, 2, 4, 5]
};
let heatmapChart = new Chart("#chart-heatmap", heatmapArgs);
Expand Down
10 changes: 2 additions & 8 deletions docs/assets/js/index.min.js

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

2 changes: 1 addition & 1 deletion docs/assets/js/index.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ <h6 class="margin-vertical-rem">
end: endDate // Date objects
},
countLabel: 'Level',
dateFormat: { month: '2-digit', day: '2-digit' },
// Formats date in tooltip based on the end user's browser language and locale
// This value is used as the options parameter in Date.prototype.toLocaleDateString()
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
// default: { year: 'numeric', month: 'short', day: 'numeric' }
discreteDomains: 0 // default: 1
colors: ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'],
// Set of five incremental colors,
Expand Down
10 changes: 6 additions & 4 deletions src/js/charts/Heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Heatmap extends BaseChart {
this.type = 'heatmap';

this.countLabel = options.countLabel || '';
this.dateFormat = options.dateFormat || { year: 'numeric', month: 'short', day: 'numeric' };

let validStarts = ['Sunday', 'Monday'];
let startSubDomain = validStarts.includes(options.startSubDomain)
Expand Down Expand Up @@ -151,17 +152,18 @@ export default class Heatmap extends BaseChart {
if(daySquares.includes(daySquare)) {

let count = daySquare.getAttribute('data-value');
let dateParts = daySquare.getAttribute('data-date').split('-');

let month = getMonthName(parseInt(dateParts[1])-1, true);
let date = new Date(daySquare.getAttribute('data-date'));

let gOff = this.container.getBoundingClientRect(), pOff = daySquare.getBoundingClientRect();

let width = parseInt(e.target.getAttribute('width'));
let x = pOff.left - gOff.left + width/2;
let y = pOff.top - gOff.top;
let value = count + ' ' + this.countLabel;
let name = ' on ' + month + ' ' + dateParts[0] + ', ' + dateParts[2];
let name = ' on ' + date.toLocaleDateString(
window.navigator.location || 'en-US',
this.dateFormat
);

this.tip.setValues(x, y, {name: name, value: value, valueFirst: 1}, []);
this.tip.showTip();
Expand Down

0 comments on commit 750be23

Please sign in to comment.