Skip to content

Commit

Permalink
fix(color): Correct the way on setting pattern value (#509)
Browse files Browse the repository at this point in the history
Internal cache isn't shared among different instances.
Use body's property to store pattern value instead.

Ref #507
Close #509
  • Loading branch information
netil authored Jul 26, 2018
1 parent beba334 commit 164a3f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spec/internals/color-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("COLOR", () => {
expect(pttrn).to.deep.equal(pattern);

// check if pattern value are cached
expect(internal.getCache("colorPattern")).to.deep.equal(pattern);
expect(document.body["__colorPattern__"]).to.deep.equal(pattern);
});

it("check if color pattern applied to data elements", () => {
Expand Down
11 changes: 5 additions & 6 deletions src/internals/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ extend(ChartInternal.prototype, {
* @private
*/
getColorFromCss() {
const $$ = this;
const cacheKey = "colorPattern";
let pattern = $$.getCache(cacheKey);
const cacheKey = "__colorPattern__";
const body = document.body;
let pattern = body[cacheKey];

if (!pattern) {
const delimiter = ";";
const span = document.createElement("span");

span.className = CLASS.colorPattern;
span.style.display = "none";
document.body.appendChild(span);
body.appendChild(span);

const content = window.getComputedStyle(span).backgroundImage;

Expand All @@ -68,8 +68,7 @@ extend(ChartInternal.prototype, {
.map(v => v.trim().replace(/[\"'\s]/g, ""))
.filter(Boolean);


$$.addCache(cacheKey, pattern);
body[cacheKey] = pattern;
}
}

Expand Down

0 comments on commit 164a3f9

Please sign in to comment.