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(ChartInternal,Options): Add new clipPath option #95

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 45 additions & 1 deletion spec/core-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe("CORE", function() {
expect(ticks.size()).to.be.equal(0);
});

it("should upaate args for empty data", () => {
it("should update args for empty data", () => {
args = {
data: {
x: "x",
Expand All @@ -165,4 +165,48 @@ describe("CORE", function() {
expect(ticks.size()).to.be.equal(0);
});
});

describe("options", () => {
before(() => {
args = {
data: {
columns: [
["data1", 30, 200, 100, 50, 120, 175],
["data2", 130, 100, 0, 170, 75, 140]
]
},
clipPath: true
};
});

it("clip-path property should be null", () => {

Choose a reason for hiding this comment

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

this test case is checking about chart element has clip-path attribute, so to change title like "chart should have clip-path property"

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

const main = chart.internal.main.select(".bb-chart");

expect(main.attr("clip-path")).to.not.be.null;
});

it("check for chart node's position", () => {
const next = chart.internal.main.select(".bb-axis-y2").node().nextSibling;

// axis element should be the last positioned
expect(next).to.be.null;
});

it("set option clipPath=true", () => {
args.clipPath = false;
});

it("clip-path property should be null", () => {
const main = chart.internal.main.select(".bb-chart");

expect(main.attr("clip-path")).to.be.null;
});

it("check for chart node's position", () => {
const previous = chart.internal.main.select(".bb-chart").node().previousSibling;

// chart element should positioned after axis element
expect(d3.select(previous).classed("bb-axis-y2")).to.be.true;
});
});
});
14 changes: 14 additions & 0 deletions src/config/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export default class Options {
*/
bindto: "#chart",

/**
* Set clip-path property of chart element
* - **NOTE:**
* > When is false, chart node element is positioned after the axis node in DOM tree hierarchy.
* > Is to make chart element positioned over axis element.
* @name clipPath
* @memberof Options
* @type {Boolean}
* @default true
* @example
* clipPath: false
*/
clipPath: true,

/**
* Set svg element's class name
* @name svg
Expand Down
13 changes: 8 additions & 5 deletions src/internals/ChartInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,13 @@ export default class ChartInternal {
// Grids
$$.initGrid();

// Add Axis here, when clipPath is 'false'
!config.clipPath && $$.axis.init();

// Define g for chart area
main.append("g")
.attr("clip-path", $$.clipPath)
.attr("class", CLASS.chart);
const g = main.append("g").attr("class", CLASS.chart);

config.clipPath && g.attr("clip-path", $$.clipPath);

// Grid lines
config.grid_lines_front && $$.initGridLines();
Expand All @@ -307,8 +310,8 @@ export default class ChartInternal {
config.axis_x_extent &&
$$.brush.scale($$.getDefaultExtent());

// Add Axis
$$.axis.init();
// Add Axis here, when clipPath is 'true'
config.clipPath && $$.axis.init();

// Set targets
$$.updateTargets($$.data.targets);
Expand Down