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(data): Fix idConverter error #2810

Merged
merged 1 commit into from
Aug 3, 2022
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
2 changes: 1 addition & 1 deletion src/ChartInternal/data/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default {
t.values.forEach((v, i) => (v.index = i));

// this needs to be sorted because its index and value.index is identical
$$.data.xs[t.id].sort((v1, v2) => v1 - v2);
$$.data.xs[t.id]?.sort((v1, v2) => v1 - v2);
});

// cache information about values
Expand Down
5 changes: 4 additions & 1 deletion src/ChartInternal/internals/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export default {
}

return function(d: IDataRow | IArcData | string): string {
const id: string = (d as IDataRow).id || (d as IArcData).data?.id || d as string;
const id: string = (d as IDataRow).id ||
(d as IArcData).data?.id ||
d as string;

const isLine = $$.isTypeOf(id, ["line", "spline", "step"]) || !config.data_types[id];
let color;

Expand Down
5 changes: 3 additions & 2 deletions src/ChartInternal/internals/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,11 @@ export default {

const getColor = id => {
const data = $$.getDataById(id);

return $$.levelColor ?
const color = $$.levelColor ?
$$.levelColor(data.values[0].value) :
$$.color(data);

return color;
};

const usePoint = config.legend_usePoint;
Expand Down
37 changes: 37 additions & 0 deletions test/internals/data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,4 +1118,41 @@ describe("DATA", () => {
});
});
});

describe("data.idConverter", () => {
before(() => {
args = {
data: {
idConverter: function(id) {
return id ? id : "data2";
},
columns: [
["data1", 30, 200, 100],
["", 50, 20, 10]
],
colors: {
data1: "red",
data2: "blue"
}
}
};
})

it("should generate chart without error.", () => {
expect(
chart = util.generate(args)
).to.not.throw;
});

it("data color should be defined correctly.", () => {
const {svg} = chart.$;

["circle", "line", "path"].forEach(type => {
const prop = type === "circle" ? "fill" : "stroke";
const node = svg.select(`[class$=data2] > ${type}`);

expect(node.style(prop)).to.be.equal("blue");
});
});
});
});