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

[BUG] Unable to parse color from object when using patterns (patternomaly.js) #4279

Closed
Irexistus opened this issue May 22, 2017 · 4 comments
Closed

Comments

@Irexistus
Copy link

Irexistus commented May 22, 2017

Expected Behavior

For the hover tooltip to show without throwing any errors when using a pattern as a background color with the help of patternomaly.js as suggested in the documentation at http://www.chartjs.org/docs/#chart-configuration-patterns

Current Behavior

Currently the tooltip fails to properly show and sort of soft-locks in place and the following error is presented in the console:

Uncaught Error: Unable to parse color from object {"shapeType":"dash"}

Possible Solution

It looks like a helper function to correct for the issue was a suggestion in #1323 but I'm unsure if it's a possible solution here.

Steps to Reproduce (for bugs)

  1. Set the background color for a dataset to a pattern.
  2. Try to hover over a point to show the tooltip

Example: http://codepen.io/anon/pen/ZKmVgo

Context

I'm trying to make use of patterns on my charts to aid colorblind individuals.

Environment

@dotjsNet
Copy link

You linked the JS using
https://irexistus.com/patternomaly.js
but its getting insecure call http://irexistus.com/patternomaly.js

@Irexistus
Copy link
Author

Changed the snippet to use just http, http://codepen.io/anon/pen/ZKmVgo

@swierczek
Copy link

I fixed this in a local version of Chart.js (drawBody method): ashiguruma/patternomaly#10

var bgColor = vm.labelColors[i].backgroundColor;
if (bgColor instanceof CanvasPattern) {
    //set the fillStyle to the pattern
    ctx.fillStyle = vm.labelColors[i].backgroundColor;
} else {
    // Inner square
    ctx.fillStyle = mergeOpacity(bgColor, opacity);
}

ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
ctx.fillStyle = textColor;

This could easily be added to the core to fix the issue.

@sanbiv
Copy link

sanbiv commented Aug 14, 2017

I use this simple workaround (with pattornamaly & chart.js 2.5)

const getPattern = (shape, color)=> {
  let rgb = Chart.helpers.colors(color)
  let bgPattern = pattern.draw(shape, color)
  return Chart.helpers.extend(bgPattern, {r: rgb.red(), g: rgb.green(), b: rgb.blue(), alpha: rgb.alpha()})
}

// in my chart options
// ...code omitted.....
const backgroundColor = getPattern("dot", "red");
let chart = new Chart(ctx, {
    data: {
        labels: ['Item 1', 'Item 2', 'Item 3'],
        datasets: [{
            data: [10, 20, 30],
            backgroundColor
        }]
    }
})

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

No branches or pull requests

6 participants