Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
calculateLayerDomain(dataset, visualChannel) {
const {allData, filteredIndexForDomain} = dataset;
const defaultDomain = [0, 1];
const {scale} = visualChannel;
const scaleType = this.config[scale];
const field = this.config[visualChannel.field];
if (!field) {
// if colorField or sizeField were set back to null
return defaultDomain;
}
if (!SCALE_TYPES[scaleType]) {
Console.error(`scale type ${scaleType} not supported`);
return defaultDomain;
}
// TODO: refactor to add valueAccessor to field
const fieldIdx = field.tableFieldIndex - 1;
const isTime = field.type === ALL_FIELD_TYPES.timestamp;
const valueAccessor = maybeToDate.bind(
null,
isTime,
fieldIdx,
field.format
);
const indexValueAccessor = i => valueAccessor(allData[i]);
const sortFunction = getSortingFunction(field.type);
const get = (fac, parent) => {
const factory = map.get(fac);
// factory is not injected
if (!factory) {
Console.error(errorMsg.noDep(fac, parent));
return MissingComp;
}
// check if custom factory deps is declared
const depsLength = factory.deps ? factory.deps.length : 0;
let instances;
if (factory.length !== depsLength) {
Console.error(errorMsg.incompatibleDeps(factory, depsLength));
const MissingDeps = () => (
<div>{factory.name} is missing dependencies</div>
);
instances = MissingDeps;
} else {
instances =
cache.get(factory) ||
factory(
...(factory.deps ? factory.deps.map(dep => get(dep, factory)) : [])
);
}
cache.set(fac, instances);
return instances;
};
export function layerTypeChangeUpdater(state, action) {
const {oldLayer, newType} = action;
if (!oldLayer) {
return state;
}
const oldId = oldLayer.id;
const idx = state.layers.findIndex(l => l.id === oldId);
if (!state.layerClasses[newType]) {
Console.error(`${newType} is not a valid layer type`);
return state;
}
// get a mint layer, with new id and type
// because deck.gl uses id to match between new and old layer.
// If type has changed but id is the same, it will break
const newLayer = new state.layerClasses[newType]();
newLayer.assignConfigToLayer(oldLayer.config, oldLayer.visConfigSettings);
if (newLayer.config.dataId) {
const dataset = state.datasets[newLayer.config.dataId];
newLayer.updateLayerDomain(dataset);
}
const {layerData, layer} = calculateLayerData(newLayer, state);
export function editShader(vs, type, originalText, testToReplace) {
if (!vs.includes(originalText)) {
// Here we call Console.error when we fail to edit deck.gl shader
// This should be caught by layer test
Console.error(`Cannot edit ${type} layer shader`);
return vs;
}
return vs.replace(originalText, testToReplace);
}
validateVersion(version) {
if (!version) {
Console.error(
'There is no version number associated with this saved map'
);
return null;
}
if (!this._validVersions[version]) {
Console.error(`${version} is not a valid version`);
return null;
}
return version;
}
export function typeCheckRecipe(recipe) {
if (!Array.isArray(recipe) || recipe.length < 2) {
Console.error(errorMsg.wrongPairType);
return false;
}
const [factory, replacement] = recipe;
if (typeof factory !== 'function') {
Console.error('Error injecting factory: ', factory);
Console.error(errorMsg.notFunc);
return false;
} else if (typeof replacement !== 'function') {
Console.error('Error injecting replacement for: ', factory);
Console.error(errorMsg.notFunc);
return false;
}
return true;
}
outdatedVersionError() {
if (!this._isCurrentVersion()) {
Console.error(
`${this.key} ${
this.version
} is outdated. save should not be called anymore`
);
}
}
export function typeCheckRecipe(recipe) {
if (!Array.isArray(recipe) || recipe.length < 2) {
Console.error(errorMsg.wrongPairType);
return false;
}
const [factory, replacement] = recipe;
if (typeof factory !== 'function') {
Console.error('Error injecting factory: ', factory);
Console.error(errorMsg.notFunc);
return false;
} else if (typeof replacement !== 'function') {
Console.error('Error injecting replacement for: ', factory);
Console.error(errorMsg.notFunc);
return false;
}
return true;
}
validateVersion(version) {
if (!version) {
Console.error(
'There is no version number associated with this saved map'
);
return null;
}
if (!this._validVersions[version]) {
Console.error(`${version} is not a valid version`);
return null;
}
return version;
}