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

feat: enable chart grid enable option #761

Merged
merged 12 commits into from
Sep 10, 2020
8 changes: 8 additions & 0 deletions packages/core/src/components/axes/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export class Grid extends Component {
backdrop: any;

render(animate = true) {
const gridEnable = Tools.getProperty(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const gridEnable = Tools.getProperty(
const isGridEnabled = Tools.getProperty(

this.model.getOptions(),
"grid",
"enabled"
);
if (!gridEnable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!gridEnable) {
if (!gridEnable) {

return;
}
// Draw the backdrop
this.drawBackdrop();
DOMUtils.appendOrSelect(this.backdrop, "g.x.grid");
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/components/axes/ruler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export class Ruler extends Component {
domainValue: number;
originalData: any;
}[];
gridEnable = Tools.getProperty(
this.model.getOptions(),
"grid",
"enable"
);

render() {
this.drawBackdrop();
Expand Down Expand Up @@ -231,7 +236,7 @@ export class Ruler extends Component {
this.backdrop = DOMUtils.appendOrSelect(svg, "svg.chart-grid-backdrop");
const backdropRect = DOMUtils.appendOrSelect(
this.backdrop,
"rect.chart-grid-backdrop"
this.gridEnable? "rect.chart-grid-backdrop" : "rect.chart-grid-backdrop-no-stroke"
);

this.backdrop
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const legend: LegendOptions = {
* Grid options
*/
export const grid: GridOptions = {
// set enable to false will not draw grid and stroke of grid backdrop
enabled: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grid cannot be disabled by default

x: {
numberOfTicks: 15
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/interfaces/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface ThresholdOptions {
}

export interface GridOptions {
enabled?: boolean;
y?: {
numberOfTicks?: number;
};
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/styles/components/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
stroke: $ui-03;
}

rect.chart-grid-backdrop-no-stroke {
@if $carbon--theme == $carbon--theme--g10 {
fill: $ui-01;
} @else if $carbon--theme == $carbon--theme--g90 {
fill: $carbon--gray-100;
} @else {
fill: $ui-background;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this extra classname?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why we need chart-grid-backdrop-no-stroke classname is because we don't want to apply stroke around the chart when there is no grid line.


g.x.grid g.tick,
g.y.grid g.tick {
line {
Expand Down