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
35 changes: 28 additions & 7 deletions packages/core/src/components/axes/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,32 @@ export class Grid extends Component {
backdrop: any;

render(animate = true) {
const isXGridEnabled = Tools.getProperty(
this.model.getOptions(),
"grid",
"xGridEnabled"
);
const isYGridEnabled = Tools.getProperty(
this.model.getOptions(),
"grid",
"yGridEnabled"
);

if (!isXGridEnabled && !isYGridEnabled) {
return;
}
// Draw the backdrop
this.drawBackdrop();
DOMUtils.appendOrSelect(this.backdrop, "g.x.grid");
DOMUtils.appendOrSelect(this.backdrop, "g.y.grid");
this.drawBackdrop(isXGridEnabled, isYGridEnabled);

this.drawXGrid(animate);
this.drawYGrid(animate);
if (isXGridEnabled) {
DOMUtils.appendOrSelect(this.backdrop, "g.x.grid");
this.drawXGrid(animate);
}

if (isYGridEnabled) {
DOMUtils.appendOrSelect(this.backdrop, "g.y.grid");
this.drawYGrid(animate);
}
}

drawXGrid(animate: boolean) {
Expand Down Expand Up @@ -184,7 +203,7 @@ export class Grid extends Component {
return xGridlines;
}

drawBackdrop() {
drawBackdrop(isXGridEnabled, isYGridEnabled) {
const svg = this.parent;

const mainXScale = this.services.cartesianScales.getMainXScale();
Expand All @@ -197,7 +216,9 @@ export class Grid extends Component {
this.backdrop = DOMUtils.appendOrSelect(svg, "svg.chart-grid-backdrop");
const backdropRect = DOMUtils.appendOrSelect(
this.backdrop,
"rect.chart-grid-backdrop"
isXGridEnabled || isYGridEnabled
? "rect.chart-grid-backdrop.stroke"
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
? "rect.chart-grid-backdrop.stroke"
? "rect.chart-grid-backdrop.stroked"

: "rect.chart-grid-backdrop"
);

this.backdrop
Expand Down
14 changes: 13 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,16 @@ export class Ruler extends Component {
domainValue: number;
originalData: any;
}[];
isXGridEnabled = Tools.getProperty(
this.model.getOptions(),
"grid",
"xGridEnabled"
);
isYGridEnabled = Tools.getProperty(
this.model.getOptions(),
"grid",
"yGridEnabled"
);

render() {
this.drawBackdrop();
Expand Down Expand Up @@ -231,7 +241,9 @@ 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.isXGridEnabled || this.isYGridEnabled
? "rect.chart-grid-backdrop.stroke"
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
? "rect.chart-grid-backdrop.stroke"
? "rect.chart-grid-backdrop.stroked"

Copy link
Member

Choose a reason for hiding this comment

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

again my feedback here still applies. seems like Ruler doesn't need to style the backdrop, just needs to grab it.

this piece seems to be in there by mistake from our previous commits.

Are you able to remove all the styling pieces for the backdrop from Ruler and test whether things still work? We should remove any of it that doesn't break charts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the code for styling backdrop in Ruler component has already been done in #765

: "rect.chart-grid-backdrop"
Copy link
Member

Choose a reason for hiding this comment

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

seems like stroke should be a separate configurable no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

圖片

A chart with grid but without stroke looks kind of weird. So I guess we would always want to add stroke when there is grid being enabled. And when there is no grid being enabled, we can let the user setup the option to disable stroke? What do you think?

With stroke.
圖片

Without stroke.
圖片

Copy link
Member

Choose a reason for hiding this comment

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

actually I think stroke might be something we'd always want to keep unless overriden

@jeanservaas could you please chime in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @theiliad and @jeanservaas,
There is the situation when we don't want to show the stroke.
圖片

);

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

Copy link
Contributor

@natashadecoste natashadecoste Sep 1, 2020

Choose a reason for hiding this comment

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

i think this should go within the x and y configurations like this

grid:{ 
    x: {
      enabled: true,
      numberOfTicks: 15
    },
    y: {
      enabled: true,
      numberOfTicks: 15
    }
}

or maybe "visible" is a better word... since its still enabled/functional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on @theiliad 's input. I will use "enabled".

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

export interface GridOptions {
xGridEnabled?: boolean;
yGridEnabled?: boolean;

y?: {
numberOfTicks?: number;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/styles/components/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
} @else {
fill: $ui-background;
}
}
rect.stroke {
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
rect.stroke {
rect.chart-grid-backdrop.stroked {

stroke: $ui-03;
}
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.


Expand Down