Skip to content

Commit

Permalink
Convert Js custom properties to Json
Browse files Browse the repository at this point in the history
Signed-off-by: Stanley-Okwii <[email protected]>
  • Loading branch information
Stanley-Okwii authored and edwinmp committed Mar 5, 2018
1 parent 0c121d6 commit c408564
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/SeriesPlayground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export interface SeriesPlaygroundProps {
type PlaygroundSeriesTrace = ({ name: string } & ScatterTrace);
interface SeriesPlaygroundState {
activeOption: string;
settings: string;
}

export class SeriesPlayground extends Component<SeriesPlaygroundProps, SeriesPlaygroundState> {
state = { activeOption: "layout" };
state = {
activeOption: "layout",
settings: this.props.layoutOptions
};
private newSeriesOptions: { layout: string, data: SeriesData[] } = {
layout: this.props.layoutOptions || "{}",
data: this.props.rawData || []
Expand Down Expand Up @@ -61,7 +65,8 @@ export class SeriesPlayground extends Component<SeriesPlaygroundProps, SeriesPla
onChange: value => this.onUpdate("layout", value),
onValidate: this.onValidate
})
),
)
,
createElement(Panel,
{
key: "modeler",
Expand Down Expand Up @@ -158,8 +163,14 @@ export class SeriesPlayground extends Component<SeriesPlaygroundProps, SeriesPla
this.timeoutId = setTimeout(() => {
try {
if (this.isValid && JSON.parse(value)) {
this.updateChart(source, 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);
}

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

0 comments on commit c408564

Please sign in to comment.