Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'TypeError: offset required' when using Heatmap.js with local tests #330

Open
jesuino opened this issue Dec 1, 2020 · 1 comment · May be fixed by #331
Open

'TypeError: offset required' when using Heatmap.js with local tests #330

jesuino opened this issue Dec 1, 2020 · 1 comment · May be fixed by #331

Comments

@jesuino
Copy link

jesuino commented Dec 1, 2020

Using latest heatmap.js with Canvas in a jest test leads to errors. It fails with:

TypeError: offset required

      43 | function createHeatmap(parent: HTMLElement, heatData: HeatData[]) {
      44 |   return heatmap
    > 45 |     .create({
         |      ^
      46 |       container: parent
      47 |     })
      48 |     .setData({

      at _getColorPalette (../../node_modules/heatmap.js/build/heatmap.js:262:16)
      at new Canvas2dRenderer (../../node_modules/heatmap.js/build/heatmap.js:355:21)
      at new Heatmap (../../node_modules/heatmap.js/build/heatmap.js:650:24)
      at Object.create (../../node_modules/heatmap.js/build/heatmap.js:715:12)
      at createHeatmap (src/SVGHeatmap.tsx:45:6)
      at src/SVGHeatmap.tsx:81:21
      at commitHookEffectList (../../node_modules/react-dom/cjs/react-dom.development.js:22030:26)
      at commitPassiveHookEffects (../../node_modules/react-dom/cjs/react-dom.development.js:22064:11)
      at HTMLUnknownElement.callCallback (../../node_modules/react-dom/cjs/react-dom.development.js:336:14)
      at innerInvokeEventListeners (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:316:27)

This is the line that throws the error:

https://github.com/pa7/heatmap.js/blob/master/src/renderer/canvas2d.js#L14

The reason is explained here:

https://stackoverflow.com/questions/62332852/how-to-create-gradient-text-in-canvas-nodejs

And you can see that in the node js canvas there's indeed a type check:

https://github.com/Automattic/node-canvas/blob/fe186e5f1e720eca598212fdc6edf16766c21ec0/src/CanvasGradient.cc#L77

Solution is simple parse the string to number.

jesuino added a commit to jesuino/heatmap.js that referenced this issue Dec 1, 2020
Will parse the offset to number so heatmap.js can be used with local jest tests (canvas node implementation).
closes pa7#330
@jesuino jesuino linked a pull request Dec 1, 2020 that will close this issue
@Khalilw1
Copy link

Khalilw1 commented May 4, 2021

I came up against the same issue too while testing using jest on my vue project hopefully your PR gets quickly merged

EDIT: Just realized this is from December well let us not lose hope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants