Skip to content

Commit

Permalink
Fix for timezone matcher - 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode committed Nov 17, 2023
1 parent 48c1f54 commit ee6caee
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .config/.cprc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.6.0"
}
2 changes: 1 addition & 1 deletion .config/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Object.defineProperty(global, 'matchMedia', {
})),
});

HTMLCanvasElement.prototype.getContext = () => { };
HTMLCanvasElement.prototype.getContext = () => {};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ nline-plotlyjs-panel-*.zip.md5
dist/
.trunk/
keys.env
.eslintcache
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nline-plotlyjs-panel",
"version": "1.6.3",
"version": "1.6.4",
"description": "Grafana Plotly Plugin",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
Expand Down
11 changes: 7 additions & 4 deletions src/SimplePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ export const SimplePanel = React.memo(

// Add convenience function for matching UTC data to timezone
const local = dayjs.tz.guess();
const matchTimezone = (timeStamps: Int32Array, correct = true) => {
const matchTimezone = (timeStamps: Int32Array) => {
const tz = timeZone === 'browser' ? local : timeZone;
const baseOffset = correct ? 0 : dayjs().tz(local).utcOffset();
const offset = (dayjs().tz(tz).utcOffset() - baseOffset) * 60 * 1000;
const localOffset = dayjs().tz(local).utcOffset();
const dashOffset = dayjs().tz(tz).utcOffset();

// We need to reverse the offset that Plotly assigns
// And then consider the dashboard timezone offset
const offset = (localOffset - dashOffset) * 60 * 1000;
return timeStamps.map((ts) => ts - offset);
};

Expand All @@ -86,7 +89,7 @@ export const SimplePanel = React.memo(

// Convert time column if selected
let prcData = props.data;
const timeColExists = prcData.series[0].fields.some((f) => f.name === options.timeCol);
const timeColExists = prcData.series?.[0]?.fields?.some((f) => f.name === options.timeCol) || false;
if (timeColExists) {
prcData = correctTimeCol(props.data);
}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2667,9 +2667,9 @@
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==

"@types/node@*", "@types/node@^20.8.7":
version "20.9.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.0.tgz#bfcdc230583aeb891cf51e73cfdaacdd8deae298"
integrity sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==
version "20.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.1.tgz#9d578c610ce1e984adda087f685ace940954fe19"
integrity sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA==
dependencies:
undici-types "~5.26.4"

Expand Down

0 comments on commit ee6caee

Please sign in to comment.