mirror of
https://github.com/apache/superset.git
synced 2026-04-07 02:21:51 +00:00
feat: Add currencies controls in country map (#39016)
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
import d3 from 'd3';
|
import d3 from 'd3';
|
||||||
import { extent as d3Extent } from 'd3-array';
|
import { extent as d3Extent } from 'd3-array';
|
||||||
import {
|
import {
|
||||||
|
ValueFormatter,
|
||||||
getNumberFormatter,
|
getNumberFormatter,
|
||||||
getSequentialSchemeRegistry,
|
getSequentialSchemeRegistry,
|
||||||
CategoricalColorNamespace,
|
CategoricalColorNamespace,
|
||||||
@@ -60,7 +61,8 @@ interface CountryMapProps {
|
|||||||
height: number;
|
height: number;
|
||||||
country: string;
|
country: string;
|
||||||
linearColorScheme: string;
|
linearColorScheme: string;
|
||||||
numberFormat: string;
|
numberFormat?: string; // left for backward compatibility
|
||||||
|
formatter: ValueFormatter;
|
||||||
colorScheme: string;
|
colorScheme: string;
|
||||||
sliceId: number;
|
sliceId: number;
|
||||||
}
|
}
|
||||||
@@ -74,13 +76,12 @@ function CountryMap(element: HTMLElement, props: CountryMapProps) {
|
|||||||
height,
|
height,
|
||||||
country,
|
country,
|
||||||
linearColorScheme,
|
linearColorScheme,
|
||||||
numberFormat,
|
formatter,
|
||||||
colorScheme,
|
colorScheme,
|
||||||
sliceId,
|
sliceId,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const container = element;
|
const container = element;
|
||||||
const format = getNumberFormatter(numberFormat);
|
|
||||||
const rawExtents = d3Extent(data, v => v.metric);
|
const rawExtents = d3Extent(data, v => v.metric);
|
||||||
const extents: [number, number] =
|
const extents: [number, number] =
|
||||||
rawExtents[0] != null && rawExtents[1] != null
|
rawExtents[0] != null && rawExtents[1] != null
|
||||||
@@ -182,7 +183,7 @@ function CountryMap(element: HTMLElement, props: CountryMapProps) {
|
|||||||
.style('top', `${position[1] + 30}px`)
|
.style('top', `${position[1] + 30}px`)
|
||||||
.style('left', `${position[0]}px`)
|
.style('left', `${position[0]}px`)
|
||||||
.html(
|
.html(
|
||||||
`<div><strong>${getNameOfRegion(d)}</strong><br>${result.length > 0 ? format(result[0].metric) : ''}</div>`,
|
`<div><strong>${getNameOfRegion(d)}</strong><br>${result.length > 0 ? formatter(result[0].metric) : ''}</div>`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ const config: ControlPanelConfig = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
['currency_format'],
|
||||||
['linear_color_scheme'],
|
['linear_color_scheme'],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,26 +16,48 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { ChartProps } from '@superset-ui/core';
|
import { ChartProps, getValueFormatter } from '@superset-ui/core';
|
||||||
|
|
||||||
export default function transformProps(chartProps: ChartProps) {
|
export default function transformProps(chartProps: ChartProps) {
|
||||||
const { width, height, formData, queriesData } = chartProps;
|
const { width, height, formData, queriesData, datasource } = chartProps;
|
||||||
const {
|
const {
|
||||||
linearColorScheme,
|
linearColorScheme,
|
||||||
numberFormat,
|
numberFormat,
|
||||||
|
currencyFormat,
|
||||||
selectCountry,
|
selectCountry,
|
||||||
colorScheme,
|
colorScheme,
|
||||||
sliceId,
|
sliceId,
|
||||||
|
metric,
|
||||||
} = formData;
|
} = formData;
|
||||||
|
|
||||||
|
const {
|
||||||
|
currencyFormats = {},
|
||||||
|
columnFormats = {},
|
||||||
|
currencyCodeColumn,
|
||||||
|
} = datasource;
|
||||||
|
const { data, detected_currency: detectedCurrency } = queriesData[0];
|
||||||
|
|
||||||
|
const formatter = getValueFormatter(
|
||||||
|
metric,
|
||||||
|
currencyFormats,
|
||||||
|
columnFormats,
|
||||||
|
numberFormat,
|
||||||
|
currencyFormat,
|
||||||
|
undefined, // key - not needed for single-metric charts
|
||||||
|
data,
|
||||||
|
currencyCodeColumn,
|
||||||
|
detectedCurrency,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
data: queriesData[0].data,
|
data: queriesData[0].data,
|
||||||
country: selectCountry ? String(selectCountry).toLowerCase() : null,
|
country: selectCountry ? String(selectCountry).toLowerCase() : null,
|
||||||
linearColorScheme,
|
linearColorScheme,
|
||||||
numberFormat,
|
numberFormat, // left for backward compatibility
|
||||||
colorScheme,
|
colorScheme,
|
||||||
sliceId,
|
sliceId,
|
||||||
|
formatter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ describe('CountryMap (legacy d3)', () => {
|
|||||||
linearColorScheme="bnbColors"
|
linearColorScheme="bnbColors"
|
||||||
colorScheme=""
|
colorScheme=""
|
||||||
numberFormat=".2f"
|
numberFormat=".2f"
|
||||||
|
formatter={jest.fn().mockReturnValue('100')}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -115,6 +116,7 @@ describe('CountryMap (legacy d3)', () => {
|
|||||||
country="canada"
|
country="canada"
|
||||||
linearColorScheme="bnbColors"
|
linearColorScheme="bnbColors"
|
||||||
colorScheme=""
|
colorScheme=""
|
||||||
|
formatter={jest.fn().mockReturnValue('100')}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -144,6 +146,7 @@ describe('CountryMap (legacy d3)', () => {
|
|||||||
country="canada"
|
country="canada"
|
||||||
linearColorScheme="bnbColors"
|
linearColorScheme="bnbColors"
|
||||||
colorScheme=""
|
colorScheme=""
|
||||||
|
formatter={jest.fn().mockReturnValue('100')}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user