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(core): stroke dissappears when remapping the dimensions #678

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 11 additions & 7 deletions packages/core/src/components/graphs/area-stacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class StackedArea extends Component {
const svg = this.getContainerSVG();
const self = this;
const options = this.model.getOptions();
const { groupMapsTo } = options.data;

const mainXScale = this.services.cartesianScales.getMainXScale();
const mainYScale = this.services.cartesianScales.getMainYScale();
Expand All @@ -46,14 +47,15 @@ export class StackedArea extends Component {
return;
}

const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
)
const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
);

const stackedData = this.model.getStackedData({ percentage });

const areas = svg
.selectAll("path.area")
.data(stackedData, (d) => d[0].group);
.data(stackedData, (d) => d[0][groupMapsTo]);

// D3 area generator function
this.areaGenerator = area()
Expand All @@ -69,8 +71,8 @@ export class StackedArea extends Component {

enteringAreas
.merge(areas)
.data(stackedData, (d) => d[0].group)
.attr("fill", (d) => self.model.getFillColor(d[0].group))
.data(stackedData, (d) => d[0][groupMapsTo])
.attr("fill", (d) => self.model.getFillColor(d[0][groupMapsTo]))
.attr("role", Roles.GRAPHICS_SYMBOL)
.attr("aria-roledescription", "area")
.transition(
Expand All @@ -86,14 +88,16 @@ export class StackedArea extends Component {

handleLegendOnHover = (event: CustomEvent) => {
const { hoveredElement } = event.detail;
const options = this.model.getOptions();
const { groupMapsTo } = options.data;

this.parent
.selectAll("path.area")
.transition(
this.services.transitions.getTransition("legend-hover-area")
)
.attr("opacity", (d) => {
if (d[0].group !== hoveredElement.datum().name) {
if (d[0][groupMapsTo] !== hoveredElement.datum().name) {
return Configuration.area.opacity.unselected;
}

Expand Down
22 changes: 12 additions & 10 deletions packages/core/src/components/graphs/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Line extends Component {
const getRangeValue = (d, i) => cartesianScales.getRangeValue(d, i);
const [
getXValue,
getYValue,
getYValue
] = Tools.flipDomainAndRangeBasedOnOrientation(
getDomainValue,
getRangeValue,
Expand All @@ -51,25 +51,27 @@ export class Line extends Component {
if (value === null || value === undefined) {
return false;
}

return true;
});

let data = [];
if (this.configs.stacked) {
const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
)
const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
);
const { groupMapsTo } = options.data;
const stackedData = this.model.getStackedData({ percentage });
const domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
const rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();

data = stackedData.map((d) => ({
name: d[0].group,
name: d[0][groupMapsTo],
data: d.map((datum) => ({
date: datum.data.sharedStackKey,
group: datum.group,
value: datum[1],
[domainIdentifier]: datum.data.sharedStackKey,
group: datum[groupMapsTo],
Copy link
Member

@theiliad theiliad Jun 25, 2020

Choose a reason for hiding this comment

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

we don't need to do [groupMapsTo]: datum[groupMapsTo] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 yeah youre right

[rangeIdentifier]: datum[1]
})),
hidden: !Tools.some(d, (datum) => datum[0] !== datum[1]),
hidden: !Tools.some(d, (datum) => datum[0] !== datum[1])
}));
} else {
data = this.model.getGroupedData();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/components/graphs/scatter-stacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export class StackedScatter extends Scatter {
const domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
const rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();

const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
const percentage = Object.keys(options.axes).some(axis =>
options.axes[axis].percentage
)
const stackedData = this.model.getStackedData({ percentage });

// Update data on dot groups
const circleGroups = svg
.selectAll("g.dots")
.data(stackedData, (d) => d[0].group);
.data(stackedData, (d) => d[0][groupMapsTo]);

// Remove dot groups that need to be removed
circleGroups.exit().attr("opacity", 0).remove();
Expand Down