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

fix(regions): Fix applying regions class #3613

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/module/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,12 @@ const toArray = (v: CSSStyleDeclaration | any): any => [].slice.call(v);
* @private
*/
function addCssRules(style, selector: string, prop: string[]): number {
const {rootSelctor, sheet} = style;
const {rootSelector = "", sheet} = style;
const getSelector = s => s
.replace(/\s?(bb-)/g, ".$1")
.replace(/\.+/g, ".");

const rule = `${rootSelctor} ${getSelector(selector)} {${prop.join(";")}}`;
const rule = `${rootSelector} ${getSelector(selector)} {${prop.join(";")}}`;

return sheet[sheet.insertRule ? "insertRule" : "addRule"](
rule,
Expand Down
3 changes: 2 additions & 1 deletion src/scss/billboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@
}
/*-- Region --*/
.bb-region {
fill: steelblue;

rect {
fill: steelblue;
fill-opacity: .1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/scss/theme/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ rect.bb-circle, use.bb-circle {

/*-- Region --*/
.bb-region {
fill: steelblue;

rect {
fill: steelblue;
fill-opacity: 0.5;
}

Expand Down
3 changes: 2 additions & 1 deletion src/scss/theme/datalab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ $text-font-size: 11px;

/*-- Region --*/
.bb-region {
fill: steelblue;

rect {
fill: steelblue;
fill-opacity: 0.1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/scss/theme/graph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ rect.bb-circle, use.bb-circle {

/*-- Region --*/
.bb-region {
fill: steelblue;

rect {
fill: steelblue;
fill-opacity: 0.1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/scss/theme/insight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ rect.bb-circle, use.bb-circle {

/*-- Region --*/
.bb-region {
fill: steelblue;

rect {
fill: steelblue;
fill-opacity: 0.1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/scss/theme/modern.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ rect.bb-circle, use.bb-circle {

/*-- Region --*/
.bb-region {
fill: #71808d;

rect {
fill: #71808d;
fill-opacity: 0.1;
}

Expand Down
4 changes: 4 additions & 0 deletions test/assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
align-items: center;
justify-content: center;
}

.regions_class1{
fill: red;
}
10 changes: 9 additions & 1 deletion test/internals/rergions-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
/* eslint-disable */
import {expect} from "chai";
import {window} from "../../src/module/browser";
import util from "../assets/util";

// exported to be used from /test/api/region-spec.ts
Expand Down Expand Up @@ -131,13 +132,20 @@ describe("REGIONS", function() {
const {$el, scale} = chart.internal;

setTimeout(() => {
$el.region.list.each(function(d) {
$el.region.list.each(function(d, i) {
const axis = scale[d.axis];
const isX = d.axis === "x";
const rect = this.querySelector("rect");
const start = +rect.getAttribute(isX ? "x" : "y");
const size = +rect.getAttribute(isX ? "width" : "height");

// first <rect> should apply .regions_class1 rule
if (i === 0) {
const {fill} = window.getComputedStyle(this.querySelector("rect"));

expect(fill).to.be.equal("rgb(255, 0, 0)");
}

// check the diemsion
expect(start).to.be.equal(axis(isX ? d.start : d.end));
expect(start + size).to.be.equal(axis(isX ? d.end : d.start));
Expand Down