Skip to content

Commit

Permalink
Merge pull request #64 from emerson-eps/fix-for-dash-wrapper-legend
Browse files Browse the repository at this point in the history
fix: Converting colortable url to array value for legend dash wrapper
  • Loading branch information
shruthirai authored Mar 13, 2022
2 parents 3eaff4c + 9c9309a commit abd1da4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
15 changes: 12 additions & 3 deletions react-app/src/component/Legend/ContinuousLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare type legendProps = {
dataObjectName: string;
position?: number[] | null;
colorName: string;
colorTables: colorTablesArray;
colorTables: colorTablesArray | string;
horizontal?: boolean | null;
}

Expand Down Expand Up @@ -38,10 +38,19 @@ export const ContinuousLegend: React.FC<legendProps> = ({
};
}, [min, max, colorName, colorTables, horizontal]);

function continuousLegend() {
async function continuousLegend() {
const itemColor: ItemColor[] = [];
let dataSet;

if (typeof colorTables === "string") {
let res = await fetch(colorTables);
dataSet = await res.json()
}
// Return the matched colors array from color.tables.json file
const colorTableColors = colorsArray(colorName, colorTables);
let colorTableColors = typeof colorTables === "string" ?
colorsArray(colorName, dataSet)
:
colorsArray(colorName, colorTables);
colorTableColors.forEach((value: [number, number, number, number]) => {
// return the color and offset needed to draw the legend
itemColor.push({
Expand Down
20 changes: 14 additions & 6 deletions react-app/src/component/Legend/DiscreteLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare type colorLegendProps = {
dataObjectName: string;
position?: number[] | null;
colorName: string;
colorTables: colorTablesArray;
colorTables: colorTablesArray | string;
horizontal?: boolean | null;
}

Expand All @@ -35,13 +35,21 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
select(divRef.current).select("svg").remove();
};
}, [discreteData, colorName, colorTables, horizontal]);
function discreteLegend() {
async function discreteLegend() {
const itemName: string[] = [];
const itemColor: ItemColor[] = [];
const colorsArray: [number, number, number, number][] = colorTableData(
colorName,
colorTables
);
let dataSet;

if (typeof colorTables === "string") {
let res = await fetch(colorTables);
dataSet = await res.json()
}

let colorsArray = typeof colorTables === "string" ?
colorTableData(colorName, dataSet)
:
colorTableData(colorName, colorTables);

Object.keys(discreteData).forEach((key) => {
// eslint-disable-next-line
let code = (discreteData as { [key: string]: any })[key][1]
Expand Down

0 comments on commit abd1da4

Please sign in to comment.