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

Slightly improve performance when using preformatted data. #1450

Merged
merged 1 commit into from
Dec 1, 2019
Merged
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
Slightly improve performance when using preformatted data.
  • Loading branch information
na9da committed Nov 27, 2019
commit 314fc9a88c4b553c5b9c1278a563d38b6ff1361f
16 changes: 10 additions & 6 deletions packages/victory-core/src/victory-util/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ function formatData(dataset, props, expectedKeys) {
const defaultKeys = ["x", "y", "y0"];
expectedKeys = Array.isArray(expectedKeys) ? expectedKeys : defaultKeys;

const stringMap = {
x: expectedKeys.indexOf("x") !== -1 ? createStringMap(props, "x") : undefined,
y: expectedKeys.indexOf("y") !== -1 ? createStringMap(props, "y") : undefined,
y0: expectedKeys.indexOf("y0") !== -1 ? createStringMap(props, "y") : undefined
};

const createAccessor = (name) => {
return Helpers.createAccessor(props[name] !== undefined ? props[name] : name);
};
Expand All @@ -202,6 +196,16 @@ function formatData(dataset, props, expectedKeys) {
props.y === "_y" &&
props.y0 === "_y0";

let stringMap;
if (preformattedData === false) {
// stringMap is not required if the data is preformatted
stringMap = {
x: expectedKeys.indexOf("x") !== -1 ? createStringMap(props, "x") : undefined,
y: expectedKeys.indexOf("y") !== -1 ? createStringMap(props, "y") : undefined,
y0: expectedKeys.indexOf("y0") !== -1 ? createStringMap(props, "y") : undefined
};
}

const data = preformattedData
? dataset
: dataset.reduce((dataArr, datum, index) => {
Expand Down