From 80390c74ceaae763147763c0acedc3bb6d98e414 Mon Sep 17 00:00:00 2001 From: Michael Bester Date: Sun, 22 Apr 2018 01:21:28 -0400 Subject: [PATCH] [Heatmap] Localize Tooltip Dates --- dist/frappe-charts.esm.js | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/dist/frappe-charts.esm.js b/dist/frappe-charts.esm.js index c2c3282f..ab822590 100644 --- a/dist/frappe-charts.esm.js +++ b/dist/frappe-charts.esm.js @@ -2,6 +2,8 @@ function $(expr, con) { return typeof expr === "string"? (con || document).querySelector(expr) : expr || null; } + + $.create = (tag, o) => { var element = document.createElement(tag); @@ -64,6 +66,10 @@ function getElementContentWidth(element) { return element.clientWidth - padding; } + + + + function fire(target, type, properties) { var evt = document.createEvent("HTMLEvents"); @@ -76,6 +82,8 @@ function fire(target, type, properties) { return target.dispatchEvent(evt); } +// https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/ + const BASE_MEASURES = { margins: { top: 10, @@ -151,6 +159,8 @@ const DEFAULT_CHART_COLORS = ['light-blue', 'blue', 'violet', 'red', 'orange', 'yellow', 'green', 'light-green', 'purple', 'magenta', 'light-grey', 'dark-grey']; const HEATMAP_COLORS_GREEN = ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']; + + const DEFAULT_COLORS = { bar: DEFAULT_CHART_COLORS, line: DEFAULT_CHART_COLORS, @@ -292,6 +302,19 @@ function floatTwo(d) { return parseFloat(d.toFixed(2)); } +/** + * Returns whether or not two given arrays are equal. + * @param {Array} arr1 First array + * @param {Array} arr2 Second array + */ + + +/** + * Shuffles array in place. ES6 version + * @param {Array} array An array containing the items. + */ + + /** * Fill an array with extra points * @param {Array} array Array @@ -317,6 +340,11 @@ function getStringWidth(string, charWidth) { return (string+"").length * charWidth; } + + +// https://stackoverflow.com/a/29325222 + + function getPositionByAngle(angle, radius) { return { x: Math.sin(angle * ANGLE_RATIO) * radius, @@ -482,6 +510,8 @@ function makeSVGGroup(className, transform='', parent=undefined) { return createSVG('g', args); } + + function makePath(pathStr, className='', stroke='none', fill='none') { return createSVG('path', { className: className, @@ -1703,14 +1733,17 @@ class AggregationChart extends BaseChart { const NO_OF_YEAR_MONTHS = 12; const NO_OF_DAYS_IN_WEEK = 7; + const NO_OF_MILLIS = 1000; const SEC_IN_DAY = 86400; const MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + const DAY_NAMES_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + // https://stackoverflow.com/a/11252167/6495043 function treatAsUtc(date) { let result = new Date(date); @@ -1732,6 +1765,10 @@ function clone(date) { return new Date(date.getTime()); } + + + + // export function getMonthsBetween(startDate, endDate) {} function getWeeksBetween(startDate, endDate) { @@ -2606,6 +2643,8 @@ function getZeroIndex(yPts) { return zeroIndex; } + + function getIntervalSize(orderedArray) { return orderedArray[1] - orderedArray[0]; } @@ -2618,6 +2657,10 @@ function scale(val, yAxis) { return floatTwo(yAxis.zeroLine - val * yAxis.scaleMultiplier); } + + + + function getClosestInArray(goal, arr, index = false) { let closest = arr.reduce(function(prev, curr) { return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev);