Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return defaultScale;
}
// use scale information if available
if (metadata.scale === 'ordinal') {
return ScaleType.Ordinal;
}
if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
}
// fall back to data type if necessary
switch (metadata.dataType) {
case 'boolean':
case 'string':
return ScaleType.Ordinal;
case 'date':
return ScaleType.Time;
default:
return ScaleType.Linear;
}
}
export function getScaleType(metadata: OperationMetadata | null, defaultScale: ScaleType) {
if (!metadata) {
return defaultScale;
}
// use scale information if available
if (metadata.scale === 'ordinal') {
return ScaleType.Ordinal;
}
if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
}
// fall back to data type if necessary
switch (metadata.dataType) {
case 'boolean':
case 'string':
return ScaleType.Ordinal;
case 'date':
return ScaleType.Time;
default:
return ScaleType.Linear;
}
}
);
return {
type: 'expression',
chain: [
{
type: 'function',
function: 'lens_xy_layer',
arguments: {
layerId: [layer.layerId],
hide: [Boolean(layer.hide)],
xAccessor: [layer.xAccessor],
yScaleType: [
getScaleType(metadata[layer.layerId][layer.accessors[0]], ScaleType.Ordinal),
],
xScaleType: [
getScaleType(metadata[layer.layerId][layer.xAccessor], ScaleType.Linear),
],
isHistogram: [isHistogramDimension],
splitAccessor: [layer.splitAccessor],
seriesType: [layer.seriesType],
accessors: layer.accessors,
columnToLabel: [JSON.stringify(columnToLabel)],
},
},
],
};
}),
},
export const barchartConfigs = (config?: { onElementClick?: ElementClickListener }) => ({
series: {
xScaleType: ScaleType.Ordinal,
yScaleType: ScaleType.Linear,
stackAccessors: ['y0'],
},
axis: {
xTickFormatter: numberFormatter,
},
settings: {
onElementClick: getOr(() => {}, 'onElementClick', config),
rotation: statItemBarchartRotation,
},
customHeight: statItemChartCustomHeight,
});