-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-chart-web): refactor, sizing calculations
- Loading branch information
1 parent
ba2abc1
commit c7c60d8
Showing
3 changed files
with
78 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
packages/pluggableWidgets/custom-chart-web/src/utils/ChartDataProcessor.ts
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
packages/pluggableWidgets/custom-chart-web/src/utils/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Config, Data, Layout } from "plotly.js-dist-min"; | ||
|
||
export function parseData(staticData?: string, attributeData?: string, sampleData?: string): Data[] { | ||
let finalData: Data[] = []; | ||
|
||
try { | ||
if (staticData) { | ||
finalData = [...finalData, ...JSON.parse(staticData)]; | ||
} | ||
if (attributeData) { | ||
finalData = [...finalData, ...JSON.parse(attributeData)]; | ||
} | ||
if (!finalData.length && sampleData) { | ||
finalData = [...finalData, ...JSON.parse(sampleData)]; | ||
} | ||
} catch (error) { | ||
console.error("Error parsing chart data:", error); | ||
} | ||
|
||
return finalData; | ||
} | ||
|
||
export function parseLayout(staticLayout?: string, attributeLayout?: string, sampleLayout?: string): Partial<Layout> { | ||
let finalLayout: Partial<Layout> = {}; | ||
|
||
try { | ||
if (staticLayout) { | ||
finalLayout = { ...finalLayout, ...JSON.parse(staticLayout) }; | ||
} | ||
if (attributeLayout) { | ||
finalLayout = { ...finalLayout, ...JSON.parse(attributeLayout) }; | ||
} | ||
if (Object.keys(finalLayout).length === 0 && sampleLayout) { | ||
finalLayout = { ...finalLayout, ...JSON.parse(sampleLayout) }; | ||
} | ||
} catch (error) { | ||
console.error("Error parsing chart layout:", error); | ||
} | ||
return finalLayout; | ||
} | ||
|
||
export function parseConfig(configOptions?: string): Partial<Config> { | ||
if (!configOptions) { | ||
return {}; | ||
} | ||
|
||
try { | ||
return JSON.parse(configOptions); | ||
} catch (error) { | ||
console.error("Error parsing chart config:", error); | ||
return {}; | ||
} | ||
} |