Skip to content

Commit

Permalink
JS to JSON convert for Heat map and Pie chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanley-Okwii authored and edwinmp committed Mar 5, 2018
2 parents c6c3dc4 + c408564 commit 113583d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion developerCheatSheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The title appears above the chart. It can be configured as:
"titlefont": {
"family": "Droid Sans, Droid Serif, sans-serif",
"size": 20,
"color": "black"
"color": "black"
}
}

Expand Down
Empty file.
3 changes: 2 additions & 1 deletion src/PieChart/components/PiePlayground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ export class PiePlayground extends Component<PiePlaygroundProps, PiePlaygroundSt
try {
if (this.isValid && JSON.parse(value)) {
this.updateChart(source, value);
} else {
this.updateChart(source, Playground.convertJSToJSON(value));
}
} catch (error) {
this.isValid = false;
console.error("An error occured while updating the playground chart", error); // tslint:disable-line
}
}, 1000);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ export class Playground extends Component<{}, PlaygroundState> {

return null;
}

public static convertJSToJSON(value: string) {
const properJSON = value.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, `"$2": `).replace(/'/g, `"`);

return JSON.stringify(JSON.parse(properJSON), null, 2);
}
}
6 changes: 1 addition & 5 deletions src/components/SeriesPlayground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ export class SeriesPlayground extends Component<SeriesPlaygroundProps, SeriesPla
if (this.isValid && JSON.parse(value)) {
this.updateChart(source, JSON.stringify(JSON.parse(value), null, 2));
} else {
const properJson = value.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, `"$2": `);
const doubleQuote = properJson.replace(/'/g, `"`);
const newValue = JSON.stringify(JSON.parse(doubleQuote), null, 2);
this.updateChart(source, newValue);
this.updateChart(source, Playground.convertJSToJSON(value));
}

} catch {
this.isValid = false;
}
Expand Down

0 comments on commit 113583d

Please sign in to comment.