id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,000 | TerriaJS/terriajs | lib/Models/SdmxJsonCatalogItem.js | canTotalBeCalculatedAndIfNotWarnUser | function canTotalBeCalculatedAndIfNotWarnUser(item) {
if (canResultsBeSummed(item)) {
return true;
}
var conceptItems = item._concepts[0].items;
var changedActive = [];
conceptItems.forEach(concept => {
var numberActive = concept.items.filter(function(subconcept) {
return subconcept.isActive;
}).length;
if (numberActive > 1) {
changedActive.push('"' + concept.name + '"');
}
});
if (changedActive.length > 0) {
item.terria.error.raiseEvent(
new TerriaError({
sender: item,
title: "Cannot calculate a total",
message:
"You have selected multiple values for " +
changedActive.join(" and ") +
", but the measure you now have chosen cannot be totalled across them. \
As a result, there is no obvious measure to use to shade the regions (although you can still choose a region to view its data).\
To see the regions shaded again, please select only one value for " +
changedActive.join(" and ") +
", or select a different measure."
})
);
return false;
}
return true;
} | javascript | function canTotalBeCalculatedAndIfNotWarnUser(item) {
if (canResultsBeSummed(item)) {
return true;
}
var conceptItems = item._concepts[0].items;
var changedActive = [];
conceptItems.forEach(concept => {
var numberActive = concept.items.filter(function(subconcept) {
return subconcept.isActive;
}).length;
if (numberActive > 1) {
changedActive.push('"' + concept.name + '"');
}
});
if (changedActive.length > 0) {
item.terria.error.raiseEvent(
new TerriaError({
sender: item,
title: "Cannot calculate a total",
message:
"You have selected multiple values for " +
changedActive.join(" and ") +
", but the measure you now have chosen cannot be totalled across them. \
As a result, there is no obvious measure to use to shade the regions (although you can still choose a region to view its data).\
To see the regions shaded again, please select only one value for " +
changedActive.join(" and ") +
", or select a different measure."
})
);
return false;
}
return true;
} | [
"function",
"canTotalBeCalculatedAndIfNotWarnUser",
"(",
"item",
")",
"{",
"if",
"(",
"canResultsBeSummed",
"(",
"item",
")",
")",
"{",
"return",
"true",
";",
"}",
"var",
"conceptItems",
"=",
"item",
".",
"_concepts",
"[",
"0",
"]",
".",
"items",
";",
"var",
"changedActive",
"=",
"[",
"]",
";",
"conceptItems",
".",
"forEach",
"(",
"concept",
"=>",
"{",
"var",
"numberActive",
"=",
"concept",
".",
"items",
".",
"filter",
"(",
"function",
"(",
"subconcept",
")",
"{",
"return",
"subconcept",
".",
"isActive",
";",
"}",
")",
".",
"length",
";",
"if",
"(",
"numberActive",
">",
"1",
")",
"{",
"changedActive",
".",
"push",
"(",
"'\"'",
"+",
"concept",
".",
"name",
"+",
"'\"'",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"changedActive",
".",
"length",
">",
"0",
")",
"{",
"item",
".",
"terria",
".",
"error",
".",
"raiseEvent",
"(",
"new",
"TerriaError",
"(",
"{",
"sender",
":",
"item",
",",
"title",
":",
"\"Cannot calculate a total\"",
",",
"message",
":",
"\"You have selected multiple values for \"",
"+",
"changedActive",
".",
"join",
"(",
"\" and \"",
")",
"+",
"\", but the measure you now have chosen cannot be totalled across them. \\\n As a result, there is no obvious measure to use to shade the regions (although you can still choose a region to view its data).\\\n To see the regions shaded again, please select only one value for \"",
"+",
"changedActive",
".",
"join",
"(",
"\" and \"",
")",
"+",
"\", or select a different measure.\"",
"}",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Only show a warning if more than one value of a concept has been selected. Returns true if the user has been warned. | [
"Only",
"show",
"a",
"warning",
"if",
"more",
"than",
"one",
"value",
"of",
"a",
"concept",
"has",
"been",
"selected",
".",
"Returns",
"true",
"if",
"the",
"user",
"has",
"been",
"warned",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/SdmxJsonCatalogItem.js#L1264-L1296 |
7,001 | TerriaJS/terriajs | lib/Models/SdmxJsonCatalogItem.js | changedActiveItems | function changedActiveItems(item) {
if (!defined(item._dataflowUrl)) {
// All the data is already here, just update the total columns.
var shownDimensionCombinations = calculateShownDimensionCombinations(
item,
item._fullDimensions
);
var columns = item._tableStructure.columns.slice(
0,
shownDimensionCombinations.ids.length + item._numberOfInitialColumns
);
if (columns.length > 0) {
columns = columns.concat(
buildTotalSelectedColumn(item, shownDimensionCombinations)
);
updateColumns(item, columns);
}
return when();
} else {
// Get the URL for the data request, and load & build the appropriate table.
var activeConceptIds = calculateActiveConceptIds(item);
var dimensionRequestString = calculateDimensionRequestString(
item,
activeConceptIds,
item._fullDimensions
);
if (!defined(dimensionRequestString)) {
return; // No value for a dimension, so ignore.
}
return loadAndBuildTable(item, dimensionRequestString);
}
} | javascript | function changedActiveItems(item) {
if (!defined(item._dataflowUrl)) {
// All the data is already here, just update the total columns.
var shownDimensionCombinations = calculateShownDimensionCombinations(
item,
item._fullDimensions
);
var columns = item._tableStructure.columns.slice(
0,
shownDimensionCombinations.ids.length + item._numberOfInitialColumns
);
if (columns.length > 0) {
columns = columns.concat(
buildTotalSelectedColumn(item, shownDimensionCombinations)
);
updateColumns(item, columns);
}
return when();
} else {
// Get the URL for the data request, and load & build the appropriate table.
var activeConceptIds = calculateActiveConceptIds(item);
var dimensionRequestString = calculateDimensionRequestString(
item,
activeConceptIds,
item._fullDimensions
);
if (!defined(dimensionRequestString)) {
return; // No value for a dimension, so ignore.
}
return loadAndBuildTable(item, dimensionRequestString);
}
} | [
"function",
"changedActiveItems",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"item",
".",
"_dataflowUrl",
")",
")",
"{",
"// All the data is already here, just update the total columns.",
"var",
"shownDimensionCombinations",
"=",
"calculateShownDimensionCombinations",
"(",
"item",
",",
"item",
".",
"_fullDimensions",
")",
";",
"var",
"columns",
"=",
"item",
".",
"_tableStructure",
".",
"columns",
".",
"slice",
"(",
"0",
",",
"shownDimensionCombinations",
".",
"ids",
".",
"length",
"+",
"item",
".",
"_numberOfInitialColumns",
")",
";",
"if",
"(",
"columns",
".",
"length",
">",
"0",
")",
"{",
"columns",
"=",
"columns",
".",
"concat",
"(",
"buildTotalSelectedColumn",
"(",
"item",
",",
"shownDimensionCombinations",
")",
")",
";",
"updateColumns",
"(",
"item",
",",
"columns",
")",
";",
"}",
"return",
"when",
"(",
")",
";",
"}",
"else",
"{",
"// Get the URL for the data request, and load & build the appropriate table.",
"var",
"activeConceptIds",
"=",
"calculateActiveConceptIds",
"(",
"item",
")",
";",
"var",
"dimensionRequestString",
"=",
"calculateDimensionRequestString",
"(",
"item",
",",
"activeConceptIds",
",",
"item",
".",
"_fullDimensions",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"dimensionRequestString",
")",
")",
"{",
"return",
";",
"// No value for a dimension, so ignore.",
"}",
"return",
"loadAndBuildTable",
"(",
"item",
",",
"dimensionRequestString",
")",
";",
"}",
"}"
] | Called when the active column changes. Returns a promise. | [
"Called",
"when",
"the",
"active",
"column",
"changes",
".",
"Returns",
"a",
"promise",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/SdmxJsonCatalogItem.js#L1426-L1457 |
7,002 | TerriaJS/terriajs | lib/Models/SdmxJsonCatalogItem.js | getUrlFromDimensionRequestString | function getUrlFromDimensionRequestString(item, dimensionRequestString) {
var url = item._originalUrl;
if (url[url.length - 1] !== "/") {
url += "/";
}
url += dimensionRequestString + "/" + item.providerId;
if (defined(item.startTime)) {
url += "?startTime=" + item.startTime;
if (defined(item.endTime)) {
url += "&endTime=" + item.endTime;
}
} else if (defined(item.endTime)) {
url += "?endTime=" + item.endTime;
}
return url;
} | javascript | function getUrlFromDimensionRequestString(item, dimensionRequestString) {
var url = item._originalUrl;
if (url[url.length - 1] !== "/") {
url += "/";
}
url += dimensionRequestString + "/" + item.providerId;
if (defined(item.startTime)) {
url += "?startTime=" + item.startTime;
if (defined(item.endTime)) {
url += "&endTime=" + item.endTime;
}
} else if (defined(item.endTime)) {
url += "?endTime=" + item.endTime;
}
return url;
} | [
"function",
"getUrlFromDimensionRequestString",
"(",
"item",
",",
"dimensionRequestString",
")",
"{",
"var",
"url",
"=",
"item",
".",
"_originalUrl",
";",
"if",
"(",
"url",
"[",
"url",
".",
"length",
"-",
"1",
"]",
"!==",
"\"/\"",
")",
"{",
"url",
"+=",
"\"/\"",
";",
"}",
"url",
"+=",
"dimensionRequestString",
"+",
"\"/\"",
"+",
"item",
".",
"providerId",
";",
"if",
"(",
"defined",
"(",
"item",
".",
"startTime",
")",
")",
"{",
"url",
"+=",
"\"?startTime=\"",
"+",
"item",
".",
"startTime",
";",
"if",
"(",
"defined",
"(",
"item",
".",
"endTime",
")",
")",
"{",
"url",
"+=",
"\"&endTime=\"",
"+",
"item",
".",
"endTime",
";",
"}",
"}",
"else",
"if",
"(",
"defined",
"(",
"item",
".",
"endTime",
")",
")",
"{",
"url",
"+=",
"\"?endTime=\"",
"+",
"item",
".",
"endTime",
";",
"}",
"return",
"url",
";",
"}"
] | Convert a dimension request string like "a+b+c.d.e+f.g" into a URL. | [
"Convert",
"a",
"dimension",
"request",
"string",
"like",
"a",
"+",
"b",
"+",
"c",
".",
"d",
".",
"e",
"+",
"f",
".",
"g",
"into",
"a",
"URL",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/SdmxJsonCatalogItem.js#L1460-L1475 |
7,003 | TerriaJS/terriajs | lib/Core/hashFromString.js | hashFromString | function hashFromString(s) {
return Math.abs(
s.split("").reduce(function(prev, c) {
var hash = (prev << 5) - prev + c.charCodeAt(0);
return hash;
}, 0)
);
} | javascript | function hashFromString(s) {
return Math.abs(
s.split("").reduce(function(prev, c) {
var hash = (prev << 5) - prev + c.charCodeAt(0);
return hash;
}, 0)
);
} | [
"function",
"hashFromString",
"(",
"s",
")",
"{",
"return",
"Math",
".",
"abs",
"(",
"s",
".",
"split",
"(",
"\"\"",
")",
".",
"reduce",
"(",
"function",
"(",
"prev",
",",
"c",
")",
"{",
"var",
"hash",
"=",
"(",
"prev",
"<<",
"5",
")",
"-",
"prev",
"+",
"c",
".",
"charCodeAt",
"(",
"0",
")",
";",
"return",
"hash",
";",
"}",
",",
"0",
")",
")",
";",
"}"
] | Returns a 32-bit integer hash of a string. '' => 0. | [
"Returns",
"a",
"32",
"-",
"bit",
"integer",
"hash",
"of",
"a",
"string",
".",
"=",
">",
"0",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/hashFromString.js#L4-L11 |
7,004 | TerriaJS/terriajs | lib/Models/LocationMarkerUtils.js | correctEntityHeight | function correctEntityHeight(
entity,
currentCartographicPosition,
terrainProvider,
levelHint
) {
sampleTerrain(terrainProvider, levelHint, [currentCartographicPosition]).then(
function(updatedPositions) {
if (updatedPositions[0].height !== undefined) {
entity.position = Ellipsoid.WGS84.cartographicToCartesian(
updatedPositions[0]
);
} else if (levelHint > 0) {
correctEntityHeight(
entity,
currentCartographicPosition,
terrainProvider,
levelHint - 1
);
}
}
);
} | javascript | function correctEntityHeight(
entity,
currentCartographicPosition,
terrainProvider,
levelHint
) {
sampleTerrain(terrainProvider, levelHint, [currentCartographicPosition]).then(
function(updatedPositions) {
if (updatedPositions[0].height !== undefined) {
entity.position = Ellipsoid.WGS84.cartographicToCartesian(
updatedPositions[0]
);
} else if (levelHint > 0) {
correctEntityHeight(
entity,
currentCartographicPosition,
terrainProvider,
levelHint - 1
);
}
}
);
} | [
"function",
"correctEntityHeight",
"(",
"entity",
",",
"currentCartographicPosition",
",",
"terrainProvider",
",",
"levelHint",
")",
"{",
"sampleTerrain",
"(",
"terrainProvider",
",",
"levelHint",
",",
"[",
"currentCartographicPosition",
"]",
")",
".",
"then",
"(",
"function",
"(",
"updatedPositions",
")",
"{",
"if",
"(",
"updatedPositions",
"[",
"0",
"]",
".",
"height",
"!==",
"undefined",
")",
"{",
"entity",
".",
"position",
"=",
"Ellipsoid",
".",
"WGS84",
".",
"cartographicToCartesian",
"(",
"updatedPositions",
"[",
"0",
"]",
")",
";",
"}",
"else",
"if",
"(",
"levelHint",
">",
"0",
")",
"{",
"correctEntityHeight",
"(",
"entity",
",",
"currentCartographicPosition",
",",
"terrainProvider",
",",
"levelHint",
"-",
"1",
")",
";",
"}",
"}",
")",
";",
"}"
] | Gets the most detailed height from terrainProvider at currentCartographicPosition and updates entity position.
It starts querying at levelHint and makes its way down to level zero. | [
"Gets",
"the",
"most",
"detailed",
"height",
"from",
"terrainProvider",
"at",
"currentCartographicPosition",
"and",
"updates",
"entity",
"position",
".",
"It",
"starts",
"querying",
"at",
"levelHint",
"and",
"makes",
"its",
"way",
"down",
"to",
"level",
"zero",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/LocationMarkerUtils.js#L79-L101 |
7,005 | TerriaJS/terriajs | lib/Models/CatalogGroup.js | indexWithDescendants | function indexWithDescendants(items, index) {
items.forEach(function(item) {
item.allShareKeys.forEach(function(key) {
var insertionKey = key;
if (index[insertionKey]) {
insertionKey = generateUniqueKey(index, key);
if (item.uniqueId === key) {
// If this duplicate was the item's main key that will be used for sharing it in general, set this
// to the new key. This means that sharing the item will still work most of the time.
item.id = insertionKey;
}
console.warn(
"Duplicate shareKey: " +
key +
". Inserting new item under " +
insertionKey
);
}
index[insertionKey] = item;
}, this);
if (defined(item.items)) {
indexWithDescendants(item.items, index);
}
});
} | javascript | function indexWithDescendants(items, index) {
items.forEach(function(item) {
item.allShareKeys.forEach(function(key) {
var insertionKey = key;
if (index[insertionKey]) {
insertionKey = generateUniqueKey(index, key);
if (item.uniqueId === key) {
// If this duplicate was the item's main key that will be used for sharing it in general, set this
// to the new key. This means that sharing the item will still work most of the time.
item.id = insertionKey;
}
console.warn(
"Duplicate shareKey: " +
key +
". Inserting new item under " +
insertionKey
);
}
index[insertionKey] = item;
}, this);
if (defined(item.items)) {
indexWithDescendants(item.items, index);
}
});
} | [
"function",
"indexWithDescendants",
"(",
"items",
",",
"index",
")",
"{",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"item",
".",
"allShareKeys",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"insertionKey",
"=",
"key",
";",
"if",
"(",
"index",
"[",
"insertionKey",
"]",
")",
"{",
"insertionKey",
"=",
"generateUniqueKey",
"(",
"index",
",",
"key",
")",
";",
"if",
"(",
"item",
".",
"uniqueId",
"===",
"key",
")",
"{",
"// If this duplicate was the item's main key that will be used for sharing it in general, set this",
"// to the new key. This means that sharing the item will still work most of the time.",
"item",
".",
"id",
"=",
"insertionKey",
";",
"}",
"console",
".",
"warn",
"(",
"\"Duplicate shareKey: \"",
"+",
"key",
"+",
"\". Inserting new item under \"",
"+",
"insertionKey",
")",
";",
"}",
"index",
"[",
"insertionKey",
"]",
"=",
"item",
";",
"}",
",",
"this",
")",
";",
"if",
"(",
"defined",
"(",
"item",
".",
"items",
")",
")",
"{",
"indexWithDescendants",
"(",
"item",
".",
"items",
",",
"index",
")",
";",
"}",
"}",
")",
";",
"}"
] | Adds all passed items to the passed index, and all the children of those items recursively.
@private
@param {CatalogMember[]} items
@param {Object} index | [
"Adds",
"all",
"passed",
"items",
"to",
"the",
"passed",
"index",
"and",
"all",
"the",
"children",
"of",
"those",
"items",
"recursively",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogGroup.js#L349-L378 |
7,006 | TerriaJS/terriajs | lib/Models/CatalogGroup.js | generateUniqueKey | function generateUniqueKey(index, initialKey) {
var currentCandidate = initialKey;
var counter = 0;
while (index[currentCandidate]) {
var numberAtEndOfKeyMatches = currentCandidate.match(
NUMBER_AT_END_OF_KEY_REGEX
);
if (numberAtEndOfKeyMatches !== null) {
var nextNumber = parseInt(numberAtEndOfKeyMatches[1], 10) + 1;
currentCandidate = currentCandidate.replace(
NUMBER_AT_END_OF_KEY_REGEX,
"(" + nextNumber + ")"
);
} else {
currentCandidate += " (1)";
}
// This loop should always find something eventually, but because it's a bit dangerous looping endlessly...
counter++;
if (counter >= 100000) {
throw new DeveloperError(
"Was not able to find a unique key for " +
initialKey +
" after 100000 iterations." +
" This is probably because the regex for matching keys was somehow unable to work for that key."
);
}
}
return currentCandidate;
} | javascript | function generateUniqueKey(index, initialKey) {
var currentCandidate = initialKey;
var counter = 0;
while (index[currentCandidate]) {
var numberAtEndOfKeyMatches = currentCandidate.match(
NUMBER_AT_END_OF_KEY_REGEX
);
if (numberAtEndOfKeyMatches !== null) {
var nextNumber = parseInt(numberAtEndOfKeyMatches[1], 10) + 1;
currentCandidate = currentCandidate.replace(
NUMBER_AT_END_OF_KEY_REGEX,
"(" + nextNumber + ")"
);
} else {
currentCandidate += " (1)";
}
// This loop should always find something eventually, but because it's a bit dangerous looping endlessly...
counter++;
if (counter >= 100000) {
throw new DeveloperError(
"Was not able to find a unique key for " +
initialKey +
" after 100000 iterations." +
" This is probably because the regex for matching keys was somehow unable to work for that key."
);
}
}
return currentCandidate;
} | [
"function",
"generateUniqueKey",
"(",
"index",
",",
"initialKey",
")",
"{",
"var",
"currentCandidate",
"=",
"initialKey",
";",
"var",
"counter",
"=",
"0",
";",
"while",
"(",
"index",
"[",
"currentCandidate",
"]",
")",
"{",
"var",
"numberAtEndOfKeyMatches",
"=",
"currentCandidate",
".",
"match",
"(",
"NUMBER_AT_END_OF_KEY_REGEX",
")",
";",
"if",
"(",
"numberAtEndOfKeyMatches",
"!==",
"null",
")",
"{",
"var",
"nextNumber",
"=",
"parseInt",
"(",
"numberAtEndOfKeyMatches",
"[",
"1",
"]",
",",
"10",
")",
"+",
"1",
";",
"currentCandidate",
"=",
"currentCandidate",
".",
"replace",
"(",
"NUMBER_AT_END_OF_KEY_REGEX",
",",
"\"(\"",
"+",
"nextNumber",
"+",
"\")\"",
")",
";",
"}",
"else",
"{",
"currentCandidate",
"+=",
"\" (1)\"",
";",
"}",
"// This loop should always find something eventually, but because it's a bit dangerous looping endlessly...",
"counter",
"++",
";",
"if",
"(",
"counter",
">=",
"100000",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"Was not able to find a unique key for \"",
"+",
"initialKey",
"+",
"\" after 100000 iterations.\"",
"+",
"\" This is probably because the regex for matching keys was somehow unable to work for that key.\"",
")",
";",
"}",
"}",
"return",
"currentCandidate",
";",
"}"
] | Generates a unique key from a non-unique one by adding a number after it. If the key already has a number added,
it will increment that number.
@private
@param index An index to check for uniqueness.
@param initialKey The key to start from.
@returns {String} A new, unique key. | [
"Generates",
"a",
"unique",
"key",
"from",
"a",
"non",
"-",
"unique",
"one",
"by",
"adding",
"a",
"number",
"after",
"it",
".",
"If",
"the",
"key",
"already",
"has",
"a",
"number",
"added",
"it",
"will",
"increment",
"that",
"number",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogGroup.js#L388-L420 |
7,007 | TerriaJS/terriajs | lib/Models/CatalogGroup.js | deIndexWithDescendants | function deIndexWithDescendants(items, index) {
items.forEach(function(item) {
item.allShareKeys.forEach(function(key) {
index[key] = undefined;
}, this);
if (defined(item.items)) {
deIndexWithDescendants(item.items, index);
}
});
} | javascript | function deIndexWithDescendants(items, index) {
items.forEach(function(item) {
item.allShareKeys.forEach(function(key) {
index[key] = undefined;
}, this);
if (defined(item.items)) {
deIndexWithDescendants(item.items, index);
}
});
} | [
"function",
"deIndexWithDescendants",
"(",
"items",
",",
"index",
")",
"{",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"item",
".",
"allShareKeys",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"index",
"[",
"key",
"]",
"=",
"undefined",
";",
"}",
",",
"this",
")",
";",
"if",
"(",
"defined",
"(",
"item",
".",
"items",
")",
")",
"{",
"deIndexWithDescendants",
"(",
"item",
".",
"items",
",",
"index",
")",
";",
"}",
"}",
")",
";",
"}"
] | Removes all passed items to the passed index, and all the children of those items recursively.
@param {CatalogMember[]} items
@param {Object} index | [
"Removes",
"all",
"passed",
"items",
"to",
"the",
"passed",
"index",
"and",
"all",
"the",
"children",
"of",
"those",
"items",
"recursively",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogGroup.js#L428-L438 |
7,008 | TerriaJS/terriajs | lib/Models/CswCatalogGroup.js | findGroup | function findGroup(catalogGroup, keywordsGroups, record) {
for (var i = 0; i < keywordsGroups.length; i++) {
var kg = keywordsGroups[i];
var fields = record[kg.field];
var matched = false;
if (defined(fields)) {
if (fields instanceof String || typeof fields === "string") {
fields = [fields];
}
for (var j = 0; j < fields.length; j++) {
var field = fields[j];
if (matchValue(kg.value, field, kg.regex)) {
matched = true;
break;
}
}
}
if (matched) {
var newGroup = addGroupIfNotAlreadyPresent(
kg.group ? kg.group : kg.value,
catalogGroup
);
if (kg.children && defined(newGroup)) {
// recurse to see if it fits into any of the children
catalogGroup = findGroup(newGroup, kg.children, record);
if (!defined(catalogGroup)) {
//console.log("No match in children for record "+record.title+"::"+record.subject+"::"+record.title+", will assign to "+newGroup.name);
catalogGroup = newGroup;
}
} else if (defined(newGroup)) {
catalogGroup = newGroup;
}
return catalogGroup;
}
}
} | javascript | function findGroup(catalogGroup, keywordsGroups, record) {
for (var i = 0; i < keywordsGroups.length; i++) {
var kg = keywordsGroups[i];
var fields = record[kg.field];
var matched = false;
if (defined(fields)) {
if (fields instanceof String || typeof fields === "string") {
fields = [fields];
}
for (var j = 0; j < fields.length; j++) {
var field = fields[j];
if (matchValue(kg.value, field, kg.regex)) {
matched = true;
break;
}
}
}
if (matched) {
var newGroup = addGroupIfNotAlreadyPresent(
kg.group ? kg.group : kg.value,
catalogGroup
);
if (kg.children && defined(newGroup)) {
// recurse to see if it fits into any of the children
catalogGroup = findGroup(newGroup, kg.children, record);
if (!defined(catalogGroup)) {
//console.log("No match in children for record "+record.title+"::"+record.subject+"::"+record.title+", will assign to "+newGroup.name);
catalogGroup = newGroup;
}
} else if (defined(newGroup)) {
catalogGroup = newGroup;
}
return catalogGroup;
}
}
} | [
"function",
"findGroup",
"(",
"catalogGroup",
",",
"keywordsGroups",
",",
"record",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keywordsGroups",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"kg",
"=",
"keywordsGroups",
"[",
"i",
"]",
";",
"var",
"fields",
"=",
"record",
"[",
"kg",
".",
"field",
"]",
";",
"var",
"matched",
"=",
"false",
";",
"if",
"(",
"defined",
"(",
"fields",
")",
")",
"{",
"if",
"(",
"fields",
"instanceof",
"String",
"||",
"typeof",
"fields",
"===",
"\"string\"",
")",
"{",
"fields",
"=",
"[",
"fields",
"]",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"fields",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"field",
"=",
"fields",
"[",
"j",
"]",
";",
"if",
"(",
"matchValue",
"(",
"kg",
".",
"value",
",",
"field",
",",
"kg",
".",
"regex",
")",
")",
"{",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"matched",
")",
"{",
"var",
"newGroup",
"=",
"addGroupIfNotAlreadyPresent",
"(",
"kg",
".",
"group",
"?",
"kg",
".",
"group",
":",
"kg",
".",
"value",
",",
"catalogGroup",
")",
";",
"if",
"(",
"kg",
".",
"children",
"&&",
"defined",
"(",
"newGroup",
")",
")",
"{",
"// recurse to see if it fits into any of the children",
"catalogGroup",
"=",
"findGroup",
"(",
"newGroup",
",",
"kg",
".",
"children",
",",
"record",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"catalogGroup",
")",
")",
"{",
"//console.log(\"No match in children for record \"+record.title+\"::\"+record.subject+\"::\"+record.title+\", will assign to \"+newGroup.name);",
"catalogGroup",
"=",
"newGroup",
";",
"}",
"}",
"else",
"if",
"(",
"defined",
"(",
"newGroup",
")",
")",
"{",
"catalogGroup",
"=",
"newGroup",
";",
"}",
"return",
"catalogGroup",
";",
"}",
"}",
"}"
] | find groups that the record belongs to and create any that don't exist already | [
"find",
"groups",
"that",
"the",
"record",
"belongs",
"to",
"and",
"create",
"any",
"that",
"don",
"t",
"exist",
"already"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CswCatalogGroup.js#L635-L670 |
7,009 | TerriaJS/terriajs | lib/ReactViews/Custom/Chart/downloadHrefWorker.js | toArrayOfRows | function toArrayOfRows(columnValueArrays, columnNames) {
if (columnValueArrays.length < 1) {
return;
}
const rows = columnValueArrays[0].map(function(value0, rowIndex) {
return columnValueArrays.map(function(values) {
return values[rowIndex];
});
});
rows.unshift(columnNames);
return rows;
} | javascript | function toArrayOfRows(columnValueArrays, columnNames) {
if (columnValueArrays.length < 1) {
return;
}
const rows = columnValueArrays[0].map(function(value0, rowIndex) {
return columnValueArrays.map(function(values) {
return values[rowIndex];
});
});
rows.unshift(columnNames);
return rows;
} | [
"function",
"toArrayOfRows",
"(",
"columnValueArrays",
",",
"columnNames",
")",
"{",
"if",
"(",
"columnValueArrays",
".",
"length",
"<",
"1",
")",
"{",
"return",
";",
"}",
"const",
"rows",
"=",
"columnValueArrays",
"[",
"0",
"]",
".",
"map",
"(",
"function",
"(",
"value0",
",",
"rowIndex",
")",
"{",
"return",
"columnValueArrays",
".",
"map",
"(",
"function",
"(",
"values",
")",
"{",
"return",
"values",
"[",
"rowIndex",
"]",
";",
"}",
")",
";",
"}",
")",
";",
"rows",
".",
"unshift",
"(",
"columnNames",
")",
";",
"return",
"rows",
";",
"}"
] | Convert an array of column values, with column names, to an array of row values.
@param {Array[]} columnValueArrays Array of column values, eg. [[1,2,3], [4,5,6]].
@param {String[]} columnNames Array of column names, eg ['x', 'y'].
@return {Array[]} Array of rows, starting with the column names, eg. [['x', 'y'], [1, 4], [2, 5], [3, 6]]. | [
"Convert",
"an",
"array",
"of",
"column",
"values",
"with",
"column",
"names",
"to",
"an",
"array",
"of",
"row",
"values",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Custom/Chart/downloadHrefWorker.js#L106-L117 |
7,010 | TerriaJS/terriajs | lib/Map/EarthGravityModel1996.js | getHeightValue | function getHeightValue(data, recordIndex, heightIndex) {
if (recordIndex > 720) {
recordIndex = 720;
} else if (recordIndex < 0) {
recordIndex = 0;
}
if (heightIndex > 1439) {
heightIndex -= 1440;
} else if (heightIndex < 0) {
heightIndex += 1440;
}
return data[recordIndex * 1440 + heightIndex];
} | javascript | function getHeightValue(data, recordIndex, heightIndex) {
if (recordIndex > 720) {
recordIndex = 720;
} else if (recordIndex < 0) {
recordIndex = 0;
}
if (heightIndex > 1439) {
heightIndex -= 1440;
} else if (heightIndex < 0) {
heightIndex += 1440;
}
return data[recordIndex * 1440 + heightIndex];
} | [
"function",
"getHeightValue",
"(",
"data",
",",
"recordIndex",
",",
"heightIndex",
")",
"{",
"if",
"(",
"recordIndex",
">",
"720",
")",
"{",
"recordIndex",
"=",
"720",
";",
"}",
"else",
"if",
"(",
"recordIndex",
"<",
"0",
")",
"{",
"recordIndex",
"=",
"0",
";",
"}",
"if",
"(",
"heightIndex",
">",
"1439",
")",
"{",
"heightIndex",
"-=",
"1440",
";",
"}",
"else",
"if",
"(",
"heightIndex",
"<",
"0",
")",
"{",
"heightIndex",
"+=",
"1440",
";",
"}",
"return",
"data",
"[",
"recordIndex",
"*",
"1440",
"+",
"heightIndex",
"]",
";",
"}"
] | Heights returned by this function are in centimeters. | [
"Heights",
"returned",
"by",
"this",
"function",
"are",
"in",
"centimeters",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/EarthGravityModel1996.js#L120-L134 |
7,011 | TerriaJS/terriajs | lib/Models/PlacesLikeMeCatalogFunction.js | function(terria) {
CatalogFunction.call(this, terria);
this.url = undefined;
this.name = "Regions like this";
this.description =
"Identifies regions that are _most like_ a given region according to a given set of characteristics.";
this._regionTypeParameter = new RegionTypeParameter({
terria: this.terria,
catalogFunction: this,
id: "regionType",
name: "Region Type",
description: "The type of region to analyze."
});
this._regionParameter = new RegionParameter({
terria: this.terria,
catalogFunction: this,
id: "region",
name: "Region",
description:
"The region to analyze. The analysis will determine which regions are most similar to this one.",
regionProvider: this._regionTypeParameter
});
this._dataParameter = new RegionDataParameter({
terria: this.terria,
catalogFunction: this,
id: "data",
name: "Characteristics",
description: "The region characteristics to include in the analysis.",
regionProvider: this._regionTypeParameter
});
this._parameters = [
this._regionTypeParameter,
this._regionParameter,
this._dataParameter
];
} | javascript | function(terria) {
CatalogFunction.call(this, terria);
this.url = undefined;
this.name = "Regions like this";
this.description =
"Identifies regions that are _most like_ a given region according to a given set of characteristics.";
this._regionTypeParameter = new RegionTypeParameter({
terria: this.terria,
catalogFunction: this,
id: "regionType",
name: "Region Type",
description: "The type of region to analyze."
});
this._regionParameter = new RegionParameter({
terria: this.terria,
catalogFunction: this,
id: "region",
name: "Region",
description:
"The region to analyze. The analysis will determine which regions are most similar to this one.",
regionProvider: this._regionTypeParameter
});
this._dataParameter = new RegionDataParameter({
terria: this.terria,
catalogFunction: this,
id: "data",
name: "Characteristics",
description: "The region characteristics to include in the analysis.",
regionProvider: this._regionTypeParameter
});
this._parameters = [
this._regionTypeParameter,
this._regionParameter,
this._dataParameter
];
} | [
"function",
"(",
"terria",
")",
"{",
"CatalogFunction",
".",
"call",
"(",
"this",
",",
"terria",
")",
";",
"this",
".",
"url",
"=",
"undefined",
";",
"this",
".",
"name",
"=",
"\"Regions like this\"",
";",
"this",
".",
"description",
"=",
"\"Identifies regions that are _most like_ a given region according to a given set of characteristics.\"",
";",
"this",
".",
"_regionTypeParameter",
"=",
"new",
"RegionTypeParameter",
"(",
"{",
"terria",
":",
"this",
".",
"terria",
",",
"catalogFunction",
":",
"this",
",",
"id",
":",
"\"regionType\"",
",",
"name",
":",
"\"Region Type\"",
",",
"description",
":",
"\"The type of region to analyze.\"",
"}",
")",
";",
"this",
".",
"_regionParameter",
"=",
"new",
"RegionParameter",
"(",
"{",
"terria",
":",
"this",
".",
"terria",
",",
"catalogFunction",
":",
"this",
",",
"id",
":",
"\"region\"",
",",
"name",
":",
"\"Region\"",
",",
"description",
":",
"\"The region to analyze. The analysis will determine which regions are most similar to this one.\"",
",",
"regionProvider",
":",
"this",
".",
"_regionTypeParameter",
"}",
")",
";",
"this",
".",
"_dataParameter",
"=",
"new",
"RegionDataParameter",
"(",
"{",
"terria",
":",
"this",
".",
"terria",
",",
"catalogFunction",
":",
"this",
",",
"id",
":",
"\"data\"",
",",
"name",
":",
"\"Characteristics\"",
",",
"description",
":",
"\"The region characteristics to include in the analysis.\"",
",",
"regionProvider",
":",
"this",
".",
"_regionTypeParameter",
"}",
")",
";",
"this",
".",
"_parameters",
"=",
"[",
"this",
".",
"_regionTypeParameter",
",",
"this",
".",
"_regionParameter",
",",
"this",
".",
"_dataParameter",
"]",
";",
"}"
] | A Terria Spatial Inference function to identify regions that are _most like_ a given region according to a
given set of characteristics.
@alias PlacesLikeMeCatalogfunction
@constructor
@extends CatalogFunction
@param {Terria} terria The Terria instance. | [
"A",
"Terria",
"Spatial",
"Inference",
"function",
"to",
"identify",
"regions",
"that",
"are",
"_most",
"like_",
"a",
"given",
"region",
"according",
"to",
"a",
"given",
"set",
"of",
"characteristics",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/PlacesLikeMeCatalogFunction.js#L28-L68 |
|
7,012 | TerriaJS/terriajs | lib/Map/TableColumn.js | applyHintsToName | function applyHintsToName(hintSet, name, unallowedTypes) {
for (var i in hintSet) {
if (hintSet[i].hint.test(name)) {
var guess = hintSet[i].type;
if (unallowedTypes.indexOf(guess) === -1) {
return guess;
}
}
}
} | javascript | function applyHintsToName(hintSet, name, unallowedTypes) {
for (var i in hintSet) {
if (hintSet[i].hint.test(name)) {
var guess = hintSet[i].type;
if (unallowedTypes.indexOf(guess) === -1) {
return guess;
}
}
}
} | [
"function",
"applyHintsToName",
"(",
"hintSet",
",",
"name",
",",
"unallowedTypes",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"hintSet",
")",
"{",
"if",
"(",
"hintSet",
"[",
"i",
"]",
".",
"hint",
".",
"test",
"(",
"name",
")",
")",
"{",
"var",
"guess",
"=",
"hintSet",
"[",
"i",
"]",
".",
"type",
";",
"if",
"(",
"unallowedTypes",
".",
"indexOf",
"(",
"guess",
")",
"===",
"-",
"1",
")",
"{",
"return",
"guess",
";",
"}",
"}",
"}",
"}"
] | Guesses the best variable type based on its name. Returns undefined if no guess.
@private
@param {Object[]} hintSet The hint set to use, eg. [{ hint: /^(.*[_ ])?(year)/i, type: VarSubType.YEAR }].
@param {String} name The variable name, eg. 'Time (AEST)'.
@param {VarType[]|VarSubType[]} unallowedTypes Types not to consider. Pass [] to consider all types or subtypes.
@return {VarType|VarSubType} The variable type or subtype, eg. VarType.SCALAR. | [
"Guesses",
"the",
"best",
"variable",
"type",
"based",
"on",
"its",
"name",
".",
"Returns",
"undefined",
"if",
"no",
"guess",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableColumn.js#L710-L719 |
7,013 | TerriaJS/terriajs | lib/Core/formatPropertyValue.js | formatPropertyValue | function formatPropertyValue(value, options) {
if (typeof value === "number") {
return formatNumberForLocale(value, options);
} else if (typeof value === "string") {
// do not linkify if it contains html elements, which we detect by looking for <x...>
// this could catch some non-html strings such as "a<3 && b>1", but not linkifying those is no big deal
if (!/<[a-z][\s\S]*>/i.test(value)) {
return linkifyContent(value);
}
}
return value;
} | javascript | function formatPropertyValue(value, options) {
if (typeof value === "number") {
return formatNumberForLocale(value, options);
} else if (typeof value === "string") {
// do not linkify if it contains html elements, which we detect by looking for <x...>
// this could catch some non-html strings such as "a<3 && b>1", but not linkifying those is no big deal
if (!/<[a-z][\s\S]*>/i.test(value)) {
return linkifyContent(value);
}
}
return value;
} | [
"function",
"formatPropertyValue",
"(",
"value",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"value",
"===",
"\"number\"",
")",
"{",
"return",
"formatNumberForLocale",
"(",
"value",
",",
"options",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"value",
"===",
"\"string\"",
")",
"{",
"// do not linkify if it contains html elements, which we detect by looking for <x...>",
"// this could catch some non-html strings such as \"a<3 && b>1\", but not linkifying those is no big deal",
"if",
"(",
"!",
"/",
"<[a-z][\\s\\S]*>",
"/",
"i",
".",
"test",
"(",
"value",
")",
")",
"{",
"return",
"linkifyContent",
"(",
"value",
")",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Format the value for the description, used by the Feature Info Panel.
Strings have markdown applied to them. Anything else is returned as-is.
@param {} value The value to format.
@param {Object} [options] Number formatting options, passed to formatNumberForLocale. | [
"Format",
"the",
"value",
"for",
"the",
"description",
"used",
"by",
"the",
"Feature",
"Info",
"Panel",
".",
"Strings",
"have",
"markdown",
"applied",
"to",
"them",
".",
"Anything",
"else",
"is",
"returned",
"as",
"-",
"is",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/formatPropertyValue.js#L14-L25 |
7,014 | TerriaJS/terriajs | lib/Core/serializeToJson.js | serializeToJson | function serializeToJson(target, filterFunction, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
filterFunction = defaultValue(filterFunction, function() {
return true;
});
var result = {};
for (var propertyName in target) {
if (
target.hasOwnProperty(propertyName) &&
propertyName.length > 0 &&
propertyName[0] !== "_" &&
propertyName !== "parent" &&
filterFunction(propertyName, target)
) {
if (target.serializers && target.serializers[propertyName]) {
target.serializers[propertyName](target, result, propertyName, options);
} else {
result[propertyName] = target[propertyName];
}
}
}
return result;
} | javascript | function serializeToJson(target, filterFunction, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
filterFunction = defaultValue(filterFunction, function() {
return true;
});
var result = {};
for (var propertyName in target) {
if (
target.hasOwnProperty(propertyName) &&
propertyName.length > 0 &&
propertyName[0] !== "_" &&
propertyName !== "parent" &&
filterFunction(propertyName, target)
) {
if (target.serializers && target.serializers[propertyName]) {
target.serializers[propertyName](target, result, propertyName, options);
} else {
result[propertyName] = target[propertyName];
}
}
}
return result;
} | [
"function",
"serializeToJson",
"(",
"target",
",",
"filterFunction",
",",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"filterFunction",
"=",
"defaultValue",
"(",
"filterFunction",
",",
"function",
"(",
")",
"{",
"return",
"true",
";",
"}",
")",
";",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"propertyName",
"in",
"target",
")",
"{",
"if",
"(",
"target",
".",
"hasOwnProperty",
"(",
"propertyName",
")",
"&&",
"propertyName",
".",
"length",
">",
"0",
"&&",
"propertyName",
"[",
"0",
"]",
"!==",
"\"_\"",
"&&",
"propertyName",
"!==",
"\"parent\"",
"&&",
"filterFunction",
"(",
"propertyName",
",",
"target",
")",
")",
"{",
"if",
"(",
"target",
".",
"serializers",
"&&",
"target",
".",
"serializers",
"[",
"propertyName",
"]",
")",
"{",
"target",
".",
"serializers",
"[",
"propertyName",
"]",
"(",
"target",
",",
"result",
",",
"propertyName",
",",
"options",
")",
";",
"}",
"else",
"{",
"result",
"[",
"propertyName",
"]",
"=",
"target",
"[",
"propertyName",
"]",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Serializes an object to JSON.
@param {Object} target The object to serialize.
@param {Function} filterFunction A function that, when passed the name of a property as its only parameter, returns true if that property should be serialized and false otherwise.
@param {Object} [options] Optional parameters to custom serializers.
@return {Object} An object literal corresponding to the serialized object, ready to pass to `JSON.stringify`. | [
"Serializes",
"an",
"object",
"to",
"JSON",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/serializeToJson.js#L13-L38 |
7,015 | TerriaJS/terriajs | lib/Models/RegionMapping.js | function(catalogItem, tableStructure, tableStyle) {
this._tableStructure = defined(tableStructure)
? tableStructure
: new TableStructure();
if (defined(tableStyle) && !(tableStyle instanceof TableStyle)) {
throw new DeveloperError("Please pass a TableStyle object.");
}
this._tableStyle = tableStyle; // Can be undefined.
this._changed = new CesiumEvent();
this._legendHelper = undefined;
this._legendUrl = undefined;
this._extent = undefined;
this._loadingData = false;
this._catalogItem = catalogItem;
this._regionMappingDefinitionsUrl = defined(catalogItem)
? catalogItem.terria.configParameters.regionMappingDefinitionsUrl
: undefined;
this._regionDetails = undefined; // For caching the region details.
this._imageryLayer = undefined;
this._nextImageryLayer = undefined; // For pre-rendering time-varying layers
this._nextImageryLayerInterval = undefined;
this._hadImageryAtLayerIndex = undefined;
this._hasDisplayedFeedback = false; // So that we only show the feedback once.
this._constantRegionRowObjects = undefined;
this._constantRegionRowDescriptions = undefined;
// Track _tableStructure so that the catalogItem's concepts are maintained.
// Track _legendUrl so that the catalogItem can update the legend if it changes.
// Track _regionDetails so that when it is discovered that region mapping applies,
// it updates the legendHelper via activeItems, and catalogItem properties like supportsReordering.
knockout.track(this, ["_tableStructure", "_legendUrl", "_regionDetails"]);
// Whenever the active item is changed, recalculate the legend and the display of all the entities.
// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.
knockout
.getObservable(this._tableStructure, "activeItems")
.subscribe(changedActiveItems.bind(null, this), this);
knockout
.getObservable(this._catalogItem, "currentTime")
.subscribe(function() {
if (this.hasActiveTimeColumn) {
onClockTick(this);
}
}, this);
} | javascript | function(catalogItem, tableStructure, tableStyle) {
this._tableStructure = defined(tableStructure)
? tableStructure
: new TableStructure();
if (defined(tableStyle) && !(tableStyle instanceof TableStyle)) {
throw new DeveloperError("Please pass a TableStyle object.");
}
this._tableStyle = tableStyle; // Can be undefined.
this._changed = new CesiumEvent();
this._legendHelper = undefined;
this._legendUrl = undefined;
this._extent = undefined;
this._loadingData = false;
this._catalogItem = catalogItem;
this._regionMappingDefinitionsUrl = defined(catalogItem)
? catalogItem.terria.configParameters.regionMappingDefinitionsUrl
: undefined;
this._regionDetails = undefined; // For caching the region details.
this._imageryLayer = undefined;
this._nextImageryLayer = undefined; // For pre-rendering time-varying layers
this._nextImageryLayerInterval = undefined;
this._hadImageryAtLayerIndex = undefined;
this._hasDisplayedFeedback = false; // So that we only show the feedback once.
this._constantRegionRowObjects = undefined;
this._constantRegionRowDescriptions = undefined;
// Track _tableStructure so that the catalogItem's concepts are maintained.
// Track _legendUrl so that the catalogItem can update the legend if it changes.
// Track _regionDetails so that when it is discovered that region mapping applies,
// it updates the legendHelper via activeItems, and catalogItem properties like supportsReordering.
knockout.track(this, ["_tableStructure", "_legendUrl", "_regionDetails"]);
// Whenever the active item is changed, recalculate the legend and the display of all the entities.
// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.
knockout
.getObservable(this._tableStructure, "activeItems")
.subscribe(changedActiveItems.bind(null, this), this);
knockout
.getObservable(this._catalogItem, "currentTime")
.subscribe(function() {
if (this.hasActiveTimeColumn) {
onClockTick(this);
}
}, this);
} | [
"function",
"(",
"catalogItem",
",",
"tableStructure",
",",
"tableStyle",
")",
"{",
"this",
".",
"_tableStructure",
"=",
"defined",
"(",
"tableStructure",
")",
"?",
"tableStructure",
":",
"new",
"TableStructure",
"(",
")",
";",
"if",
"(",
"defined",
"(",
"tableStyle",
")",
"&&",
"!",
"(",
"tableStyle",
"instanceof",
"TableStyle",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"Please pass a TableStyle object.\"",
")",
";",
"}",
"this",
".",
"_tableStyle",
"=",
"tableStyle",
";",
"// Can be undefined.",
"this",
".",
"_changed",
"=",
"new",
"CesiumEvent",
"(",
")",
";",
"this",
".",
"_legendHelper",
"=",
"undefined",
";",
"this",
".",
"_legendUrl",
"=",
"undefined",
";",
"this",
".",
"_extent",
"=",
"undefined",
";",
"this",
".",
"_loadingData",
"=",
"false",
";",
"this",
".",
"_catalogItem",
"=",
"catalogItem",
";",
"this",
".",
"_regionMappingDefinitionsUrl",
"=",
"defined",
"(",
"catalogItem",
")",
"?",
"catalogItem",
".",
"terria",
".",
"configParameters",
".",
"regionMappingDefinitionsUrl",
":",
"undefined",
";",
"this",
".",
"_regionDetails",
"=",
"undefined",
";",
"// For caching the region details.",
"this",
".",
"_imageryLayer",
"=",
"undefined",
";",
"this",
".",
"_nextImageryLayer",
"=",
"undefined",
";",
"// For pre-rendering time-varying layers",
"this",
".",
"_nextImageryLayerInterval",
"=",
"undefined",
";",
"this",
".",
"_hadImageryAtLayerIndex",
"=",
"undefined",
";",
"this",
".",
"_hasDisplayedFeedback",
"=",
"false",
";",
"// So that we only show the feedback once.",
"this",
".",
"_constantRegionRowObjects",
"=",
"undefined",
";",
"this",
".",
"_constantRegionRowDescriptions",
"=",
"undefined",
";",
"// Track _tableStructure so that the catalogItem's concepts are maintained.",
"// Track _legendUrl so that the catalogItem can update the legend if it changes.",
"// Track _regionDetails so that when it is discovered that region mapping applies,",
"// it updates the legendHelper via activeItems, and catalogItem properties like supportsReordering.",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"_tableStructure\"",
",",
"\"_legendUrl\"",
",",
"\"_regionDetails\"",
"]",
")",
";",
"// Whenever the active item is changed, recalculate the legend and the display of all the entities.",
"// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.",
"knockout",
".",
"getObservable",
"(",
"this",
".",
"_tableStructure",
",",
"\"activeItems\"",
")",
".",
"subscribe",
"(",
"changedActiveItems",
".",
"bind",
"(",
"null",
",",
"this",
")",
",",
"this",
")",
";",
"knockout",
".",
"getObservable",
"(",
"this",
".",
"_catalogItem",
",",
"\"currentTime\"",
")",
".",
"subscribe",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"hasActiveTimeColumn",
")",
"{",
"onClockTick",
"(",
"this",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"}"
] | A DataSource for table-based data.
Handles the graphical display of lat-lon and region-mapped datasets.
For lat-lon data sets, each row is taken to be a feature. RegionMapping generates Cesium entities for each row.
For region-mapped data sets, each row is a region. The regions are displayed using a WMS imagery layer.
Displaying the points or regions requires a legend.
@name RegionMapping
@alias RegionMapping
@constructor
@param {CatalogItem} [catalogItem] The CatalogItem instance.
@param {TableStructure} [tableStructure] The Table Structure instance; defaults to a new one.
@param {TableStyle} [tableStyle] The table style; defaults to undefined. | [
"A",
"DataSource",
"for",
"table",
"-",
"based",
"data",
".",
"Handles",
"the",
"graphical",
"display",
"of",
"lat",
"-",
"lon",
"and",
"region",
"-",
"mapped",
"datasets",
".",
"For",
"lat",
"-",
"lon",
"data",
"sets",
"each",
"row",
"is",
"taken",
"to",
"be",
"a",
"feature",
".",
"RegionMapping",
"generates",
"Cesium",
"entities",
"for",
"each",
"row",
".",
"For",
"region",
"-",
"mapped",
"data",
"sets",
"each",
"row",
"is",
"a",
"region",
".",
"The",
"regions",
"are",
"displayed",
"using",
"a",
"WMS",
"imagery",
"layer",
".",
"Displaying",
"the",
"points",
"or",
"regions",
"requires",
"a",
"legend",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionMapping.js#L52-L99 |
|
7,016 | TerriaJS/terriajs | lib/Models/RegionMapping.js | loadRegionIds | function loadRegionIds(regionMapping, rawRegionDetails) {
var promises = rawRegionDetails.map(function(rawRegionDetail) {
return rawRegionDetail.regionProvider.loadRegionIDs();
});
return when
.all(promises)
.then(function() {
// Cache the details in a nicer format, storing the actual columns rather than just the column names.
regionMapping._regionDetails = rawRegionDetails.map(function(
rawRegionDetail
) {
return {
regionProvider: rawRegionDetail.regionProvider,
columnName: rawRegionDetail.variableName,
disambigColumnName: rawRegionDetail.disambigVariableName
};
});
return regionMapping._regionDetails;
})
.otherwise(function(e) {
console.log("error loading region ids", e);
});
} | javascript | function loadRegionIds(regionMapping, rawRegionDetails) {
var promises = rawRegionDetails.map(function(rawRegionDetail) {
return rawRegionDetail.regionProvider.loadRegionIDs();
});
return when
.all(promises)
.then(function() {
// Cache the details in a nicer format, storing the actual columns rather than just the column names.
regionMapping._regionDetails = rawRegionDetails.map(function(
rawRegionDetail
) {
return {
regionProvider: rawRegionDetail.regionProvider,
columnName: rawRegionDetail.variableName,
disambigColumnName: rawRegionDetail.disambigVariableName
};
});
return regionMapping._regionDetails;
})
.otherwise(function(e) {
console.log("error loading region ids", e);
});
} | [
"function",
"loadRegionIds",
"(",
"regionMapping",
",",
"rawRegionDetails",
")",
"{",
"var",
"promises",
"=",
"rawRegionDetails",
".",
"map",
"(",
"function",
"(",
"rawRegionDetail",
")",
"{",
"return",
"rawRegionDetail",
".",
"regionProvider",
".",
"loadRegionIDs",
"(",
")",
";",
"}",
")",
";",
"return",
"when",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"// Cache the details in a nicer format, storing the actual columns rather than just the column names.",
"regionMapping",
".",
"_regionDetails",
"=",
"rawRegionDetails",
".",
"map",
"(",
"function",
"(",
"rawRegionDetail",
")",
"{",
"return",
"{",
"regionProvider",
":",
"rawRegionDetail",
".",
"regionProvider",
",",
"columnName",
":",
"rawRegionDetail",
".",
"variableName",
",",
"disambigColumnName",
":",
"rawRegionDetail",
".",
"disambigVariableName",
"}",
";",
"}",
")",
";",
"return",
"regionMapping",
".",
"_regionDetails",
";",
"}",
")",
".",
"otherwise",
"(",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"error loading region ids\"",
",",
"e",
")",
";",
"}",
")",
";",
"}"
] | Loads region ids from the region providers, and returns the region details. | [
"Loads",
"region",
"ids",
"from",
"the",
"region",
"providers",
"and",
"returns",
"the",
"region",
"details",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionMapping.js#L439-L461 |
7,017 | TerriaJS/terriajs | lib/Models/RegionMapping.js | calculateRegionIndices | function calculateRegionIndices(
regionMapping,
time,
failedMatches,
ambiguousMatches
) {
// As described in load, currently we only use the first possible region column.
var regionDetail = regionMapping._regionDetails[0];
var tableStructure = regionMapping._tableStructure;
var regionColumn = tableStructure.getColumnWithNameIdOrIndex(
regionDetail.columnName
);
if (!defined(regionColumn)) {
return;
}
var regionColumnValues = regionColumn.values;
// Wipe out the region names from the rows that do not apply at this time, if there is a time column.
var timeColumn = tableStructure.activeTimeColumn;
var disambigColumn = defined(regionDetail.disambigColumnName)
? tableStructure.getColumnWithNameIdOrIndex(regionDetail.disambigColumnName)
: undefined;
// regionIndices will be an array the same length as regionProvider.regions, giving the index of each region into the table.
var regionIndices = regionDetail.regionProvider.mapRegionsToIndicesInto(
regionColumnValues,
disambigColumn && disambigColumn.values,
failedMatches,
ambiguousMatches,
defined(timeColumn) ? timeColumn.timeIntervals : undefined,
time
);
return regionIndices;
} | javascript | function calculateRegionIndices(
regionMapping,
time,
failedMatches,
ambiguousMatches
) {
// As described in load, currently we only use the first possible region column.
var regionDetail = regionMapping._regionDetails[0];
var tableStructure = regionMapping._tableStructure;
var regionColumn = tableStructure.getColumnWithNameIdOrIndex(
regionDetail.columnName
);
if (!defined(regionColumn)) {
return;
}
var regionColumnValues = regionColumn.values;
// Wipe out the region names from the rows that do not apply at this time, if there is a time column.
var timeColumn = tableStructure.activeTimeColumn;
var disambigColumn = defined(regionDetail.disambigColumnName)
? tableStructure.getColumnWithNameIdOrIndex(regionDetail.disambigColumnName)
: undefined;
// regionIndices will be an array the same length as regionProvider.regions, giving the index of each region into the table.
var regionIndices = regionDetail.regionProvider.mapRegionsToIndicesInto(
regionColumnValues,
disambigColumn && disambigColumn.values,
failedMatches,
ambiguousMatches,
defined(timeColumn) ? timeColumn.timeIntervals : undefined,
time
);
return regionIndices;
} | [
"function",
"calculateRegionIndices",
"(",
"regionMapping",
",",
"time",
",",
"failedMatches",
",",
"ambiguousMatches",
")",
"{",
"// As described in load, currently we only use the first possible region column.",
"var",
"regionDetail",
"=",
"regionMapping",
".",
"_regionDetails",
"[",
"0",
"]",
";",
"var",
"tableStructure",
"=",
"regionMapping",
".",
"_tableStructure",
";",
"var",
"regionColumn",
"=",
"tableStructure",
".",
"getColumnWithNameIdOrIndex",
"(",
"regionDetail",
".",
"columnName",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"regionColumn",
")",
")",
"{",
"return",
";",
"}",
"var",
"regionColumnValues",
"=",
"regionColumn",
".",
"values",
";",
"// Wipe out the region names from the rows that do not apply at this time, if there is a time column.",
"var",
"timeColumn",
"=",
"tableStructure",
".",
"activeTimeColumn",
";",
"var",
"disambigColumn",
"=",
"defined",
"(",
"regionDetail",
".",
"disambigColumnName",
")",
"?",
"tableStructure",
".",
"getColumnWithNameIdOrIndex",
"(",
"regionDetail",
".",
"disambigColumnName",
")",
":",
"undefined",
";",
"// regionIndices will be an array the same length as regionProvider.regions, giving the index of each region into the table.",
"var",
"regionIndices",
"=",
"regionDetail",
".",
"regionProvider",
".",
"mapRegionsToIndicesInto",
"(",
"regionColumnValues",
",",
"disambigColumn",
"&&",
"disambigColumn",
".",
"values",
",",
"failedMatches",
",",
"ambiguousMatches",
",",
"defined",
"(",
"timeColumn",
")",
"?",
"timeColumn",
".",
"timeIntervals",
":",
"undefined",
",",
"time",
")",
";",
"return",
"regionIndices",
";",
"}"
] | Returns an array the same length as regionProvider.regions, mapping each region into the relevant index into the table data source.
Takes the current time into account if a time is provided, and there is a time column with timeIntervals defined.
@private
@param {RegionMapping} regionMapping The table data source.
@param {JulianDate} [time] The current time, eg. terria.clock.currentTime. NOT the time column's ._clock's time, which is different (and comes from a DataSourceClock).
@param {Array} [failedMatches] An optional empty array. If provided, indices of failed matches are appended to the array.
@param {Array} [ambiguousMatches] An optional empty array. If provided, indices of matches which duplicate prior matches are appended to the array.
@return {Array} An array the same length as regionProvider.regions, mapping each region into the relevant index into the table data source. | [
"Returns",
"an",
"array",
"the",
"same",
"length",
"as",
"regionProvider",
".",
"regions",
"mapping",
"each",
"region",
"into",
"the",
"relevant",
"index",
"into",
"the",
"table",
"data",
"source",
".",
"Takes",
"the",
"current",
"time",
"into",
"account",
"if",
"a",
"time",
"is",
"provided",
"and",
"there",
"is",
"a",
"time",
"column",
"with",
"timeIntervals",
"defined",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionMapping.js#L473-L504 |
7,018 | TerriaJS/terriajs | lib/Models/LegendHelper.js | function(tableColumn, tableStyle, regionProvider, name) {
this.tableColumn = tableColumn;
this.tableStyle = defined(tableStyle) ? tableStyle : new TableStyle(); // instead of defaultValue, so new object only created if needed.
this.tableColumnStyle = getTableColumnStyle(tableColumn, this.tableStyle);
this.name = name;
var noColumnIndex =
hashFromString(name || "") % defaultNoColumnColorCodes.length;
this._noColumnColorArray = getColorArrayFromCssColorString(
defaultNoColumnColorCodes[noColumnIndex],
defaultNoColumnColorAlpha
);
this._legend = undefined; // We could make a getter for this if it is ever needed.
this._colorGradient = undefined;
this._binColors = undefined; // An array of objects with upperBound and colorArray properties.
this._regionProvider = regionProvider;
if (defined(this.tableColumnStyle.nullColor)) {
this._nullColorArray = getColorArrayFromCssColorString(
this.tableColumnStyle.nullColor
);
} else {
this._nullColorArray = defined(regionProvider)
? noColorArray
: defaultColorArray;
}
this._cycleEnumValues = false;
this._cycleColors = undefined; // Array of colors used for the cycle method
this.tableColumnStyle.legendTicks = defaultValue(
this.tableColumnStyle.legendTicks,
0
);
this.tableColumnStyle.scale = defaultValue(this.tableColumnStyle.scale, 1);
} | javascript | function(tableColumn, tableStyle, regionProvider, name) {
this.tableColumn = tableColumn;
this.tableStyle = defined(tableStyle) ? tableStyle : new TableStyle(); // instead of defaultValue, so new object only created if needed.
this.tableColumnStyle = getTableColumnStyle(tableColumn, this.tableStyle);
this.name = name;
var noColumnIndex =
hashFromString(name || "") % defaultNoColumnColorCodes.length;
this._noColumnColorArray = getColorArrayFromCssColorString(
defaultNoColumnColorCodes[noColumnIndex],
defaultNoColumnColorAlpha
);
this._legend = undefined; // We could make a getter for this if it is ever needed.
this._colorGradient = undefined;
this._binColors = undefined; // An array of objects with upperBound and colorArray properties.
this._regionProvider = regionProvider;
if (defined(this.tableColumnStyle.nullColor)) {
this._nullColorArray = getColorArrayFromCssColorString(
this.tableColumnStyle.nullColor
);
} else {
this._nullColorArray = defined(regionProvider)
? noColorArray
: defaultColorArray;
}
this._cycleEnumValues = false;
this._cycleColors = undefined; // Array of colors used for the cycle method
this.tableColumnStyle.legendTicks = defaultValue(
this.tableColumnStyle.legendTicks,
0
);
this.tableColumnStyle.scale = defaultValue(this.tableColumnStyle.scale, 1);
} | [
"function",
"(",
"tableColumn",
",",
"tableStyle",
",",
"regionProvider",
",",
"name",
")",
"{",
"this",
".",
"tableColumn",
"=",
"tableColumn",
";",
"this",
".",
"tableStyle",
"=",
"defined",
"(",
"tableStyle",
")",
"?",
"tableStyle",
":",
"new",
"TableStyle",
"(",
")",
";",
"// instead of defaultValue, so new object only created if needed.",
"this",
".",
"tableColumnStyle",
"=",
"getTableColumnStyle",
"(",
"tableColumn",
",",
"this",
".",
"tableStyle",
")",
";",
"this",
".",
"name",
"=",
"name",
";",
"var",
"noColumnIndex",
"=",
"hashFromString",
"(",
"name",
"||",
"\"\"",
")",
"%",
"defaultNoColumnColorCodes",
".",
"length",
";",
"this",
".",
"_noColumnColorArray",
"=",
"getColorArrayFromCssColorString",
"(",
"defaultNoColumnColorCodes",
"[",
"noColumnIndex",
"]",
",",
"defaultNoColumnColorAlpha",
")",
";",
"this",
".",
"_legend",
"=",
"undefined",
";",
"// We could make a getter for this if it is ever needed.",
"this",
".",
"_colorGradient",
"=",
"undefined",
";",
"this",
".",
"_binColors",
"=",
"undefined",
";",
"// An array of objects with upperBound and colorArray properties.",
"this",
".",
"_regionProvider",
"=",
"regionProvider",
";",
"if",
"(",
"defined",
"(",
"this",
".",
"tableColumnStyle",
".",
"nullColor",
")",
")",
"{",
"this",
".",
"_nullColorArray",
"=",
"getColorArrayFromCssColorString",
"(",
"this",
".",
"tableColumnStyle",
".",
"nullColor",
")",
";",
"}",
"else",
"{",
"this",
".",
"_nullColorArray",
"=",
"defined",
"(",
"regionProvider",
")",
"?",
"noColorArray",
":",
"defaultColorArray",
";",
"}",
"this",
".",
"_cycleEnumValues",
"=",
"false",
";",
"this",
".",
"_cycleColors",
"=",
"undefined",
";",
"// Array of colors used for the cycle method",
"this",
".",
"tableColumnStyle",
".",
"legendTicks",
"=",
"defaultValue",
"(",
"this",
".",
"tableColumnStyle",
".",
"legendTicks",
",",
"0",
")",
";",
"this",
".",
"tableColumnStyle",
".",
"scale",
"=",
"defaultValue",
"(",
"this",
".",
"tableColumnStyle",
".",
"scale",
",",
"1",
")",
";",
"}"
] | Legends for table columns depend on both the table style and the selected column.
This class brings the two together to generate a legend.
Its key output is legendUrl.
@alias LegendHelper
@constructor
@param {TableColumn} tableColumn The column whose values inform the legend.
@param {TableStyle} [tableStyle] The styling for the table.
@param {RegionProvider} [regionProvider] The region provider, if region mapped. Used if no table column set.
@param {String} [name] A name used in the legend if no active column is selected. | [
"Legends",
"for",
"table",
"columns",
"depend",
"on",
"both",
"the",
"table",
"style",
"and",
"the",
"selected",
"column",
".",
"This",
"class",
"brings",
"the",
"two",
"together",
"to",
"generate",
"a",
"legend",
".",
"Its",
"key",
"output",
"is",
"legendUrl",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/LegendHelper.js#L50-L82 |
|
7,019 | TerriaJS/terriajs | lib/Models/LegendHelper.js | getTableColumnStyle | function getTableColumnStyle(tableColumn, tableStyle) {
var tableColumnStyle;
if (defined(tableColumn) && defined(tableStyle.columns)) {
if (defined(tableStyle.columns[tableColumn.id])) {
tableColumnStyle = clone(tableStyle.columns[tableColumn.id]);
} else {
// Also support column indices as keys into tableStyle.columns
var tableStructure = tableColumn.parent;
var columnIndex = tableStructure.columns.indexOf(tableColumn);
if (defined(tableStyle.columns[columnIndex])) {
tableColumnStyle = clone(tableStyle.columns[columnIndex]);
}
}
}
if (!defined(tableColumnStyle)) {
return tableStyle;
}
// Copy defaults from tableStyle too.
for (var propertyName in tableStyle) {
if (
tableStyle.hasOwnProperty(propertyName) &&
tableColumnStyle.hasOwnProperty(propertyName)
) {
if (!defined(tableColumnStyle[propertyName])) {
tableColumnStyle[propertyName] = tableStyle[propertyName];
}
}
}
return tableColumnStyle;
} | javascript | function getTableColumnStyle(tableColumn, tableStyle) {
var tableColumnStyle;
if (defined(tableColumn) && defined(tableStyle.columns)) {
if (defined(tableStyle.columns[tableColumn.id])) {
tableColumnStyle = clone(tableStyle.columns[tableColumn.id]);
} else {
// Also support column indices as keys into tableStyle.columns
var tableStructure = tableColumn.parent;
var columnIndex = tableStructure.columns.indexOf(tableColumn);
if (defined(tableStyle.columns[columnIndex])) {
tableColumnStyle = clone(tableStyle.columns[columnIndex]);
}
}
}
if (!defined(tableColumnStyle)) {
return tableStyle;
}
// Copy defaults from tableStyle too.
for (var propertyName in tableStyle) {
if (
tableStyle.hasOwnProperty(propertyName) &&
tableColumnStyle.hasOwnProperty(propertyName)
) {
if (!defined(tableColumnStyle[propertyName])) {
tableColumnStyle[propertyName] = tableStyle[propertyName];
}
}
}
return tableColumnStyle;
} | [
"function",
"getTableColumnStyle",
"(",
"tableColumn",
",",
"tableStyle",
")",
"{",
"var",
"tableColumnStyle",
";",
"if",
"(",
"defined",
"(",
"tableColumn",
")",
"&&",
"defined",
"(",
"tableStyle",
".",
"columns",
")",
")",
"{",
"if",
"(",
"defined",
"(",
"tableStyle",
".",
"columns",
"[",
"tableColumn",
".",
"id",
"]",
")",
")",
"{",
"tableColumnStyle",
"=",
"clone",
"(",
"tableStyle",
".",
"columns",
"[",
"tableColumn",
".",
"id",
"]",
")",
";",
"}",
"else",
"{",
"// Also support column indices as keys into tableStyle.columns",
"var",
"tableStructure",
"=",
"tableColumn",
".",
"parent",
";",
"var",
"columnIndex",
"=",
"tableStructure",
".",
"columns",
".",
"indexOf",
"(",
"tableColumn",
")",
";",
"if",
"(",
"defined",
"(",
"tableStyle",
".",
"columns",
"[",
"columnIndex",
"]",
")",
")",
"{",
"tableColumnStyle",
"=",
"clone",
"(",
"tableStyle",
".",
"columns",
"[",
"columnIndex",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"defined",
"(",
"tableColumnStyle",
")",
")",
"{",
"return",
"tableStyle",
";",
"}",
"// Copy defaults from tableStyle too.",
"for",
"(",
"var",
"propertyName",
"in",
"tableStyle",
")",
"{",
"if",
"(",
"tableStyle",
".",
"hasOwnProperty",
"(",
"propertyName",
")",
"&&",
"tableColumnStyle",
".",
"hasOwnProperty",
"(",
"propertyName",
")",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"tableColumnStyle",
"[",
"propertyName",
"]",
")",
")",
"{",
"tableColumnStyle",
"[",
"propertyName",
"]",
"=",
"tableStyle",
"[",
"propertyName",
"]",
";",
"}",
"}",
"}",
"return",
"tableColumnStyle",
";",
"}"
] | Find the right table column style for this column. By default, take styling directly from the tableStyle, unless there is a suitable 'columns' entry. | [
"Find",
"the",
"right",
"table",
"column",
"style",
"for",
"this",
"column",
".",
"By",
"default",
"take",
"styling",
"directly",
"from",
"the",
"tableStyle",
"unless",
"there",
"is",
"a",
"suitable",
"columns",
"entry",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/LegendHelper.js#L86-L115 |
7,020 | TerriaJS/terriajs | lib/Models/LegendHelper.js | getFractionalValue | function getFractionalValue(legendHelper, value) {
var extremes = getExtremes(
legendHelper.tableColumn,
legendHelper.tableColumnStyle
);
var f =
extremes.maximum === extremes.minimum
? 0
: (value - extremes.minimum) / (extremes.maximum - extremes.minimum);
if (legendHelper.tableColumnStyle.clampDisplayValue) {
f = Math.max(0.0, Math.min(1.0, f));
}
return f;
} | javascript | function getFractionalValue(legendHelper, value) {
var extremes = getExtremes(
legendHelper.tableColumn,
legendHelper.tableColumnStyle
);
var f =
extremes.maximum === extremes.minimum
? 0
: (value - extremes.minimum) / (extremes.maximum - extremes.minimum);
if (legendHelper.tableColumnStyle.clampDisplayValue) {
f = Math.max(0.0, Math.min(1.0, f));
}
return f;
} | [
"function",
"getFractionalValue",
"(",
"legendHelper",
",",
"value",
")",
"{",
"var",
"extremes",
"=",
"getExtremes",
"(",
"legendHelper",
".",
"tableColumn",
",",
"legendHelper",
".",
"tableColumnStyle",
")",
";",
"var",
"f",
"=",
"extremes",
".",
"maximum",
"===",
"extremes",
".",
"minimum",
"?",
"0",
":",
"(",
"value",
"-",
"extremes",
".",
"minimum",
")",
"/",
"(",
"extremes",
".",
"maximum",
"-",
"extremes",
".",
"minimum",
")",
";",
"if",
"(",
"legendHelper",
".",
"tableColumnStyle",
".",
"clampDisplayValue",
")",
"{",
"f",
"=",
"Math",
".",
"max",
"(",
"0.0",
",",
"Math",
".",
"min",
"(",
"1.0",
",",
"f",
")",
")",
";",
"}",
"return",
"f",
";",
"}"
] | Convert a value to a fractional value, eg. in a column that ranges from 0 to 100, 20 -> 0.2.
TableStyle can override the minimum and maximum of the range.
@private
@param {Number} value The value.
@return {Number} The fractional value. | [
"Convert",
"a",
"value",
"to",
"a",
"fractional",
"value",
"eg",
".",
"in",
"a",
"column",
"that",
"ranges",
"from",
"0",
"to",
"100",
"20",
"-",
">",
"0",
".",
"2",
".",
"TableStyle",
"can",
"override",
"the",
"minimum",
"and",
"maximum",
"of",
"the",
"range",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/LegendHelper.js#L330-L343 |
7,021 | TerriaJS/terriajs | lib/Models/RegionDataValue.js | RegionDataValue | function RegionDataValue(
regionCodes,
columnHeadings,
table,
singleSelectValues
) {
this.regionCodes = regionCodes;
this.columnHeadings = columnHeadings;
this.table = table;
this.singleSelectValues = singleSelectValues;
} | javascript | function RegionDataValue(
regionCodes,
columnHeadings,
table,
singleSelectValues
) {
this.regionCodes = regionCodes;
this.columnHeadings = columnHeadings;
this.table = table;
this.singleSelectValues = singleSelectValues;
} | [
"function",
"RegionDataValue",
"(",
"regionCodes",
",",
"columnHeadings",
",",
"table",
",",
"singleSelectValues",
")",
"{",
"this",
".",
"regionCodes",
"=",
"regionCodes",
";",
"this",
".",
"columnHeadings",
"=",
"columnHeadings",
";",
"this",
".",
"table",
"=",
"table",
";",
"this",
".",
"singleSelectValues",
"=",
"singleSelectValues",
";",
"}"
] | Holds a collection of region data.
@param {String[]} regionCodes The list of region codes.
@param {String[]} columnHeadings The list of column headings describing the values associated with each region.
@param {Number[][]} table An array of arrays where each array in the outer array corresponds to a single region in the regionCodes list
and each inner array has a value corresponding to each colum in columnHeadings. For a {@link RegionDataParameter#singleSelect}
parameter, this property should be undefined.
@param {Number[]} singleSelectValues The single value for each region. For a parameter that is not {@link RegionDataParameter#singleSelect}, this
property should be undefined. | [
"Holds",
"a",
"collection",
"of",
"region",
"data",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionDataValue.js#L14-L24 |
7,022 | TerriaJS/terriajs | lib/Models/CsvCatalogItem.js | loadTableFromCsv | function loadTableFromCsv(item, csvString) {
var tableStyle = item._tableStyle;
var options = {
idColumnNames: item.idColumns,
isSampled: item.isSampled,
initialTimeSource: item.initialTimeSource,
displayDuration: tableStyle.displayDuration,
replaceWithNullValues: tableStyle.replaceWithNullValues,
replaceWithZeroValues: tableStyle.replaceWithZeroValues,
columnOptions: tableStyle.columns // may contain per-column replacements for these
};
var tableStructure = new TableStructure(undefined, options);
tableStructure.loadFromCsv(csvString);
return item.initializeFromTableStructure(tableStructure);
} | javascript | function loadTableFromCsv(item, csvString) {
var tableStyle = item._tableStyle;
var options = {
idColumnNames: item.idColumns,
isSampled: item.isSampled,
initialTimeSource: item.initialTimeSource,
displayDuration: tableStyle.displayDuration,
replaceWithNullValues: tableStyle.replaceWithNullValues,
replaceWithZeroValues: tableStyle.replaceWithZeroValues,
columnOptions: tableStyle.columns // may contain per-column replacements for these
};
var tableStructure = new TableStructure(undefined, options);
tableStructure.loadFromCsv(csvString);
return item.initializeFromTableStructure(tableStructure);
} | [
"function",
"loadTableFromCsv",
"(",
"item",
",",
"csvString",
")",
"{",
"var",
"tableStyle",
"=",
"item",
".",
"_tableStyle",
";",
"var",
"options",
"=",
"{",
"idColumnNames",
":",
"item",
".",
"idColumns",
",",
"isSampled",
":",
"item",
".",
"isSampled",
",",
"initialTimeSource",
":",
"item",
".",
"initialTimeSource",
",",
"displayDuration",
":",
"tableStyle",
".",
"displayDuration",
",",
"replaceWithNullValues",
":",
"tableStyle",
".",
"replaceWithNullValues",
",",
"replaceWithZeroValues",
":",
"tableStyle",
".",
"replaceWithZeroValues",
",",
"columnOptions",
":",
"tableStyle",
".",
"columns",
"// may contain per-column replacements for these",
"}",
";",
"var",
"tableStructure",
"=",
"new",
"TableStructure",
"(",
"undefined",
",",
"options",
")",
";",
"tableStructure",
".",
"loadFromCsv",
"(",
"csvString",
")",
";",
"return",
"item",
".",
"initializeFromTableStructure",
"(",
"tableStructure",
")",
";",
"}"
] | Loads the TableStructure from a csv file.
@param {CsvCatalogItem} item Item that tableDataSource is created for
@param {String} csvString String in csv format.
@return {Promise} A promise that resolves to true if it is a recognised format.
@private | [
"Loads",
"the",
"TableStructure",
"from",
"a",
"csv",
"file",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CsvCatalogItem.js#L139-L153 |
7,023 | TerriaJS/terriajs | lib/Models/RegionDataParameter.js | function(options) {
if (!defined(options) || !defined(options.regionProvider)) {
throw new DeveloperError("options.regionProvider is required.");
}
FunctionParameter.call(this, options);
this._regionProvider = options.regionProvider;
this.singleSelect = defaultValue(options.singleSelect, false);
knockout.track(this, ["_regionProvider"]);
} | javascript | function(options) {
if (!defined(options) || !defined(options.regionProvider)) {
throw new DeveloperError("options.regionProvider is required.");
}
FunctionParameter.call(this, options);
this._regionProvider = options.regionProvider;
this.singleSelect = defaultValue(options.singleSelect, false);
knockout.track(this, ["_regionProvider"]);
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"options",
")",
"||",
"!",
"defined",
"(",
"options",
".",
"regionProvider",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"options.regionProvider is required.\"",
")",
";",
"}",
"FunctionParameter",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"_regionProvider",
"=",
"options",
".",
"regionProvider",
";",
"this",
".",
"singleSelect",
"=",
"defaultValue",
"(",
"options",
".",
"singleSelect",
",",
"false",
")",
";",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"_regionProvider\"",
"]",
")",
";",
"}"
] | A parameter that specifies a set of characteristics for regions of a particular type.
@alias RegionDataParameter
@constructor
@extends FunctionParameter
@param {Object} [options] Object with the following properties:
@param {Terria} options.terria The Terria instance.
@param {String} options.id The unique ID of this parameter.
@param {String} [options.name] The name of this parameter. If not specified, the ID is used as the name.
@param {String} [options.description] The description of the parameter.
@param {RegionProvider|RegionTypeParameter} options.regionProvider The {@link RegionProvider} from which a region may be selected. This may also
be a {@link RegionTypeParameter} that specifies the type of region.
@param {Boolean} [options.singleSelect] True if only one characteristic may be selected; false if any number of characteristics may be selected. | [
"A",
"parameter",
"that",
"specifies",
"a",
"set",
"of",
"characteristics",
"for",
"regions",
"of",
"a",
"particular",
"type",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionDataParameter.js#L30-L41 |
|
7,024 | TerriaJS/terriajs | lib/Map/LeafletVisualizer.js | recolorBillboard | function recolorBillboard(img, color) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
// Copy the image contents to the canvas
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
var image = context.getImageData(0, 0, canvas.width, canvas.height);
var normClr = [color.red, color.green, color.blue, color.alpha];
var length = image.data.length; //pixel count * 4
for (var i = 0; i < length; i += 4) {
for (var j = 0; j < 4; j++) {
image.data[j + i] *= normClr[j];
}
}
context.putImageData(image, 0, 0);
return canvas.toDataURL();
// return context.getImageData(0, 0, canvas.width, canvas.height);
} | javascript | function recolorBillboard(img, color) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
// Copy the image contents to the canvas
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
var image = context.getImageData(0, 0, canvas.width, canvas.height);
var normClr = [color.red, color.green, color.blue, color.alpha];
var length = image.data.length; //pixel count * 4
for (var i = 0; i < length; i += 4) {
for (var j = 0; j < 4; j++) {
image.data[j + i] *= normClr[j];
}
}
context.putImageData(image, 0, 0);
return canvas.toDataURL();
// return context.getImageData(0, 0, canvas.width, canvas.height);
} | [
"function",
"recolorBillboard",
"(",
"img",
",",
"color",
")",
"{",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"\"canvas\"",
")",
";",
"canvas",
".",
"width",
"=",
"img",
".",
"width",
";",
"canvas",
".",
"height",
"=",
"img",
".",
"height",
";",
"// Copy the image contents to the canvas",
"var",
"context",
"=",
"canvas",
".",
"getContext",
"(",
"\"2d\"",
")",
";",
"context",
".",
"drawImage",
"(",
"img",
",",
"0",
",",
"0",
")",
";",
"var",
"image",
"=",
"context",
".",
"getImageData",
"(",
"0",
",",
"0",
",",
"canvas",
".",
"width",
",",
"canvas",
".",
"height",
")",
";",
"var",
"normClr",
"=",
"[",
"color",
".",
"red",
",",
"color",
".",
"green",
",",
"color",
".",
"blue",
",",
"color",
".",
"alpha",
"]",
";",
"var",
"length",
"=",
"image",
".",
"data",
".",
"length",
";",
"//pixel count * 4",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"+=",
"4",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
")",
"{",
"image",
".",
"data",
"[",
"j",
"+",
"i",
"]",
"*=",
"normClr",
"[",
"j",
"]",
";",
"}",
"}",
"context",
".",
"putImageData",
"(",
"image",
",",
"0",
",",
"0",
")",
";",
"return",
"canvas",
".",
"toDataURL",
"(",
")",
";",
"// return context.getImageData(0, 0, canvas.width, canvas.height);",
"}"
] | Recolor an image using 2d canvas | [
"Recolor",
"an",
"image",
"using",
"2d",
"canvas"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/LeafletVisualizer.js#L524-L545 |
7,025 | TerriaJS/terriajs | lib/Core/printWindow.js | printWindow | function printWindow(windowToPrint) {
const deferred = when.defer();
let printInProgressCount = 0;
const timeout = setTimeout(function() {
deferred.reject(
new TerriaError({
title: "Error printing",
message:
"Printing did not start within 10 seconds. Maybe this web browser does not support printing?"
})
);
}, 10000);
function cancelTimeout() {
clearTimeout(timeout);
}
function resolveIfZero() {
if (printInProgressCount <= 0) {
deferred.resolve();
}
}
if (windowToPrint.matchMedia) {
windowToPrint.matchMedia("print").addListener(function(evt) {
cancelTimeout();
if (evt.matches) {
console.log("print media start");
++printInProgressCount;
} else {
console.log("print media end");
--printInProgressCount;
resolveIfZero();
}
});
}
windowToPrint.onbeforeprint = function() {
cancelTimeout();
console.log("onbeforeprint");
++printInProgressCount;
};
windowToPrint.onafterprint = function() {
cancelTimeout();
console.log("onafterprint");
--printInProgressCount;
resolveIfZero();
};
// First try printing with execCommand, because, in IE11, `printWindow.print()`
// prints the entire page instead of just the embedded iframe (if the window
// is an iframe, anyway).
const result = windowToPrint.document.execCommand("print", true, null);
if (!result) {
windowToPrint.print();
}
return deferred.promise;
} | javascript | function printWindow(windowToPrint) {
const deferred = when.defer();
let printInProgressCount = 0;
const timeout = setTimeout(function() {
deferred.reject(
new TerriaError({
title: "Error printing",
message:
"Printing did not start within 10 seconds. Maybe this web browser does not support printing?"
})
);
}, 10000);
function cancelTimeout() {
clearTimeout(timeout);
}
function resolveIfZero() {
if (printInProgressCount <= 0) {
deferred.resolve();
}
}
if (windowToPrint.matchMedia) {
windowToPrint.matchMedia("print").addListener(function(evt) {
cancelTimeout();
if (evt.matches) {
console.log("print media start");
++printInProgressCount;
} else {
console.log("print media end");
--printInProgressCount;
resolveIfZero();
}
});
}
windowToPrint.onbeforeprint = function() {
cancelTimeout();
console.log("onbeforeprint");
++printInProgressCount;
};
windowToPrint.onafterprint = function() {
cancelTimeout();
console.log("onafterprint");
--printInProgressCount;
resolveIfZero();
};
// First try printing with execCommand, because, in IE11, `printWindow.print()`
// prints the entire page instead of just the embedded iframe (if the window
// is an iframe, anyway).
const result = windowToPrint.document.execCommand("print", true, null);
if (!result) {
windowToPrint.print();
}
return deferred.promise;
} | [
"function",
"printWindow",
"(",
"windowToPrint",
")",
"{",
"const",
"deferred",
"=",
"when",
".",
"defer",
"(",
")",
";",
"let",
"printInProgressCount",
"=",
"0",
";",
"const",
"timeout",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"deferred",
".",
"reject",
"(",
"new",
"TerriaError",
"(",
"{",
"title",
":",
"\"Error printing\"",
",",
"message",
":",
"\"Printing did not start within 10 seconds. Maybe this web browser does not support printing?\"",
"}",
")",
")",
";",
"}",
",",
"10000",
")",
";",
"function",
"cancelTimeout",
"(",
")",
"{",
"clearTimeout",
"(",
"timeout",
")",
";",
"}",
"function",
"resolveIfZero",
"(",
")",
"{",
"if",
"(",
"printInProgressCount",
"<=",
"0",
")",
"{",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
"}",
"if",
"(",
"windowToPrint",
".",
"matchMedia",
")",
"{",
"windowToPrint",
".",
"matchMedia",
"(",
"\"print\"",
")",
".",
"addListener",
"(",
"function",
"(",
"evt",
")",
"{",
"cancelTimeout",
"(",
")",
";",
"if",
"(",
"evt",
".",
"matches",
")",
"{",
"console",
".",
"log",
"(",
"\"print media start\"",
")",
";",
"++",
"printInProgressCount",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"print media end\"",
")",
";",
"--",
"printInProgressCount",
";",
"resolveIfZero",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"windowToPrint",
".",
"onbeforeprint",
"=",
"function",
"(",
")",
"{",
"cancelTimeout",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"onbeforeprint\"",
")",
";",
"++",
"printInProgressCount",
";",
"}",
";",
"windowToPrint",
".",
"onafterprint",
"=",
"function",
"(",
")",
"{",
"cancelTimeout",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"onafterprint\"",
")",
";",
"--",
"printInProgressCount",
";",
"resolveIfZero",
"(",
")",
";",
"}",
";",
"// First try printing with execCommand, because, in IE11, `printWindow.print()`",
"// prints the entire page instead of just the embedded iframe (if the window",
"// is an iframe, anyway).",
"const",
"result",
"=",
"windowToPrint",
".",
"document",
".",
"execCommand",
"(",
"\"print\"",
",",
"true",
",",
"null",
")",
";",
"if",
"(",
"!",
"result",
")",
"{",
"windowToPrint",
".",
"print",
"(",
")",
";",
"}",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Tells the web browser to print a given window, which my be an iframe window, and
returns a promise that resolves when printing is safely over so that, for example
the window can be removed.
@param {Window} windowToPrint The window to print.
@returns {Promise} A promise that resolves when printing is safely over. The prommise is rejected if
there is no indication that the browser's print | [
"Tells",
"the",
"web",
"browser",
"to",
"print",
"a",
"given",
"window",
"which",
"my",
"be",
"an",
"iframe",
"window",
"and",
"returns",
"a",
"promise",
"that",
"resolves",
"when",
"printing",
"is",
"safely",
"over",
"so",
"that",
"for",
"example",
"the",
"window",
"can",
"be",
"removed",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/printWindow.js#L12-L71 |
7,026 | TerriaJS/terriajs | lib/Models/TableStyle.js | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
TableColumnStyle.call(this, options);
/**
* The name of the variable (column) to be used for region mapping.
* @type {String}
*/
this.regionVariable = options.regionVariable;
/**
* The identifier of a region type, as used by RegionProviderList.
* @type {String}
*/
this.regionType = options.regionType;
/**
* The name of the default variable (column) containing data to be used for scaling and coloring.
* @type {String}
*/
this.dataVariable = options.dataVariable;
/**
* The column name or index to use as the time column. Defaults to the first one found. Pass null for none.
* Pass an array of two, eg. [0, 1], to provide both start and end date columns.
* @type {String|Integer|String[]|Integer[]|null}
*/
this.timeColumn = options.timeColumn;
/**
* The column name or index to use as the time column. Defaults to the first one found. Pass null for none.
* Pass an array of two, eg. [0, 1], to provide both start and end date columns.
* @type {String|Integer}
*/
this.xAxis = options.xAxis;
/**
* Column-specific styling, with the format { columnIdentifier1: tableColumnStyle1, columnIdentifier2: tableColumnStyle2, ... },
* where columnIdentifier is either the name or the column index (zero-based).
* @type {Object}
*/
this.columns = objectToTableColumnStyle(options, []); // If any promises are created (thanks to colorPalette), they are lost here.
} | javascript | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
TableColumnStyle.call(this, options);
/**
* The name of the variable (column) to be used for region mapping.
* @type {String}
*/
this.regionVariable = options.regionVariable;
/**
* The identifier of a region type, as used by RegionProviderList.
* @type {String}
*/
this.regionType = options.regionType;
/**
* The name of the default variable (column) containing data to be used for scaling and coloring.
* @type {String}
*/
this.dataVariable = options.dataVariable;
/**
* The column name or index to use as the time column. Defaults to the first one found. Pass null for none.
* Pass an array of two, eg. [0, 1], to provide both start and end date columns.
* @type {String|Integer|String[]|Integer[]|null}
*/
this.timeColumn = options.timeColumn;
/**
* The column name or index to use as the time column. Defaults to the first one found. Pass null for none.
* Pass an array of two, eg. [0, 1], to provide both start and end date columns.
* @type {String|Integer}
*/
this.xAxis = options.xAxis;
/**
* Column-specific styling, with the format { columnIdentifier1: tableColumnStyle1, columnIdentifier2: tableColumnStyle2, ... },
* where columnIdentifier is either the name or the column index (zero-based).
* @type {Object}
*/
this.columns = objectToTableColumnStyle(options, []); // If any promises are created (thanks to colorPalette), they are lost here.
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"TableColumnStyle",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"/**\n * The name of the variable (column) to be used for region mapping.\n * @type {String}\n */",
"this",
".",
"regionVariable",
"=",
"options",
".",
"regionVariable",
";",
"/**\n * The identifier of a region type, as used by RegionProviderList.\n * @type {String}\n */",
"this",
".",
"regionType",
"=",
"options",
".",
"regionType",
";",
"/**\n * The name of the default variable (column) containing data to be used for scaling and coloring.\n * @type {String}\n */",
"this",
".",
"dataVariable",
"=",
"options",
".",
"dataVariable",
";",
"/**\n * The column name or index to use as the time column. Defaults to the first one found. Pass null for none.\n * Pass an array of two, eg. [0, 1], to provide both start and end date columns.\n * @type {String|Integer|String[]|Integer[]|null}\n */",
"this",
".",
"timeColumn",
"=",
"options",
".",
"timeColumn",
";",
"/**\n * The column name or index to use as the time column. Defaults to the first one found. Pass null for none.\n * Pass an array of two, eg. [0, 1], to provide both start and end date columns.\n * @type {String|Integer}\n */",
"this",
".",
"xAxis",
"=",
"options",
".",
"xAxis",
";",
"/**\n * Column-specific styling, with the format { columnIdentifier1: tableColumnStyle1, columnIdentifier2: tableColumnStyle2, ... },\n * where columnIdentifier is either the name or the column index (zero-based).\n * @type {Object}\n */",
"this",
".",
"columns",
"=",
"objectToTableColumnStyle",
"(",
"options",
",",
"[",
"]",
")",
";",
"// If any promises are created (thanks to colorPalette), they are lost here.",
"}"
] | A set of properties that define how a table, such as a CSV file, should be displayed.
If not set explicitly, many of these properties will be given default or guessed values elsewhere,
such as in CsvCatalogItem.
@alias TableStyle
@constructor
@extends TableColumnStyle
@param {Object} [options] The values of the properties of the new instance. Options may include all those options found in TableColumnStyle, plus:
@param {String} [options.regionVariable] The name of the variable (column) to be used for region mapping.
@param {String} [options.regionType] The identifier of a region type, as used by RegionProviderList.
@param {String} [options.dataVariable] The name of the default variable (column) containing data to be used for scaling and coloring.
@param {String|Integer|null} [options.timeColumn] The column name or index to use as the time column. Defaults to the first one found.
Pass null for none. Pass an array of two, eg. [0, 1], to provide both start and end date columns.
@param {String|Integer} [options.xAxis] The column name or index to use as the x-axis, if charted. Defaults to the first one found.
@param {Object} [options.columns] Column-specific styling, with the format { columnIdentifier1: tableColumnStyle1, columnIdentifier2: tableColumnStyle2, ... },
where columnIdentifier is either the name or the column index (zero-based). | [
"A",
"set",
"of",
"properties",
"that",
"define",
"how",
"a",
"table",
"such",
"as",
"a",
"CSV",
"file",
"should",
"be",
"displayed",
".",
"If",
"not",
"set",
"explicitly",
"many",
"of",
"these",
"properties",
"will",
"be",
"given",
"default",
"or",
"guessed",
"values",
"elsewhere",
"such",
"as",
"in",
"CsvCatalogItem",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/TableStyle.js#L33-L76 |
|
7,027 | TerriaJS/terriajs | lib/Map/GnafAddressGeocoder.js | prefilterAddresses | function prefilterAddresses(addressList) {
var addressesPlusInd = { skipIndices: [], nullAddresses: 0, addresses: [] };
for (var i = 0; i < addressList.length; i++) {
var address = addressList[i];
if (address === null) {
addressesPlusInd.skipIndices.push(i);
addressesPlusInd.nullAddresses++;
continue;
}
if (
address.toLowerCase().indexOf("po box") !== -1 ||
address.toLowerCase().indexOf("post office box") !== -1
) {
addressesPlusInd.skipIndices.push(i);
continue;
}
addressesPlusInd.addresses.push(address);
}
return addressesPlusInd;
} | javascript | function prefilterAddresses(addressList) {
var addressesPlusInd = { skipIndices: [], nullAddresses: 0, addresses: [] };
for (var i = 0; i < addressList.length; i++) {
var address = addressList[i];
if (address === null) {
addressesPlusInd.skipIndices.push(i);
addressesPlusInd.nullAddresses++;
continue;
}
if (
address.toLowerCase().indexOf("po box") !== -1 ||
address.toLowerCase().indexOf("post office box") !== -1
) {
addressesPlusInd.skipIndices.push(i);
continue;
}
addressesPlusInd.addresses.push(address);
}
return addressesPlusInd;
} | [
"function",
"prefilterAddresses",
"(",
"addressList",
")",
"{",
"var",
"addressesPlusInd",
"=",
"{",
"skipIndices",
":",
"[",
"]",
",",
"nullAddresses",
":",
"0",
",",
"addresses",
":",
"[",
"]",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"addressList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"address",
"=",
"addressList",
"[",
"i",
"]",
";",
"if",
"(",
"address",
"===",
"null",
")",
"{",
"addressesPlusInd",
".",
"skipIndices",
".",
"push",
"(",
"i",
")",
";",
"addressesPlusInd",
".",
"nullAddresses",
"++",
";",
"continue",
";",
"}",
"if",
"(",
"address",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"\"po box\"",
")",
"!==",
"-",
"1",
"||",
"address",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"\"post office box\"",
")",
"!==",
"-",
"1",
")",
"{",
"addressesPlusInd",
".",
"skipIndices",
".",
"push",
"(",
"i",
")",
";",
"continue",
";",
"}",
"addressesPlusInd",
".",
"addresses",
".",
"push",
"(",
"address",
")",
";",
"}",
"return",
"addressesPlusInd",
";",
"}"
] | Do not try to geocode addresses that don't look valid.
@param {Array} addressList List of addresses that will be considered for geocoding
@return {Object} Probably shorter list of addresses that should be geocoded, as well as indices of addresses that
were removed.
@private | [
"Do",
"not",
"try",
"to",
"geocode",
"addresses",
"that",
"don",
"t",
"look",
"valid",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/GnafAddressGeocoder.js#L139-L159 |
7,028 | TerriaJS/terriajs | lib/Models/TableDataSource.js | function(
terria,
tableStructure,
tableStyle,
name,
isUpdating
) {
this._guid = createGuid(); // Used internally to give features a globally unique id.
this._name = name;
this._isUpdating = isUpdating || false;
this._hasFeaturePerRow = undefined; // If this changes, need to remove old features.
this._changed = new CesiumEvent();
this._error = new CesiumEvent();
this._loading = new CesiumEvent();
this._entityCollection = new EntityCollection(this);
this._entityCluster = new EntityCluster();
this._terria = terria;
this._tableStructure = defined(tableStructure)
? tableStructure
: new TableStructure();
if (defined(tableStyle) && !(tableStyle instanceof TableStyle)) {
throw new DeveloperError("Please pass a TableStyle object.");
}
/**
* Gets the TableStyle object showing how to style the data.
* @memberof TableDataSource.prototype
* @type {TableStyle}
*/
this.tableStyle = tableStyle; // Can be undefined.
this._legendHelper = undefined;
this._legendUrl = undefined;
this._extent = undefined;
this._rowObjects = undefined; // The most recent properties and descriptions are saved here.
this._rowDescriptions = undefined;
this.loadingData = false;
// Track _tableStructure so that csvCatalogItem's concepts are maintained.
// Track _legendUrl so that csvCatalogItem can update the legend if it changes.
// Track _extent so that the TableCatalogItem's rectangle updates properly, which also feeds into catalog item's canZoomTo property.
knockout.track(this, ["_tableStructure", "_legendUrl", "_extent"]);
// Whenever the active item is changed, recalculate the legend and the display of all the entities.
// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.
knockout
.getObservable(this._tableStructure, "activeItems")
.subscribe(changedActiveItems.bind(null, this), this);
} | javascript | function(
terria,
tableStructure,
tableStyle,
name,
isUpdating
) {
this._guid = createGuid(); // Used internally to give features a globally unique id.
this._name = name;
this._isUpdating = isUpdating || false;
this._hasFeaturePerRow = undefined; // If this changes, need to remove old features.
this._changed = new CesiumEvent();
this._error = new CesiumEvent();
this._loading = new CesiumEvent();
this._entityCollection = new EntityCollection(this);
this._entityCluster = new EntityCluster();
this._terria = terria;
this._tableStructure = defined(tableStructure)
? tableStructure
: new TableStructure();
if (defined(tableStyle) && !(tableStyle instanceof TableStyle)) {
throw new DeveloperError("Please pass a TableStyle object.");
}
/**
* Gets the TableStyle object showing how to style the data.
* @memberof TableDataSource.prototype
* @type {TableStyle}
*/
this.tableStyle = tableStyle; // Can be undefined.
this._legendHelper = undefined;
this._legendUrl = undefined;
this._extent = undefined;
this._rowObjects = undefined; // The most recent properties and descriptions are saved here.
this._rowDescriptions = undefined;
this.loadingData = false;
// Track _tableStructure so that csvCatalogItem's concepts are maintained.
// Track _legendUrl so that csvCatalogItem can update the legend if it changes.
// Track _extent so that the TableCatalogItem's rectangle updates properly, which also feeds into catalog item's canZoomTo property.
knockout.track(this, ["_tableStructure", "_legendUrl", "_extent"]);
// Whenever the active item is changed, recalculate the legend and the display of all the entities.
// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.
knockout
.getObservable(this._tableStructure, "activeItems")
.subscribe(changedActiveItems.bind(null, this), this);
} | [
"function",
"(",
"terria",
",",
"tableStructure",
",",
"tableStyle",
",",
"name",
",",
"isUpdating",
")",
"{",
"this",
".",
"_guid",
"=",
"createGuid",
"(",
")",
";",
"// Used internally to give features a globally unique id.",
"this",
".",
"_name",
"=",
"name",
";",
"this",
".",
"_isUpdating",
"=",
"isUpdating",
"||",
"false",
";",
"this",
".",
"_hasFeaturePerRow",
"=",
"undefined",
";",
"// If this changes, need to remove old features.",
"this",
".",
"_changed",
"=",
"new",
"CesiumEvent",
"(",
")",
";",
"this",
".",
"_error",
"=",
"new",
"CesiumEvent",
"(",
")",
";",
"this",
".",
"_loading",
"=",
"new",
"CesiumEvent",
"(",
")",
";",
"this",
".",
"_entityCollection",
"=",
"new",
"EntityCollection",
"(",
"this",
")",
";",
"this",
".",
"_entityCluster",
"=",
"new",
"EntityCluster",
"(",
")",
";",
"this",
".",
"_terria",
"=",
"terria",
";",
"this",
".",
"_tableStructure",
"=",
"defined",
"(",
"tableStructure",
")",
"?",
"tableStructure",
":",
"new",
"TableStructure",
"(",
")",
";",
"if",
"(",
"defined",
"(",
"tableStyle",
")",
"&&",
"!",
"(",
"tableStyle",
"instanceof",
"TableStyle",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"Please pass a TableStyle object.\"",
")",
";",
"}",
"/**\n * Gets the TableStyle object showing how to style the data.\n * @memberof TableDataSource.prototype\n * @type {TableStyle}\n */",
"this",
".",
"tableStyle",
"=",
"tableStyle",
";",
"// Can be undefined.",
"this",
".",
"_legendHelper",
"=",
"undefined",
";",
"this",
".",
"_legendUrl",
"=",
"undefined",
";",
"this",
".",
"_extent",
"=",
"undefined",
";",
"this",
".",
"_rowObjects",
"=",
"undefined",
";",
"// The most recent properties and descriptions are saved here.",
"this",
".",
"_rowDescriptions",
"=",
"undefined",
";",
"this",
".",
"loadingData",
"=",
"false",
";",
"// Track _tableStructure so that csvCatalogItem's concepts are maintained.",
"// Track _legendUrl so that csvCatalogItem can update the legend if it changes.",
"// Track _extent so that the TableCatalogItem's rectangle updates properly, which also feeds into catalog item's canZoomTo property.",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"_tableStructure\"",
",",
"\"_legendUrl\"",
",",
"\"_extent\"",
"]",
")",
";",
"// Whenever the active item is changed, recalculate the legend and the display of all the entities.",
"// This is triggered both on deactivation and on reactivation, ie. twice per change; it would be nicer to trigger once.",
"knockout",
".",
"getObservable",
"(",
"this",
".",
"_tableStructure",
",",
"\"activeItems\"",
")",
".",
"subscribe",
"(",
"changedActiveItems",
".",
"bind",
"(",
"null",
",",
"this",
")",
",",
"this",
")",
";",
"}"
] | A DataSource for table-based data where each row corresponds to a single feature or point - not region-mapped.
Generates Cesium entities for each row.
Displaying the points requires a legend.
@name TableDataSource
@alias TableDataSource
@constructor
@param {TableStructure} [tableStructure] The Table Structure instance; defaults to a new one.
@param {TableStyle} [tableStyle] The table style; defaults to undefined.
@param {String} [name] A name to show in the legend if no columns are available.
@param {Boolean} [isUpdating] Is the underlying data going to update? Defaults to false.
If true, replaces constant feature properties and description with a CallbackProperty. | [
"A",
"DataSource",
"for",
"table",
"-",
"based",
"data",
"where",
"each",
"row",
"corresponds",
"to",
"a",
"single",
"feature",
"or",
"point",
"-",
"not",
"region",
"-",
"mapped",
".",
"Generates",
"Cesium",
"entities",
"for",
"each",
"row",
".",
"Displaying",
"the",
"points",
"requires",
"a",
"legend",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/TableDataSource.js#L52-L102 |
|
7,029 | TerriaJS/terriajs | lib/Core/CorsProxy.js | hostInDomains | function hostInDomains(host, domains) {
if (!defined(domains)) {
return false;
}
host = host.toLowerCase();
for (var i = 0; i < domains.length; i++) {
if (host.match("(^|\\.)" + domains[i] + "$")) {
return true;
}
}
return false;
} | javascript | function hostInDomains(host, domains) {
if (!defined(domains)) {
return false;
}
host = host.toLowerCase();
for (var i = 0; i < domains.length; i++) {
if (host.match("(^|\\.)" + domains[i] + "$")) {
return true;
}
}
return false;
} | [
"function",
"hostInDomains",
"(",
"host",
",",
"domains",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"domains",
")",
")",
"{",
"return",
"false",
";",
"}",
"host",
"=",
"host",
".",
"toLowerCase",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"domains",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"host",
".",
"match",
"(",
"\"(^|\\\\.)\"",
"+",
"domains",
"[",
"i",
"]",
"+",
"\"$\"",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines whether this host is, or is a subdomain of, an item in the provided array.
@param {String} host The host to search for
@param {String[]} domains The array of domains to look in
@returns {boolean} The result. | [
"Determines",
"whether",
"this",
"host",
"is",
"or",
"is",
"a",
"subdomain",
"of",
"an",
"item",
"in",
"the",
"provided",
"array",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/CorsProxy.js#L181-L193 |
7,030 | TerriaJS/terriajs | lib/Models/TimeSeriesStack.js | function(clock) {
this.clock = clock;
this._layerStack = [];
knockout.track(this, ["_layerStack"]);
/**
* The highest time-series layer, or undefined if there are no time series layers.
*/
knockout.defineProperty(this, "topLayer", {
get: function() {
if (this._layerStack.length) {
return this._layerStack[this._layerStack.length - 1];
}
return undefined;
}
});
knockout.getObservable(this, "topLayer").subscribe(function(topLayer) {
if (defined(topLayer)) {
// If there's a top layer, make the clock track it.
this.clock.setCatalogItem(this.topLayer);
} else {
// If there's no layers, stop the clock from running.
this.clock.shouldAnimate = false;
}
}, this);
} | javascript | function(clock) {
this.clock = clock;
this._layerStack = [];
knockout.track(this, ["_layerStack"]);
/**
* The highest time-series layer, or undefined if there are no time series layers.
*/
knockout.defineProperty(this, "topLayer", {
get: function() {
if (this._layerStack.length) {
return this._layerStack[this._layerStack.length - 1];
}
return undefined;
}
});
knockout.getObservable(this, "topLayer").subscribe(function(topLayer) {
if (defined(topLayer)) {
// If there's a top layer, make the clock track it.
this.clock.setCatalogItem(this.topLayer);
} else {
// If there's no layers, stop the clock from running.
this.clock.shouldAnimate = false;
}
}, this);
} | [
"function",
"(",
"clock",
")",
"{",
"this",
".",
"clock",
"=",
"clock",
";",
"this",
".",
"_layerStack",
"=",
"[",
"]",
";",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"_layerStack\"",
"]",
")",
";",
"/**\n * The highest time-series layer, or undefined if there are no time series layers.\n */",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"topLayer\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_layerStack",
".",
"length",
")",
"{",
"return",
"this",
".",
"_layerStack",
"[",
"this",
".",
"_layerStack",
".",
"length",
"-",
"1",
"]",
";",
"}",
"return",
"undefined",
";",
"}",
"}",
")",
";",
"knockout",
".",
"getObservable",
"(",
"this",
",",
"\"topLayer\"",
")",
".",
"subscribe",
"(",
"function",
"(",
"topLayer",
")",
"{",
"if",
"(",
"defined",
"(",
"topLayer",
")",
")",
"{",
"// If there's a top layer, make the clock track it.",
"this",
".",
"clock",
".",
"setCatalogItem",
"(",
"this",
".",
"topLayer",
")",
";",
"}",
"else",
"{",
"// If there's no layers, stop the clock from running.",
"this",
".",
"clock",
".",
"shouldAnimate",
"=",
"false",
";",
"}",
"}",
",",
"this",
")",
";",
"}"
] | Manages a stack of all the time series layers currently being shown and makes sure the clock provided is always tracking
the highest one. When the top-most layer is disabled, the clock will track the next highest in the stack. Provides access
to the current top layer so that can be displayed to the user.
@param clock The clock that should track the highest layer.
@constructor | [
"Manages",
"a",
"stack",
"of",
"all",
"the",
"time",
"series",
"layers",
"currently",
"being",
"shown",
"and",
"makes",
"sure",
"the",
"clock",
"provided",
"is",
"always",
"tracking",
"the",
"highest",
"one",
".",
"When",
"the",
"top",
"-",
"most",
"layer",
"is",
"disabled",
"the",
"clock",
"will",
"track",
"the",
"next",
"highest",
"in",
"the",
"stack",
".",
"Provides",
"access",
"to",
"the",
"current",
"top",
"layer",
"so",
"that",
"can",
"be",
"displayed",
"to",
"the",
"user",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/TimeSeriesStack.js#L16-L44 |
|
7,031 | TerriaJS/terriajs | lib/Core/triggerResize.js | triggerResize | function triggerResize() {
try {
window.dispatchEvent(new Event("resize"));
} catch (e) {
var evt = window.document.createEvent("UIEvents");
evt.initUIEvent("resize", true, false, window, 0);
window.dispatchEvent(evt);
}
} | javascript | function triggerResize() {
try {
window.dispatchEvent(new Event("resize"));
} catch (e) {
var evt = window.document.createEvent("UIEvents");
evt.initUIEvent("resize", true, false, window, 0);
window.dispatchEvent(evt);
}
} | [
"function",
"triggerResize",
"(",
")",
"{",
"try",
"{",
"window",
".",
"dispatchEvent",
"(",
"new",
"Event",
"(",
"\"resize\"",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"evt",
"=",
"window",
".",
"document",
".",
"createEvent",
"(",
"\"UIEvents\"",
")",
";",
"evt",
".",
"initUIEvent",
"(",
"\"resize\"",
",",
"true",
",",
"false",
",",
"window",
",",
"0",
")",
";",
"window",
".",
"dispatchEvent",
"(",
"evt",
")",
";",
"}",
"}"
] | Trigger a window resize event. | [
"Trigger",
"a",
"window",
"resize",
"event",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/triggerResize.js#L6-L14 |
7,032 | TerriaJS/terriajs | lib/Models/WebMapServiceCatalogItem.js | objectToLowercase | function objectToLowercase(obj) {
var result = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
result[key.toLowerCase()] = obj[key];
}
}
return result;
} | javascript | function objectToLowercase(obj) {
var result = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
result[key.toLowerCase()] = obj[key];
}
}
return result;
} | [
"function",
"objectToLowercase",
"(",
"obj",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"result",
"[",
"key",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | This is copied directly from Cesium's WebMapServiceImageryProvider. | [
"This",
"is",
"copied",
"directly",
"from",
"Cesium",
"s",
"WebMapServiceImageryProvider",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/WebMapServiceCatalogItem.js#L2044-L2052 |
7,033 | TerriaJS/terriajs | lib/Core/combineFilters.js | combineFilters | function combineFilters(filters) {
var allFilters, returnFn;
allFilters = filters
.filter(function(filter) {
return defined(filter);
})
.reduce(function(filtersSoFar, thisFilter) {
if (thisFilter._filterIndex) {
// If a filter is an instance of this function just pull that filter's index into this one's.
thisFilter._filterIndex.forEach(
addToListUnique.bind(undefined, filtersSoFar)
);
} else {
// Otherwise add it.
addToListUnique(filtersSoFar, thisFilter);
}
return filtersSoFar;
}, []);
returnFn = function() {
var outerArgs = arguments;
return !allFilters.some(function(filter) {
return !filter.apply(this, outerArgs);
}, this);
};
returnFn._filterIndex = allFilters;
return returnFn;
} | javascript | function combineFilters(filters) {
var allFilters, returnFn;
allFilters = filters
.filter(function(filter) {
return defined(filter);
})
.reduce(function(filtersSoFar, thisFilter) {
if (thisFilter._filterIndex) {
// If a filter is an instance of this function just pull that filter's index into this one's.
thisFilter._filterIndex.forEach(
addToListUnique.bind(undefined, filtersSoFar)
);
} else {
// Otherwise add it.
addToListUnique(filtersSoFar, thisFilter);
}
return filtersSoFar;
}, []);
returnFn = function() {
var outerArgs = arguments;
return !allFilters.some(function(filter) {
return !filter.apply(this, outerArgs);
}, this);
};
returnFn._filterIndex = allFilters;
return returnFn;
} | [
"function",
"combineFilters",
"(",
"filters",
")",
"{",
"var",
"allFilters",
",",
"returnFn",
";",
"allFilters",
"=",
"filters",
".",
"filter",
"(",
"function",
"(",
"filter",
")",
"{",
"return",
"defined",
"(",
"filter",
")",
";",
"}",
")",
".",
"reduce",
"(",
"function",
"(",
"filtersSoFar",
",",
"thisFilter",
")",
"{",
"if",
"(",
"thisFilter",
".",
"_filterIndex",
")",
"{",
"// If a filter is an instance of this function just pull that filter's index into this one's.",
"thisFilter",
".",
"_filterIndex",
".",
"forEach",
"(",
"addToListUnique",
".",
"bind",
"(",
"undefined",
",",
"filtersSoFar",
")",
")",
";",
"}",
"else",
"{",
"// Otherwise add it.",
"addToListUnique",
"(",
"filtersSoFar",
",",
"thisFilter",
")",
";",
"}",
"return",
"filtersSoFar",
";",
"}",
",",
"[",
"]",
")",
";",
"returnFn",
"=",
"function",
"(",
")",
"{",
"var",
"outerArgs",
"=",
"arguments",
";",
"return",
"!",
"allFilters",
".",
"some",
"(",
"function",
"(",
"filter",
")",
"{",
"return",
"!",
"filter",
".",
"apply",
"(",
"this",
",",
"outerArgs",
")",
";",
"}",
",",
"this",
")",
";",
"}",
";",
"returnFn",
".",
"_filterIndex",
"=",
"allFilters",
";",
"return",
"returnFn",
";",
"}"
] | Combines a number of functions that return a boolean into a single function that executes all of them and returns
true only if all them do. Maintains an set of filter functions, so if the same function is combined
more than once, it is only executed one time. This means that it is also safe to call combineFilter on its own result
to combine the result with another filter - the set of filters from the previous result will simply
be merged into that of the new result so that only individual filter functions are executed.
@param {Array} filters A number of functions to combine into one logical function.
@returns {Function} The resulting function. | [
"Combines",
"a",
"number",
"of",
"functions",
"that",
"return",
"a",
"boolean",
"into",
"a",
"single",
"function",
"that",
"executes",
"all",
"of",
"them",
"and",
"returns",
"true",
"only",
"if",
"all",
"them",
"do",
".",
"Maintains",
"an",
"set",
"of",
"filter",
"functions",
"so",
"if",
"the",
"same",
"function",
"is",
"combined",
"more",
"than",
"once",
"it",
"is",
"only",
"executed",
"one",
"time",
".",
"This",
"means",
"that",
"it",
"is",
"also",
"safe",
"to",
"call",
"combineFilter",
"on",
"its",
"own",
"result",
"to",
"combine",
"the",
"result",
"with",
"another",
"filter",
"-",
"the",
"set",
"of",
"filters",
"from",
"the",
"previous",
"result",
"will",
"simply",
"be",
"merged",
"into",
"that",
"of",
"the",
"new",
"result",
"so",
"that",
"only",
"individual",
"filter",
"functions",
"are",
"executed",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/combineFilters.js#L15-L46 |
7,034 | TerriaJS/terriajs | lib/Core/propertyGetTimeValues.js | propertyGetTimeValues | function propertyGetTimeValues(properties, currentTime) {
// properties itself may be a time-varying "property" with a getValue function.
// If not, check each of its properties for a getValue function; if it exists, use it to get the current value.
if (!defined(properties)) {
return;
}
var result = {};
if (typeof properties.getValue === "function") {
return properties.getValue(currentTime);
}
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
if (properties[key] && typeof properties[key].getValue === "function") {
result[key] = properties[key].getValue(currentTime);
} else {
result[key] = properties[key];
}
}
}
return result;
} | javascript | function propertyGetTimeValues(properties, currentTime) {
// properties itself may be a time-varying "property" with a getValue function.
// If not, check each of its properties for a getValue function; if it exists, use it to get the current value.
if (!defined(properties)) {
return;
}
var result = {};
if (typeof properties.getValue === "function") {
return properties.getValue(currentTime);
}
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
if (properties[key] && typeof properties[key].getValue === "function") {
result[key] = properties[key].getValue(currentTime);
} else {
result[key] = properties[key];
}
}
}
return result;
} | [
"function",
"propertyGetTimeValues",
"(",
"properties",
",",
"currentTime",
")",
"{",
"// properties itself may be a time-varying \"property\" with a getValue function.",
"// If not, check each of its properties for a getValue function; if it exists, use it to get the current value.",
"if",
"(",
"!",
"defined",
"(",
"properties",
")",
")",
"{",
"return",
";",
"}",
"var",
"result",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"properties",
".",
"getValue",
"===",
"\"function\"",
")",
"{",
"return",
"properties",
".",
"getValue",
"(",
"currentTime",
")",
";",
"}",
"for",
"(",
"var",
"key",
"in",
"properties",
")",
"{",
"if",
"(",
"properties",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"properties",
"[",
"key",
"]",
"&&",
"typeof",
"properties",
"[",
"key",
"]",
".",
"getValue",
"===",
"\"function\"",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"properties",
"[",
"key",
"]",
".",
"getValue",
"(",
"currentTime",
")",
";",
"}",
"else",
"{",
"result",
"[",
"key",
"]",
"=",
"properties",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Gets the values from a Entity's properties object for the time on the current clock.
@param properties An entity's property object
@param {JulianDate} currentTime The current time if it is a time varying catalog item.
@returns {Object} a simple key-value object of properties. | [
"Gets",
"the",
"values",
"from",
"a",
"Entity",
"s",
"properties",
"object",
"for",
"the",
"time",
"on",
"the",
"current",
"clock",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/propertyGetTimeValues.js#L12-L32 |
7,035 | TerriaJS/terriajs | lib/Map/gmlToGeoJson.js | gmlToGeoJson | function gmlToGeoJson(xml) {
if (typeof xml === "string") {
var parser = new DOMParser();
xml = parser.parseFromString(xml, "text/xml");
}
var result = [];
var featureCollection = xml.documentElement;
var featureMembers = featureCollection.getElementsByTagNameNS(
gmlNamespace,
"featureMember"
);
for (
var featureIndex = 0;
featureIndex < featureMembers.length;
++featureIndex
) {
var featureMember = featureMembers[featureIndex];
var properties = {};
getGmlPropertiesRecursively(featureMember, properties);
var feature = {
type: "Feature",
geometry: getGmlGeometry(featureMember),
properties: properties
};
if (defined(feature.geometry)) {
result.push(feature);
}
}
return {
type: "FeatureCollection",
crs: { type: "EPSG", properties: { code: "4326" } },
features: result
};
} | javascript | function gmlToGeoJson(xml) {
if (typeof xml === "string") {
var parser = new DOMParser();
xml = parser.parseFromString(xml, "text/xml");
}
var result = [];
var featureCollection = xml.documentElement;
var featureMembers = featureCollection.getElementsByTagNameNS(
gmlNamespace,
"featureMember"
);
for (
var featureIndex = 0;
featureIndex < featureMembers.length;
++featureIndex
) {
var featureMember = featureMembers[featureIndex];
var properties = {};
getGmlPropertiesRecursively(featureMember, properties);
var feature = {
type: "Feature",
geometry: getGmlGeometry(featureMember),
properties: properties
};
if (defined(feature.geometry)) {
result.push(feature);
}
}
return {
type: "FeatureCollection",
crs: { type: "EPSG", properties: { code: "4326" } },
features: result
};
} | [
"function",
"gmlToGeoJson",
"(",
"xml",
")",
"{",
"if",
"(",
"typeof",
"xml",
"===",
"\"string\"",
")",
"{",
"var",
"parser",
"=",
"new",
"DOMParser",
"(",
")",
";",
"xml",
"=",
"parser",
".",
"parseFromString",
"(",
"xml",
",",
"\"text/xml\"",
")",
";",
"}",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"featureCollection",
"=",
"xml",
".",
"documentElement",
";",
"var",
"featureMembers",
"=",
"featureCollection",
".",
"getElementsByTagNameNS",
"(",
"gmlNamespace",
",",
"\"featureMember\"",
")",
";",
"for",
"(",
"var",
"featureIndex",
"=",
"0",
";",
"featureIndex",
"<",
"featureMembers",
".",
"length",
";",
"++",
"featureIndex",
")",
"{",
"var",
"featureMember",
"=",
"featureMembers",
"[",
"featureIndex",
"]",
";",
"var",
"properties",
"=",
"{",
"}",
";",
"getGmlPropertiesRecursively",
"(",
"featureMember",
",",
"properties",
")",
";",
"var",
"feature",
"=",
"{",
"type",
":",
"\"Feature\"",
",",
"geometry",
":",
"getGmlGeometry",
"(",
"featureMember",
")",
",",
"properties",
":",
"properties",
"}",
";",
"if",
"(",
"defined",
"(",
"feature",
".",
"geometry",
")",
")",
"{",
"result",
".",
"push",
"(",
"feature",
")",
";",
"}",
"}",
"return",
"{",
"type",
":",
"\"FeatureCollection\"",
",",
"crs",
":",
"{",
"type",
":",
"\"EPSG\"",
",",
"properties",
":",
"{",
"code",
":",
"\"4326\"",
"}",
"}",
",",
"features",
":",
"result",
"}",
";",
"}"
] | Converts a GML v3.1.1 simple features document to GeoJSON.
@param {Document|String} xml The GML document.
@return {Object} The GeoJSON object. | [
"Converts",
"a",
"GML",
"v3",
".",
"1",
".",
"1",
"simple",
"features",
"document",
"to",
"GeoJSON",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/gmlToGeoJson.js#L14-L55 |
7,036 | TerriaJS/terriajs | lib/Map/gmlToGeoJson.js | gml2coord | function gml2coord(posList) {
var pnts = posList.split(/[ ,]+/).filter(isNotEmpty);
var coords = [];
for (var i = 0; i < pnts.length; i += 2) {
coords.push([parseFloat(pnts[i + 1]), parseFloat(pnts[i])]);
}
return coords;
} | javascript | function gml2coord(posList) {
var pnts = posList.split(/[ ,]+/).filter(isNotEmpty);
var coords = [];
for (var i = 0; i < pnts.length; i += 2) {
coords.push([parseFloat(pnts[i + 1]), parseFloat(pnts[i])]);
}
return coords;
} | [
"function",
"gml2coord",
"(",
"posList",
")",
"{",
"var",
"pnts",
"=",
"posList",
".",
"split",
"(",
"/",
"[ ,]+",
"/",
")",
".",
"filter",
"(",
"isNotEmpty",
")",
";",
"var",
"coords",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pnts",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"coords",
".",
"push",
"(",
"[",
"parseFloat",
"(",
"pnts",
"[",
"i",
"+",
"1",
"]",
")",
",",
"parseFloat",
"(",
"pnts",
"[",
"i",
"]",
")",
"]",
")",
";",
"}",
"return",
"coords",
";",
"}"
] | Utility function to change esri gml positions to geojson positions | [
"Utility",
"function",
"to",
"change",
"esri",
"gml",
"positions",
"to",
"geojson",
"positions"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/gmlToGeoJson.js#L277-L284 |
7,037 | TerriaJS/terriajs | lib/Models/Catalog.js | function(terria) {
if (!defined(terria)) {
throw new DeveloperError("terria is required");
}
this._terria = terria;
this._shareKeyIndex = {};
this._group = new CatalogGroup(terria);
this._group.name = "Root Group";
this._group.preserveOrder = true;
/**
* Gets or sets a flag indicating whether the catalog is currently loading.
* @type {Boolean}
*/
this.isLoading = false;
this._chartableItems = [];
knockout.track(this, ["isLoading", "_chartableItems"]);
knockout.defineProperty(this, "userAddedDataGroup", {
get: this.upsertCatalogGroup.bind(
this,
CatalogGroup,
USER_ADDED_CATEGORY_NAME,
"The group for data that was added by the user via the Add Data panel."
)
});
/**
* Array of the items that should be shown as a chart.
*/
knockout.defineProperty(this, "chartableItems", {
get: function() {
return this._chartableItems;
}
});
} | javascript | function(terria) {
if (!defined(terria)) {
throw new DeveloperError("terria is required");
}
this._terria = terria;
this._shareKeyIndex = {};
this._group = new CatalogGroup(terria);
this._group.name = "Root Group";
this._group.preserveOrder = true;
/**
* Gets or sets a flag indicating whether the catalog is currently loading.
* @type {Boolean}
*/
this.isLoading = false;
this._chartableItems = [];
knockout.track(this, ["isLoading", "_chartableItems"]);
knockout.defineProperty(this, "userAddedDataGroup", {
get: this.upsertCatalogGroup.bind(
this,
CatalogGroup,
USER_ADDED_CATEGORY_NAME,
"The group for data that was added by the user via the Add Data panel."
)
});
/**
* Array of the items that should be shown as a chart.
*/
knockout.defineProperty(this, "chartableItems", {
get: function() {
return this._chartableItems;
}
});
} | [
"function",
"(",
"terria",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"terria",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"terria is required\"",
")",
";",
"}",
"this",
".",
"_terria",
"=",
"terria",
";",
"this",
".",
"_shareKeyIndex",
"=",
"{",
"}",
";",
"this",
".",
"_group",
"=",
"new",
"CatalogGroup",
"(",
"terria",
")",
";",
"this",
".",
"_group",
".",
"name",
"=",
"\"Root Group\"",
";",
"this",
".",
"_group",
".",
"preserveOrder",
"=",
"true",
";",
"/**\n * Gets or sets a flag indicating whether the catalog is currently loading.\n * @type {Boolean}\n */",
"this",
".",
"isLoading",
"=",
"false",
";",
"this",
".",
"_chartableItems",
"=",
"[",
"]",
";",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"isLoading\"",
",",
"\"_chartableItems\"",
"]",
")",
";",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"userAddedDataGroup\"",
",",
"{",
"get",
":",
"this",
".",
"upsertCatalogGroup",
".",
"bind",
"(",
"this",
",",
"CatalogGroup",
",",
"USER_ADDED_CATEGORY_NAME",
",",
"\"The group for data that was added by the user via the Add Data panel.\"",
")",
"}",
")",
";",
"/**\n * Array of the items that should be shown as a chart.\n */",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"chartableItems\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"_chartableItems",
";",
"}",
"}",
")",
";",
"}"
] | The view model for the data catalog.
@param {Terria} terria The Terria instance.
@alias Catalog
@constructor | [
"The",
"view",
"model",
"for",
"the",
"data",
"catalog",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/Catalog.js#L23-L62 |
|
7,038 | TerriaJS/terriajs | lib/Models/TableColumnStyle.js | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
/**
* All data values less than or equal to this are considered equal for the purpose of display.
* @type {Float}
*/
this.minDisplayValue = options.minDisplayValue;
/**
* Minimum y value to display in charts; if not specified, minimum data value will be used.
* @type {Float}
*/
this.yAxisMin = options.yAxisMin;
/**
* Maximum y value to display in charts; if not specified, maximum data value will be used.
* @type {Float}
*/
this.yAxisMax = options.yAxisMax;
/**
* All data values greater than or equal to this are considered equal for the purpose of display.
* @type {Float}
*/
this.maxDisplayValue = options.maxDisplayValue;
/**
* Display duration for each row in the table, in minutes. If not provided, this is estimated from the data.
* @type {Float}
*/
this.displayDuration = options.displayDuration;
/**
* Values to replace with zero, eg. ['-', null].
* @type {Array}
*/
this.replaceWithZeroValues = options.replaceWithZeroValues;
/**
* Values to replace with null, eg. ['na', 'NA'].
* @type {Array}
*/
this.replaceWithNullValues = options.replaceWithNullValues;
/**
* The css string for the color with which to display null values.
* @type {String}
*/
this.nullColor = options.nullColor;
/**
* The legend label for null values.
* @type {String}
*/
this.nullLabel = options.nullLabel;
/**
* The size of each point or billboard.
* @type {Float}
*/
this.scale = options.scale;
/**
* Should points and billboards representing each feature be scaled by the size of their data variable?
* @type {Boolean}
*/
this.scaleByValue = options.scaleByValue;
/**
* Display values that fall outside the display range as min and max colors.
* @type {Boolean}
*/
this.clampDisplayValue = options.clampDisplayValue;
/**
* A string representing an image to display at each point, for lat-long datasets.
* @type {String}
*/
this.imageUrl = options.imageUrl;
/**
* An object of { "myCol": "My column" } properties, defining which columns get displayed in feature info boxes
* (when clicked on), and what label is used instead of the column's actual name.
* @type {Object}
*/
this.featureInfoFields = options.featureInfoFields;
/**
* Color for column (css string)
* @type {String}
*/
this.chartLineColor = options.chartLineColor;
/**
* Either the number of discrete colours that a color gradient should be quantised into (ie. an integer), or
* an array of values specifying the boundaries between the color bins.
* @type {Integer|Number[]}
*/
this.colorBins = options.colorBins;
/**
* The method for quantising colors:
* * For numeric columns: "auto" (default), "ckmeans", "quantile" or "none" (equivalent to colorBins: 0).
* * For enumerated columns: "auto" (default), "top", or "cycle"
* @type {String}
*/
this.colorBinMethod = defaultValue(options.colorBinMethod, "auto");
/**
* Gets or sets a string or {@link ColorMap} array, specifying how to map values to colors. Setting this property sets
* {@link TableColumnStyle#colorPalette} to undefined. If this property is a string, it specifies a list of CSS colors separated by hyphens (-),
* and the colors are evenly spaced over the range of values. For example, "red-white-hsl(240,50%,50%)".
* @memberOf TableColumnStyle.prototype
* @type {String|Array}
* @see TableColumnStyle#colorPalette
*/
if (defined(options.colorMap)) {
this.colorMap = new ColorMap(options.colorMap);
} else {
this.colorMap = undefined;
}
/**
* Gets or sets the [ColorBrewer](http://colorbrewer2.org/) palette to use when mapping values to colors. Setting this
* property sets {@link TableColumnStyle#colorMap} to undefined. This property is ignored if {@link TableColumnStyle#colorMap} is defined.
* @memberOf TableColumnStyle.prototype
* @type {String}
* @see TableColumnStyle#colorMap
*/
this.colorPalette = options.colorPalette; // Only need this here so that updateFromJson sees colorPalette as a property.
if (defined(options.colorPalette)) {
// Note the promise created here is lost.
var that = this;
ColorMap.loadFromPalette(this.colorPalette).then(function(colorMap) {
that.colorMap = colorMap;
});
}
/**
* How many horizontal ticks to draw on the generated color ramp legend, not counting the top or bottom.
* @type {Integer}
*/
this.legendTicks = defaultValue(options.legendTicks, 3);
/**
* Display name for this column.
* @type {String}
*/
this.name = options.name;
/**
* Display name for the legend for this column (defaults to the column name).
* @type {String}
*/
this.legendName = options.legendName;
/**
* The variable type of this column.
* Converts strings, which are case-insensitive keys of VarType, to numbers. See TableStructure for further information.
* @type {String|Number}
*/
this.type = options.type;
/**
* The units of this column.
* @type {String}
*/
this.units = options.units;
/**
* Is this column active?
* @type {Boolean}
*/
this.active = options.active;
/**
* A format string for this column. For numbers, this is passed as options to toLocaleString.
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString .
* @type {String|Number}
*/
this.format = options.format;
} | javascript | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
/**
* All data values less than or equal to this are considered equal for the purpose of display.
* @type {Float}
*/
this.minDisplayValue = options.minDisplayValue;
/**
* Minimum y value to display in charts; if not specified, minimum data value will be used.
* @type {Float}
*/
this.yAxisMin = options.yAxisMin;
/**
* Maximum y value to display in charts; if not specified, maximum data value will be used.
* @type {Float}
*/
this.yAxisMax = options.yAxisMax;
/**
* All data values greater than or equal to this are considered equal for the purpose of display.
* @type {Float}
*/
this.maxDisplayValue = options.maxDisplayValue;
/**
* Display duration for each row in the table, in minutes. If not provided, this is estimated from the data.
* @type {Float}
*/
this.displayDuration = options.displayDuration;
/**
* Values to replace with zero, eg. ['-', null].
* @type {Array}
*/
this.replaceWithZeroValues = options.replaceWithZeroValues;
/**
* Values to replace with null, eg. ['na', 'NA'].
* @type {Array}
*/
this.replaceWithNullValues = options.replaceWithNullValues;
/**
* The css string for the color with which to display null values.
* @type {String}
*/
this.nullColor = options.nullColor;
/**
* The legend label for null values.
* @type {String}
*/
this.nullLabel = options.nullLabel;
/**
* The size of each point or billboard.
* @type {Float}
*/
this.scale = options.scale;
/**
* Should points and billboards representing each feature be scaled by the size of their data variable?
* @type {Boolean}
*/
this.scaleByValue = options.scaleByValue;
/**
* Display values that fall outside the display range as min and max colors.
* @type {Boolean}
*/
this.clampDisplayValue = options.clampDisplayValue;
/**
* A string representing an image to display at each point, for lat-long datasets.
* @type {String}
*/
this.imageUrl = options.imageUrl;
/**
* An object of { "myCol": "My column" } properties, defining which columns get displayed in feature info boxes
* (when clicked on), and what label is used instead of the column's actual name.
* @type {Object}
*/
this.featureInfoFields = options.featureInfoFields;
/**
* Color for column (css string)
* @type {String}
*/
this.chartLineColor = options.chartLineColor;
/**
* Either the number of discrete colours that a color gradient should be quantised into (ie. an integer), or
* an array of values specifying the boundaries between the color bins.
* @type {Integer|Number[]}
*/
this.colorBins = options.colorBins;
/**
* The method for quantising colors:
* * For numeric columns: "auto" (default), "ckmeans", "quantile" or "none" (equivalent to colorBins: 0).
* * For enumerated columns: "auto" (default), "top", or "cycle"
* @type {String}
*/
this.colorBinMethod = defaultValue(options.colorBinMethod, "auto");
/**
* Gets or sets a string or {@link ColorMap} array, specifying how to map values to colors. Setting this property sets
* {@link TableColumnStyle#colorPalette} to undefined. If this property is a string, it specifies a list of CSS colors separated by hyphens (-),
* and the colors are evenly spaced over the range of values. For example, "red-white-hsl(240,50%,50%)".
* @memberOf TableColumnStyle.prototype
* @type {String|Array}
* @see TableColumnStyle#colorPalette
*/
if (defined(options.colorMap)) {
this.colorMap = new ColorMap(options.colorMap);
} else {
this.colorMap = undefined;
}
/**
* Gets or sets the [ColorBrewer](http://colorbrewer2.org/) palette to use when mapping values to colors. Setting this
* property sets {@link TableColumnStyle#colorMap} to undefined. This property is ignored if {@link TableColumnStyle#colorMap} is defined.
* @memberOf TableColumnStyle.prototype
* @type {String}
* @see TableColumnStyle#colorMap
*/
this.colorPalette = options.colorPalette; // Only need this here so that updateFromJson sees colorPalette as a property.
if (defined(options.colorPalette)) {
// Note the promise created here is lost.
var that = this;
ColorMap.loadFromPalette(this.colorPalette).then(function(colorMap) {
that.colorMap = colorMap;
});
}
/**
* How many horizontal ticks to draw on the generated color ramp legend, not counting the top or bottom.
* @type {Integer}
*/
this.legendTicks = defaultValue(options.legendTicks, 3);
/**
* Display name for this column.
* @type {String}
*/
this.name = options.name;
/**
* Display name for the legend for this column (defaults to the column name).
* @type {String}
*/
this.legendName = options.legendName;
/**
* The variable type of this column.
* Converts strings, which are case-insensitive keys of VarType, to numbers. See TableStructure for further information.
* @type {String|Number}
*/
this.type = options.type;
/**
* The units of this column.
* @type {String}
*/
this.units = options.units;
/**
* Is this column active?
* @type {Boolean}
*/
this.active = options.active;
/**
* A format string for this column. For numbers, this is passed as options to toLocaleString.
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString .
* @type {String|Number}
*/
this.format = options.format;
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"/**\n * All data values less than or equal to this are considered equal for the purpose of display.\n * @type {Float}\n */",
"this",
".",
"minDisplayValue",
"=",
"options",
".",
"minDisplayValue",
";",
"/**\n * Minimum y value to display in charts; if not specified, minimum data value will be used.\n * @type {Float}\n */",
"this",
".",
"yAxisMin",
"=",
"options",
".",
"yAxisMin",
";",
"/**\n * Maximum y value to display in charts; if not specified, maximum data value will be used.\n * @type {Float}\n */",
"this",
".",
"yAxisMax",
"=",
"options",
".",
"yAxisMax",
";",
"/**\n * All data values greater than or equal to this are considered equal for the purpose of display.\n * @type {Float}\n */",
"this",
".",
"maxDisplayValue",
"=",
"options",
".",
"maxDisplayValue",
";",
"/**\n * Display duration for each row in the table, in minutes. If not provided, this is estimated from the data.\n * @type {Float}\n */",
"this",
".",
"displayDuration",
"=",
"options",
".",
"displayDuration",
";",
"/**\n * Values to replace with zero, eg. ['-', null].\n * @type {Array}\n */",
"this",
".",
"replaceWithZeroValues",
"=",
"options",
".",
"replaceWithZeroValues",
";",
"/**\n * Values to replace with null, eg. ['na', 'NA'].\n * @type {Array}\n */",
"this",
".",
"replaceWithNullValues",
"=",
"options",
".",
"replaceWithNullValues",
";",
"/**\n * The css string for the color with which to display null values.\n * @type {String}\n */",
"this",
".",
"nullColor",
"=",
"options",
".",
"nullColor",
";",
"/**\n * The legend label for null values.\n * @type {String}\n */",
"this",
".",
"nullLabel",
"=",
"options",
".",
"nullLabel",
";",
"/**\n * The size of each point or billboard.\n * @type {Float}\n */",
"this",
".",
"scale",
"=",
"options",
".",
"scale",
";",
"/**\n * Should points and billboards representing each feature be scaled by the size of their data variable?\n * @type {Boolean}\n */",
"this",
".",
"scaleByValue",
"=",
"options",
".",
"scaleByValue",
";",
"/**\n * Display values that fall outside the display range as min and max colors.\n * @type {Boolean}\n */",
"this",
".",
"clampDisplayValue",
"=",
"options",
".",
"clampDisplayValue",
";",
"/**\n * A string representing an image to display at each point, for lat-long datasets.\n * @type {String}\n */",
"this",
".",
"imageUrl",
"=",
"options",
".",
"imageUrl",
";",
"/**\n * An object of { \"myCol\": \"My column\" } properties, defining which columns get displayed in feature info boxes\n * (when clicked on), and what label is used instead of the column's actual name.\n * @type {Object}\n */",
"this",
".",
"featureInfoFields",
"=",
"options",
".",
"featureInfoFields",
";",
"/**\n * Color for column (css string)\n * @type {String}\n */",
"this",
".",
"chartLineColor",
"=",
"options",
".",
"chartLineColor",
";",
"/**\n * Either the number of discrete colours that a color gradient should be quantised into (ie. an integer), or\n * an array of values specifying the boundaries between the color bins.\n * @type {Integer|Number[]}\n */",
"this",
".",
"colorBins",
"=",
"options",
".",
"colorBins",
";",
"/**\n * The method for quantising colors:\n * * For numeric columns: \"auto\" (default), \"ckmeans\", \"quantile\" or \"none\" (equivalent to colorBins: 0).\n * * For enumerated columns: \"auto\" (default), \"top\", or \"cycle\"\n * @type {String}\n */",
"this",
".",
"colorBinMethod",
"=",
"defaultValue",
"(",
"options",
".",
"colorBinMethod",
",",
"\"auto\"",
")",
";",
"/**\n * Gets or sets a string or {@link ColorMap} array, specifying how to map values to colors. Setting this property sets\n * {@link TableColumnStyle#colorPalette} to undefined. If this property is a string, it specifies a list of CSS colors separated by hyphens (-),\n * and the colors are evenly spaced over the range of values. For example, \"red-white-hsl(240,50%,50%)\".\n * @memberOf TableColumnStyle.prototype\n * @type {String|Array}\n * @see TableColumnStyle#colorPalette\n */",
"if",
"(",
"defined",
"(",
"options",
".",
"colorMap",
")",
")",
"{",
"this",
".",
"colorMap",
"=",
"new",
"ColorMap",
"(",
"options",
".",
"colorMap",
")",
";",
"}",
"else",
"{",
"this",
".",
"colorMap",
"=",
"undefined",
";",
"}",
"/**\n * Gets or sets the [ColorBrewer](http://colorbrewer2.org/) palette to use when mapping values to colors. Setting this\n * property sets {@link TableColumnStyle#colorMap} to undefined. This property is ignored if {@link TableColumnStyle#colorMap} is defined.\n * @memberOf TableColumnStyle.prototype\n * @type {String}\n * @see TableColumnStyle#colorMap\n */",
"this",
".",
"colorPalette",
"=",
"options",
".",
"colorPalette",
";",
"// Only need this here so that updateFromJson sees colorPalette as a property.",
"if",
"(",
"defined",
"(",
"options",
".",
"colorPalette",
")",
")",
"{",
"// Note the promise created here is lost.",
"var",
"that",
"=",
"this",
";",
"ColorMap",
".",
"loadFromPalette",
"(",
"this",
".",
"colorPalette",
")",
".",
"then",
"(",
"function",
"(",
"colorMap",
")",
"{",
"that",
".",
"colorMap",
"=",
"colorMap",
";",
"}",
")",
";",
"}",
"/**\n * How many horizontal ticks to draw on the generated color ramp legend, not counting the top or bottom.\n * @type {Integer}\n */",
"this",
".",
"legendTicks",
"=",
"defaultValue",
"(",
"options",
".",
"legendTicks",
",",
"3",
")",
";",
"/**\n * Display name for this column.\n * @type {String}\n */",
"this",
".",
"name",
"=",
"options",
".",
"name",
";",
"/**\n * Display name for the legend for this column (defaults to the column name).\n * @type {String}\n */",
"this",
".",
"legendName",
"=",
"options",
".",
"legendName",
";",
"/**\n * The variable type of this column.\n * Converts strings, which are case-insensitive keys of VarType, to numbers. See TableStructure for further information.\n * @type {String|Number}\n */",
"this",
".",
"type",
"=",
"options",
".",
"type",
";",
"/**\n * The units of this column.\n * @type {String}\n */",
"this",
".",
"units",
"=",
"options",
".",
"units",
";",
"/**\n * Is this column active?\n * @type {Boolean}\n */",
"this",
".",
"active",
"=",
"options",
".",
"active",
";",
"/**\n * A format string for this column. For numbers, this is passed as options to toLocaleString.\n * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString .\n * @type {String|Number}\n */",
"this",
".",
"format",
"=",
"options",
".",
"format",
";",
"}"
] | A set of properties that define how a table column should be displayed.
If not set explicitly, many of these properties will be given default or guessed values elsewhere,
such as in CsvCatalogItem.
@alias TableColumnStyle
@constructor
@param {Object} [options] The values of the properties of the new instance.
@param {Float} [options.minDisplayValue] All data values less than or equal to this are considered equal for the purpose of display.
@param {Float} [options.yAxisMin] Minimum y value to display in charts; if not specified, minimum data value will be used.
@param {Float} [options.yAxisMax] Maximum y value to display in charts; if not specified, maximum data value will be used.
@param {Float} [options.maxDisplayValue] All data values reater than or equal to this are considered equal for the purpose of display.
@param {Float} [options.displayDuration] Display duration for each row in the table, in minutes. If not provided, this is estimated from the data.
@param {Array} [options.replaceWithZeroValues] Values to replace with zero, eg. ['-', null] will replace '-' and empty values with 0.
@param {Array} [options.replaceWithNullValues] Values to replace with null, eg. ['na', 'NA'] will replace these values with null.
@param {String} [options.nullColor] The css string for the color with which to display null values.
@param {String} [options.nullLabel] The legend label for null values.
@param {Float} [options.scale] The size of each point or billboard.
@param {Boolean} [options.scaleByValue] Should points and billboards representing each feature be scaled by the size of their data variable?
@param {Boolean} [options.clampDisplayValue] Display values that fall outside the display range as min and max colors.
@param {String} [options.imageUrl] A string representing an image to display at each point, for lat-long datasets.
@param {Object} [options.featureInfoFields] An object of { "myCol": "My column" } properties, defining which columns get displayed in feature info boxes
and what label is used instead of the column's actual name.
@param {String} [options.chartLineColor] Override color for column for charts.
@param {Integer|Number[]} [options.colorBins] Either the number of discrete colours that a color gradient should be quantised into (ie. an integer), or
an array of values specifying the boundaries between the color bins.
@param {String} [options.colorBinMethod] The method for quantising colors: "auto" (default), "ckmeans", "quantile" or "none" (equivalent to colorBins: 0).
@param {String|Array} [options.colorMap] Gets or sets a string or {@link ColorMap} array, specifying how to map values to colors. Setting this property sets
colorPalette to undefined. If this property is a string, it specifies a list of CSS colors separated by hyphens (-),
and the colors are evenly spaced over the range of values. For example, "red-white-hsl(240,50%,50%)".
@param {String} [options.colorPalette] Gets or sets the [ColorBrewer](http://colorbrewer2.org/) palette to use when mapping values to colors. Setting this
property sets colorMap to undefined. This property is ignored if colorMap is defined.
@param {Integer} [options.legendTicks] How many horizontal ticks to draw on the generated color ramp legend, not counting the top or bottom.
@param {String} [options.name] Display name for this column.
@param {String} [options.legendName] Display name for this column to use for the legend (defaults to the column name).
@param {String|Number} [options.type] The variable type of this column. Should be one of the keys of VarType (case-insensitive), eg. 'ENUM', 'SCALAR', 'TIME'.
@param {String} [options.units] Display units for this column. Currently only displayed in charts.
@param {Boolean} [options.active] Is this column active? | [
"A",
"set",
"of",
"properties",
"that",
"define",
"how",
"a",
"table",
"column",
"should",
"be",
"displayed",
".",
"If",
"not",
"set",
"explicitly",
"many",
"of",
"these",
"properties",
"will",
"be",
"given",
"default",
"or",
"guessed",
"values",
"elsewhere",
"such",
"as",
"in",
"CsvCatalogItem",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/TableColumnStyle.js#L52-L234 |
|
7,039 | TerriaJS/terriajs | lib/Map/AbsConcept.js | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Concept.call(this, options.name || options.id);
/**
* Gets or sets the name of the concept item. This property is observable.
* @type {String}
*/
this.id = options.id;
/**
* Gets the list of absCodes contained in this group. This property is observable.
* @type {AbsConcept[]}
*/
this.items = [];
/**
* Gets or sets a value indicating whether this concept item is currently open. When an
* item is open, its child items (if any) are visible. This property is observable.
* @type {Boolean}
*/
this.isOpen = true;
/**
* Flag to say if this if this node is selectable. This property is observable.
* @type {Boolean}
*/
this.isSelectable = false;
/**
* Flag to say if this if this concept only allows more than one active child. (Defaults to false.)
* @type {Boolean}
*/
this.allowMultiple = defaultValue(options.allowMultiple, false);
if (defined(options.codes)) {
var anyActive = buildConceptTree(this, options.filter, this, options.codes);
// If no codes were made active via the 'filter' parameter, activate the first one.
if (!anyActive && this.items.length > 0) {
this.items[0].isActive = true;
}
}
knockout.track(this, ["items", "isOpen"]); // name, isSelectable already tracked by Concept
// Returns a flat array of all the active AbsCodes under this concept (walking the tree).
// For this calculation, a concept may be active independently of its children.
knockout.defineProperty(this, "activeItems", {
get: function() {
return getActiveChildren(this);
}
});
knockout.getObservable(this, "activeItems").subscribe(function(activeItems) {
options.activeItemsChangedCallback(this, activeItems);
}, this);
} | javascript | function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Concept.call(this, options.name || options.id);
/**
* Gets or sets the name of the concept item. This property is observable.
* @type {String}
*/
this.id = options.id;
/**
* Gets the list of absCodes contained in this group. This property is observable.
* @type {AbsConcept[]}
*/
this.items = [];
/**
* Gets or sets a value indicating whether this concept item is currently open. When an
* item is open, its child items (if any) are visible. This property is observable.
* @type {Boolean}
*/
this.isOpen = true;
/**
* Flag to say if this if this node is selectable. This property is observable.
* @type {Boolean}
*/
this.isSelectable = false;
/**
* Flag to say if this if this concept only allows more than one active child. (Defaults to false.)
* @type {Boolean}
*/
this.allowMultiple = defaultValue(options.allowMultiple, false);
if (defined(options.codes)) {
var anyActive = buildConceptTree(this, options.filter, this, options.codes);
// If no codes were made active via the 'filter' parameter, activate the first one.
if (!anyActive && this.items.length > 0) {
this.items[0].isActive = true;
}
}
knockout.track(this, ["items", "isOpen"]); // name, isSelectable already tracked by Concept
// Returns a flat array of all the active AbsCodes under this concept (walking the tree).
// For this calculation, a concept may be active independently of its children.
knockout.defineProperty(this, "activeItems", {
get: function() {
return getActiveChildren(this);
}
});
knockout.getObservable(this, "activeItems").subscribe(function(activeItems) {
options.activeItemsChangedCallback(this, activeItems);
}, this);
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"Concept",
".",
"call",
"(",
"this",
",",
"options",
".",
"name",
"||",
"options",
".",
"id",
")",
";",
"/**\n * Gets or sets the name of the concept item. This property is observable.\n * @type {String}\n */",
"this",
".",
"id",
"=",
"options",
".",
"id",
";",
"/**\n * Gets the list of absCodes contained in this group. This property is observable.\n * @type {AbsConcept[]}\n */",
"this",
".",
"items",
"=",
"[",
"]",
";",
"/**\n * Gets or sets a value indicating whether this concept item is currently open. When an\n * item is open, its child items (if any) are visible. This property is observable.\n * @type {Boolean}\n */",
"this",
".",
"isOpen",
"=",
"true",
";",
"/**\n * Flag to say if this if this node is selectable. This property is observable.\n * @type {Boolean}\n */",
"this",
".",
"isSelectable",
"=",
"false",
";",
"/**\n * Flag to say if this if this concept only allows more than one active child. (Defaults to false.)\n * @type {Boolean}\n */",
"this",
".",
"allowMultiple",
"=",
"defaultValue",
"(",
"options",
".",
"allowMultiple",
",",
"false",
")",
";",
"if",
"(",
"defined",
"(",
"options",
".",
"codes",
")",
")",
"{",
"var",
"anyActive",
"=",
"buildConceptTree",
"(",
"this",
",",
"options",
".",
"filter",
",",
"this",
",",
"options",
".",
"codes",
")",
";",
"// If no codes were made active via the 'filter' parameter, activate the first one.",
"if",
"(",
"!",
"anyActive",
"&&",
"this",
".",
"items",
".",
"length",
">",
"0",
")",
"{",
"this",
".",
"items",
"[",
"0",
"]",
".",
"isActive",
"=",
"true",
";",
"}",
"}",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"items\"",
",",
"\"isOpen\"",
"]",
")",
";",
"// name, isSelectable already tracked by Concept",
"// Returns a flat array of all the active AbsCodes under this concept (walking the tree).",
"// For this calculation, a concept may be active independently of its children.",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"activeItems\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"getActiveChildren",
"(",
"this",
")",
";",
"}",
"}",
")",
";",
"knockout",
".",
"getObservable",
"(",
"this",
",",
"\"activeItems\"",
")",
".",
"subscribe",
"(",
"function",
"(",
"activeItems",
")",
"{",
"options",
".",
"activeItemsChangedCallback",
"(",
"this",
",",
"activeItems",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Represents an ABS concept associated with a AbsDataset.
An AbsConcept contains an array one of more AbsCodes.
@alias AbsConcept
@constructor
@extends Concept
@param {Object} [options] Object with the following properties:
@param {String} [options.name] The concept's human-readable name, eg. "Region Type".
@param {String[]} [options.id] The concept's id (the name given to it by the ABS), eg. "REGIONTYPE".
@param {Object[]} [options.codes] ABS code objects describing a tree of codes under this concept,
eg. [{code: '01_02', description: 'Negative/Nil Income', parentCode: 'TOT', parentDescription: 'Total'}, ...].
@param {String[]} [options.filter] The initial concepts and codes to activate.
@param {Boolean} [options.allowMultiple] Does this concept only allow multiple active children (eg. all except Region type)?
@param {Function} [options.activeItemsChangedCallback] A function called when activeItems changes. | [
"Represents",
"an",
"ABS",
"concept",
"associated",
"with",
"a",
"AbsDataset",
".",
"An",
"AbsConcept",
"contains",
"an",
"array",
"one",
"of",
"more",
"AbsCodes",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/AbsConcept.js#L31-L88 |
|
7,040 | TerriaJS/terriajs | lib/Map/AbsConcept.js | buildConceptTree | function buildConceptTree(parent, filter, concept, codes) {
// Use natural sort for fields with included ages or incomes.
codes.sort(function(a, b) {
return naturalSort(
a.description.replace(",", ""),
b.description.replace(",", "")
);
});
var anyActive = false;
for (var i = 0; i < codes.length; ++i) {
var parentCode = parent instanceof AbsCode ? parent.code : "";
if (codes[i].parentCode === parentCode) {
var absCode = new AbsCode(codes[i].code, codes[i].description, concept);
var codeFilter = concept.id + "." + absCode.code;
if (defined(filter) && filter.indexOf(codeFilter) !== -1) {
absCode.isActive = true;
anyActive = true;
}
if (parentCode === "" && codes.length < 50) {
absCode.isOpen = true;
}
absCode.parent = parent;
parent.items.push(absCode);
var anyChildrenActive = buildConceptTree(absCode, filter, concept, codes);
anyActive = anyChildrenActive || anyActive;
}
}
return anyActive;
} | javascript | function buildConceptTree(parent, filter, concept, codes) {
// Use natural sort for fields with included ages or incomes.
codes.sort(function(a, b) {
return naturalSort(
a.description.replace(",", ""),
b.description.replace(",", "")
);
});
var anyActive = false;
for (var i = 0; i < codes.length; ++i) {
var parentCode = parent instanceof AbsCode ? parent.code : "";
if (codes[i].parentCode === parentCode) {
var absCode = new AbsCode(codes[i].code, codes[i].description, concept);
var codeFilter = concept.id + "." + absCode.code;
if (defined(filter) && filter.indexOf(codeFilter) !== -1) {
absCode.isActive = true;
anyActive = true;
}
if (parentCode === "" && codes.length < 50) {
absCode.isOpen = true;
}
absCode.parent = parent;
parent.items.push(absCode);
var anyChildrenActive = buildConceptTree(absCode, filter, concept, codes);
anyActive = anyChildrenActive || anyActive;
}
}
return anyActive;
} | [
"function",
"buildConceptTree",
"(",
"parent",
",",
"filter",
",",
"concept",
",",
"codes",
")",
"{",
"// Use natural sort for fields with included ages or incomes.",
"codes",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"naturalSort",
"(",
"a",
".",
"description",
".",
"replace",
"(",
"\",\"",
",",
"\"\"",
")",
",",
"b",
".",
"description",
".",
"replace",
"(",
"\",\"",
",",
"\"\"",
")",
")",
";",
"}",
")",
";",
"var",
"anyActive",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"codes",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"parentCode",
"=",
"parent",
"instanceof",
"AbsCode",
"?",
"parent",
".",
"code",
":",
"\"\"",
";",
"if",
"(",
"codes",
"[",
"i",
"]",
".",
"parentCode",
"===",
"parentCode",
")",
"{",
"var",
"absCode",
"=",
"new",
"AbsCode",
"(",
"codes",
"[",
"i",
"]",
".",
"code",
",",
"codes",
"[",
"i",
"]",
".",
"description",
",",
"concept",
")",
";",
"var",
"codeFilter",
"=",
"concept",
".",
"id",
"+",
"\".\"",
"+",
"absCode",
".",
"code",
";",
"if",
"(",
"defined",
"(",
"filter",
")",
"&&",
"filter",
".",
"indexOf",
"(",
"codeFilter",
")",
"!==",
"-",
"1",
")",
"{",
"absCode",
".",
"isActive",
"=",
"true",
";",
"anyActive",
"=",
"true",
";",
"}",
"if",
"(",
"parentCode",
"===",
"\"\"",
"&&",
"codes",
".",
"length",
"<",
"50",
")",
"{",
"absCode",
".",
"isOpen",
"=",
"true",
";",
"}",
"absCode",
".",
"parent",
"=",
"parent",
";",
"parent",
".",
"items",
".",
"push",
"(",
"absCode",
")",
";",
"var",
"anyChildrenActive",
"=",
"buildConceptTree",
"(",
"absCode",
",",
"filter",
",",
"concept",
",",
"codes",
")",
";",
"anyActive",
"=",
"anyChildrenActive",
"||",
"anyActive",
";",
"}",
"}",
"return",
"anyActive",
";",
"}"
] | Recursively builds out the AbsCodes underneath this AbsConcept. Returns true if any codes were made active, false if none. | [
"Recursively",
"builds",
"out",
"the",
"AbsCodes",
"underneath",
"this",
"AbsConcept",
".",
"Returns",
"true",
"if",
"any",
"codes",
"were",
"made",
"active",
"false",
"if",
"none",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/AbsConcept.js#L139-L167 |
7,041 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | loadConceptIdsAndConceptNameMap | function loadConceptIdsAndConceptNameMap(item) {
if (!defined(item._loadConceptIdsAndNameMapPromise)) {
var parameters = {
method: "GetDatasetConcepts",
datasetid: item.datasetId,
format: "json"
};
var datasetConceptsUrl = item._baseUrl + "?" + objectToQuery(parameters);
var loadDatasetConceptsPromise = loadJson(datasetConceptsUrl)
.then(function(json) {
item._conceptIds = json.concepts;
if (
json.concepts.indexOf(item.regionConcept) === -1 ||
json.concepts.indexOf("REGIONTYPE") === -1
) {
throw new DeveloperError(
"datasetId " +
item.datasetId +
" concepts [" +
json.concepts.join(", ") +
'] do not include "' +
item.regionConcept +
'" and "REGIONTYPE".'
);
}
})
.otherwise(throwLoadError.bind(null, item, "GetDatasetConcepts"));
var loadConceptNamesPromise = loadJson(item.conceptNamesUrl).then(function(
json
) {
item._conceptNamesMap = json;
});
item._loadConceptIdsAndNameMapPromise = when.all([
loadConceptNamesPromise,
loadDatasetConceptsPromise
]);
// item.concepts and item.conceptNameMap are now defined with the results.
}
return item._loadConceptIdsAndNameMapPromise;
} | javascript | function loadConceptIdsAndConceptNameMap(item) {
if (!defined(item._loadConceptIdsAndNameMapPromise)) {
var parameters = {
method: "GetDatasetConcepts",
datasetid: item.datasetId,
format: "json"
};
var datasetConceptsUrl = item._baseUrl + "?" + objectToQuery(parameters);
var loadDatasetConceptsPromise = loadJson(datasetConceptsUrl)
.then(function(json) {
item._conceptIds = json.concepts;
if (
json.concepts.indexOf(item.regionConcept) === -1 ||
json.concepts.indexOf("REGIONTYPE") === -1
) {
throw new DeveloperError(
"datasetId " +
item.datasetId +
" concepts [" +
json.concepts.join(", ") +
'] do not include "' +
item.regionConcept +
'" and "REGIONTYPE".'
);
}
})
.otherwise(throwLoadError.bind(null, item, "GetDatasetConcepts"));
var loadConceptNamesPromise = loadJson(item.conceptNamesUrl).then(function(
json
) {
item._conceptNamesMap = json;
});
item._loadConceptIdsAndNameMapPromise = when.all([
loadConceptNamesPromise,
loadDatasetConceptsPromise
]);
// item.concepts and item.conceptNameMap are now defined with the results.
}
return item._loadConceptIdsAndNameMapPromise;
} | [
"function",
"loadConceptIdsAndConceptNameMap",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"item",
".",
"_loadConceptIdsAndNameMapPromise",
")",
")",
"{",
"var",
"parameters",
"=",
"{",
"method",
":",
"\"GetDatasetConcepts\"",
",",
"datasetid",
":",
"item",
".",
"datasetId",
",",
"format",
":",
"\"json\"",
"}",
";",
"var",
"datasetConceptsUrl",
"=",
"item",
".",
"_baseUrl",
"+",
"\"?\"",
"+",
"objectToQuery",
"(",
"parameters",
")",
";",
"var",
"loadDatasetConceptsPromise",
"=",
"loadJson",
"(",
"datasetConceptsUrl",
")",
".",
"then",
"(",
"function",
"(",
"json",
")",
"{",
"item",
".",
"_conceptIds",
"=",
"json",
".",
"concepts",
";",
"if",
"(",
"json",
".",
"concepts",
".",
"indexOf",
"(",
"item",
".",
"regionConcept",
")",
"===",
"-",
"1",
"||",
"json",
".",
"concepts",
".",
"indexOf",
"(",
"\"REGIONTYPE\"",
")",
"===",
"-",
"1",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"datasetId \"",
"+",
"item",
".",
"datasetId",
"+",
"\" concepts [\"",
"+",
"json",
".",
"concepts",
".",
"join",
"(",
"\", \"",
")",
"+",
"'] do not include \"'",
"+",
"item",
".",
"regionConcept",
"+",
"'\" and \"REGIONTYPE\".'",
")",
";",
"}",
"}",
")",
".",
"otherwise",
"(",
"throwLoadError",
".",
"bind",
"(",
"null",
",",
"item",
",",
"\"GetDatasetConcepts\"",
")",
")",
";",
"var",
"loadConceptNamesPromise",
"=",
"loadJson",
"(",
"item",
".",
"conceptNamesUrl",
")",
".",
"then",
"(",
"function",
"(",
"json",
")",
"{",
"item",
".",
"_conceptNamesMap",
"=",
"json",
";",
"}",
")",
";",
"item",
".",
"_loadConceptIdsAndNameMapPromise",
"=",
"when",
".",
"all",
"(",
"[",
"loadConceptNamesPromise",
",",
"loadDatasetConceptsPromise",
"]",
")",
";",
"// item.concepts and item.conceptNameMap are now defined with the results.",
"}",
"return",
"item",
".",
"_loadConceptIdsAndNameMapPromise",
";",
"}"
] | Returns a promise which, when resolved, indicates that item._conceptIds and item._conceptNamesMap are loaded.
@private
@param {AbsIttCatalogItem} item This catalog item.
@return {Promise} Promise which, when resolved, indicates that item._conceptIds and item._conceptNamesMap are loaded. | [
"Returns",
"a",
"promise",
"which",
"when",
"resolved",
"indicates",
"that",
"item",
".",
"_conceptIds",
"and",
"item",
".",
"_conceptNamesMap",
"are",
"loaded",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L445-L485 |
7,042 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | loadConcepts | function loadConcepts(item) {
if (!defined(item._loadConceptsPromise)) {
var absConcepts = [];
var promises = item._conceptIds
.filter(function(conceptId) {
return item.conceptsNotToLoad.indexOf(conceptId) === -1;
})
.map(function(conceptId) {
var parameters = {
method: "GetCodeListValue",
datasetid: item.datasetId,
concept: conceptId,
format: "json"
};
var conceptCodesUrl = item._baseUrl + "?" + objectToQuery(parameters);
return loadJson(conceptCodesUrl)
.then(function(json) {
// If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA).
// Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv
var codes = json.codes;
if (conceptId === item.regionTypeConcept) {
codes = codes.filter(function(absCode) {
return allowedRegionCodes.indexOf(absCode.code) >= 0;
});
}
// We have loaded the file, process it into an AbsConcept.
var concept = new AbsConcept({
id: conceptId,
codes: codes,
filter: item.filter,
allowMultiple: !(
conceptId === item.regionTypeConcept ||
item.uniqueValuedConcepts.indexOf(conceptId) >= 0
),
activeItemsChangedCallback: function() {
// Close any picked features, as the description of any associated with this catalog item may change.
item.terria.pickedFeatures = undefined;
rebuildData(item);
}
});
// Give the concept its human-readable name.
concept.name = getHumanReadableConceptName(
item._conceptNamesMap,
concept
);
absConcepts.push(concept);
})
.otherwise(throwLoadError.bind(null, item, "GetCodeListValue"));
});
item._loadConceptsPromise = when.all(promises).then(function() {
// All the AbsConcept objects have been created, we just need to order them correctly and save them.
// Put the region type concept first.
var makeFirst = item.regionTypeConcept;
absConcepts.sort(function(a, b) {
return a.id === makeFirst
? -1
: b.id === makeFirst
? 1
: a.name > b.name
? 1
: -1;
});
item._concepts = absConcepts;
});
}
return item._loadConceptsPromise;
} | javascript | function loadConcepts(item) {
if (!defined(item._loadConceptsPromise)) {
var absConcepts = [];
var promises = item._conceptIds
.filter(function(conceptId) {
return item.conceptsNotToLoad.indexOf(conceptId) === -1;
})
.map(function(conceptId) {
var parameters = {
method: "GetCodeListValue",
datasetid: item.datasetId,
concept: conceptId,
format: "json"
};
var conceptCodesUrl = item._baseUrl + "?" + objectToQuery(parameters);
return loadJson(conceptCodesUrl)
.then(function(json) {
// If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA).
// Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv
var codes = json.codes;
if (conceptId === item.regionTypeConcept) {
codes = codes.filter(function(absCode) {
return allowedRegionCodes.indexOf(absCode.code) >= 0;
});
}
// We have loaded the file, process it into an AbsConcept.
var concept = new AbsConcept({
id: conceptId,
codes: codes,
filter: item.filter,
allowMultiple: !(
conceptId === item.regionTypeConcept ||
item.uniqueValuedConcepts.indexOf(conceptId) >= 0
),
activeItemsChangedCallback: function() {
// Close any picked features, as the description of any associated with this catalog item may change.
item.terria.pickedFeatures = undefined;
rebuildData(item);
}
});
// Give the concept its human-readable name.
concept.name = getHumanReadableConceptName(
item._conceptNamesMap,
concept
);
absConcepts.push(concept);
})
.otherwise(throwLoadError.bind(null, item, "GetCodeListValue"));
});
item._loadConceptsPromise = when.all(promises).then(function() {
// All the AbsConcept objects have been created, we just need to order them correctly and save them.
// Put the region type concept first.
var makeFirst = item.regionTypeConcept;
absConcepts.sort(function(a, b) {
return a.id === makeFirst
? -1
: b.id === makeFirst
? 1
: a.name > b.name
? 1
: -1;
});
item._concepts = absConcepts;
});
}
return item._loadConceptsPromise;
} | [
"function",
"loadConcepts",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"item",
".",
"_loadConceptsPromise",
")",
")",
"{",
"var",
"absConcepts",
"=",
"[",
"]",
";",
"var",
"promises",
"=",
"item",
".",
"_conceptIds",
".",
"filter",
"(",
"function",
"(",
"conceptId",
")",
"{",
"return",
"item",
".",
"conceptsNotToLoad",
".",
"indexOf",
"(",
"conceptId",
")",
"===",
"-",
"1",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"conceptId",
")",
"{",
"var",
"parameters",
"=",
"{",
"method",
":",
"\"GetCodeListValue\"",
",",
"datasetid",
":",
"item",
".",
"datasetId",
",",
"concept",
":",
"conceptId",
",",
"format",
":",
"\"json\"",
"}",
";",
"var",
"conceptCodesUrl",
"=",
"item",
".",
"_baseUrl",
"+",
"\"?\"",
"+",
"objectToQuery",
"(",
"parameters",
")",
";",
"return",
"loadJson",
"(",
"conceptCodesUrl",
")",
".",
"then",
"(",
"function",
"(",
"json",
")",
"{",
"// If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA).",
"// Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv",
"var",
"codes",
"=",
"json",
".",
"codes",
";",
"if",
"(",
"conceptId",
"===",
"item",
".",
"regionTypeConcept",
")",
"{",
"codes",
"=",
"codes",
".",
"filter",
"(",
"function",
"(",
"absCode",
")",
"{",
"return",
"allowedRegionCodes",
".",
"indexOf",
"(",
"absCode",
".",
"code",
")",
">=",
"0",
";",
"}",
")",
";",
"}",
"// We have loaded the file, process it into an AbsConcept.",
"var",
"concept",
"=",
"new",
"AbsConcept",
"(",
"{",
"id",
":",
"conceptId",
",",
"codes",
":",
"codes",
",",
"filter",
":",
"item",
".",
"filter",
",",
"allowMultiple",
":",
"!",
"(",
"conceptId",
"===",
"item",
".",
"regionTypeConcept",
"||",
"item",
".",
"uniqueValuedConcepts",
".",
"indexOf",
"(",
"conceptId",
")",
">=",
"0",
")",
",",
"activeItemsChangedCallback",
":",
"function",
"(",
")",
"{",
"// Close any picked features, as the description of any associated with this catalog item may change.",
"item",
".",
"terria",
".",
"pickedFeatures",
"=",
"undefined",
";",
"rebuildData",
"(",
"item",
")",
";",
"}",
"}",
")",
";",
"// Give the concept its human-readable name.",
"concept",
".",
"name",
"=",
"getHumanReadableConceptName",
"(",
"item",
".",
"_conceptNamesMap",
",",
"concept",
")",
";",
"absConcepts",
".",
"push",
"(",
"concept",
")",
";",
"}",
")",
".",
"otherwise",
"(",
"throwLoadError",
".",
"bind",
"(",
"null",
",",
"item",
",",
"\"GetCodeListValue\"",
")",
")",
";",
"}",
")",
";",
"item",
".",
"_loadConceptsPromise",
"=",
"when",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"// All the AbsConcept objects have been created, we just need to order them correctly and save them.",
"// Put the region type concept first.",
"var",
"makeFirst",
"=",
"item",
".",
"regionTypeConcept",
";",
"absConcepts",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"id",
"===",
"makeFirst",
"?",
"-",
"1",
":",
"b",
".",
"id",
"===",
"makeFirst",
"?",
"1",
":",
"a",
".",
"name",
">",
"b",
".",
"name",
"?",
"1",
":",
"-",
"1",
";",
"}",
")",
";",
"item",
".",
"_concepts",
"=",
"absConcepts",
";",
"}",
")",
";",
"}",
"return",
"item",
".",
"_loadConceptsPromise",
";",
"}"
] | Loads concept codes.
As they are loaded, each is processed into a tree of AbsCodes under an AbsConcept.
Returns a promise which, when resolved, indicates that item._concepts is complete.
The promise is cached, since the promise won't ever change for a given datasetId.
@private
@param {AbsIttCatalogItem} item This catalog item.
@return {Promise} Promise. | [
"Loads",
"concept",
"codes",
".",
"As",
"they",
"are",
"loaded",
"each",
"is",
"processed",
"into",
"a",
"tree",
"of",
"AbsCodes",
"under",
"an",
"AbsConcept",
".",
"Returns",
"a",
"promise",
"which",
"when",
"resolved",
"indicates",
"that",
"item",
".",
"_concepts",
"is",
"complete",
".",
"The",
"promise",
"is",
"cached",
"since",
"the",
"promise",
"won",
"t",
"ever",
"change",
"for",
"a",
"given",
"datasetId",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L536-L604 |
7,043 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | getHumanReadableConceptName | function getHumanReadableConceptName(conceptNameMap, concept) {
if (!defined(conceptNameMap[concept.name])) {
return concept.name; // Default to the name given in the file.
}
if (typeof conceptNameMap[concept.name] === "string") {
return conceptNameMap[concept.name];
} else {
var codeMap = conceptNameMap[concept.name];
for (var j = 0; j < concept.items.length; j++) {
if (defined(codeMap[concept.items[j].name])) {
return codeMap[concept.items[j].name];
}
}
// Use the wildcard, if defined, or else fall back to the name in the file.
return codeMap["*"] || concept.name;
}
} | javascript | function getHumanReadableConceptName(conceptNameMap, concept) {
if (!defined(conceptNameMap[concept.name])) {
return concept.name; // Default to the name given in the file.
}
if (typeof conceptNameMap[concept.name] === "string") {
return conceptNameMap[concept.name];
} else {
var codeMap = conceptNameMap[concept.name];
for (var j = 0; j < concept.items.length; j++) {
if (defined(codeMap[concept.items[j].name])) {
return codeMap[concept.items[j].name];
}
}
// Use the wildcard, if defined, or else fall back to the name in the file.
return codeMap["*"] || concept.name;
}
} | [
"function",
"getHumanReadableConceptName",
"(",
"conceptNameMap",
",",
"concept",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"conceptNameMap",
"[",
"concept",
".",
"name",
"]",
")",
")",
"{",
"return",
"concept",
".",
"name",
";",
"// Default to the name given in the file.",
"}",
"if",
"(",
"typeof",
"conceptNameMap",
"[",
"concept",
".",
"name",
"]",
"===",
"\"string\"",
")",
"{",
"return",
"conceptNameMap",
"[",
"concept",
".",
"name",
"]",
";",
"}",
"else",
"{",
"var",
"codeMap",
"=",
"conceptNameMap",
"[",
"concept",
".",
"name",
"]",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"concept",
".",
"items",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"defined",
"(",
"codeMap",
"[",
"concept",
".",
"items",
"[",
"j",
"]",
".",
"name",
"]",
")",
")",
"{",
"return",
"codeMap",
"[",
"concept",
".",
"items",
"[",
"j",
"]",
".",
"name",
"]",
";",
"}",
"}",
"// Use the wildcard, if defined, or else fall back to the name in the file.",
"return",
"codeMap",
"[",
"\"*\"",
"]",
"||",
"concept",
".",
"name",
";",
"}",
"}"
] | Given a concept object with name and possibly items properties, return its human-readable version.
@private
@param {Object} conceptNameMap An object whose keys are the concept.names, eg. "ANCP".
Values may be Strings (eg. "Ancestry"), or
a 'code map' (eg. "MEASURE" : {"Persons": "Sex", "85 years and over": "Age", "*": "Measure"}.
@param {AbsConcept} concept An object with a name property and, if a codemap is to be used, an items array of objects with a name property.
In that case, it finds the first of those names to appear as a key in the code map. The value of this property is returned. (Phew!)
@return {String} Human-readable concept name. | [
"Given",
"a",
"concept",
"object",
"with",
"name",
"and",
"possibly",
"items",
"properties",
"return",
"its",
"human",
"-",
"readable",
"version",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L616-L632 |
7,044 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | getActiveRegionTypeCode | function getActiveRegionTypeCode(item) {
// We always put the region first, and at most one is active.
var activeRegions = item._concepts[0].activeItems;
if (activeRegions.length === 1) {
return activeRegions[0].code;
}
} | javascript | function getActiveRegionTypeCode(item) {
// We always put the region first, and at most one is active.
var activeRegions = item._concepts[0].activeItems;
if (activeRegions.length === 1) {
return activeRegions[0].code;
}
} | [
"function",
"getActiveRegionTypeCode",
"(",
"item",
")",
"{",
"// We always put the region first, and at most one is active.",
"var",
"activeRegions",
"=",
"item",
".",
"_concepts",
"[",
"0",
"]",
".",
"activeItems",
";",
"if",
"(",
"activeRegions",
".",
"length",
"===",
"1",
")",
"{",
"return",
"activeRegions",
"[",
"0",
"]",
".",
"code",
";",
"}",
"}"
] | Returns the active regiontype code, eg. SA4, or undefined if none _or more than one_ active. | [
"Returns",
"the",
"active",
"regiontype",
"code",
"eg",
".",
"SA4",
"or",
"undefined",
"if",
"none",
"_or",
"more",
"than",
"one_",
"active",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L635-L641 |
7,045 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | loadDataFiles | function loadDataFiles(item) {
// An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex].
var activeCodesPerConcept = item._concepts.map(function(concept) {
return concept.activeItems;
});
// If any one of the concepts has no active selection, there will be no files to load.
for (var i = activeCodesPerConcept.length - 1; i >= 0; i--) {
if (activeCodesPerConcept[i].length === 0) {
return when();
}
}
// If there is no valid region selected (including when there are two!), stop.
if (!defined(getActiveRegionTypeCode(item))) {
return when();
}
// Find every possible combination, taking a single code from each concept.
var activeCombinations = arrayProduct(activeCodesPerConcept);
// Construct the 'and' part of the requests by combining concept.id and the AbsCode.name,
// eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3
var andParameters = activeCombinations.map(function(codes) {
return codes
.map(function(code, index) {
return code.concept.id + "." + code.code;
})
.join(",");
});
var loadDataPromises = andParameters.map(function(andParameter) {
// Build a promise which resolves once this datafile has loaded (unless we have cached this promise already).
// Note in the original there was different cacheing stuff... but not sure if it was being used?
if (!defined(item._loadDataFilePromise[andParameter])) {
var parameters = {
method: "GetGenericData",
datasetid: item.datasetId,
and: andParameter,
or: item.regionConcept,
format: "csv"
};
var url = item._baseUrl + "?" + objectToQuery(parameters);
item._loadDataFilePromise[andParameter] = loadText(url).then(
loadTableStructure.bind(undefined, item)
);
}
return item._loadDataFilePromise[andParameter];
});
var totalPopulationsUrl =
item.regionPopulationsUrlPrefix + getActiveRegionTypeCode(item) + ".csv";
loadDataPromises.push(
loadText(totalPopulationsUrl).then(loadTableStructure.bind(undefined, item))
);
return when.all(loadDataPromises).then(function(tableStructures) {
return {
tableStructures: tableStructures,
activeCombinations: activeCombinations
};
});
} | javascript | function loadDataFiles(item) {
// An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex].
var activeCodesPerConcept = item._concepts.map(function(concept) {
return concept.activeItems;
});
// If any one of the concepts has no active selection, there will be no files to load.
for (var i = activeCodesPerConcept.length - 1; i >= 0; i--) {
if (activeCodesPerConcept[i].length === 0) {
return when();
}
}
// If there is no valid region selected (including when there are two!), stop.
if (!defined(getActiveRegionTypeCode(item))) {
return when();
}
// Find every possible combination, taking a single code from each concept.
var activeCombinations = arrayProduct(activeCodesPerConcept);
// Construct the 'and' part of the requests by combining concept.id and the AbsCode.name,
// eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3
var andParameters = activeCombinations.map(function(codes) {
return codes
.map(function(code, index) {
return code.concept.id + "." + code.code;
})
.join(",");
});
var loadDataPromises = andParameters.map(function(andParameter) {
// Build a promise which resolves once this datafile has loaded (unless we have cached this promise already).
// Note in the original there was different cacheing stuff... but not sure if it was being used?
if (!defined(item._loadDataFilePromise[andParameter])) {
var parameters = {
method: "GetGenericData",
datasetid: item.datasetId,
and: andParameter,
or: item.regionConcept,
format: "csv"
};
var url = item._baseUrl + "?" + objectToQuery(parameters);
item._loadDataFilePromise[andParameter] = loadText(url).then(
loadTableStructure.bind(undefined, item)
);
}
return item._loadDataFilePromise[andParameter];
});
var totalPopulationsUrl =
item.regionPopulationsUrlPrefix + getActiveRegionTypeCode(item) + ".csv";
loadDataPromises.push(
loadText(totalPopulationsUrl).then(loadTableStructure.bind(undefined, item))
);
return when.all(loadDataPromises).then(function(tableStructures) {
return {
tableStructures: tableStructures,
activeCombinations: activeCombinations
};
});
} | [
"function",
"loadDataFiles",
"(",
"item",
")",
"{",
"// An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex].",
"var",
"activeCodesPerConcept",
"=",
"item",
".",
"_concepts",
".",
"map",
"(",
"function",
"(",
"concept",
")",
"{",
"return",
"concept",
".",
"activeItems",
";",
"}",
")",
";",
"// If any one of the concepts has no active selection, there will be no files to load.",
"for",
"(",
"var",
"i",
"=",
"activeCodesPerConcept",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"activeCodesPerConcept",
"[",
"i",
"]",
".",
"length",
"===",
"0",
")",
"{",
"return",
"when",
"(",
")",
";",
"}",
"}",
"// If there is no valid region selected (including when there are two!), stop.",
"if",
"(",
"!",
"defined",
"(",
"getActiveRegionTypeCode",
"(",
"item",
")",
")",
")",
"{",
"return",
"when",
"(",
")",
";",
"}",
"// Find every possible combination, taking a single code from each concept.",
"var",
"activeCombinations",
"=",
"arrayProduct",
"(",
"activeCodesPerConcept",
")",
";",
"// Construct the 'and' part of the requests by combining concept.id and the AbsCode.name,",
"// eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3",
"var",
"andParameters",
"=",
"activeCombinations",
".",
"map",
"(",
"function",
"(",
"codes",
")",
"{",
"return",
"codes",
".",
"map",
"(",
"function",
"(",
"code",
",",
"index",
")",
"{",
"return",
"code",
".",
"concept",
".",
"id",
"+",
"\".\"",
"+",
"code",
".",
"code",
";",
"}",
")",
".",
"join",
"(",
"\",\"",
")",
";",
"}",
")",
";",
"var",
"loadDataPromises",
"=",
"andParameters",
".",
"map",
"(",
"function",
"(",
"andParameter",
")",
"{",
"// Build a promise which resolves once this datafile has loaded (unless we have cached this promise already).",
"// Note in the original there was different cacheing stuff... but not sure if it was being used?",
"if",
"(",
"!",
"defined",
"(",
"item",
".",
"_loadDataFilePromise",
"[",
"andParameter",
"]",
")",
")",
"{",
"var",
"parameters",
"=",
"{",
"method",
":",
"\"GetGenericData\"",
",",
"datasetid",
":",
"item",
".",
"datasetId",
",",
"and",
":",
"andParameter",
",",
"or",
":",
"item",
".",
"regionConcept",
",",
"format",
":",
"\"csv\"",
"}",
";",
"var",
"url",
"=",
"item",
".",
"_baseUrl",
"+",
"\"?\"",
"+",
"objectToQuery",
"(",
"parameters",
")",
";",
"item",
".",
"_loadDataFilePromise",
"[",
"andParameter",
"]",
"=",
"loadText",
"(",
"url",
")",
".",
"then",
"(",
"loadTableStructure",
".",
"bind",
"(",
"undefined",
",",
"item",
")",
")",
";",
"}",
"return",
"item",
".",
"_loadDataFilePromise",
"[",
"andParameter",
"]",
";",
"}",
")",
";",
"var",
"totalPopulationsUrl",
"=",
"item",
".",
"regionPopulationsUrlPrefix",
"+",
"getActiveRegionTypeCode",
"(",
"item",
")",
"+",
"\".csv\"",
";",
"loadDataPromises",
".",
"push",
"(",
"loadText",
"(",
"totalPopulationsUrl",
")",
".",
"then",
"(",
"loadTableStructure",
".",
"bind",
"(",
"undefined",
",",
"item",
")",
")",
")",
";",
"return",
"when",
".",
"all",
"(",
"loadDataPromises",
")",
".",
"then",
"(",
"function",
"(",
"tableStructures",
")",
"{",
"return",
"{",
"tableStructures",
":",
"tableStructures",
",",
"activeCombinations",
":",
"activeCombinations",
"}",
";",
"}",
")",
";",
"}"
] | Loads all the datafiles for this catalog item, given the active concepts.
@private
@param {AbsIttCatalogItem} item The AbsIttCatalogItem instance.
@return {Promise} A Promise which resolves to an object of TableStructures for each loaded dataset,
with the total populations as the final one; and the active combinations. | [
"Loads",
"all",
"the",
"datafiles",
"for",
"this",
"catalog",
"item",
"given",
"the",
"active",
"concepts",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L656-L718 |
7,046 | TerriaJS/terriajs | lib/Models/AbsIttCatalogItem.js | buildValueColumns | function buildValueColumns(item, tableStructures, activeCombinations) {
// The tableStructures are from the raw data files, one per activeCombinations.
return tableStructures.map(function(tableStructure, index) {
var columnNames = tableStructure.getColumnNames();
// Check that the data is not blank, and that the column names are ["Time", "Value", "REGION" (or equivalent), "Description"]
if (columnNames.length === 0) {
throwLoadError(item, "GetGenericData");
} else if (
!arraysAreEqual(columnNames, [
"Time",
"Value",
item.regionConcept,
"Description"
])
) {
throwDataColumnsError(item, columnNames);
}
var absCodes = activeCombinations[index];
// Pull out and clone the 'Value' column, and rename it to match all the codes except the region type, eg. Persons 0-4 years.
var valueColumn = tableStructure.columns[columnNames.indexOf("Value")];
var valueName = absCodes
.filter(function(absCode) {
return absCode.concept.id !== item.regionTypeConcept;
})
.map(function(absCode) {
return absCode.name.trim();
})
.reverse() // It would be nice to specify a preferred order of codes here; reverse because "Persons 0-4 years" sounds better than "0-4 years Persons".
.join(" ");
valueColumn = new TableColumn(
valueName,
valueColumn.values,
valueColumn.options
);
return valueColumn;
});
} | javascript | function buildValueColumns(item, tableStructures, activeCombinations) {
// The tableStructures are from the raw data files, one per activeCombinations.
return tableStructures.map(function(tableStructure, index) {
var columnNames = tableStructure.getColumnNames();
// Check that the data is not blank, and that the column names are ["Time", "Value", "REGION" (or equivalent), "Description"]
if (columnNames.length === 0) {
throwLoadError(item, "GetGenericData");
} else if (
!arraysAreEqual(columnNames, [
"Time",
"Value",
item.regionConcept,
"Description"
])
) {
throwDataColumnsError(item, columnNames);
}
var absCodes = activeCombinations[index];
// Pull out and clone the 'Value' column, and rename it to match all the codes except the region type, eg. Persons 0-4 years.
var valueColumn = tableStructure.columns[columnNames.indexOf("Value")];
var valueName = absCodes
.filter(function(absCode) {
return absCode.concept.id !== item.regionTypeConcept;
})
.map(function(absCode) {
return absCode.name.trim();
})
.reverse() // It would be nice to specify a preferred order of codes here; reverse because "Persons 0-4 years" sounds better than "0-4 years Persons".
.join(" ");
valueColumn = new TableColumn(
valueName,
valueColumn.values,
valueColumn.options
);
return valueColumn;
});
} | [
"function",
"buildValueColumns",
"(",
"item",
",",
"tableStructures",
",",
"activeCombinations",
")",
"{",
"// The tableStructures are from the raw data files, one per activeCombinations.",
"return",
"tableStructures",
".",
"map",
"(",
"function",
"(",
"tableStructure",
",",
"index",
")",
"{",
"var",
"columnNames",
"=",
"tableStructure",
".",
"getColumnNames",
"(",
")",
";",
"// Check that the data is not blank, and that the column names are [\"Time\", \"Value\", \"REGION\" (or equivalent), \"Description\"]",
"if",
"(",
"columnNames",
".",
"length",
"===",
"0",
")",
"{",
"throwLoadError",
"(",
"item",
",",
"\"GetGenericData\"",
")",
";",
"}",
"else",
"if",
"(",
"!",
"arraysAreEqual",
"(",
"columnNames",
",",
"[",
"\"Time\"",
",",
"\"Value\"",
",",
"item",
".",
"regionConcept",
",",
"\"Description\"",
"]",
")",
")",
"{",
"throwDataColumnsError",
"(",
"item",
",",
"columnNames",
")",
";",
"}",
"var",
"absCodes",
"=",
"activeCombinations",
"[",
"index",
"]",
";",
"// Pull out and clone the 'Value' column, and rename it to match all the codes except the region type, eg. Persons 0-4 years.",
"var",
"valueColumn",
"=",
"tableStructure",
".",
"columns",
"[",
"columnNames",
".",
"indexOf",
"(",
"\"Value\"",
")",
"]",
";",
"var",
"valueName",
"=",
"absCodes",
".",
"filter",
"(",
"function",
"(",
"absCode",
")",
"{",
"return",
"absCode",
".",
"concept",
".",
"id",
"!==",
"item",
".",
"regionTypeConcept",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"absCode",
")",
"{",
"return",
"absCode",
".",
"name",
".",
"trim",
"(",
")",
";",
"}",
")",
".",
"reverse",
"(",
")",
"// It would be nice to specify a preferred order of codes here; reverse because \"Persons 0-4 years\" sounds better than \"0-4 years Persons\".",
".",
"join",
"(",
"\" \"",
")",
";",
"valueColumn",
"=",
"new",
"TableColumn",
"(",
"valueName",
",",
"valueColumn",
".",
"values",
",",
"valueColumn",
".",
"options",
")",
";",
"return",
"valueColumn",
";",
"}",
")",
";",
"}"
] | Given the loaded data files in their TableStructures, create a suitably named array of columns, from their "Value" columns. | [
"Given",
"the",
"loaded",
"data",
"files",
"in",
"their",
"TableStructures",
"create",
"a",
"suitably",
"named",
"array",
"of",
"columns",
"from",
"their",
"Value",
"columns",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/AbsIttCatalogItem.js#L721-L757 |
7,047 | TerriaJS/terriajs | lib/Map/TableStructure.js | function(name, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
DisplayVariablesConcept.call(this, name, {
getColorCallback: options.getColorCallback,
requireSomeActive: defaultValue(options.requireSomeActive, false)
});
this.displayVariableTypes = defaultValue(
options.displayVariableTypes,
defaultDisplayVariableTypes
);
this.shaveSeconds = defaultValue(options.shaveSeconds, defaultShaveSeconds);
this.finalEndJulianDate = options.finalEndJulianDate;
this.unallowedTypes = options.unallowedTypes;
this.initialTimeSource = options.initialTimeSource;
this.displayDuration = options.displayDuration;
this.replaceWithNullValues = options.replaceWithNullValues;
this.replaceWithZeroValues = options.replaceWithZeroValues;
this.columnOptions = options.columnOptions;
this.sourceFeature = options.sourceFeature;
this.idColumnNames = options.idColumnNames; // Actually names, ids or indexes.
this.isSampled = options.isSampled;
/**
* Gets or sets the active time column name, id or index.
* If you pass an array of two such, eg. [0, 1], treats these as the start and end date column identifiers.
* @type {String|Number|String[]|Number[]|undefined}
*/
this._activeTimeColumnNameIdOrIndex = undefined;
// Track sourceFeature as it is shown on the NowViewing panel.
// Track items so that charts can update live. (Already done by DisplayVariableConcept.)
knockout.track(this, ["sourceFeature", "_activeTimeColumnNameIdOrIndex"]);
/**
* Gets the columnsByType for this structure,
* an object whose keys are VarTypes, and whose values are arrays of TableColumn with matching type.
* Only existing types are present (eg. columnsByType[VarType.ALT] may be undefined).
* @memberOf TableStructure.prototype
* @type {Object}
*/
knockout.defineProperty(this, "columnsByType", {
get: function() {
return getColumnsByType(this.items);
}
});
} | javascript | function(name, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
DisplayVariablesConcept.call(this, name, {
getColorCallback: options.getColorCallback,
requireSomeActive: defaultValue(options.requireSomeActive, false)
});
this.displayVariableTypes = defaultValue(
options.displayVariableTypes,
defaultDisplayVariableTypes
);
this.shaveSeconds = defaultValue(options.shaveSeconds, defaultShaveSeconds);
this.finalEndJulianDate = options.finalEndJulianDate;
this.unallowedTypes = options.unallowedTypes;
this.initialTimeSource = options.initialTimeSource;
this.displayDuration = options.displayDuration;
this.replaceWithNullValues = options.replaceWithNullValues;
this.replaceWithZeroValues = options.replaceWithZeroValues;
this.columnOptions = options.columnOptions;
this.sourceFeature = options.sourceFeature;
this.idColumnNames = options.idColumnNames; // Actually names, ids or indexes.
this.isSampled = options.isSampled;
/**
* Gets or sets the active time column name, id or index.
* If you pass an array of two such, eg. [0, 1], treats these as the start and end date column identifiers.
* @type {String|Number|String[]|Number[]|undefined}
*/
this._activeTimeColumnNameIdOrIndex = undefined;
// Track sourceFeature as it is shown on the NowViewing panel.
// Track items so that charts can update live. (Already done by DisplayVariableConcept.)
knockout.track(this, ["sourceFeature", "_activeTimeColumnNameIdOrIndex"]);
/**
* Gets the columnsByType for this structure,
* an object whose keys are VarTypes, and whose values are arrays of TableColumn with matching type.
* Only existing types are present (eg. columnsByType[VarType.ALT] may be undefined).
* @memberOf TableStructure.prototype
* @type {Object}
*/
knockout.defineProperty(this, "columnsByType", {
get: function() {
return getColumnsByType(this.items);
}
});
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"DisplayVariablesConcept",
".",
"call",
"(",
"this",
",",
"name",
",",
"{",
"getColorCallback",
":",
"options",
".",
"getColorCallback",
",",
"requireSomeActive",
":",
"defaultValue",
"(",
"options",
".",
"requireSomeActive",
",",
"false",
")",
"}",
")",
";",
"this",
".",
"displayVariableTypes",
"=",
"defaultValue",
"(",
"options",
".",
"displayVariableTypes",
",",
"defaultDisplayVariableTypes",
")",
";",
"this",
".",
"shaveSeconds",
"=",
"defaultValue",
"(",
"options",
".",
"shaveSeconds",
",",
"defaultShaveSeconds",
")",
";",
"this",
".",
"finalEndJulianDate",
"=",
"options",
".",
"finalEndJulianDate",
";",
"this",
".",
"unallowedTypes",
"=",
"options",
".",
"unallowedTypes",
";",
"this",
".",
"initialTimeSource",
"=",
"options",
".",
"initialTimeSource",
";",
"this",
".",
"displayDuration",
"=",
"options",
".",
"displayDuration",
";",
"this",
".",
"replaceWithNullValues",
"=",
"options",
".",
"replaceWithNullValues",
";",
"this",
".",
"replaceWithZeroValues",
"=",
"options",
".",
"replaceWithZeroValues",
";",
"this",
".",
"columnOptions",
"=",
"options",
".",
"columnOptions",
";",
"this",
".",
"sourceFeature",
"=",
"options",
".",
"sourceFeature",
";",
"this",
".",
"idColumnNames",
"=",
"options",
".",
"idColumnNames",
";",
"// Actually names, ids or indexes.",
"this",
".",
"isSampled",
"=",
"options",
".",
"isSampled",
";",
"/**\n * Gets or sets the active time column name, id or index.\n * If you pass an array of two such, eg. [0, 1], treats these as the start and end date column identifiers.\n * @type {String|Number|String[]|Number[]|undefined}\n */",
"this",
".",
"_activeTimeColumnNameIdOrIndex",
"=",
"undefined",
";",
"// Track sourceFeature as it is shown on the NowViewing panel.",
"// Track items so that charts can update live. (Already done by DisplayVariableConcept.)",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"sourceFeature\"",
",",
"\"_activeTimeColumnNameIdOrIndex\"",
"]",
")",
";",
"/**\n * Gets the columnsByType for this structure,\n * an object whose keys are VarTypes, and whose values are arrays of TableColumn with matching type.\n * Only existing types are present (eg. columnsByType[VarType.ALT] may be undefined).\n * @memberOf TableStructure.prototype\n * @type {Object}\n */",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"columnsByType\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"getColumnsByType",
"(",
"this",
".",
"items",
")",
";",
"}",
"}",
")",
";",
"}"
] | TableStructure provides an abstraction of a data table, ie. a structure with rows and columns.
Its primary responsibility is to load and parse the data, from csvs or other.
It stores each column as a TableColumn, and saves the rows too if conversion to rows is requested.
Columns are also sorted by type for easier access.
@alias TableStructure
@constructor
@extends {DisplayVariablesConcept}
@param {String} [name] Name to use in the NowViewing tab, defaults to 'Display Variable'.
@param {Object} [options] Options:
@param {Array} [options.displayVariableTypes] Which variable types to show in the NowViewing tab. Defaults to ENUM, SCALAR, and ALT (not LAT, LON or TIME).
@param {VarType[]} [options.unallowedTypes] An array of types which should not be guessed. If not present, all types are allowed. Cannot include VarType.SCALAR.
@param {String} [options.initialTimeSource] A string specifiying the value of the animation timeline at start. Valid options are:
("present": closest to today's date,
"start": start of time range of animation,
"end": end of time range of animation,
An ISO8601 date e.g. "2015-08-08": specified date or nearest if date is outside range).
@param {Number} [options.displayDuration] Passed on to TableColumn, unless overridden by options.columnOptions.
@param {String[]} [options.replaceWithNullValues] Passed on to TableColumn, unless overridden by options.columnOptions.
@param {String[]} [options.replaceWithZeroValues] Passed on to TableColumn, unless overridden by options.columnOptions.
@param {Object} [options.columnOptions] An object with keys identifying columns (column names or indices),
and per-column properties displayDuration, replaceWithNullValues, replaceWithZeroValues, name, active, units and/or type.
For type, converts strings, which are case-insensitive keys of VarType, to their VarType integer.
@param {Function} [options.getColorCallback] Passed to DisplayVariableConcept.
@param {Entity} [options.sourceFeature] The feature to which this table applies, if any; not used internally by TableStructure or TableColumn.
@param {Array} [options.idColumnNames] An array of column names/indexes/ids which identify unique features across rows
(see CsvCatalogItem.idColumns).
@param {Boolean} [options.isSampled] Does this data correspond to "sampled" data?
See CsvCatalogItem.isSampled for an explanation.
@param {Number} [options.shaveSeconds] How many seconds to shave off each time period so periods do not overlap. Defaults to 1 second.
@param {JulianDate} [options.finalEndJulianDate] If present, use this as the final end date for all points.
@param {Boolean} [options.requireSomeActive=false] Set to true if at least one column must be selected at all times. | [
"TableStructure",
"provides",
"an",
"abstraction",
"of",
"a",
"data",
"table",
"ie",
".",
"a",
"structure",
"with",
"rows",
"and",
"columns",
".",
"Its",
"primary",
"responsibility",
"is",
"to",
"load",
"and",
"parse",
"the",
"data",
"from",
"csvs",
"or",
"other",
".",
"It",
"stores",
"each",
"column",
"as",
"a",
"TableColumn",
"and",
"saves",
"the",
"rows",
"too",
"if",
"conversion",
"to",
"rows",
"is",
"requested",
".",
"Columns",
"are",
"also",
"sorted",
"by",
"type",
"for",
"easier",
"access",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L66-L112 |
|
7,048 | TerriaJS/terriajs | lib/Map/TableStructure.js | castToScalar | function castToScalar(value, state) {
if (state.rowNum === 1) {
// Don't cast column names
return value;
} else {
var hasDot = /\./;
var leadingZero = /^0[0-9]/;
var numberWithThousands = /^[1-9]\d?\d?(,\d\d\d)+(\.\d+)?$/;
if (numberWithThousands.test(value)) {
value = value.replace(/,/g, "");
}
if (isNaN(value)) {
return value;
}
if (leadingZero.test(value)) {
return value;
}
if (hasDot.test(value)) {
return parseFloat(value);
}
var integer = parseInt(value, 10);
if (isNaN(integer)) {
return null;
}
return integer;
}
} | javascript | function castToScalar(value, state) {
if (state.rowNum === 1) {
// Don't cast column names
return value;
} else {
var hasDot = /\./;
var leadingZero = /^0[0-9]/;
var numberWithThousands = /^[1-9]\d?\d?(,\d\d\d)+(\.\d+)?$/;
if (numberWithThousands.test(value)) {
value = value.replace(/,/g, "");
}
if (isNaN(value)) {
return value;
}
if (leadingZero.test(value)) {
return value;
}
if (hasDot.test(value)) {
return parseFloat(value);
}
var integer = parseInt(value, 10);
if (isNaN(integer)) {
return null;
}
return integer;
}
} | [
"function",
"castToScalar",
"(",
"value",
",",
"state",
")",
"{",
"if",
"(",
"state",
".",
"rowNum",
"===",
"1",
")",
"{",
"// Don't cast column names",
"return",
"value",
";",
"}",
"else",
"{",
"var",
"hasDot",
"=",
"/",
"\\.",
"/",
";",
"var",
"leadingZero",
"=",
"/",
"^0[0-9]",
"/",
";",
"var",
"numberWithThousands",
"=",
"/",
"^[1-9]\\d?\\d?(,\\d\\d\\d)+(\\.\\d+)?$",
"/",
";",
"if",
"(",
"numberWithThousands",
".",
"test",
"(",
"value",
")",
")",
"{",
"value",
"=",
"value",
".",
"replace",
"(",
"/",
",",
"/",
"g",
",",
"\"\"",
")",
";",
"}",
"if",
"(",
"isNaN",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"if",
"(",
"leadingZero",
".",
"test",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"if",
"(",
"hasDot",
".",
"test",
"(",
"value",
")",
")",
"{",
"return",
"parseFloat",
"(",
"value",
")",
";",
"}",
"var",
"integer",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"if",
"(",
"isNaN",
"(",
"integer",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"integer",
";",
"}",
"}"
] | Originally from jquery-csv plugin. Modified to avoid stripping leading zeros. | [
"Originally",
"from",
"jquery",
"-",
"csv",
"plugin",
".",
"Modified",
"to",
"avoid",
"stripping",
"leading",
"zeros",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L358-L384 |
7,049 | TerriaJS/terriajs | lib/Map/TableStructure.js | finishFromIndex | function finishFromIndex(timeColumn, index) {
if (!defined(timeColumn.displayDuration)) {
return timeColumn.finishJulianDates[index];
} else {
return JulianDate.addMinutes(
timeColumn.julianDates[index],
timeColumn.displayDuration,
endScratch
);
}
} | javascript | function finishFromIndex(timeColumn, index) {
if (!defined(timeColumn.displayDuration)) {
return timeColumn.finishJulianDates[index];
} else {
return JulianDate.addMinutes(
timeColumn.julianDates[index],
timeColumn.displayDuration,
endScratch
);
}
} | [
"function",
"finishFromIndex",
"(",
"timeColumn",
",",
"index",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"timeColumn",
".",
"displayDuration",
")",
")",
"{",
"return",
"timeColumn",
".",
"finishJulianDates",
"[",
"index",
"]",
";",
"}",
"else",
"{",
"return",
"JulianDate",
".",
"addMinutes",
"(",
"timeColumn",
".",
"julianDates",
"[",
"index",
"]",
",",
"timeColumn",
".",
"displayDuration",
",",
"endScratch",
")",
";",
"}",
"}"
] | Gets the finish time for the specified index.
@private
@param {TableColumn} timeColumn The time column that applies to this data.
@param {Integer} index The index into the time column.
@return {JulianDate} The finnish time that corresponds to the index. | [
"Gets",
"the",
"finish",
"time",
"for",
"the",
"specified",
"index",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L631-L641 |
7,050 | TerriaJS/terriajs | lib/Map/TableStructure.js | calculateAvailability | function calculateAvailability(timeColumn, index, endTime) {
var startJulianDate = timeColumn.julianDates[index];
if (defined(startJulianDate)) {
var finishJulianDate = finishFromIndex(timeColumn, index);
return new TimeInterval({
start: timeColumn.julianDates[index],
stop: finishJulianDate,
isStopIncluded: JulianDate.equals(finishJulianDate, endTime),
data: timeColumn.julianDates[index] // Stop overlapping intervals being collapsed into one interval unless they start at the same time
});
}
} | javascript | function calculateAvailability(timeColumn, index, endTime) {
var startJulianDate = timeColumn.julianDates[index];
if (defined(startJulianDate)) {
var finishJulianDate = finishFromIndex(timeColumn, index);
return new TimeInterval({
start: timeColumn.julianDates[index],
stop: finishJulianDate,
isStopIncluded: JulianDate.equals(finishJulianDate, endTime),
data: timeColumn.julianDates[index] // Stop overlapping intervals being collapsed into one interval unless they start at the same time
});
}
} | [
"function",
"calculateAvailability",
"(",
"timeColumn",
",",
"index",
",",
"endTime",
")",
"{",
"var",
"startJulianDate",
"=",
"timeColumn",
".",
"julianDates",
"[",
"index",
"]",
";",
"if",
"(",
"defined",
"(",
"startJulianDate",
")",
")",
"{",
"var",
"finishJulianDate",
"=",
"finishFromIndex",
"(",
"timeColumn",
",",
"index",
")",
";",
"return",
"new",
"TimeInterval",
"(",
"{",
"start",
":",
"timeColumn",
".",
"julianDates",
"[",
"index",
"]",
",",
"stop",
":",
"finishJulianDate",
",",
"isStopIncluded",
":",
"JulianDate",
".",
"equals",
"(",
"finishJulianDate",
",",
"endTime",
")",
",",
"data",
":",
"timeColumn",
".",
"julianDates",
"[",
"index",
"]",
"// Stop overlapping intervals being collapsed into one interval unless they start at the same time",
"}",
")",
";",
"}",
"}"
] | Calculate and return the availability interval for the index'th entry in timeColumn.
If the entry has no valid time, returns undefined.
@private
@param {TableColumn} timeColumn The time column that applies to this data.
@param {Integer} index The index into the time column.
@param {JulianDate} endTime The last time for all intervals.
@return {TimeInterval} The time interval over which this entry is visible. | [
"Calculate",
"and",
"return",
"the",
"availability",
"interval",
"for",
"the",
"index",
"th",
"entry",
"in",
"timeColumn",
".",
"If",
"the",
"entry",
"has",
"no",
"valid",
"time",
"returns",
"undefined",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L652-L663 |
7,051 | TerriaJS/terriajs | lib/Map/TableStructure.js | calculateTimeIntervals | function calculateTimeIntervals(timeColumn) {
// First we find the last time for all of the data (this is an optomisation for the calculateAvailability operation.
const endTime = timeColumn.values.reduce(function(latest, value, index) {
const current = finishFromIndex(timeColumn, index);
if (
!defined(latest) ||
(defined(current) && JulianDate.greaterThan(current, latest))
) {
return current;
}
return latest;
}, finishFromIndex(timeColumn, 0));
return timeColumn.values.map(function(value, index) {
return calculateAvailability(timeColumn, index, endTime);
});
} | javascript | function calculateTimeIntervals(timeColumn) {
// First we find the last time for all of the data (this is an optomisation for the calculateAvailability operation.
const endTime = timeColumn.values.reduce(function(latest, value, index) {
const current = finishFromIndex(timeColumn, index);
if (
!defined(latest) ||
(defined(current) && JulianDate.greaterThan(current, latest))
) {
return current;
}
return latest;
}, finishFromIndex(timeColumn, 0));
return timeColumn.values.map(function(value, index) {
return calculateAvailability(timeColumn, index, endTime);
});
} | [
"function",
"calculateTimeIntervals",
"(",
"timeColumn",
")",
"{",
"// First we find the last time for all of the data (this is an optomisation for the calculateAvailability operation.",
"const",
"endTime",
"=",
"timeColumn",
".",
"values",
".",
"reduce",
"(",
"function",
"(",
"latest",
",",
"value",
",",
"index",
")",
"{",
"const",
"current",
"=",
"finishFromIndex",
"(",
"timeColumn",
",",
"index",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"latest",
")",
"||",
"(",
"defined",
"(",
"current",
")",
"&&",
"JulianDate",
".",
"greaterThan",
"(",
"current",
",",
"latest",
")",
")",
")",
"{",
"return",
"current",
";",
"}",
"return",
"latest",
";",
"}",
",",
"finishFromIndex",
"(",
"timeColumn",
",",
"0",
")",
")",
";",
"return",
"timeColumn",
".",
"values",
".",
"map",
"(",
"function",
"(",
"value",
",",
"index",
")",
"{",
"return",
"calculateAvailability",
"(",
"timeColumn",
",",
"index",
",",
"endTime",
")",
";",
"}",
")",
";",
"}"
] | Calculates and returns TimeInterval array, whose elements say when to display each row.
@private | [
"Calculates",
"and",
"returns",
"TimeInterval",
"array",
"whose",
"elements",
"say",
"when",
"to",
"display",
"each",
"row",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L669-L685 |
7,052 | TerriaJS/terriajs | lib/Map/TableStructure.js | createClock | function createClock(timeColumn, tableStructure) {
var availabilityCollection = new TimeIntervalCollection();
timeColumn._timeIntervals
.filter(function(availability) {
return defined(availability && availability.start);
})
.forEach(function(availability) {
availabilityCollection.addInterval(availability);
});
if (!defined(timeColumn._clock)) {
if (
availabilityCollection.length > 0 &&
!availabilityCollection.start.equals(Iso8601.MINIMUM_VALUE)
) {
var startTime = availabilityCollection.start;
var stopTime = availabilityCollection.stop;
var totalSeconds = JulianDate.secondsDifference(stopTime, startTime);
var multiplier = Math.round(totalSeconds / 120.0);
if (
defined(tableStructure.idColumnNames) &&
tableStructure.idColumnNames.length > 0
) {
stopTime = timeColumn.julianDates.reduce((d1, d2) =>
JulianDate.greaterThan(d1, d2) ? d1 : d2
);
}
var clock = new DataSourceClock();
clock.startTime = JulianDate.clone(startTime);
clock.stopTime = JulianDate.clone(stopTime);
clock.clockRange = ClockRange.LOOP_STOP;
clock.multiplier = multiplier;
clock.currentTime = JulianDate.clone(startTime);
clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
return clock;
}
}
return timeColumn._clock;
} | javascript | function createClock(timeColumn, tableStructure) {
var availabilityCollection = new TimeIntervalCollection();
timeColumn._timeIntervals
.filter(function(availability) {
return defined(availability && availability.start);
})
.forEach(function(availability) {
availabilityCollection.addInterval(availability);
});
if (!defined(timeColumn._clock)) {
if (
availabilityCollection.length > 0 &&
!availabilityCollection.start.equals(Iso8601.MINIMUM_VALUE)
) {
var startTime = availabilityCollection.start;
var stopTime = availabilityCollection.stop;
var totalSeconds = JulianDate.secondsDifference(stopTime, startTime);
var multiplier = Math.round(totalSeconds / 120.0);
if (
defined(tableStructure.idColumnNames) &&
tableStructure.idColumnNames.length > 0
) {
stopTime = timeColumn.julianDates.reduce((d1, d2) =>
JulianDate.greaterThan(d1, d2) ? d1 : d2
);
}
var clock = new DataSourceClock();
clock.startTime = JulianDate.clone(startTime);
clock.stopTime = JulianDate.clone(stopTime);
clock.clockRange = ClockRange.LOOP_STOP;
clock.multiplier = multiplier;
clock.currentTime = JulianDate.clone(startTime);
clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
return clock;
}
}
return timeColumn._clock;
} | [
"function",
"createClock",
"(",
"timeColumn",
",",
"tableStructure",
")",
"{",
"var",
"availabilityCollection",
"=",
"new",
"TimeIntervalCollection",
"(",
")",
";",
"timeColumn",
".",
"_timeIntervals",
".",
"filter",
"(",
"function",
"(",
"availability",
")",
"{",
"return",
"defined",
"(",
"availability",
"&&",
"availability",
".",
"start",
")",
";",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"availability",
")",
"{",
"availabilityCollection",
".",
"addInterval",
"(",
"availability",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"timeColumn",
".",
"_clock",
")",
")",
"{",
"if",
"(",
"availabilityCollection",
".",
"length",
">",
"0",
"&&",
"!",
"availabilityCollection",
".",
"start",
".",
"equals",
"(",
"Iso8601",
".",
"MINIMUM_VALUE",
")",
")",
"{",
"var",
"startTime",
"=",
"availabilityCollection",
".",
"start",
";",
"var",
"stopTime",
"=",
"availabilityCollection",
".",
"stop",
";",
"var",
"totalSeconds",
"=",
"JulianDate",
".",
"secondsDifference",
"(",
"stopTime",
",",
"startTime",
")",
";",
"var",
"multiplier",
"=",
"Math",
".",
"round",
"(",
"totalSeconds",
"/",
"120.0",
")",
";",
"if",
"(",
"defined",
"(",
"tableStructure",
".",
"idColumnNames",
")",
"&&",
"tableStructure",
".",
"idColumnNames",
".",
"length",
">",
"0",
")",
"{",
"stopTime",
"=",
"timeColumn",
".",
"julianDates",
".",
"reduce",
"(",
"(",
"d1",
",",
"d2",
")",
"=>",
"JulianDate",
".",
"greaterThan",
"(",
"d1",
",",
"d2",
")",
"?",
"d1",
":",
"d2",
")",
";",
"}",
"var",
"clock",
"=",
"new",
"DataSourceClock",
"(",
")",
";",
"clock",
".",
"startTime",
"=",
"JulianDate",
".",
"clone",
"(",
"startTime",
")",
";",
"clock",
".",
"stopTime",
"=",
"JulianDate",
".",
"clone",
"(",
"stopTime",
")",
";",
"clock",
".",
"clockRange",
"=",
"ClockRange",
".",
"LOOP_STOP",
";",
"clock",
".",
"multiplier",
"=",
"multiplier",
";",
"clock",
".",
"currentTime",
"=",
"JulianDate",
".",
"clone",
"(",
"startTime",
")",
";",
"clock",
".",
"clockStep",
"=",
"ClockStep",
".",
"SYSTEM_CLOCK_MULTIPLIER",
";",
"return",
"clock",
";",
"}",
"}",
"return",
"timeColumn",
".",
"_clock",
";",
"}"
] | Returns a DataSourceClock out of this column. Only call if this is a time column.
@private | [
"Returns",
"a",
"DataSourceClock",
"out",
"of",
"this",
"column",
".",
"Only",
"call",
"if",
"this",
"is",
"a",
"time",
"column",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L691-L730 |
7,053 | TerriaJS/terriajs | lib/Map/TableStructure.js | getIndexOfColumn | function getIndexOfColumn(tableStructure, column) {
for (var i = 0; i < tableStructure.columns.length; i++) {
if (tableStructure.columns[i] === column) {
return i;
}
}
} | javascript | function getIndexOfColumn(tableStructure, column) {
for (var i = 0; i < tableStructure.columns.length; i++) {
if (tableStructure.columns[i] === column) {
return i;
}
}
} | [
"function",
"getIndexOfColumn",
"(",
"tableStructure",
",",
"column",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tableStructure",
".",
"columns",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"tableStructure",
".",
"columns",
"[",
"i",
"]",
"===",
"column",
")",
"{",
"return",
"i",
";",
"}",
"}",
"}"
] | Returns the index of the given column, or undefined if none match.
@param {TableStructure} tableStructure the table structure.
@param {TableColumn} column The column.
@returns {integer} The index of the column.
@private | [
"Returns",
"the",
"index",
"of",
"the",
"given",
"column",
"or",
"undefined",
"if",
"none",
"match",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1030-L1036 |
7,054 | TerriaJS/terriajs | lib/Map/TableStructure.js | getColumnWithNameOrId | function getColumnWithNameOrId(nameOrId, columns) {
for (var i = 0; i < columns.length; i++) {
if (columns[i].name === nameOrId || columns[i].id === nameOrId) {
return columns[i];
}
}
} | javascript | function getColumnWithNameOrId(nameOrId, columns) {
for (var i = 0; i < columns.length; i++) {
if (columns[i].name === nameOrId || columns[i].id === nameOrId) {
return columns[i];
}
}
} | [
"function",
"getColumnWithNameOrId",
"(",
"nameOrId",
",",
"columns",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"columns",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"columns",
"[",
"i",
"]",
".",
"name",
"===",
"nameOrId",
"||",
"columns",
"[",
"i",
"]",
".",
"id",
"===",
"nameOrId",
")",
"{",
"return",
"columns",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] | Returns the first column with the given name or id, or undefined if none match.
@param {String} nameOrId The column name or id.
@param {TableColumn[]} columns Test on these columns.
@returns {TableColumn} The matching column.
@private | [
"Returns",
"the",
"first",
"column",
"with",
"the",
"given",
"name",
"or",
"id",
"or",
"undefined",
"if",
"none",
"match",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1045-L1051 |
7,055 | TerriaJS/terriajs | lib/Map/TableStructure.js | getIdColumns | function getIdColumns(idColumnNames, columns) {
if (!defined(idColumnNames)) {
return [];
}
return idColumnNames.map(name => getColumnWithNameIdOrIndex(name, columns));
} | javascript | function getIdColumns(idColumnNames, columns) {
if (!defined(idColumnNames)) {
return [];
}
return idColumnNames.map(name => getColumnWithNameIdOrIndex(name, columns));
} | [
"function",
"getIdColumns",
"(",
"idColumnNames",
",",
"columns",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"idColumnNames",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"idColumnNames",
".",
"map",
"(",
"name",
"=>",
"getColumnWithNameIdOrIndex",
"(",
"name",
",",
"columns",
")",
")",
";",
"}"
] | columns is a required parameter. | [
"columns",
"is",
"a",
"required",
"parameter",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1101-L1106 |
7,056 | TerriaJS/terriajs | lib/Map/TableStructure.js | getIdMapping | function getIdMapping(idColumnNames, columns) {
var idColumns = getIdColumns(idColumnNames, columns);
if (idColumns.length === 0) {
return {};
}
return idColumns[0].values.reduce(function(result, value, rowNumber) {
var idString = getIdStringForRowNumber(idColumns, rowNumber);
if (!defined(result[idString])) {
result[idString] = [];
}
result[idString].push(rowNumber);
return result;
}, {});
} | javascript | function getIdMapping(idColumnNames, columns) {
var idColumns = getIdColumns(idColumnNames, columns);
if (idColumns.length === 0) {
return {};
}
return idColumns[0].values.reduce(function(result, value, rowNumber) {
var idString = getIdStringForRowNumber(idColumns, rowNumber);
if (!defined(result[idString])) {
result[idString] = [];
}
result[idString].push(rowNumber);
return result;
}, {});
} | [
"function",
"getIdMapping",
"(",
"idColumnNames",
",",
"columns",
")",
"{",
"var",
"idColumns",
"=",
"getIdColumns",
"(",
"idColumnNames",
",",
"columns",
")",
";",
"if",
"(",
"idColumns",
".",
"length",
"===",
"0",
")",
"{",
"return",
"{",
"}",
";",
"}",
"return",
"idColumns",
"[",
"0",
"]",
".",
"values",
".",
"reduce",
"(",
"function",
"(",
"result",
",",
"value",
",",
"rowNumber",
")",
"{",
"var",
"idString",
"=",
"getIdStringForRowNumber",
"(",
"idColumns",
",",
"rowNumber",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"result",
"[",
"idString",
"]",
")",
")",
"{",
"result",
"[",
"idString",
"]",
"=",
"[",
"]",
";",
"}",
"result",
"[",
"idString",
"]",
".",
"push",
"(",
"rowNumber",
")",
";",
"return",
"result",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Both arguments are required. | [
"Both",
"arguments",
"are",
"required",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1137-L1150 |
7,057 | TerriaJS/terriajs | lib/Map/TableStructure.js | getSortedColumns | function getSortedColumns(tableStructure, sortColumn, compareFunction) {
// With help from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
var mappedArray = sortColumn.julianDatesOrValues.map(function(value, i) {
return { index: i, value: value };
});
if (!defined(compareFunction)) {
if (sortColumn.type === VarType.TIME) {
compareFunction = function(a, b) {
if (defined(a) && defined(b)) {
return JulianDate.compare(a, b);
}
return defined(a) ? -1 : defined(b) ? 1 : 0; // so that undefined > defined, ie. all undefined dates go to the end.
};
} else {
compareFunction = function(a, b) {
return +(a > b) || +(a === b) - 1;
};
}
}
mappedArray.sort(function(a, b) {
return compareFunction(a.value, b.value);
});
return tableStructure.columns.map(column => {
var sortedValues = mappedArray.map(element => column.values[element.index]);
return new TableColumn(column.name, sortedValues, column.getFullOptions());
});
} | javascript | function getSortedColumns(tableStructure, sortColumn, compareFunction) {
// With help from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
var mappedArray = sortColumn.julianDatesOrValues.map(function(value, i) {
return { index: i, value: value };
});
if (!defined(compareFunction)) {
if (sortColumn.type === VarType.TIME) {
compareFunction = function(a, b) {
if (defined(a) && defined(b)) {
return JulianDate.compare(a, b);
}
return defined(a) ? -1 : defined(b) ? 1 : 0; // so that undefined > defined, ie. all undefined dates go to the end.
};
} else {
compareFunction = function(a, b) {
return +(a > b) || +(a === b) - 1;
};
}
}
mappedArray.sort(function(a, b) {
return compareFunction(a.value, b.value);
});
return tableStructure.columns.map(column => {
var sortedValues = mappedArray.map(element => column.values[element.index]);
return new TableColumn(column.name, sortedValues, column.getFullOptions());
});
} | [
"function",
"getSortedColumns",
"(",
"tableStructure",
",",
"sortColumn",
",",
"compareFunction",
")",
"{",
"// With help from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort",
"var",
"mappedArray",
"=",
"sortColumn",
".",
"julianDatesOrValues",
".",
"map",
"(",
"function",
"(",
"value",
",",
"i",
")",
"{",
"return",
"{",
"index",
":",
"i",
",",
"value",
":",
"value",
"}",
";",
"}",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"compareFunction",
")",
")",
"{",
"if",
"(",
"sortColumn",
".",
"type",
"===",
"VarType",
".",
"TIME",
")",
"{",
"compareFunction",
"=",
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"defined",
"(",
"a",
")",
"&&",
"defined",
"(",
"b",
")",
")",
"{",
"return",
"JulianDate",
".",
"compare",
"(",
"a",
",",
"b",
")",
";",
"}",
"return",
"defined",
"(",
"a",
")",
"?",
"-",
"1",
":",
"defined",
"(",
"b",
")",
"?",
"1",
":",
"0",
";",
"// so that undefined > defined, ie. all undefined dates go to the end.",
"}",
";",
"}",
"else",
"{",
"compareFunction",
"=",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"+",
"(",
"a",
">",
"b",
")",
"||",
"+",
"(",
"a",
"===",
"b",
")",
"-",
"1",
";",
"}",
";",
"}",
"}",
"mappedArray",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"compareFunction",
"(",
"a",
".",
"value",
",",
"b",
".",
"value",
")",
";",
"}",
")",
";",
"return",
"tableStructure",
".",
"columns",
".",
"map",
"(",
"column",
"=>",
"{",
"var",
"sortedValues",
"=",
"mappedArray",
".",
"map",
"(",
"element",
"=>",
"column",
".",
"values",
"[",
"element",
".",
"index",
"]",
")",
";",
"return",
"new",
"TableColumn",
"(",
"column",
".",
"name",
",",
"sortedValues",
",",
"column",
".",
"getFullOptions",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | Returns new columns sorted in sortColumn order. | [
"Returns",
"new",
"columns",
"sorted",
"in",
"sortColumn",
"order",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1380-L1406 |
7,058 | TerriaJS/terriajs | lib/Map/TableStructure.js | getColumnOptions | function getColumnOptions(name, tableStructure, columnNumber) {
var columnOptions = defaultValue.EMPTY_OBJECT;
if (defined(tableStructure.columnOptions)) {
columnOptions = defaultValue(
tableStructure.columnOptions[name],
defaultValue(
tableStructure.columnOptions[columnNumber],
defaultValue.EMPTY_OBJECT
)
);
}
var niceName = defaultValue(columnOptions.name, name);
var type = getVarTypeFromString(columnOptions.type);
var format = defaultValue(columnOptions.format, format);
var displayDuration = defaultValue(
columnOptions.displayDuration,
tableStructure.displayDuration
);
var replaceWithNullValues = defaultValue(
columnOptions.replaceWithNullValues,
tableStructure.replaceWithNullValues
);
var replaceWithZeroValues = defaultValue(
columnOptions.replaceWithZeroValues,
tableStructure.replaceWithZeroValues
);
var colOptions = {
tableStructure: tableStructure,
displayVariableTypes: tableStructure.displayVariableTypes,
unallowedTypes: tableStructure.unallowedTypes,
displayDuration: displayDuration,
replaceWithNullValues: replaceWithNullValues,
replaceWithZeroValues: replaceWithZeroValues,
id: name,
type: type,
units: columnOptions.units,
format: columnOptions.format,
active: columnOptions.active,
chartLineColor: columnOptions.chartLineColor,
yAxisMin: columnOptions.yAxisMin,
yAxisMax: columnOptions.yAxisMax
};
return [niceName, colOptions];
} | javascript | function getColumnOptions(name, tableStructure, columnNumber) {
var columnOptions = defaultValue.EMPTY_OBJECT;
if (defined(tableStructure.columnOptions)) {
columnOptions = defaultValue(
tableStructure.columnOptions[name],
defaultValue(
tableStructure.columnOptions[columnNumber],
defaultValue.EMPTY_OBJECT
)
);
}
var niceName = defaultValue(columnOptions.name, name);
var type = getVarTypeFromString(columnOptions.type);
var format = defaultValue(columnOptions.format, format);
var displayDuration = defaultValue(
columnOptions.displayDuration,
tableStructure.displayDuration
);
var replaceWithNullValues = defaultValue(
columnOptions.replaceWithNullValues,
tableStructure.replaceWithNullValues
);
var replaceWithZeroValues = defaultValue(
columnOptions.replaceWithZeroValues,
tableStructure.replaceWithZeroValues
);
var colOptions = {
tableStructure: tableStructure,
displayVariableTypes: tableStructure.displayVariableTypes,
unallowedTypes: tableStructure.unallowedTypes,
displayDuration: displayDuration,
replaceWithNullValues: replaceWithNullValues,
replaceWithZeroValues: replaceWithZeroValues,
id: name,
type: type,
units: columnOptions.units,
format: columnOptions.format,
active: columnOptions.active,
chartLineColor: columnOptions.chartLineColor,
yAxisMin: columnOptions.yAxisMin,
yAxisMax: columnOptions.yAxisMax
};
return [niceName, colOptions];
} | [
"function",
"getColumnOptions",
"(",
"name",
",",
"tableStructure",
",",
"columnNumber",
")",
"{",
"var",
"columnOptions",
"=",
"defaultValue",
".",
"EMPTY_OBJECT",
";",
"if",
"(",
"defined",
"(",
"tableStructure",
".",
"columnOptions",
")",
")",
"{",
"columnOptions",
"=",
"defaultValue",
"(",
"tableStructure",
".",
"columnOptions",
"[",
"name",
"]",
",",
"defaultValue",
"(",
"tableStructure",
".",
"columnOptions",
"[",
"columnNumber",
"]",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
")",
";",
"}",
"var",
"niceName",
"=",
"defaultValue",
"(",
"columnOptions",
".",
"name",
",",
"name",
")",
";",
"var",
"type",
"=",
"getVarTypeFromString",
"(",
"columnOptions",
".",
"type",
")",
";",
"var",
"format",
"=",
"defaultValue",
"(",
"columnOptions",
".",
"format",
",",
"format",
")",
";",
"var",
"displayDuration",
"=",
"defaultValue",
"(",
"columnOptions",
".",
"displayDuration",
",",
"tableStructure",
".",
"displayDuration",
")",
";",
"var",
"replaceWithNullValues",
"=",
"defaultValue",
"(",
"columnOptions",
".",
"replaceWithNullValues",
",",
"tableStructure",
".",
"replaceWithNullValues",
")",
";",
"var",
"replaceWithZeroValues",
"=",
"defaultValue",
"(",
"columnOptions",
".",
"replaceWithZeroValues",
",",
"tableStructure",
".",
"replaceWithZeroValues",
")",
";",
"var",
"colOptions",
"=",
"{",
"tableStructure",
":",
"tableStructure",
",",
"displayVariableTypes",
":",
"tableStructure",
".",
"displayVariableTypes",
",",
"unallowedTypes",
":",
"tableStructure",
".",
"unallowedTypes",
",",
"displayDuration",
":",
"displayDuration",
",",
"replaceWithNullValues",
":",
"replaceWithNullValues",
",",
"replaceWithZeroValues",
":",
"replaceWithZeroValues",
",",
"id",
":",
"name",
",",
"type",
":",
"type",
",",
"units",
":",
"columnOptions",
".",
"units",
",",
"format",
":",
"columnOptions",
".",
"format",
",",
"active",
":",
"columnOptions",
".",
"active",
",",
"chartLineColor",
":",
"columnOptions",
".",
"chartLineColor",
",",
"yAxisMin",
":",
"columnOptions",
".",
"yAxisMin",
",",
"yAxisMax",
":",
"columnOptions",
".",
"yAxisMax",
"}",
";",
"return",
"[",
"niceName",
",",
"colOptions",
"]",
";",
"}"
] | Return column options object, using defaults where appropriate.
@param {String} name Name of column
@param {TableStructure} tableStructure TableStructure to use to calculate values.
@param {Int} columnNumber Which column should be used as template for default column options
@return {Object} Column options that TableColumn's constructor understands | [
"Return",
"column",
"options",
"object",
"using",
"defaults",
"where",
"appropriate",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1534-L1577 |
7,059 | TerriaJS/terriajs | lib/Map/TableStructure.js | areColumnsEqualLength | function areColumnsEqualLength(columns) {
if (columns.length <= 1) {
return true;
}
var firstLength = columns[0].values.length;
var columnsWithTheSameLength = columns.slice(1).filter(function(column) {
return column.values.length === firstLength;
});
return columnsWithTheSameLength.length === columns.length - 1;
} | javascript | function areColumnsEqualLength(columns) {
if (columns.length <= 1) {
return true;
}
var firstLength = columns[0].values.length;
var columnsWithTheSameLength = columns.slice(1).filter(function(column) {
return column.values.length === firstLength;
});
return columnsWithTheSameLength.length === columns.length - 1;
} | [
"function",
"areColumnsEqualLength",
"(",
"columns",
")",
"{",
"if",
"(",
"columns",
".",
"length",
"<=",
"1",
")",
"{",
"return",
"true",
";",
"}",
"var",
"firstLength",
"=",
"columns",
"[",
"0",
"]",
".",
"values",
".",
"length",
";",
"var",
"columnsWithTheSameLength",
"=",
"columns",
".",
"slice",
"(",
"1",
")",
".",
"filter",
"(",
"function",
"(",
"column",
")",
"{",
"return",
"column",
".",
"values",
".",
"length",
"===",
"firstLength",
";",
"}",
")",
";",
"return",
"columnsWithTheSameLength",
".",
"length",
"===",
"columns",
".",
"length",
"-",
"1",
";",
"}"
] | Normally a TableStructure is generated from a csvString, using loadFromCsv, or via loadFromJson.
However, if its columns are set directly, we should check the columns are all the same length.
@private
@param {Concept[]} columns Array of columns to check.
@return {Boolean} True if the columns are all the same length, false otherwise. | [
"Normally",
"a",
"TableStructure",
"is",
"generated",
"from",
"a",
"csvString",
"using",
"loadFromCsv",
"or",
"via",
"loadFromJson",
".",
"However",
"if",
"its",
"columns",
"are",
"set",
"directly",
"we",
"should",
"check",
"the",
"columns",
"are",
"all",
"the",
"same",
"length",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/TableStructure.js#L1586-L1595 |
7,060 | TerriaJS/terriajs | lib/Map/DisplayVariablesConcept.js | function(name, options) {
const that = this;
name = defaultValue(name, "Display Variable");
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
VariableConcept.call(this, name, options);
/**
* Gets or sets a flag for whether more than one checkbox can be selected at a time.
* Default false.
* @type {Boolean}
*/
this.allowMultiple = defaultValue(options.allowMultiple, false);
/**
* Gets or sets a flag for whether at least one checkbox must be selected at all times.
* Default false.
* @type {Boolean}
*/
this.requireSomeActive = defaultValue(options.requireSomeActive, false);
/**
* Gets or sets a function with no arguments that returns a color for the VariableConcept. If undefined, no color is set (the default).
* @type {Function}
*/
this.getColorCallback = options.getColorCallback;
/**
* Gets or sets the array of concepts contained in this group.
* If options.items is present, each item's parent property is overridden with `this`.
* @type {Concept[]}
*/
this.items = defaultValue(options.items, []);
this.items.forEach(function(item) {
item.parent = that;
});
/**
* Gets or sets a value indicating whether this concept item is currently open. When an
* item is open, its child items (if any) are visible. Default true.
* @type {Boolean}
*/
this.isOpen = defaultValue(options.isOpen, true);
/**
* Gets or sets a flag indicating whether this node is selectable.
* @type {Boolean}
*/
this.isSelectable = defaultValue(options.isSelectable, false);
/**
* Gets or sets a list of child ids which cannot be selected at the same time as any other child. Defaults to [].
* Only relevant with allowMultiple = true.
* Eg. Suppose the child concepts have ids "10" for 10 year olds, etc, plus "ALL" for all ages,
* "U21" and "21PLUS" for under and over 21 year olds.
* Then by specifying ["ALL", "U21", "21PLUS"], when the user selects one of these values, any other values will be unselected.
* And when the user selects any other value (eg. "10"), if any of these values were selected, they will be unselected.
* @type {String[]}
*/
this.exclusiveChildIds = defaultValue(options.exclusiveChildIds, []);
/**
* Gets or sets a function which is called whenever a child item is successfully toggled.
* Its sole argument is the toggled child item.
* @type {Function}
*/
this.toggleActiveCallback = undefined;
knockout.track(this, [
"items",
"isOpen",
"allowMultiple",
"requireSomeActive"
]);
/**
* Gets an array of currently active/selected items.
* @return {VariableConcept[]} Array of active/selected items.
*/
knockout.defineProperty(this, "activeItems", {
get: function() {
return this.items.filter(function(item) {
return item.isActive;
});
}
});
} | javascript | function(name, options) {
const that = this;
name = defaultValue(name, "Display Variable");
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
VariableConcept.call(this, name, options);
/**
* Gets or sets a flag for whether more than one checkbox can be selected at a time.
* Default false.
* @type {Boolean}
*/
this.allowMultiple = defaultValue(options.allowMultiple, false);
/**
* Gets or sets a flag for whether at least one checkbox must be selected at all times.
* Default false.
* @type {Boolean}
*/
this.requireSomeActive = defaultValue(options.requireSomeActive, false);
/**
* Gets or sets a function with no arguments that returns a color for the VariableConcept. If undefined, no color is set (the default).
* @type {Function}
*/
this.getColorCallback = options.getColorCallback;
/**
* Gets or sets the array of concepts contained in this group.
* If options.items is present, each item's parent property is overridden with `this`.
* @type {Concept[]}
*/
this.items = defaultValue(options.items, []);
this.items.forEach(function(item) {
item.parent = that;
});
/**
* Gets or sets a value indicating whether this concept item is currently open. When an
* item is open, its child items (if any) are visible. Default true.
* @type {Boolean}
*/
this.isOpen = defaultValue(options.isOpen, true);
/**
* Gets or sets a flag indicating whether this node is selectable.
* @type {Boolean}
*/
this.isSelectable = defaultValue(options.isSelectable, false);
/**
* Gets or sets a list of child ids which cannot be selected at the same time as any other child. Defaults to [].
* Only relevant with allowMultiple = true.
* Eg. Suppose the child concepts have ids "10" for 10 year olds, etc, plus "ALL" for all ages,
* "U21" and "21PLUS" for under and over 21 year olds.
* Then by specifying ["ALL", "U21", "21PLUS"], when the user selects one of these values, any other values will be unselected.
* And when the user selects any other value (eg. "10"), if any of these values were selected, they will be unselected.
* @type {String[]}
*/
this.exclusiveChildIds = defaultValue(options.exclusiveChildIds, []);
/**
* Gets or sets a function which is called whenever a child item is successfully toggled.
* Its sole argument is the toggled child item.
* @type {Function}
*/
this.toggleActiveCallback = undefined;
knockout.track(this, [
"items",
"isOpen",
"allowMultiple",
"requireSomeActive"
]);
/**
* Gets an array of currently active/selected items.
* @return {VariableConcept[]} Array of active/selected items.
*/
knockout.defineProperty(this, "activeItems", {
get: function() {
return this.items.filter(function(item) {
return item.isActive;
});
}
});
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"const",
"that",
"=",
"this",
";",
"name",
"=",
"defaultValue",
"(",
"name",
",",
"\"Display Variable\"",
")",
";",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"VariableConcept",
".",
"call",
"(",
"this",
",",
"name",
",",
"options",
")",
";",
"/**\n * Gets or sets a flag for whether more than one checkbox can be selected at a time.\n * Default false.\n * @type {Boolean}\n */",
"this",
".",
"allowMultiple",
"=",
"defaultValue",
"(",
"options",
".",
"allowMultiple",
",",
"false",
")",
";",
"/**\n * Gets or sets a flag for whether at least one checkbox must be selected at all times.\n * Default false.\n * @type {Boolean}\n */",
"this",
".",
"requireSomeActive",
"=",
"defaultValue",
"(",
"options",
".",
"requireSomeActive",
",",
"false",
")",
";",
"/**\n * Gets or sets a function with no arguments that returns a color for the VariableConcept. If undefined, no color is set (the default).\n * @type {Function}\n */",
"this",
".",
"getColorCallback",
"=",
"options",
".",
"getColorCallback",
";",
"/**\n * Gets or sets the array of concepts contained in this group.\n * If options.items is present, each item's parent property is overridden with `this`.\n * @type {Concept[]}\n */",
"this",
".",
"items",
"=",
"defaultValue",
"(",
"options",
".",
"items",
",",
"[",
"]",
")",
";",
"this",
".",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"item",
".",
"parent",
"=",
"that",
";",
"}",
")",
";",
"/**\n * Gets or sets a value indicating whether this concept item is currently open. When an\n * item is open, its child items (if any) are visible. Default true.\n * @type {Boolean}\n */",
"this",
".",
"isOpen",
"=",
"defaultValue",
"(",
"options",
".",
"isOpen",
",",
"true",
")",
";",
"/**\n * Gets or sets a flag indicating whether this node is selectable.\n * @type {Boolean}\n */",
"this",
".",
"isSelectable",
"=",
"defaultValue",
"(",
"options",
".",
"isSelectable",
",",
"false",
")",
";",
"/**\n * Gets or sets a list of child ids which cannot be selected at the same time as any other child. Defaults to [].\n * Only relevant with allowMultiple = true.\n * Eg. Suppose the child concepts have ids \"10\" for 10 year olds, etc, plus \"ALL\" for all ages,\n * \"U21\" and \"21PLUS\" for under and over 21 year olds.\n * Then by specifying [\"ALL\", \"U21\", \"21PLUS\"], when the user selects one of these values, any other values will be unselected.\n * And when the user selects any other value (eg. \"10\"), if any of these values were selected, they will be unselected.\n * @type {String[]}\n */",
"this",
".",
"exclusiveChildIds",
"=",
"defaultValue",
"(",
"options",
".",
"exclusiveChildIds",
",",
"[",
"]",
")",
";",
"/**\n * Gets or sets a function which is called whenever a child item is successfully toggled.\n * Its sole argument is the toggled child item.\n * @type {Function}\n */",
"this",
".",
"toggleActiveCallback",
"=",
"undefined",
";",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"items\"",
",",
"\"isOpen\"",
",",
"\"allowMultiple\"",
",",
"\"requireSomeActive\"",
"]",
")",
";",
"/**\n * Gets an array of currently active/selected items.\n * @return {VariableConcept[]} Array of active/selected items.\n */",
"knockout",
".",
"defineProperty",
"(",
"this",
",",
"\"activeItems\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"items",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"isActive",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Represents a concept which contains a list of variables which can be used to change the appearance of data.
A DisplayVariablesConcept contains an items array of VariableConcepts.
@alias DisplayVariablesConcept
@constructor
@extends VariableConcept
@param {String} [name='Display Variable'] Display name of this concept.
@param {Boolean|Object} [options] Options; for backwards compatibility, if a boolean is passed, it is interpreted as options.allowMultiple. Also, VariableConcept options are passed through.
@param {Function} [getColorCallback] For backwards compatibility, a third argument is interpreted as options.getColorCallback. Use options.getColorCallback in preference.
@param {Boolean} [options.allowMultiple=false] Set to true if more than one checkbox can be selected at a time.
@param {Boolean} [options.requireSomeActive=false] Set to true if at least one checkbox must be selected at all times.
@param {Function} [options.getColorCallback] A function with no arguments that returns a color for the VariableConcept. If undefined, no color is set.
@param {Concept[]} [options.items] The array of concepts contained in this group. Each item's parent property is overridden with `this`.
@param {Boolean} [options.isOpen] Whether this concept item is currently open.
@param {Boolean} [options.isSelectable] Whether this node is selectable.
@param {String[]} [options.exclusiveChildIds] A list of child ids which cannot be selected at the same time as any other child. Default []. | [
"Represents",
"a",
"concept",
"which",
"contains",
"a",
"list",
"of",
"variables",
"which",
"can",
"be",
"used",
"to",
"change",
"the",
"appearance",
"of",
"data",
".",
"A",
"DisplayVariablesConcept",
"contains",
"an",
"items",
"array",
"of",
"VariableConcepts",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/DisplayVariablesConcept.js#L31-L117 |
|
7,061 | TerriaJS/terriajs | lib/Map/DisplayVariablesConcept.js | getNestedNodes | function getNestedNodes(concept, condition) {
if (condition(concept)) {
return concept;
}
if (!concept.items) {
return [];
}
return concept.items.map(child => getNestedNodes(child, condition));
} | javascript | function getNestedNodes(concept, condition) {
if (condition(concept)) {
return concept;
}
if (!concept.items) {
return [];
}
return concept.items.map(child => getNestedNodes(child, condition));
} | [
"function",
"getNestedNodes",
"(",
"concept",
",",
"condition",
")",
"{",
"if",
"(",
"condition",
"(",
"concept",
")",
")",
"{",
"return",
"concept",
";",
"}",
"if",
"(",
"!",
"concept",
".",
"items",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"concept",
".",
"items",
".",
"map",
"(",
"child",
"=>",
"getNestedNodes",
"(",
"child",
",",
"condition",
")",
")",
";",
"}"
] | Returns a nested array containing only the leaf concepts, at their actual depths in the tree of nodes. | [
"Returns",
"a",
"nested",
"array",
"containing",
"only",
"the",
"leaf",
"concepts",
"at",
"their",
"actual",
"depths",
"in",
"the",
"tree",
"of",
"nodes",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/DisplayVariablesConcept.js#L139-L147 |
7,062 | TerriaJS/terriajs | lib/Models/RegionParameter.js | function(options) {
if (!defined(options) || !defined(options.regionProvider)) {
throw new DeveloperError("options.regionProvider is required.");
}
FunctionParameter.call(this, options);
this._regionProvider = options.regionProvider;
} | javascript | function(options) {
if (!defined(options) || !defined(options.regionProvider)) {
throw new DeveloperError("options.regionProvider is required.");
}
FunctionParameter.call(this, options);
this._regionProvider = options.regionProvider;
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"options",
")",
"||",
"!",
"defined",
"(",
"options",
".",
"regionProvider",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"\"options.regionProvider is required.\"",
")",
";",
"}",
"FunctionParameter",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"_regionProvider",
"=",
"options",
".",
"regionProvider",
";",
"}"
] | A parameter that specifies a particular region.
@alias RegionParameter
@constructor
@extends FunctionParameter
@param {Object} [options] Object with the following properties:
@param {Terria} options.terria The Terria instance.
@param {String} options.id The unique ID of this parameter.
@param {String} [options.name] The name of this parameter. If not specified, the ID is used as the name.
@param {String} [options.description] The description of the parameter.
@param {RegionProvider|RegionTypeParameter} options.regionProvider The {@link RegionProvider} from which a region may be selected. This may also
be a {@link RegionTypeParameter} that specifies the type of region. | [
"A",
"parameter",
"that",
"specifies",
"a",
"particular",
"region",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionParameter.js#L26-L34 |
|
7,063 | TerriaJS/terriajs | lib/Models/setClockCurrentTime.js | setClockCurrentTime | function setClockCurrentTime(clock, initialTimeSource, stopTime) {
if (!defined(clock)) {
return;
}
// This is our default. Start at the nearest instant in time.
var now = JulianDate.now();
_setTimeIfInRange(clock, now, stopTime);
initialTimeSource = defaultValue(initialTimeSource, "present");
switch (initialTimeSource) {
case "start":
clock.currentTime = clock.startTime.clone(clock.currentTime);
break;
case "end":
clock.currentTime = clock.stopTime.clone(clock.currentTime);
break;
case "present":
// Set to present by default.
break;
default:
// Note that if it's not an ISO8601 timestamp, it ends up being set to present.
// Find out whether it's an ISO8601 timestamp.
var timestamp;
try {
timestamp = JulianDate.fromIso8601(initialTimeSource);
// Cesium no longer validates dates in the release build.
// So convert to a JavaScript date as a cheesy means of checking if the date is valid.
if (isNaN(JulianDate.toDate(timestamp))) {
throw new Error("Invalid Date");
}
} catch (e) {
throw new TerriaError(
"Invalid initialTimeSource specified in config file: " +
initialTimeSource
);
}
if (defined(timestamp)) {
_setTimeIfInRange(clock, timestamp);
}
}
} | javascript | function setClockCurrentTime(clock, initialTimeSource, stopTime) {
if (!defined(clock)) {
return;
}
// This is our default. Start at the nearest instant in time.
var now = JulianDate.now();
_setTimeIfInRange(clock, now, stopTime);
initialTimeSource = defaultValue(initialTimeSource, "present");
switch (initialTimeSource) {
case "start":
clock.currentTime = clock.startTime.clone(clock.currentTime);
break;
case "end":
clock.currentTime = clock.stopTime.clone(clock.currentTime);
break;
case "present":
// Set to present by default.
break;
default:
// Note that if it's not an ISO8601 timestamp, it ends up being set to present.
// Find out whether it's an ISO8601 timestamp.
var timestamp;
try {
timestamp = JulianDate.fromIso8601(initialTimeSource);
// Cesium no longer validates dates in the release build.
// So convert to a JavaScript date as a cheesy means of checking if the date is valid.
if (isNaN(JulianDate.toDate(timestamp))) {
throw new Error("Invalid Date");
}
} catch (e) {
throw new TerriaError(
"Invalid initialTimeSource specified in config file: " +
initialTimeSource
);
}
if (defined(timestamp)) {
_setTimeIfInRange(clock, timestamp);
}
}
} | [
"function",
"setClockCurrentTime",
"(",
"clock",
",",
"initialTimeSource",
",",
"stopTime",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"clock",
")",
")",
"{",
"return",
";",
"}",
"// This is our default. Start at the nearest instant in time.",
"var",
"now",
"=",
"JulianDate",
".",
"now",
"(",
")",
";",
"_setTimeIfInRange",
"(",
"clock",
",",
"now",
",",
"stopTime",
")",
";",
"initialTimeSource",
"=",
"defaultValue",
"(",
"initialTimeSource",
",",
"\"present\"",
")",
";",
"switch",
"(",
"initialTimeSource",
")",
"{",
"case",
"\"start\"",
":",
"clock",
".",
"currentTime",
"=",
"clock",
".",
"startTime",
".",
"clone",
"(",
"clock",
".",
"currentTime",
")",
";",
"break",
";",
"case",
"\"end\"",
":",
"clock",
".",
"currentTime",
"=",
"clock",
".",
"stopTime",
".",
"clone",
"(",
"clock",
".",
"currentTime",
")",
";",
"break",
";",
"case",
"\"present\"",
":",
"// Set to present by default.",
"break",
";",
"default",
":",
"// Note that if it's not an ISO8601 timestamp, it ends up being set to present.",
"// Find out whether it's an ISO8601 timestamp.",
"var",
"timestamp",
";",
"try",
"{",
"timestamp",
"=",
"JulianDate",
".",
"fromIso8601",
"(",
"initialTimeSource",
")",
";",
"// Cesium no longer validates dates in the release build.",
"// So convert to a JavaScript date as a cheesy means of checking if the date is valid.",
"if",
"(",
"isNaN",
"(",
"JulianDate",
".",
"toDate",
"(",
"timestamp",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Invalid Date\"",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"TerriaError",
"(",
"\"Invalid initialTimeSource specified in config file: \"",
"+",
"initialTimeSource",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"timestamp",
")",
")",
"{",
"_setTimeIfInRange",
"(",
"clock",
",",
"timestamp",
")",
";",
"}",
"}",
"}"
] | Sets the current time of the clock, using a string defined specification for the time point to use.
@param {DataSourceClock} clock clock to set the current time on.
@param {String} initialTimeSource A string specifiying the value to use when setting the currentTime of the clock. Valid options are:
("present": closest to today's date,
"start": start of time range of animation,
"end": end of time range of animation,
An ISO8601 date e.g. "2015-08-08": specified date or nearest if date is outside range). | [
"Sets",
"the",
"current",
"time",
"of",
"the",
"clock",
"using",
"a",
"string",
"defined",
"specification",
"for",
"the",
"time",
"point",
"to",
"use",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/setClockCurrentTime.js#L39-L81 |
7,064 | TerriaJS/terriajs | lib/ViewModels/GazetteerSearchProviderViewModel.js | stripDuplicates | function stripDuplicates(results) {
var i;
var placeshash = {};
var stripped = [];
for (i = 0; i < results.length; i++) {
var lat = Number(results[i].location.split(",")[0]).toFixed(1);
var lng = Number(results[i].location.split(",")[1]).toFixed(1);
var hash = results[i].name + "_" + lat + " " + lng;
if (!defined(placeshash[hash])) {
placeshash[hash] = results[i];
stripped.push(results[i]);
}
}
return stripped;
} | javascript | function stripDuplicates(results) {
var i;
var placeshash = {};
var stripped = [];
for (i = 0; i < results.length; i++) {
var lat = Number(results[i].location.split(",")[0]).toFixed(1);
var lng = Number(results[i].location.split(",")[1]).toFixed(1);
var hash = results[i].name + "_" + lat + " " + lng;
if (!defined(placeshash[hash])) {
placeshash[hash] = results[i];
stripped.push(results[i]);
}
}
return stripped;
} | [
"function",
"stripDuplicates",
"(",
"results",
")",
"{",
"var",
"i",
";",
"var",
"placeshash",
"=",
"{",
"}",
";",
"var",
"stripped",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"results",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"lat",
"=",
"Number",
"(",
"results",
"[",
"i",
"]",
".",
"location",
".",
"split",
"(",
"\",\"",
")",
"[",
"0",
"]",
")",
".",
"toFixed",
"(",
"1",
")",
";",
"var",
"lng",
"=",
"Number",
"(",
"results",
"[",
"i",
"]",
".",
"location",
".",
"split",
"(",
"\",\"",
")",
"[",
"1",
"]",
")",
".",
"toFixed",
"(",
"1",
")",
";",
"var",
"hash",
"=",
"results",
"[",
"i",
"]",
".",
"name",
"+",
"\"_\"",
"+",
"lat",
"+",
"\" \"",
"+",
"lng",
";",
"if",
"(",
"!",
"defined",
"(",
"placeshash",
"[",
"hash",
"]",
")",
")",
"{",
"placeshash",
"[",
"hash",
"]",
"=",
"results",
"[",
"i",
"]",
";",
"stripped",
".",
"push",
"(",
"results",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"stripped",
";",
"}"
] | Given a list of results sorted in decreasing importance, strip results that are close to another result with the same name | [
"Given",
"a",
"list",
"of",
"results",
"sorted",
"in",
"decreasing",
"importance",
"strip",
"results",
"that",
"are",
"close",
"to",
"another",
"result",
"with",
"the",
"same",
"name"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ViewModels/GazetteerSearchProviderViewModel.js#L124-L139 |
7,065 | TerriaJS/terriajs | lib/ViewModels/GnafSearchProviderViewModel.js | function(options) {
SearchProviderViewModel.call(this);
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
this.terria = options.terria;
var url = defaultValue(
options.url,
this.terria.configParameters.gnafSearchUrl
);
this.name = NAME;
this.gnafApi = defaultValue(
options.gnafApi,
new GnafApi(this.terria.corsProxy, url)
);
this._geocodeInProgress = undefined;
this.flightDurationSeconds = defaultValue(options.flightDurationSeconds, 1.5);
} | javascript | function(options) {
SearchProviderViewModel.call(this);
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
this.terria = options.terria;
var url = defaultValue(
options.url,
this.terria.configParameters.gnafSearchUrl
);
this.name = NAME;
this.gnafApi = defaultValue(
options.gnafApi,
new GnafApi(this.terria.corsProxy, url)
);
this._geocodeInProgress = undefined;
this.flightDurationSeconds = defaultValue(options.flightDurationSeconds, 1.5);
} | [
"function",
"(",
"options",
")",
"{",
"SearchProviderViewModel",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"this",
".",
"terria",
"=",
"options",
".",
"terria",
";",
"var",
"url",
"=",
"defaultValue",
"(",
"options",
".",
"url",
",",
"this",
".",
"terria",
".",
"configParameters",
".",
"gnafSearchUrl",
")",
";",
"this",
".",
"name",
"=",
"NAME",
";",
"this",
".",
"gnafApi",
"=",
"defaultValue",
"(",
"options",
".",
"gnafApi",
",",
"new",
"GnafApi",
"(",
"this",
".",
"terria",
".",
"corsProxy",
",",
"url",
")",
")",
";",
"this",
".",
"_geocodeInProgress",
"=",
"undefined",
";",
"this",
".",
"flightDurationSeconds",
"=",
"defaultValue",
"(",
"options",
".",
"flightDurationSeconds",
",",
"1.5",
")",
";",
"}"
] | Search provider that uses the Data61 Elastic Search GNAF service to look up addresses.
@param options.terria Terria instance
@param [options.gnafApi] The GnafApi object to query - if none is provided one will be created using terria.corsProxy
and the default settings.
@param [options.flightDurationSeconds] The number of seconds for the flight animation when zooming to new results.
@constructor | [
"Search",
"provider",
"that",
"uses",
"the",
"Data61",
"Elastic",
"Search",
"GNAF",
"service",
"to",
"look",
"up",
"addresses",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ViewModels/GnafSearchProviderViewModel.js#L24-L42 |
|
7,066 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | getShareData | function getShareData(terria) {
const initSources = terria.initSources.slice();
addUserAddedCatalog(terria, initSources);
addSharedMembers(terria, initSources);
addViewSettings(terria, initSources);
addFeaturePicking(terria, initSources);
addLocationMarker(terria, initSources);
return {
version: "0.0.05",
initSources: initSources
};
} | javascript | function getShareData(terria) {
const initSources = terria.initSources.slice();
addUserAddedCatalog(terria, initSources);
addSharedMembers(terria, initSources);
addViewSettings(terria, initSources);
addFeaturePicking(terria, initSources);
addLocationMarker(terria, initSources);
return {
version: "0.0.05",
initSources: initSources
};
} | [
"function",
"getShareData",
"(",
"terria",
")",
"{",
"const",
"initSources",
"=",
"terria",
".",
"initSources",
".",
"slice",
"(",
")",
";",
"addUserAddedCatalog",
"(",
"terria",
",",
"initSources",
")",
";",
"addSharedMembers",
"(",
"terria",
",",
"initSources",
")",
";",
"addViewSettings",
"(",
"terria",
",",
"initSources",
")",
";",
"addFeaturePicking",
"(",
"terria",
",",
"initSources",
")",
";",
"addLocationMarker",
"(",
"terria",
",",
"initSources",
")",
";",
"return",
"{",
"version",
":",
"\"0.0.05\"",
",",
"initSources",
":",
"initSources",
"}",
";",
"}"
] | Returns just the JSON that defines the current view.
@param {Object} terria The Terria object.
@return {Object} | [
"Returns",
"just",
"the",
"JSON",
"that",
"defines",
"the",
"current",
"view",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L40-L53 |
7,067 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | addUserAddedCatalog | function addUserAddedCatalog(terria, initSources) {
const localDataFilterRemembering = rememberRejections(
CatalogMember.itemFilters.noLocalData
);
const userAddedCatalog = terria.catalog.serializeToJson({
itemFilter: combineFilters([
localDataFilterRemembering.filter,
CatalogMember.itemFilters.userSuppliedOnly,
function(item) {
// If the parent has a URL then this item will just load from that, so don't bother serializing it.
// Properties that change when an item is enabled like opacity will be included in the shared members
// anyway.
return !item.parent || !item.parent.url;
}
])
});
// Add an init source with user-added catalog members.
if (userAddedCatalog.length > 0) {
initSources.push({
catalog: userAddedCatalog
});
}
return localDataFilterRemembering.rejections;
} | javascript | function addUserAddedCatalog(terria, initSources) {
const localDataFilterRemembering = rememberRejections(
CatalogMember.itemFilters.noLocalData
);
const userAddedCatalog = terria.catalog.serializeToJson({
itemFilter: combineFilters([
localDataFilterRemembering.filter,
CatalogMember.itemFilters.userSuppliedOnly,
function(item) {
// If the parent has a URL then this item will just load from that, so don't bother serializing it.
// Properties that change when an item is enabled like opacity will be included in the shared members
// anyway.
return !item.parent || !item.parent.url;
}
])
});
// Add an init source with user-added catalog members.
if (userAddedCatalog.length > 0) {
initSources.push({
catalog: userAddedCatalog
});
}
return localDataFilterRemembering.rejections;
} | [
"function",
"addUserAddedCatalog",
"(",
"terria",
",",
"initSources",
")",
"{",
"const",
"localDataFilterRemembering",
"=",
"rememberRejections",
"(",
"CatalogMember",
".",
"itemFilters",
".",
"noLocalData",
")",
";",
"const",
"userAddedCatalog",
"=",
"terria",
".",
"catalog",
".",
"serializeToJson",
"(",
"{",
"itemFilter",
":",
"combineFilters",
"(",
"[",
"localDataFilterRemembering",
".",
"filter",
",",
"CatalogMember",
".",
"itemFilters",
".",
"userSuppliedOnly",
",",
"function",
"(",
"item",
")",
"{",
"// If the parent has a URL then this item will just load from that, so don't bother serializing it.",
"// Properties that change when an item is enabled like opacity will be included in the shared members",
"// anyway.",
"return",
"!",
"item",
".",
"parent",
"||",
"!",
"item",
".",
"parent",
".",
"url",
";",
"}",
"]",
")",
"}",
")",
";",
"// Add an init source with user-added catalog members.",
"if",
"(",
"userAddedCatalog",
".",
"length",
">",
"0",
")",
"{",
"initSources",
".",
"push",
"(",
"{",
"catalog",
":",
"userAddedCatalog",
"}",
")",
";",
"}",
"return",
"localDataFilterRemembering",
".",
"rejections",
";",
"}"
] | Adds user-added catalog members to the passed initSources.
@private | [
"Adds",
"user",
"-",
"added",
"catalog",
"members",
"to",
"the",
"passed",
"initSources",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L89-L115 |
7,068 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | addSharedMembers | function addSharedMembers(terria, initSources) {
const catalogForSharing = flattenCatalog(
terria.catalog.serializeToJson({
itemFilter: combineFilters([CatalogMember.itemFilters.noLocalData]),
propertyFilter: combineFilters([
CatalogMember.propertyFilters.sharedOnly,
function(property) {
return property !== "name";
}
])
})
)
.filter(function(item) {
return item.isEnabled || item.isOpen;
})
.reduce(function(soFar, item) {
soFar[item.id] = item;
item.id = undefined;
return soFar;
}, {});
// Eliminate open groups without all ancestors open
Object.keys(catalogForSharing).forEach(key => {
const item = catalogForSharing[key];
const isGroupWithClosedParent =
item.isOpen &&
item.parents.some(parentId => !catalogForSharing[parentId]);
if (isGroupWithClosedParent) {
catalogForSharing[key] = undefined;
}
});
if (Object.keys(catalogForSharing).length > 0) {
initSources.push({
sharedCatalogMembers: catalogForSharing
});
}
} | javascript | function addSharedMembers(terria, initSources) {
const catalogForSharing = flattenCatalog(
terria.catalog.serializeToJson({
itemFilter: combineFilters([CatalogMember.itemFilters.noLocalData]),
propertyFilter: combineFilters([
CatalogMember.propertyFilters.sharedOnly,
function(property) {
return property !== "name";
}
])
})
)
.filter(function(item) {
return item.isEnabled || item.isOpen;
})
.reduce(function(soFar, item) {
soFar[item.id] = item;
item.id = undefined;
return soFar;
}, {});
// Eliminate open groups without all ancestors open
Object.keys(catalogForSharing).forEach(key => {
const item = catalogForSharing[key];
const isGroupWithClosedParent =
item.isOpen &&
item.parents.some(parentId => !catalogForSharing[parentId]);
if (isGroupWithClosedParent) {
catalogForSharing[key] = undefined;
}
});
if (Object.keys(catalogForSharing).length > 0) {
initSources.push({
sharedCatalogMembers: catalogForSharing
});
}
} | [
"function",
"addSharedMembers",
"(",
"terria",
",",
"initSources",
")",
"{",
"const",
"catalogForSharing",
"=",
"flattenCatalog",
"(",
"terria",
".",
"catalog",
".",
"serializeToJson",
"(",
"{",
"itemFilter",
":",
"combineFilters",
"(",
"[",
"CatalogMember",
".",
"itemFilters",
".",
"noLocalData",
"]",
")",
",",
"propertyFilter",
":",
"combineFilters",
"(",
"[",
"CatalogMember",
".",
"propertyFilters",
".",
"sharedOnly",
",",
"function",
"(",
"property",
")",
"{",
"return",
"property",
"!==",
"\"name\"",
";",
"}",
"]",
")",
"}",
")",
")",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"isEnabled",
"||",
"item",
".",
"isOpen",
";",
"}",
")",
".",
"reduce",
"(",
"function",
"(",
"soFar",
",",
"item",
")",
"{",
"soFar",
"[",
"item",
".",
"id",
"]",
"=",
"item",
";",
"item",
".",
"id",
"=",
"undefined",
";",
"return",
"soFar",
";",
"}",
",",
"{",
"}",
")",
";",
"// Eliminate open groups without all ancestors open",
"Object",
".",
"keys",
"(",
"catalogForSharing",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"const",
"item",
"=",
"catalogForSharing",
"[",
"key",
"]",
";",
"const",
"isGroupWithClosedParent",
"=",
"item",
".",
"isOpen",
"&&",
"item",
".",
"parents",
".",
"some",
"(",
"parentId",
"=>",
"!",
"catalogForSharing",
"[",
"parentId",
"]",
")",
";",
"if",
"(",
"isGroupWithClosedParent",
")",
"{",
"catalogForSharing",
"[",
"key",
"]",
"=",
"undefined",
";",
"}",
"}",
")",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"catalogForSharing",
")",
".",
"length",
">",
"0",
")",
"{",
"initSources",
".",
"push",
"(",
"{",
"sharedCatalogMembers",
":",
"catalogForSharing",
"}",
")",
";",
"}",
"}"
] | Adds existing catalog members that the user has enabled or opened to the passed initSources object.
@private | [
"Adds",
"existing",
"catalog",
"members",
"that",
"the",
"user",
"has",
"enabled",
"or",
"opened",
"to",
"the",
"passed",
"initSources",
"object",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L121-L159 |
7,069 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | addViewSettings | function addViewSettings(terria, initSources) {
const cameraExtent = terria.currentViewer.getCurrentExtent();
// Add an init source with the camera position.
const initialCamera = {
west: CesiumMath.toDegrees(cameraExtent.west),
south: CesiumMath.toDegrees(cameraExtent.south),
east: CesiumMath.toDegrees(cameraExtent.east),
north: CesiumMath.toDegrees(cameraExtent.north)
};
if (defined(terria.cesium)) {
const cesiumCamera = terria.cesium.scene.camera;
initialCamera.position = cesiumCamera.positionWC;
initialCamera.direction = cesiumCamera.directionWC;
initialCamera.up = cesiumCamera.upWC;
}
const homeCamera = {
west: CesiumMath.toDegrees(terria.homeView.rectangle.west),
south: CesiumMath.toDegrees(terria.homeView.rectangle.south),
east: CesiumMath.toDegrees(terria.homeView.rectangle.east),
north: CesiumMath.toDegrees(terria.homeView.rectangle.north),
position: terria.homeView.position,
direction: terria.homeView.direction,
up: terria.homeView.up
};
const time = {
dayNumber: terria.clock.currentTime.dayNumber,
secondsOfDay: terria.clock.currentTime.secondsOfDay
};
let viewerMode;
switch (terria.viewerMode) {
case ViewerMode.CesiumTerrain:
viewerMode = "3d";
break;
case ViewerMode.CesiumEllipsoid:
viewerMode = "3dSmooth";
break;
case ViewerMode.Leaflet:
viewerMode = "2d";
break;
}
const terriaSettings = {
initialCamera: initialCamera,
homeCamera: homeCamera,
baseMapName: terria.baseMap.name,
viewerMode: viewerMode,
currentTime: time
};
if (terria.showSplitter) {
terriaSettings.showSplitter = terria.showSplitter;
terriaSettings.splitPosition = terria.splitPosition;
}
initSources.push(terriaSettings);
} | javascript | function addViewSettings(terria, initSources) {
const cameraExtent = terria.currentViewer.getCurrentExtent();
// Add an init source with the camera position.
const initialCamera = {
west: CesiumMath.toDegrees(cameraExtent.west),
south: CesiumMath.toDegrees(cameraExtent.south),
east: CesiumMath.toDegrees(cameraExtent.east),
north: CesiumMath.toDegrees(cameraExtent.north)
};
if (defined(terria.cesium)) {
const cesiumCamera = terria.cesium.scene.camera;
initialCamera.position = cesiumCamera.positionWC;
initialCamera.direction = cesiumCamera.directionWC;
initialCamera.up = cesiumCamera.upWC;
}
const homeCamera = {
west: CesiumMath.toDegrees(terria.homeView.rectangle.west),
south: CesiumMath.toDegrees(terria.homeView.rectangle.south),
east: CesiumMath.toDegrees(terria.homeView.rectangle.east),
north: CesiumMath.toDegrees(terria.homeView.rectangle.north),
position: terria.homeView.position,
direction: terria.homeView.direction,
up: terria.homeView.up
};
const time = {
dayNumber: terria.clock.currentTime.dayNumber,
secondsOfDay: terria.clock.currentTime.secondsOfDay
};
let viewerMode;
switch (terria.viewerMode) {
case ViewerMode.CesiumTerrain:
viewerMode = "3d";
break;
case ViewerMode.CesiumEllipsoid:
viewerMode = "3dSmooth";
break;
case ViewerMode.Leaflet:
viewerMode = "2d";
break;
}
const terriaSettings = {
initialCamera: initialCamera,
homeCamera: homeCamera,
baseMapName: terria.baseMap.name,
viewerMode: viewerMode,
currentTime: time
};
if (terria.showSplitter) {
terriaSettings.showSplitter = terria.showSplitter;
terriaSettings.splitPosition = terria.splitPosition;
}
initSources.push(terriaSettings);
} | [
"function",
"addViewSettings",
"(",
"terria",
",",
"initSources",
")",
"{",
"const",
"cameraExtent",
"=",
"terria",
".",
"currentViewer",
".",
"getCurrentExtent",
"(",
")",
";",
"// Add an init source with the camera position.",
"const",
"initialCamera",
"=",
"{",
"west",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"cameraExtent",
".",
"west",
")",
",",
"south",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"cameraExtent",
".",
"south",
")",
",",
"east",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"cameraExtent",
".",
"east",
")",
",",
"north",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"cameraExtent",
".",
"north",
")",
"}",
";",
"if",
"(",
"defined",
"(",
"terria",
".",
"cesium",
")",
")",
"{",
"const",
"cesiumCamera",
"=",
"terria",
".",
"cesium",
".",
"scene",
".",
"camera",
";",
"initialCamera",
".",
"position",
"=",
"cesiumCamera",
".",
"positionWC",
";",
"initialCamera",
".",
"direction",
"=",
"cesiumCamera",
".",
"directionWC",
";",
"initialCamera",
".",
"up",
"=",
"cesiumCamera",
".",
"upWC",
";",
"}",
"const",
"homeCamera",
"=",
"{",
"west",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"terria",
".",
"homeView",
".",
"rectangle",
".",
"west",
")",
",",
"south",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"terria",
".",
"homeView",
".",
"rectangle",
".",
"south",
")",
",",
"east",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"terria",
".",
"homeView",
".",
"rectangle",
".",
"east",
")",
",",
"north",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"terria",
".",
"homeView",
".",
"rectangle",
".",
"north",
")",
",",
"position",
":",
"terria",
".",
"homeView",
".",
"position",
",",
"direction",
":",
"terria",
".",
"homeView",
".",
"direction",
",",
"up",
":",
"terria",
".",
"homeView",
".",
"up",
"}",
";",
"const",
"time",
"=",
"{",
"dayNumber",
":",
"terria",
".",
"clock",
".",
"currentTime",
".",
"dayNumber",
",",
"secondsOfDay",
":",
"terria",
".",
"clock",
".",
"currentTime",
".",
"secondsOfDay",
"}",
";",
"let",
"viewerMode",
";",
"switch",
"(",
"terria",
".",
"viewerMode",
")",
"{",
"case",
"ViewerMode",
".",
"CesiumTerrain",
":",
"viewerMode",
"=",
"\"3d\"",
";",
"break",
";",
"case",
"ViewerMode",
".",
"CesiumEllipsoid",
":",
"viewerMode",
"=",
"\"3dSmooth\"",
";",
"break",
";",
"case",
"ViewerMode",
".",
"Leaflet",
":",
"viewerMode",
"=",
"\"2d\"",
";",
"break",
";",
"}",
"const",
"terriaSettings",
"=",
"{",
"initialCamera",
":",
"initialCamera",
",",
"homeCamera",
":",
"homeCamera",
",",
"baseMapName",
":",
"terria",
".",
"baseMap",
".",
"name",
",",
"viewerMode",
":",
"viewerMode",
",",
"currentTime",
":",
"time",
"}",
";",
"if",
"(",
"terria",
".",
"showSplitter",
")",
"{",
"terriaSettings",
".",
"showSplitter",
"=",
"terria",
".",
"showSplitter",
";",
"terriaSettings",
".",
"splitPosition",
"=",
"terria",
".",
"splitPosition",
";",
"}",
"initSources",
".",
"push",
"(",
"terriaSettings",
")",
";",
"}"
] | Adds the details of the current view to the init sources.
@private | [
"Adds",
"the",
"details",
"of",
"the",
"current",
"view",
"to",
"the",
"init",
"sources",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L165-L223 |
7,070 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | addFeaturePicking | function addFeaturePicking(terria, initSources) {
if (
defined(terria.pickedFeatures) &&
terria.pickedFeatures.features.length > 0
) {
const positionInRadians = Ellipsoid.WGS84.cartesianToCartographic(
terria.pickedFeatures.pickPosition
);
const pickedFeatures = {
providerCoords: terria.pickedFeatures.providerCoords,
pickCoords: {
lat: CesiumMath.toDegrees(positionInRadians.latitude),
lng: CesiumMath.toDegrees(positionInRadians.longitude),
height: positionInRadians.height
}
};
if (defined(terria.selectedFeature)) {
// Sometimes features have stable ids and sometimes they're randomly generated every time, so include both
// id and name as a fallback.
pickedFeatures.current = {
name: terria.selectedFeature.name,
hash: hashEntity(terria.selectedFeature, terria.clock)
};
}
// Remember the ids of vector features only, the raster ones we can reconstruct from providerCoords.
pickedFeatures.entities = terria.pickedFeatures.features
.filter(feature => !defined(feature.imageryLayer))
.map(entity => {
return {
name: entity.name,
hash: hashEntity(entity, terria.clock)
};
});
initSources.push({
pickedFeatures: pickedFeatures
});
}
} | javascript | function addFeaturePicking(terria, initSources) {
if (
defined(terria.pickedFeatures) &&
terria.pickedFeatures.features.length > 0
) {
const positionInRadians = Ellipsoid.WGS84.cartesianToCartographic(
terria.pickedFeatures.pickPosition
);
const pickedFeatures = {
providerCoords: terria.pickedFeatures.providerCoords,
pickCoords: {
lat: CesiumMath.toDegrees(positionInRadians.latitude),
lng: CesiumMath.toDegrees(positionInRadians.longitude),
height: positionInRadians.height
}
};
if (defined(terria.selectedFeature)) {
// Sometimes features have stable ids and sometimes they're randomly generated every time, so include both
// id and name as a fallback.
pickedFeatures.current = {
name: terria.selectedFeature.name,
hash: hashEntity(terria.selectedFeature, terria.clock)
};
}
// Remember the ids of vector features only, the raster ones we can reconstruct from providerCoords.
pickedFeatures.entities = terria.pickedFeatures.features
.filter(feature => !defined(feature.imageryLayer))
.map(entity => {
return {
name: entity.name,
hash: hashEntity(entity, terria.clock)
};
});
initSources.push({
pickedFeatures: pickedFeatures
});
}
} | [
"function",
"addFeaturePicking",
"(",
"terria",
",",
"initSources",
")",
"{",
"if",
"(",
"defined",
"(",
"terria",
".",
"pickedFeatures",
")",
"&&",
"terria",
".",
"pickedFeatures",
".",
"features",
".",
"length",
">",
"0",
")",
"{",
"const",
"positionInRadians",
"=",
"Ellipsoid",
".",
"WGS84",
".",
"cartesianToCartographic",
"(",
"terria",
".",
"pickedFeatures",
".",
"pickPosition",
")",
";",
"const",
"pickedFeatures",
"=",
"{",
"providerCoords",
":",
"terria",
".",
"pickedFeatures",
".",
"providerCoords",
",",
"pickCoords",
":",
"{",
"lat",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"positionInRadians",
".",
"latitude",
")",
",",
"lng",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"positionInRadians",
".",
"longitude",
")",
",",
"height",
":",
"positionInRadians",
".",
"height",
"}",
"}",
";",
"if",
"(",
"defined",
"(",
"terria",
".",
"selectedFeature",
")",
")",
"{",
"// Sometimes features have stable ids and sometimes they're randomly generated every time, so include both",
"// id and name as a fallback.",
"pickedFeatures",
".",
"current",
"=",
"{",
"name",
":",
"terria",
".",
"selectedFeature",
".",
"name",
",",
"hash",
":",
"hashEntity",
"(",
"terria",
".",
"selectedFeature",
",",
"terria",
".",
"clock",
")",
"}",
";",
"}",
"// Remember the ids of vector features only, the raster ones we can reconstruct from providerCoords.",
"pickedFeatures",
".",
"entities",
"=",
"terria",
".",
"pickedFeatures",
".",
"features",
".",
"filter",
"(",
"feature",
"=>",
"!",
"defined",
"(",
"feature",
".",
"imageryLayer",
")",
")",
".",
"map",
"(",
"entity",
"=>",
"{",
"return",
"{",
"name",
":",
"entity",
".",
"name",
",",
"hash",
":",
"hashEntity",
"(",
"entity",
",",
"terria",
".",
"clock",
")",
"}",
";",
"}",
")",
";",
"initSources",
".",
"push",
"(",
"{",
"pickedFeatures",
":",
"pickedFeatures",
"}",
")",
";",
"}",
"}"
] | Add details of currently picked features.
@private | [
"Add",
"details",
"of",
"currently",
"picked",
"features",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L229-L270 |
7,071 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | addLocationMarker | function addLocationMarker(terria, initSources) {
if (defined(terria.locationMarker)) {
const position = terria.locationMarker.entities.values[0].position.getValue();
const positionDegrees = Ellipsoid.WGS84.cartesianToCartographic(position);
initSources.push({
locationMarker: {
name: terria.locationMarker.entities.values[0].name,
latitude: CesiumMath.toDegrees(positionDegrees.latitude),
longitude: CesiumMath.toDegrees(positionDegrees.longitude)
}
});
}
} | javascript | function addLocationMarker(terria, initSources) {
if (defined(terria.locationMarker)) {
const position = terria.locationMarker.entities.values[0].position.getValue();
const positionDegrees = Ellipsoid.WGS84.cartesianToCartographic(position);
initSources.push({
locationMarker: {
name: terria.locationMarker.entities.values[0].name,
latitude: CesiumMath.toDegrees(positionDegrees.latitude),
longitude: CesiumMath.toDegrees(positionDegrees.longitude)
}
});
}
} | [
"function",
"addLocationMarker",
"(",
"terria",
",",
"initSources",
")",
"{",
"if",
"(",
"defined",
"(",
"terria",
".",
"locationMarker",
")",
")",
"{",
"const",
"position",
"=",
"terria",
".",
"locationMarker",
".",
"entities",
".",
"values",
"[",
"0",
"]",
".",
"position",
".",
"getValue",
"(",
")",
";",
"const",
"positionDegrees",
"=",
"Ellipsoid",
".",
"WGS84",
".",
"cartesianToCartographic",
"(",
"position",
")",
";",
"initSources",
".",
"push",
"(",
"{",
"locationMarker",
":",
"{",
"name",
":",
"terria",
".",
"locationMarker",
".",
"entities",
".",
"values",
"[",
"0",
"]",
".",
"name",
",",
"latitude",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"positionDegrees",
".",
"latitude",
")",
",",
"longitude",
":",
"CesiumMath",
".",
"toDegrees",
"(",
"positionDegrees",
".",
"longitude",
")",
"}",
"}",
")",
";",
"}",
"}"
] | Add details of the location marker if it is set.
@private | [
"Add",
"details",
"of",
"the",
"location",
"marker",
"if",
"it",
"is",
"set",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L276-L289 |
7,072 | TerriaJS/terriajs | lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js | rememberRejections | function rememberRejections(filterFn) {
const rejections = [];
return {
filter: function(item) {
const allowed = filterFn(item);
if (!allowed) {
rejections.push(item);
}
return allowed;
},
rejections: rejections
};
} | javascript | function rememberRejections(filterFn) {
const rejections = [];
return {
filter: function(item) {
const allowed = filterFn(item);
if (!allowed) {
rejections.push(item);
}
return allowed;
},
rejections: rejections
};
} | [
"function",
"rememberRejections",
"(",
"filterFn",
")",
"{",
"const",
"rejections",
"=",
"[",
"]",
";",
"return",
"{",
"filter",
":",
"function",
"(",
"item",
")",
"{",
"const",
"allowed",
"=",
"filterFn",
"(",
"item",
")",
";",
"if",
"(",
"!",
"allowed",
")",
"{",
"rejections",
".",
"push",
"(",
"item",
")",
";",
"}",
"return",
"allowed",
";",
"}",
",",
"rejections",
":",
"rejections",
"}",
";",
"}"
] | Wraps around a filter function and records all items that are excluded by it. Does not modify the function passed in.
@param filterFn The fn to wrap around
@returns {{filter: filter, rejections: Array}} The resulting filter function that remembers rejections, and an array
array of the rejected items. As the filter function is used, the rejections array with be populated. | [
"Wraps",
"around",
"a",
"filter",
"function",
"and",
"records",
"all",
"items",
"that",
"are",
"excluded",
"by",
"it",
".",
"Does",
"not",
"modify",
"the",
"function",
"passed",
"in",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Map/Panels/SharePanel/BuildShareLink.js#L298-L313 |
7,073 | TerriaJS/terriajs | lib/Models/getAncestors.js | getAncestors | function getAncestors(member) {
var parent = member.parent;
var ancestors = [];
while (defined(parent) && defined(parent.parent)) {
ancestors = [parent].concat(ancestors);
parent = parent.parent;
}
return ancestors;
} | javascript | function getAncestors(member) {
var parent = member.parent;
var ancestors = [];
while (defined(parent) && defined(parent.parent)) {
ancestors = [parent].concat(ancestors);
parent = parent.parent;
}
return ancestors;
} | [
"function",
"getAncestors",
"(",
"member",
")",
"{",
"var",
"parent",
"=",
"member",
".",
"parent",
";",
"var",
"ancestors",
"=",
"[",
"]",
";",
"while",
"(",
"defined",
"(",
"parent",
")",
"&&",
"defined",
"(",
"parent",
".",
"parent",
")",
")",
"{",
"ancestors",
"=",
"[",
"parent",
"]",
".",
"concat",
"(",
"ancestors",
")",
";",
"parent",
"=",
"parent",
".",
"parent",
";",
"}",
"return",
"ancestors",
";",
"}"
] | Return the ancestors in the data catalog of the given catalog member, recursively using "member.parent".
The "Root Group" is not included.
@param {CatalogMember} member The catalog member.
@return {CatalogMember[]} The members' ancestors in its parent tree, starting at the top, not including this member. | [
"Return",
"the",
"ancestors",
"in",
"the",
"data",
"catalog",
"of",
"the",
"given",
"catalog",
"member",
"recursively",
"using",
"member",
".",
"parent",
".",
"The",
"Root",
"Group",
"is",
"not",
"included",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/getAncestors.js#L12-L20 |
7,074 | TerriaJS/terriajs | lib/ReactViews/Preview/Description.js | getBetterFileName | function getBetterFileName(dataUrlType, itemName, format) {
let name = itemName;
const extension = "." + format;
// Only add the extension if it's not already there.
if (name.indexOf(extension) !== name.length - extension.length) {
name = name + extension;
}
// For local files, the file already exists on the user's computer with the original name, so give it a modified name.
if (dataUrlType === "local") {
name = "processed " + name;
}
return name;
} | javascript | function getBetterFileName(dataUrlType, itemName, format) {
let name = itemName;
const extension = "." + format;
// Only add the extension if it's not already there.
if (name.indexOf(extension) !== name.length - extension.length) {
name = name + extension;
}
// For local files, the file already exists on the user's computer with the original name, so give it a modified name.
if (dataUrlType === "local") {
name = "processed " + name;
}
return name;
} | [
"function",
"getBetterFileName",
"(",
"dataUrlType",
",",
"itemName",
",",
"format",
")",
"{",
"let",
"name",
"=",
"itemName",
";",
"const",
"extension",
"=",
"\".\"",
"+",
"format",
";",
"// Only add the extension if it's not already there.",
"if",
"(",
"name",
".",
"indexOf",
"(",
"extension",
")",
"!==",
"name",
".",
"length",
"-",
"extension",
".",
"length",
")",
"{",
"name",
"=",
"name",
"+",
"extension",
";",
"}",
"// For local files, the file already exists on the user's computer with the original name, so give it a modified name.",
"if",
"(",
"dataUrlType",
"===",
"\"local\"",
")",
"{",
"name",
"=",
"\"processed \"",
"+",
"name",
";",
"}",
"return",
"name",
";",
"}"
] | Return a nicer filename for this file.
@private | [
"Return",
"a",
"nicer",
"filename",
"for",
"this",
"file",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Preview/Description.js#L329-L341 |
7,075 | TerriaJS/terriajs | lib/Map/RegionProvider.js | applyReplacements | function applyReplacements(regionProvider, s, replacementsProp) {
if (!defined(s)) {
return undefined;
}
var r;
if (typeof s === "number") {
r = String(s);
} else {
r = s.toLowerCase().trim();
}
var replacements = regionProvider[replacementsProp];
if (replacements === undefined || replacements.length === 0) {
return r;
}
if (regionProvider._appliedReplacements[replacementsProp][r] !== undefined) {
return regionProvider._appliedReplacements[replacementsProp][r];
}
replacements.forEach(function(rep) {
r = r.replace(rep[2], rep[1]);
});
regionProvider._appliedReplacements[replacementsProp][s] = r;
return r;
} | javascript | function applyReplacements(regionProvider, s, replacementsProp) {
if (!defined(s)) {
return undefined;
}
var r;
if (typeof s === "number") {
r = String(s);
} else {
r = s.toLowerCase().trim();
}
var replacements = regionProvider[replacementsProp];
if (replacements === undefined || replacements.length === 0) {
return r;
}
if (regionProvider._appliedReplacements[replacementsProp][r] !== undefined) {
return regionProvider._appliedReplacements[replacementsProp][r];
}
replacements.forEach(function(rep) {
r = r.replace(rep[2], rep[1]);
});
regionProvider._appliedReplacements[replacementsProp][s] = r;
return r;
} | [
"function",
"applyReplacements",
"(",
"regionProvider",
",",
"s",
",",
"replacementsProp",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"s",
")",
")",
"{",
"return",
"undefined",
";",
"}",
"var",
"r",
";",
"if",
"(",
"typeof",
"s",
"===",
"\"number\"",
")",
"{",
"r",
"=",
"String",
"(",
"s",
")",
";",
"}",
"else",
"{",
"r",
"=",
"s",
".",
"toLowerCase",
"(",
")",
".",
"trim",
"(",
")",
";",
"}",
"var",
"replacements",
"=",
"regionProvider",
"[",
"replacementsProp",
"]",
";",
"if",
"(",
"replacements",
"===",
"undefined",
"||",
"replacements",
".",
"length",
"===",
"0",
")",
"{",
"return",
"r",
";",
"}",
"if",
"(",
"regionProvider",
".",
"_appliedReplacements",
"[",
"replacementsProp",
"]",
"[",
"r",
"]",
"!==",
"undefined",
")",
"{",
"return",
"regionProvider",
".",
"_appliedReplacements",
"[",
"replacementsProp",
"]",
"[",
"r",
"]",
";",
"}",
"replacements",
".",
"forEach",
"(",
"function",
"(",
"rep",
")",
"{",
"r",
"=",
"r",
".",
"replace",
"(",
"rep",
"[",
"2",
"]",
",",
"rep",
"[",
"1",
"]",
")",
";",
"}",
")",
";",
"regionProvider",
".",
"_appliedReplacements",
"[",
"replacementsProp",
"]",
"[",
"s",
"]",
"=",
"r",
";",
"return",
"r",
";",
"}"
] | Apply an array of regular expression replacements to a string. Also caches the applied replacements in regionProvider._appliedReplacements.
@private
@param {RegionProvider} regionProvider The RegionProvider instance.
@param {String} s The string.
@param {String} replacementsProp Name of a property containing [ [ regex, replacement], ... ], where replacement is a string which can contain '$1' etc. | [
"Apply",
"an",
"array",
"of",
"regular",
"expression",
"replacements",
"to",
"a",
"string",
".",
"Also",
"caches",
"the",
"applied",
"replacements",
"in",
"regionProvider",
".",
"_appliedReplacements",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/RegionProvider.js#L689-L713 |
7,076 | TerriaJS/terriajs | lib/Map/RegionProvider.js | findRegionIndex | function findRegionIndex(regionProvider, code, disambigCode) {
if (!defined(code) || code === "") {
// Note a code of 0 is ok
return -1;
}
var processedCode = applyReplacements(
regionProvider,
code,
"dataReplacements"
);
var id = regionProvider._idIndex[processedCode];
if (!defined(id)) {
// didn't find anything
return -1;
} else if (typeof id === "number") {
// found an unambiguous match
return id;
} else {
var ids = id; // found an ambiguous match
if (!defined(disambigCode)) {
// we have an ambiguous value, but nothing with which to disambiguate. We pick the first, warn.
console.warn("Ambiguous value found in region mapping: " + processedCode);
return ids[0];
}
var processedDisambigCode = applyReplacements(
regionProvider,
disambigCode,
"disambigDataReplacements"
);
// Check out each of the matching IDs to see if the disambiguation field matches the one we have.
for (var i = 0; i < ids.length; i++) {
if (
regionProvider.regions[ids[i]][regionProvider.disambigProp] ===
processedDisambigCode
) {
return ids[i];
}
}
}
return -1;
} | javascript | function findRegionIndex(regionProvider, code, disambigCode) {
if (!defined(code) || code === "") {
// Note a code of 0 is ok
return -1;
}
var processedCode = applyReplacements(
regionProvider,
code,
"dataReplacements"
);
var id = regionProvider._idIndex[processedCode];
if (!defined(id)) {
// didn't find anything
return -1;
} else if (typeof id === "number") {
// found an unambiguous match
return id;
} else {
var ids = id; // found an ambiguous match
if (!defined(disambigCode)) {
// we have an ambiguous value, but nothing with which to disambiguate. We pick the first, warn.
console.warn("Ambiguous value found in region mapping: " + processedCode);
return ids[0];
}
var processedDisambigCode = applyReplacements(
regionProvider,
disambigCode,
"disambigDataReplacements"
);
// Check out each of the matching IDs to see if the disambiguation field matches the one we have.
for (var i = 0; i < ids.length; i++) {
if (
regionProvider.regions[ids[i]][regionProvider.disambigProp] ===
processedDisambigCode
) {
return ids[i];
}
}
}
return -1;
} | [
"function",
"findRegionIndex",
"(",
"regionProvider",
",",
"code",
",",
"disambigCode",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"code",
")",
"||",
"code",
"===",
"\"\"",
")",
"{",
"// Note a code of 0 is ok",
"return",
"-",
"1",
";",
"}",
"var",
"processedCode",
"=",
"applyReplacements",
"(",
"regionProvider",
",",
"code",
",",
"\"dataReplacements\"",
")",
";",
"var",
"id",
"=",
"regionProvider",
".",
"_idIndex",
"[",
"processedCode",
"]",
";",
"if",
"(",
"!",
"defined",
"(",
"id",
")",
")",
"{",
"// didn't find anything",
"return",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"typeof",
"id",
"===",
"\"number\"",
")",
"{",
"// found an unambiguous match",
"return",
"id",
";",
"}",
"else",
"{",
"var",
"ids",
"=",
"id",
";",
"// found an ambiguous match",
"if",
"(",
"!",
"defined",
"(",
"disambigCode",
")",
")",
"{",
"// we have an ambiguous value, but nothing with which to disambiguate. We pick the first, warn.",
"console",
".",
"warn",
"(",
"\"Ambiguous value found in region mapping: \"",
"+",
"processedCode",
")",
";",
"return",
"ids",
"[",
"0",
"]",
";",
"}",
"var",
"processedDisambigCode",
"=",
"applyReplacements",
"(",
"regionProvider",
",",
"disambigCode",
",",
"\"disambigDataReplacements\"",
")",
";",
"// Check out each of the matching IDs to see if the disambiguation field matches the one we have.",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ids",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"regionProvider",
".",
"regions",
"[",
"ids",
"[",
"i",
"]",
"]",
"[",
"regionProvider",
".",
"disambigProp",
"]",
"===",
"processedDisambigCode",
")",
"{",
"return",
"ids",
"[",
"i",
"]",
";",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Given a region code, try to find a region that matches it, using replacements, disambiguation, indexes and other wizardry.
@private
@param {RegionProvider} regionProvider The RegionProvider instance.
@param {String} code Code to search for. Falsy codes return -1.
@returns {Number} Zero-based index in list of regions if successful, or -1. | [
"Given",
"a",
"region",
"code",
"try",
"to",
"find",
"a",
"region",
"that",
"matches",
"it",
"using",
"replacements",
"disambiguation",
"indexes",
"and",
"other",
"wizardry",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/RegionProvider.js#L722-L763 |
7,077 | TerriaJS/terriajs | lib/ReactViews/Custom/registerCustomComponentTypes.js | getSourceData | function getSourceData(node, children) {
const sourceData = node.attribs["data"];
if (sourceData) {
return sourceData;
}
if (Array.isArray(children) && children.length > 0) {
return children[0];
}
return children;
} | javascript | function getSourceData(node, children) {
const sourceData = node.attribs["data"];
if (sourceData) {
return sourceData;
}
if (Array.isArray(children) && children.length > 0) {
return children[0];
}
return children;
} | [
"function",
"getSourceData",
"(",
"node",
",",
"children",
")",
"{",
"const",
"sourceData",
"=",
"node",
".",
"attribs",
"[",
"\"data\"",
"]",
";",
"if",
"(",
"sourceData",
")",
"{",
"return",
"sourceData",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"children",
")",
"&&",
"children",
".",
"length",
">",
"0",
")",
"{",
"return",
"children",
"[",
"0",
"]",
";",
"}",
"return",
"children",
";",
"}"
] | Returns the 'data' attribute if available, otherwise the child of this node.
@private | [
"Returns",
"the",
"data",
"attribute",
"if",
"available",
"otherwise",
"the",
"child",
"of",
"this",
"node",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Custom/registerCustomComponentTypes.js#L249-L258 |
7,078 | TerriaJS/terriajs | lib/ReactViews/Custom/registerCustomComponentTypes.js | tableStructureFromStringData | function tableStructureFromStringData(stringData) {
// sourceData can be either json (starts with a '[') or csv format (contains a true line feed or '\n'; \n is replaced with a real linefeed).
if (!defined(stringData) || stringData.length < 2) {
return;
}
// We prevent ALT, LON and LAT from being chosen, since we know this is a non-geo csv already.
const result = new TableStructure("chart", {
unallowedTypes: [VarType.ALT, VarType.LAT, VarType.LON]
});
if (stringData[0] === "[") {
// Treat as json.
const json = JSON.parse(stringData.replace(/"/g, '"'));
return TableStructure.fromJson(json, result);
}
if (stringData.indexOf("\\n") >= 0 || stringData.indexOf("\n") >= 0) {
// Treat as csv.
return TableStructure.fromCsv(stringData.replace(/\\n/g, "\n"), result);
}
} | javascript | function tableStructureFromStringData(stringData) {
// sourceData can be either json (starts with a '[') or csv format (contains a true line feed or '\n'; \n is replaced with a real linefeed).
if (!defined(stringData) || stringData.length < 2) {
return;
}
// We prevent ALT, LON and LAT from being chosen, since we know this is a non-geo csv already.
const result = new TableStructure("chart", {
unallowedTypes: [VarType.ALT, VarType.LAT, VarType.LON]
});
if (stringData[0] === "[") {
// Treat as json.
const json = JSON.parse(stringData.replace(/"/g, '"'));
return TableStructure.fromJson(json, result);
}
if (stringData.indexOf("\\n") >= 0 || stringData.indexOf("\n") >= 0) {
// Treat as csv.
return TableStructure.fromCsv(stringData.replace(/\\n/g, "\n"), result);
}
} | [
"function",
"tableStructureFromStringData",
"(",
"stringData",
")",
"{",
"// sourceData can be either json (starts with a '[') or csv format (contains a true line feed or '\\n'; \\n is replaced with a real linefeed).",
"if",
"(",
"!",
"defined",
"(",
"stringData",
")",
"||",
"stringData",
".",
"length",
"<",
"2",
")",
"{",
"return",
";",
"}",
"// We prevent ALT, LON and LAT from being chosen, since we know this is a non-geo csv already.",
"const",
"result",
"=",
"new",
"TableStructure",
"(",
"\"chart\"",
",",
"{",
"unallowedTypes",
":",
"[",
"VarType",
".",
"ALT",
",",
"VarType",
".",
"LAT",
",",
"VarType",
".",
"LON",
"]",
"}",
")",
";",
"if",
"(",
"stringData",
"[",
"0",
"]",
"===",
"\"[\"",
")",
"{",
"// Treat as json.",
"const",
"json",
"=",
"JSON",
".",
"parse",
"(",
"stringData",
".",
"replace",
"(",
"/",
""",
"/",
"g",
",",
"'\"'",
")",
")",
";",
"return",
"TableStructure",
".",
"fromJson",
"(",
"json",
",",
"result",
")",
";",
"}",
"if",
"(",
"stringData",
".",
"indexOf",
"(",
"\"\\\\n\"",
")",
">=",
"0",
"||",
"stringData",
".",
"indexOf",
"(",
"\"\\n\"",
")",
">=",
"0",
")",
"{",
"// Treat as csv.",
"return",
"TableStructure",
".",
"fromCsv",
"(",
"stringData",
".",
"replace",
"(",
"/",
"\\\\n",
"/",
"g",
",",
"\"\\n\"",
")",
",",
"result",
")",
";",
"}",
"}"
] | This function does not activate any columns in itself.
That should be done by TableCatalogItem when it is created around this.
@private | [
"This",
"function",
"does",
"not",
"activate",
"any",
"columns",
"in",
"itself",
".",
"That",
"should",
"be",
"done",
"by",
"TableCatalogItem",
"when",
"it",
"is",
"created",
"around",
"this",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Custom/registerCustomComponentTypes.js#L265-L283 |
7,079 | TerriaJS/terriajs | lib/Core/readJson.js | readJson | function readJson(file) {
return when(
readText(file),
function(result) {
try {
return JSON.parse(result);
} catch (e) {
if (e instanceof SyntaxError) {
return json5.parse(result);
} else {
throw e;
}
}
},
function(e) {
throw e;
}
);
} | javascript | function readJson(file) {
return when(
readText(file),
function(result) {
try {
return JSON.parse(result);
} catch (e) {
if (e instanceof SyntaxError) {
return json5.parse(result);
} else {
throw e;
}
}
},
function(e) {
throw e;
}
);
} | [
"function",
"readJson",
"(",
"file",
")",
"{",
"return",
"when",
"(",
"readText",
"(",
"file",
")",
",",
"function",
"(",
"result",
")",
"{",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"result",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"e",
"instanceof",
"SyntaxError",
")",
"{",
"return",
"json5",
".",
"parse",
"(",
"result",
")",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}",
",",
"function",
"(",
"e",
")",
"{",
"throw",
"e",
";",
"}",
")",
";",
"}"
] | Try to read the file as JSON. If that fails, try JSON5.
@param {File} file The file.
@return {Object} The JSON or json5 object described by the file. | [
"Try",
"to",
"read",
"the",
"file",
"as",
"JSON",
".",
"If",
"that",
"fails",
"try",
"JSON5",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/readJson.js#L14-L32 |
7,080 | TerriaJS/terriajs | lib/Models/GeoJsonParameter.js | function(options) {
FunctionParameter.call(this, options);
this.regionParameter = options.regionParameter;
this.value = "";
this._subtype = undefined;
} | javascript | function(options) {
FunctionParameter.call(this, options);
this.regionParameter = options.regionParameter;
this.value = "";
this._subtype = undefined;
} | [
"function",
"(",
"options",
")",
"{",
"FunctionParameter",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"regionParameter",
"=",
"options",
".",
"regionParameter",
";",
"this",
".",
"value",
"=",
"\"\"",
";",
"this",
".",
"_subtype",
"=",
"undefined",
";",
"}"
] | A parameter that specifies an arbitrary polygon on the globe.
@alias GeoJsonParameter
@constructor
@extends FunctionParameter
@param {Object} options Object with the following properties:
@param {Terria} options.terria The Terria instance.
@param {String} options.id The unique ID of this parameter.
@param {String} [options.name] The name of this parameter. If not specified, the ID is used as the name.
@param {String} [options.description] The description of the parameter.
@param {Boolean} [options.defaultValue] The default value. | [
"A",
"parameter",
"that",
"specifies",
"an",
"arbitrary",
"polygon",
"on",
"the",
"globe",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/GeoJsonParameter.js#L26-L31 |
|
7,081 | TerriaJS/terriajs | lib/Models/createCatalogItemFromFileOrUrl.js | function(
terria,
viewState,
fileOrUrl,
dataType,
confirmConversion
) {
function tryConversionService(newItem) {
if (terria.configParameters.conversionServiceBaseUrl === false) {
// Don't allow conversion service. Duplicated in OgrCatalogItem.js
terria.error.raiseEvent(
new TerriaError({
title: "Unsupported file type",
message:
"This file format is not supported by " +
terria.appName +
". Supported file formats include: " +
'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href="https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au">csv-geo-au format</a>)</li></ul>'
})
);
return undefined;
} else if (
name.match(
/\.(shp|jpg|jpeg|pdf|xlsx|xls|tif|tiff|png|txt|doc|docx|xml|json)$/
)
) {
terria.error.raiseEvent(
new TerriaError({
title: "Unsupported file type",
message:
"This file format is not supported by " +
terria.appName +
". Directly supported file formats include: " +
'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href="https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au">csv-geo-au format</a>)</li></ul>' +
"File formats supported through the online conversion service include: " +
'<ul><li>Shapefile (.zip)</li><li>MapInfo TAB (.zip)</li><li>Possibly other <a href="http://www.gdal.org/ogr_formats.html">OGR Vector Formats</a></li></ul>'
})
);
return undefined;
}
return getConfirmation(
terria,
viewState,
confirmConversion,
"This file is not directly supported by " +
terria.appName +
".\n\n" +
"Do you want to try uploading it to the " +
terria.appName +
" conversion service? This may work for " +
"small, zipped Esri Shapefiles or MapInfo TAB files."
).then(function(confirmed) {
return confirmed
? loadItem(new OgrCatalogItem(terria), name, fileOrUrl)
: undefined;
});
}
var isUrl = typeof fileOrUrl === "string";
dataType = defaultValue(dataType, "auto");
var name = isUrl ? fileOrUrl : fileOrUrl.name;
if (dataType === "auto") {
return when(createCatalogItemFromUrl(name, terria, isUrl)).then(function(
newItem
) {
//##Doesn't work for file uploads
if (!defined(newItem)) {
return tryConversionService();
} else {
// It's a file or service we support directly
// In some cases (web services), the item will already have been loaded by this point.
return loadItem(newItem, name, fileOrUrl);
}
});
} else if (dataType === "other") {
// user explicitly chose "Other (use conversion service)"
return getConfirmation(
terria,
viewState,
confirmConversion,
"Ready to upload your file to the " +
terria.appName +
" conversion service?"
).then(function(confirmed) {
return confirmed
? loadItem(createCatalogMemberFromType("ogr", terria), name, fileOrUrl)
: undefined;
});
} else {
// User has provided a type, so we go with that.
return loadItem(
createCatalogMemberFromType(dataType, terria),
name,
fileOrUrl
);
}
} | javascript | function(
terria,
viewState,
fileOrUrl,
dataType,
confirmConversion
) {
function tryConversionService(newItem) {
if (terria.configParameters.conversionServiceBaseUrl === false) {
// Don't allow conversion service. Duplicated in OgrCatalogItem.js
terria.error.raiseEvent(
new TerriaError({
title: "Unsupported file type",
message:
"This file format is not supported by " +
terria.appName +
". Supported file formats include: " +
'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href="https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au">csv-geo-au format</a>)</li></ul>'
})
);
return undefined;
} else if (
name.match(
/\.(shp|jpg|jpeg|pdf|xlsx|xls|tif|tiff|png|txt|doc|docx|xml|json)$/
)
) {
terria.error.raiseEvent(
new TerriaError({
title: "Unsupported file type",
message:
"This file format is not supported by " +
terria.appName +
". Directly supported file formats include: " +
'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href="https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au">csv-geo-au format</a>)</li></ul>' +
"File formats supported through the online conversion service include: " +
'<ul><li>Shapefile (.zip)</li><li>MapInfo TAB (.zip)</li><li>Possibly other <a href="http://www.gdal.org/ogr_formats.html">OGR Vector Formats</a></li></ul>'
})
);
return undefined;
}
return getConfirmation(
terria,
viewState,
confirmConversion,
"This file is not directly supported by " +
terria.appName +
".\n\n" +
"Do you want to try uploading it to the " +
terria.appName +
" conversion service? This may work for " +
"small, zipped Esri Shapefiles or MapInfo TAB files."
).then(function(confirmed) {
return confirmed
? loadItem(new OgrCatalogItem(terria), name, fileOrUrl)
: undefined;
});
}
var isUrl = typeof fileOrUrl === "string";
dataType = defaultValue(dataType, "auto");
var name = isUrl ? fileOrUrl : fileOrUrl.name;
if (dataType === "auto") {
return when(createCatalogItemFromUrl(name, terria, isUrl)).then(function(
newItem
) {
//##Doesn't work for file uploads
if (!defined(newItem)) {
return tryConversionService();
} else {
// It's a file or service we support directly
// In some cases (web services), the item will already have been loaded by this point.
return loadItem(newItem, name, fileOrUrl);
}
});
} else if (dataType === "other") {
// user explicitly chose "Other (use conversion service)"
return getConfirmation(
terria,
viewState,
confirmConversion,
"Ready to upload your file to the " +
terria.appName +
" conversion service?"
).then(function(confirmed) {
return confirmed
? loadItem(createCatalogMemberFromType("ogr", terria), name, fileOrUrl)
: undefined;
});
} else {
// User has provided a type, so we go with that.
return loadItem(
createCatalogMemberFromType(dataType, terria),
name,
fileOrUrl
);
}
} | [
"function",
"(",
"terria",
",",
"viewState",
",",
"fileOrUrl",
",",
"dataType",
",",
"confirmConversion",
")",
"{",
"function",
"tryConversionService",
"(",
"newItem",
")",
"{",
"if",
"(",
"terria",
".",
"configParameters",
".",
"conversionServiceBaseUrl",
"===",
"false",
")",
"{",
"// Don't allow conversion service. Duplicated in OgrCatalogItem.js",
"terria",
".",
"error",
".",
"raiseEvent",
"(",
"new",
"TerriaError",
"(",
"{",
"title",
":",
"\"Unsupported file type\"",
",",
"message",
":",
"\"This file format is not supported by \"",
"+",
"terria",
".",
"appName",
"+",
"\". Supported file formats include: \"",
"+",
"'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href=\"https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au\">csv-geo-au format</a>)</li></ul>'",
"}",
")",
")",
";",
"return",
"undefined",
";",
"}",
"else",
"if",
"(",
"name",
".",
"match",
"(",
"/",
"\\.(shp|jpg|jpeg|pdf|xlsx|xls|tif|tiff|png|txt|doc|docx|xml|json)$",
"/",
")",
")",
"{",
"terria",
".",
"error",
".",
"raiseEvent",
"(",
"new",
"TerriaError",
"(",
"{",
"title",
":",
"\"Unsupported file type\"",
",",
"message",
":",
"\"This file format is not supported by \"",
"+",
"terria",
".",
"appName",
"+",
"\". Directly supported file formats include: \"",
"+",
"'<ul><li>.geojson</li><li>.kml, .kmz</li><li>.csv (in <a href=\"https://github.com/TerriaJS/nationalmap/wiki/csv-geo-au\">csv-geo-au format</a>)</li></ul>'",
"+",
"\"File formats supported through the online conversion service include: \"",
"+",
"'<ul><li>Shapefile (.zip)</li><li>MapInfo TAB (.zip)</li><li>Possibly other <a href=\"http://www.gdal.org/ogr_formats.html\">OGR Vector Formats</a></li></ul>'",
"}",
")",
")",
";",
"return",
"undefined",
";",
"}",
"return",
"getConfirmation",
"(",
"terria",
",",
"viewState",
",",
"confirmConversion",
",",
"\"This file is not directly supported by \"",
"+",
"terria",
".",
"appName",
"+",
"\".\\n\\n\"",
"+",
"\"Do you want to try uploading it to the \"",
"+",
"terria",
".",
"appName",
"+",
"\" conversion service? This may work for \"",
"+",
"\"small, zipped Esri Shapefiles or MapInfo TAB files.\"",
")",
".",
"then",
"(",
"function",
"(",
"confirmed",
")",
"{",
"return",
"confirmed",
"?",
"loadItem",
"(",
"new",
"OgrCatalogItem",
"(",
"terria",
")",
",",
"name",
",",
"fileOrUrl",
")",
":",
"undefined",
";",
"}",
")",
";",
"}",
"var",
"isUrl",
"=",
"typeof",
"fileOrUrl",
"===",
"\"string\"",
";",
"dataType",
"=",
"defaultValue",
"(",
"dataType",
",",
"\"auto\"",
")",
";",
"var",
"name",
"=",
"isUrl",
"?",
"fileOrUrl",
":",
"fileOrUrl",
".",
"name",
";",
"if",
"(",
"dataType",
"===",
"\"auto\"",
")",
"{",
"return",
"when",
"(",
"createCatalogItemFromUrl",
"(",
"name",
",",
"terria",
",",
"isUrl",
")",
")",
".",
"then",
"(",
"function",
"(",
"newItem",
")",
"{",
"//##Doesn't work for file uploads",
"if",
"(",
"!",
"defined",
"(",
"newItem",
")",
")",
"{",
"return",
"tryConversionService",
"(",
")",
";",
"}",
"else",
"{",
"// It's a file or service we support directly",
"// In some cases (web services), the item will already have been loaded by this point.",
"return",
"loadItem",
"(",
"newItem",
",",
"name",
",",
"fileOrUrl",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"dataType",
"===",
"\"other\"",
")",
"{",
"// user explicitly chose \"Other (use conversion service)\"",
"return",
"getConfirmation",
"(",
"terria",
",",
"viewState",
",",
"confirmConversion",
",",
"\"Ready to upload your file to the \"",
"+",
"terria",
".",
"appName",
"+",
"\" conversion service?\"",
")",
".",
"then",
"(",
"function",
"(",
"confirmed",
")",
"{",
"return",
"confirmed",
"?",
"loadItem",
"(",
"createCatalogMemberFromType",
"(",
"\"ogr\"",
",",
"terria",
")",
",",
"name",
",",
"fileOrUrl",
")",
":",
"undefined",
";",
"}",
")",
";",
"}",
"else",
"{",
"// User has provided a type, so we go with that.",
"return",
"loadItem",
"(",
"createCatalogMemberFromType",
"(",
"dataType",
",",
"terria",
")",
",",
"name",
",",
"fileOrUrl",
")",
";",
"}",
"}"
] | Asynchronously creates and loads a catalog item for a given file. The returned promise does not resolve until
the catalog item is successfully loaded, and it rejects if the file is not in the expected format or
another error occurs during loading. If the OGR-based conversion service needs to be invoked to convert the file or URL
to a compatible format, the user
@param {Terria} terria The Terria instance in which to create the item.
@param {File|String} fileOrUrl The file or URL for which to create a catalog item.
@param {String} [dataType='auto'] The type of catalog item to create. If 'auto', the type is deduced from the URL or filename.
If 'other', the OGR-based conversion service is used. This can also be any valid catalog item
{@link CatalogItem#type}.
@param {Boolean} [confirmConversion=true] If true, and the OGR-based conversion service needs to be invoked, the user will first
be asked for permission to upload the file to the conversion service. If false, the
user will not be asked for permission. If the user denies the request, the promise
will be rejected with the string 'The user declined to use the conversion service.'.
@return {Promise} A promise that resolves to the created catalog item. | [
"Asynchronously",
"creates",
"and",
"loads",
"a",
"catalog",
"item",
"for",
"a",
"given",
"file",
".",
"The",
"returned",
"promise",
"does",
"not",
"resolve",
"until",
"the",
"catalog",
"item",
"is",
"successfully",
"loaded",
"and",
"it",
"rejects",
"if",
"the",
"file",
"is",
"not",
"in",
"the",
"expected",
"format",
"or",
"another",
"error",
"occurs",
"during",
"loading",
".",
"If",
"the",
"OGR",
"-",
"based",
"conversion",
"service",
"needs",
"to",
"be",
"invoked",
"to",
"convert",
"the",
"file",
"or",
"URL",
"to",
"a",
"compatible",
"format",
"the",
"user"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/createCatalogItemFromFileOrUrl.js#L30-L128 |
|
7,082 | TerriaJS/terriajs | lib/Map/Legend.js | drawTick | function drawTick(y) {
barGroup.appendChild(
svgElement(
legend,
"line",
{
x1: legend.itemWidth,
x2: legend.itemWidth + 5,
y1: y,
y2: y
},
"tick-mark"
)
);
} | javascript | function drawTick(y) {
barGroup.appendChild(
svgElement(
legend,
"line",
{
x1: legend.itemWidth,
x2: legend.itemWidth + 5,
y1: y,
y2: y
},
"tick-mark"
)
);
} | [
"function",
"drawTick",
"(",
"y",
")",
"{",
"barGroup",
".",
"appendChild",
"(",
"svgElement",
"(",
"legend",
",",
"\"line\"",
",",
"{",
"x1",
":",
"legend",
".",
"itemWidth",
",",
"x2",
":",
"legend",
".",
"itemWidth",
"+",
"5",
",",
"y1",
":",
"y",
",",
"y2",
":",
"y",
"}",
",",
"\"tick-mark\"",
")",
")",
";",
"}"
] | draw a subtle tick to help indicate what the label refers to | [
"draw",
"a",
"subtle",
"tick",
"to",
"help",
"indicate",
"what",
"the",
"label",
"refers",
"to"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/Legend.js#L412-L426 |
7,083 | TerriaJS/terriajs | lib/Map/AbsCode.js | function(code, name, concept) {
Concept.call(this, name);
/**
* Gets or sets the value of the abs code.
* @type {String}
*/
this.code = code;
/**
* Gets the list of abs codes contained in this group. This property is observable.
* @type {AbsCode[]}
*/
this.items = [];
/**
* Gets or sets the parent for a code. This property is observable.
* @type {AbsCode|AbsConcept}
*/
this.parent = undefined;
/**
* Gets or sets the ultimate parent concept for a code. This property is observable.
* @type {AbsConcept}
*/
this.concept = concept;
/**
* Flag to say if this if this concept only allows more than one active child.
* Defaults to the same as concept.
* Only meaningful if this concept has an items array.
* @type {Boolean}
*/
this.allowMultiple = this.concept.allowMultiple;
/**
* Gets or sets a value indicating whether this abs code is currently open. When an
* item is open, its child items (if any) are visible. This property is observable.
* @type {Boolean}
*/
this.isOpen = false;
/**
* Gets or sets a value indicating whether this abs code is currently active. When a
* code is active, it is included in the abs data query. This property is observable.
* @type {Boolean}
*/
this.isActive = false;
/**
* Flag to say if this is selectable. This property is observable.
* @type {Boolean}
*/
this.isSelectable = true; //for ko
knockout.track(this, ["code", "items", "isOpen", "isActive"]);
} | javascript | function(code, name, concept) {
Concept.call(this, name);
/**
* Gets or sets the value of the abs code.
* @type {String}
*/
this.code = code;
/**
* Gets the list of abs codes contained in this group. This property is observable.
* @type {AbsCode[]}
*/
this.items = [];
/**
* Gets or sets the parent for a code. This property is observable.
* @type {AbsCode|AbsConcept}
*/
this.parent = undefined;
/**
* Gets or sets the ultimate parent concept for a code. This property is observable.
* @type {AbsConcept}
*/
this.concept = concept;
/**
* Flag to say if this if this concept only allows more than one active child.
* Defaults to the same as concept.
* Only meaningful if this concept has an items array.
* @type {Boolean}
*/
this.allowMultiple = this.concept.allowMultiple;
/**
* Gets or sets a value indicating whether this abs code is currently open. When an
* item is open, its child items (if any) are visible. This property is observable.
* @type {Boolean}
*/
this.isOpen = false;
/**
* Gets or sets a value indicating whether this abs code is currently active. When a
* code is active, it is included in the abs data query. This property is observable.
* @type {Boolean}
*/
this.isActive = false;
/**
* Flag to say if this is selectable. This property is observable.
* @type {Boolean}
*/
this.isSelectable = true; //for ko
knockout.track(this, ["code", "items", "isOpen", "isActive"]);
} | [
"function",
"(",
"code",
",",
"name",
",",
"concept",
")",
"{",
"Concept",
".",
"call",
"(",
"this",
",",
"name",
")",
";",
"/**\n * Gets or sets the value of the abs code.\n * @type {String}\n */",
"this",
".",
"code",
"=",
"code",
";",
"/**\n * Gets the list of abs codes contained in this group. This property is observable.\n * @type {AbsCode[]}\n */",
"this",
".",
"items",
"=",
"[",
"]",
";",
"/**\n * Gets or sets the parent for a code. This property is observable.\n * @type {AbsCode|AbsConcept}\n */",
"this",
".",
"parent",
"=",
"undefined",
";",
"/**\n * Gets or sets the ultimate parent concept for a code. This property is observable.\n * @type {AbsConcept}\n */",
"this",
".",
"concept",
"=",
"concept",
";",
"/**\n * Flag to say if this if this concept only allows more than one active child.\n * Defaults to the same as concept.\n * Only meaningful if this concept has an items array.\n * @type {Boolean}\n */",
"this",
".",
"allowMultiple",
"=",
"this",
".",
"concept",
".",
"allowMultiple",
";",
"/**\n * Gets or sets a value indicating whether this abs code is currently open. When an\n * item is open, its child items (if any) are visible. This property is observable.\n * @type {Boolean}\n */",
"this",
".",
"isOpen",
"=",
"false",
";",
"/**\n * Gets or sets a value indicating whether this abs code is currently active. When a\n * code is active, it is included in the abs data query. This property is observable.\n * @type {Boolean}\n */",
"this",
".",
"isActive",
"=",
"false",
";",
"/**\n * Flag to say if this is selectable. This property is observable.\n * @type {Boolean}\n */",
"this",
".",
"isSelectable",
"=",
"true",
";",
"//for ko",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"code\"",
",",
"\"items\"",
",",
"\"isOpen\"",
",",
"\"isActive\"",
"]",
")",
";",
"}"
] | Represents an ABS code associated with a AbsConcept.
An AbsCode may contains an array one of more child AbsCodes.
@alias AbsCode
@constructor
@extends {Concept} | [
"Represents",
"an",
"ABS",
"code",
"associated",
"with",
"a",
"AbsConcept",
".",
"An",
"AbsCode",
"may",
"contains",
"an",
"array",
"one",
"of",
"more",
"child",
"AbsCodes",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Map/AbsCode.js#L20-L75 |
|
7,084 | TerriaJS/terriajs | lib/ReactViews/ObserveModelMixin.js | disposeSubscription | function disposeSubscription(component) {
if (defined(component.__observeModelChangeSubscriptions)) {
for (
let i = 0;
i < component.__observeModelChangeSubscriptions.length;
++i
) {
component.__observeModelChangeSubscriptions[i].dispose();
}
component.__observeModelChangeSubscriptions = undefined;
}
} | javascript | function disposeSubscription(component) {
if (defined(component.__observeModelChangeSubscriptions)) {
for (
let i = 0;
i < component.__observeModelChangeSubscriptions.length;
++i
) {
component.__observeModelChangeSubscriptions[i].dispose();
}
component.__observeModelChangeSubscriptions = undefined;
}
} | [
"function",
"disposeSubscription",
"(",
"component",
")",
"{",
"if",
"(",
"defined",
"(",
"component",
".",
"__observeModelChangeSubscriptions",
")",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"component",
".",
"__observeModelChangeSubscriptions",
".",
"length",
";",
"++",
"i",
")",
"{",
"component",
".",
"__observeModelChangeSubscriptions",
"[",
"i",
"]",
".",
"dispose",
"(",
")",
";",
"}",
"component",
".",
"__observeModelChangeSubscriptions",
"=",
"undefined",
";",
"}",
"}"
] | Disposes of all subscriptions that a component currently has.
@param component The component to find and dispose subscriptions on. | [
"Disposes",
"of",
"all",
"subscriptions",
"that",
"a",
"component",
"currently",
"has",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/ObserveModelMixin.js#L98-L109 |
7,085 | TerriaJS/terriajs | lib/Models/RegionTypeParameter.js | function(options) {
FunctionParameter.call(this, options);
this._regionProviderPromise = undefined;
this._regionProviderList = undefined;
this.validRegionTypes = options.validRegionTypes;
// Track this so that defaultValue can update once regionProviderList is known.
knockout.track(this, ["_regionProviderList"]);
/**
* Gets the default region provider if the user has not specified one. If region-mapped data
* is loaded on the map, this property returns the {@link RegionProvider} of the topmost
* region-mapped catalog item. Otherwise, it returns the first region provider. If the
* parameter has not yet been loaded, this property returns undefined.
* @memberof RegionTypeParameter.prototype
* @type {RegionProvider}
*/
overrideProperty(this, "defaultValue", {
get: function() {
if (defined(this._defaultValue)) {
return this._defaultValue;
}
const nowViewingItems = this.terria.nowViewing.items;
if (nowViewingItems.length > 0) {
for (let i = 0; i < nowViewingItems.length; ++i) {
const item = nowViewingItems[i];
if (
defined(item.regionMapping) &&
defined(item.regionMapping.regionDetails) &&
item.regionMapping.regionDetails.length > 0
) {
return item.regionMapping.regionDetails[0].regionProvider;
}
}
}
if (
defined(this._regionProviderList) &&
this._regionProviderList.length > 0
) {
return this._regionProviderList[0];
}
// No defaults available; have we requested the region providers yet?
this.load();
return undefined;
}
});
} | javascript | function(options) {
FunctionParameter.call(this, options);
this._regionProviderPromise = undefined;
this._regionProviderList = undefined;
this.validRegionTypes = options.validRegionTypes;
// Track this so that defaultValue can update once regionProviderList is known.
knockout.track(this, ["_regionProviderList"]);
/**
* Gets the default region provider if the user has not specified one. If region-mapped data
* is loaded on the map, this property returns the {@link RegionProvider} of the topmost
* region-mapped catalog item. Otherwise, it returns the first region provider. If the
* parameter has not yet been loaded, this property returns undefined.
* @memberof RegionTypeParameter.prototype
* @type {RegionProvider}
*/
overrideProperty(this, "defaultValue", {
get: function() {
if (defined(this._defaultValue)) {
return this._defaultValue;
}
const nowViewingItems = this.terria.nowViewing.items;
if (nowViewingItems.length > 0) {
for (let i = 0; i < nowViewingItems.length; ++i) {
const item = nowViewingItems[i];
if (
defined(item.regionMapping) &&
defined(item.regionMapping.regionDetails) &&
item.regionMapping.regionDetails.length > 0
) {
return item.regionMapping.regionDetails[0].regionProvider;
}
}
}
if (
defined(this._regionProviderList) &&
this._regionProviderList.length > 0
) {
return this._regionProviderList[0];
}
// No defaults available; have we requested the region providers yet?
this.load();
return undefined;
}
});
} | [
"function",
"(",
"options",
")",
"{",
"FunctionParameter",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"_regionProviderPromise",
"=",
"undefined",
";",
"this",
".",
"_regionProviderList",
"=",
"undefined",
";",
"this",
".",
"validRegionTypes",
"=",
"options",
".",
"validRegionTypes",
";",
"// Track this so that defaultValue can update once regionProviderList is known.",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"_regionProviderList\"",
"]",
")",
";",
"/**\n * Gets the default region provider if the user has not specified one. If region-mapped data\n * is loaded on the map, this property returns the {@link RegionProvider} of the topmost\n * region-mapped catalog item. Otherwise, it returns the first region provider. If the\n * parameter has not yet been loaded, this property returns undefined.\n * @memberof RegionTypeParameter.prototype\n * @type {RegionProvider}\n */",
"overrideProperty",
"(",
"this",
",",
"\"defaultValue\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"if",
"(",
"defined",
"(",
"this",
".",
"_defaultValue",
")",
")",
"{",
"return",
"this",
".",
"_defaultValue",
";",
"}",
"const",
"nowViewingItems",
"=",
"this",
".",
"terria",
".",
"nowViewing",
".",
"items",
";",
"if",
"(",
"nowViewingItems",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"nowViewingItems",
".",
"length",
";",
"++",
"i",
")",
"{",
"const",
"item",
"=",
"nowViewingItems",
"[",
"i",
"]",
";",
"if",
"(",
"defined",
"(",
"item",
".",
"regionMapping",
")",
"&&",
"defined",
"(",
"item",
".",
"regionMapping",
".",
"regionDetails",
")",
"&&",
"item",
".",
"regionMapping",
".",
"regionDetails",
".",
"length",
">",
"0",
")",
"{",
"return",
"item",
".",
"regionMapping",
".",
"regionDetails",
"[",
"0",
"]",
".",
"regionProvider",
";",
"}",
"}",
"}",
"if",
"(",
"defined",
"(",
"this",
".",
"_regionProviderList",
")",
"&&",
"this",
".",
"_regionProviderList",
".",
"length",
">",
"0",
")",
"{",
"return",
"this",
".",
"_regionProviderList",
"[",
"0",
"]",
";",
"}",
"// No defaults available; have we requested the region providers yet?",
"this",
".",
"load",
"(",
")",
";",
"return",
"undefined",
";",
"}",
"}",
")",
";",
"}"
] | A parameter that specifies a type of region.
@alias RegionTypeParameter
@constructor
@extends FunctionParameter
@param {Object} [options] Object with the following properties:
@param {Terria} options.terria The Terria instance.
@param {String} options.id The unique ID of this parameter.
@param {String} [options.name] The name of this parameter. If not specified, the ID is used as the name.
@param {String} [options.description] The description of the parameter.
@param {String[]} [options.validRegionTypes] The region types from which this RegionTypeParameter selects. If this parameter is not specified, all region types
known to {@link Terria} may be selected. | [
"A",
"parameter",
"that",
"specifies",
"a",
"type",
"of",
"region",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/RegionTypeParameter.js#L29-L79 |
|
7,086 | TerriaJS/terriajs | lib/Models/NowViewing.js | function(terria) {
this._terria = terria;
this._eventSubscriptions = new EventHelper();
/**
* Gets the list of items that we are "now viewing". It is recommended that you use
* the methods on this instance instead of manipulating the list of items directly.
* This property is observable.
* @type {CatalogItem[]}
*/
this.items = [];
knockout.track(this, ["items"]);
this.showNowViewingRequested = new CesiumEvent();
this._eventSubscriptions.add(
this.terria.beforeViewerChanged,
function() {
beforeViewerChanged(this);
},
this
);
this._eventSubscriptions.add(
this.terria.afterViewerChanged,
function() {
afterViewerChanged(this);
},
this
);
} | javascript | function(terria) {
this._terria = terria;
this._eventSubscriptions = new EventHelper();
/**
* Gets the list of items that we are "now viewing". It is recommended that you use
* the methods on this instance instead of manipulating the list of items directly.
* This property is observable.
* @type {CatalogItem[]}
*/
this.items = [];
knockout.track(this, ["items"]);
this.showNowViewingRequested = new CesiumEvent();
this._eventSubscriptions.add(
this.terria.beforeViewerChanged,
function() {
beforeViewerChanged(this);
},
this
);
this._eventSubscriptions.add(
this.terria.afterViewerChanged,
function() {
afterViewerChanged(this);
},
this
);
} | [
"function",
"(",
"terria",
")",
"{",
"this",
".",
"_terria",
"=",
"terria",
";",
"this",
".",
"_eventSubscriptions",
"=",
"new",
"EventHelper",
"(",
")",
";",
"/**\n * Gets the list of items that we are \"now viewing\". It is recommended that you use\n * the methods on this instance instead of manipulating the list of items directly.\n * This property is observable.\n * @type {CatalogItem[]}\n */",
"this",
".",
"items",
"=",
"[",
"]",
";",
"knockout",
".",
"track",
"(",
"this",
",",
"[",
"\"items\"",
"]",
")",
";",
"this",
".",
"showNowViewingRequested",
"=",
"new",
"CesiumEvent",
"(",
")",
";",
"this",
".",
"_eventSubscriptions",
".",
"add",
"(",
"this",
".",
"terria",
".",
"beforeViewerChanged",
",",
"function",
"(",
")",
"{",
"beforeViewerChanged",
"(",
"this",
")",
";",
"}",
",",
"this",
")",
";",
"this",
".",
"_eventSubscriptions",
".",
"add",
"(",
"this",
".",
"terria",
".",
"afterViewerChanged",
",",
"function",
"(",
")",
"{",
"afterViewerChanged",
"(",
"this",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | The model for the "Now Viewing" pane. | [
"The",
"model",
"for",
"the",
"Now",
"Viewing",
"pane",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/NowViewing.js#L16-L47 |
|
7,087 | TerriaJS/terriajs | lib/ReactViews/Custom/parseCustomHtmlToReact.js | parseCustomHtmlToReact | function parseCustomHtmlToReact(html, context) {
if (!defined(html) || html.length === 0) {
return html;
}
return htmlToReactParser.parseWithInstructions(
html,
isValidNode,
getProcessingInstructions(context || {})
);
} | javascript | function parseCustomHtmlToReact(html, context) {
if (!defined(html) || html.length === 0) {
return html;
}
return htmlToReactParser.parseWithInstructions(
html,
isValidNode,
getProcessingInstructions(context || {})
);
} | [
"function",
"parseCustomHtmlToReact",
"(",
"html",
",",
"context",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"html",
")",
"||",
"html",
".",
"length",
"===",
"0",
")",
"{",
"return",
"html",
";",
"}",
"return",
"htmlToReactParser",
".",
"parseWithInstructions",
"(",
"html",
",",
"isValidNode",
",",
"getProcessingInstructions",
"(",
"context",
"||",
"{",
"}",
")",
")",
";",
"}"
] | Return html as a React Element.
@param {String} html
@param {Object} [context] Provide any further information that custom components need to know here, eg. which feature and catalogItem they come from.
@return {ReactElement} | [
"Return",
"html",
"as",
"a",
"React",
"Element",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ReactViews/Custom/parseCustomHtmlToReact.js#L89-L98 |
7,088 | TerriaJS/terriajs | lib/ThirdParty/sdmxjsonlib.js | function(observations, seriesKey, dimIdx, attrIdx) {
if (observations === undefined || observations === null) return;
// process each observation in object.
for (var key in observations) {
// convert key from string to an array of numbers
var obsDimIdx = key.split(KEY_SEPARATOR).map(Number);
obsDimIdx.forEach(updateObsKey);
var value = observations[key];
if (value === null) continue;
results.push(
iterator.call(
context,
// String of dimension id values e.g. 'M.FI.P.2000'
obsKey.join(KEY_SEPARATOR),
// Same as obsKey but without obs level dims
seriesKey,
// observation value
value[0],
// Array of dimension indices e.g. [ 0, 4, 5, 18 ]
dimIdx.concat(obsDimIdx),
// Array of attribute indices e.g. [ 1, 92, 27 ]
attrIdx.concat(value.slice(1)),
// Array of dimension objects
allDims,
// Array of attribute objects
allAttrs
)
);
}
} | javascript | function(observations, seriesKey, dimIdx, attrIdx) {
if (observations === undefined || observations === null) return;
// process each observation in object.
for (var key in observations) {
// convert key from string to an array of numbers
var obsDimIdx = key.split(KEY_SEPARATOR).map(Number);
obsDimIdx.forEach(updateObsKey);
var value = observations[key];
if (value === null) continue;
results.push(
iterator.call(
context,
// String of dimension id values e.g. 'M.FI.P.2000'
obsKey.join(KEY_SEPARATOR),
// Same as obsKey but without obs level dims
seriesKey,
// observation value
value[0],
// Array of dimension indices e.g. [ 0, 4, 5, 18 ]
dimIdx.concat(obsDimIdx),
// Array of attribute indices e.g. [ 1, 92, 27 ]
attrIdx.concat(value.slice(1)),
// Array of dimension objects
allDims,
// Array of attribute objects
allAttrs
)
);
}
} | [
"function",
"(",
"observations",
",",
"seriesKey",
",",
"dimIdx",
",",
"attrIdx",
")",
"{",
"if",
"(",
"observations",
"===",
"undefined",
"||",
"observations",
"===",
"null",
")",
"return",
";",
"// process each observation in object.",
"for",
"(",
"var",
"key",
"in",
"observations",
")",
"{",
"// convert key from string to an array of numbers",
"var",
"obsDimIdx",
"=",
"key",
".",
"split",
"(",
"KEY_SEPARATOR",
")",
".",
"map",
"(",
"Number",
")",
";",
"obsDimIdx",
".",
"forEach",
"(",
"updateObsKey",
")",
";",
"var",
"value",
"=",
"observations",
"[",
"key",
"]",
";",
"if",
"(",
"value",
"===",
"null",
")",
"continue",
";",
"results",
".",
"push",
"(",
"iterator",
".",
"call",
"(",
"context",
",",
"// String of dimension id values e.g. 'M.FI.P.2000'",
"obsKey",
".",
"join",
"(",
"KEY_SEPARATOR",
")",
",",
"// Same as obsKey but without obs level dims",
"seriesKey",
",",
"// observation value",
"value",
"[",
"0",
"]",
",",
"// Array of dimension indices e.g. [ 0, 4, 5, 18 ]",
"dimIdx",
".",
"concat",
"(",
"obsDimIdx",
")",
",",
"// Array of attribute indices e.g. [ 1, 92, 27 ]",
"attrIdx",
".",
"concat",
"(",
"value",
".",
"slice",
"(",
"1",
")",
")",
",",
"// Array of dimension objects",
"allDims",
",",
"// Array of attribute objects",
"allAttrs",
")",
")",
";",
"}",
"}"
] | Process observations object and call the iterator function for each observation. Works for both dataset and series level observations. Updates the results array. | [
"Process",
"observations",
"object",
"and",
"call",
"the",
"iterator",
"function",
"for",
"each",
"observation",
".",
"Works",
"for",
"both",
"dataset",
"and",
"series",
"level",
"observations",
".",
"Updates",
"the",
"results",
"array",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ThirdParty/sdmxjsonlib.js#L319-L351 |
|
7,089 | TerriaJS/terriajs | lib/ThirdParty/sdmxjsonlib.js | function(dvi, di) {
var dim = msg.structure.dimensions.series[di];
var pos = dimPosition(dim);
seriesKey[pos] = obsKey[pos] = dim.values[dvi].id;
} | javascript | function(dvi, di) {
var dim = msg.structure.dimensions.series[di];
var pos = dimPosition(dim);
seriesKey[pos] = obsKey[pos] = dim.values[dvi].id;
} | [
"function",
"(",
"dvi",
",",
"di",
")",
"{",
"var",
"dim",
"=",
"msg",
".",
"structure",
".",
"dimensions",
".",
"series",
"[",
"di",
"]",
";",
"var",
"pos",
"=",
"dimPosition",
"(",
"dim",
")",
";",
"seriesKey",
"[",
"pos",
"]",
"=",
"obsKey",
"[",
"pos",
"]",
"=",
"dim",
".",
"values",
"[",
"dvi",
"]",
".",
"id",
";",
"}"
] | Update series and obs keys with a series level dimension value. | [
"Update",
"series",
"and",
"obs",
"keys",
"with",
"a",
"series",
"level",
"dimension",
"value",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ThirdParty/sdmxjsonlib.js#L354-L358 |
|
7,090 | TerriaJS/terriajs | lib/ThirdParty/sdmxjsonlib.js | function(series) {
if (series === undefined || series === null) return;
for (var key in series) {
// Convert key from string into array of numbers
var serDimIdx = key.split(KEY_SEPARATOR).map(Number);
// Update series and obs keys
serDimIdx.forEach(updateSeriesAndObsKeys);
var value = series[key];
var serAttrIdx = [];
if (Array.isArray(value.attributes)) {
serAttrIdx = value.attributes;
}
processObservations(
value.observations,
seriesKey.join(KEY_SEPARATOR),
dsDimIdx.concat(serDimIdx),
dsAttrIdx.concat(serAttrIdx)
);
}
} | javascript | function(series) {
if (series === undefined || series === null) return;
for (var key in series) {
// Convert key from string into array of numbers
var serDimIdx = key.split(KEY_SEPARATOR).map(Number);
// Update series and obs keys
serDimIdx.forEach(updateSeriesAndObsKeys);
var value = series[key];
var serAttrIdx = [];
if (Array.isArray(value.attributes)) {
serAttrIdx = value.attributes;
}
processObservations(
value.observations,
seriesKey.join(KEY_SEPARATOR),
dsDimIdx.concat(serDimIdx),
dsAttrIdx.concat(serAttrIdx)
);
}
} | [
"function",
"(",
"series",
")",
"{",
"if",
"(",
"series",
"===",
"undefined",
"||",
"series",
"===",
"null",
")",
"return",
";",
"for",
"(",
"var",
"key",
"in",
"series",
")",
"{",
"// Convert key from string into array of numbers",
"var",
"serDimIdx",
"=",
"key",
".",
"split",
"(",
"KEY_SEPARATOR",
")",
".",
"map",
"(",
"Number",
")",
";",
"// Update series and obs keys",
"serDimIdx",
".",
"forEach",
"(",
"updateSeriesAndObsKeys",
")",
";",
"var",
"value",
"=",
"series",
"[",
"key",
"]",
";",
"var",
"serAttrIdx",
"=",
"[",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
".",
"attributes",
")",
")",
"{",
"serAttrIdx",
"=",
"value",
".",
"attributes",
";",
"}",
"processObservations",
"(",
"value",
".",
"observations",
",",
"seriesKey",
".",
"join",
"(",
"KEY_SEPARATOR",
")",
",",
"dsDimIdx",
".",
"concat",
"(",
"serDimIdx",
")",
",",
"dsAttrIdx",
".",
"concat",
"(",
"serAttrIdx",
")",
")",
";",
"}",
"}"
] | Call processObservations for each series object | [
"Call",
"processObservations",
"for",
"each",
"series",
"object"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ThirdParty/sdmxjsonlib.js#L361-L384 |
|
7,091 | TerriaJS/terriajs | lib/ThirdParty/sdmxjsonlib.js | function(c, i, array) {
if (c === undefined || c === null) return;
// c is the component, type is dimension|attribute,
// level is dataset|series|observation, i is index,
// array is the component array
failed += !iterator.call(context, c, type, level, i, array);
} | javascript | function(c, i, array) {
if (c === undefined || c === null) return;
// c is the component, type is dimension|attribute,
// level is dataset|series|observation, i is index,
// array is the component array
failed += !iterator.call(context, c, type, level, i, array);
} | [
"function",
"(",
"c",
",",
"i",
",",
"array",
")",
"{",
"if",
"(",
"c",
"===",
"undefined",
"||",
"c",
"===",
"null",
")",
"return",
";",
"// c is the component, type is dimension|attribute,",
"// level is dataset|series|observation, i is index,",
"// array is the component array",
"failed",
"+=",
"!",
"iterator",
".",
"call",
"(",
"context",
",",
"c",
",",
"type",
",",
"level",
",",
"i",
",",
"array",
")",
";",
"}"
] | Applies the iterator function and collects boolean results | [
"Applies",
"the",
"iterator",
"function",
"and",
"collects",
"boolean",
"results"
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ThirdParty/sdmxjsonlib.js#L567-L573 |
|
7,092 | TerriaJS/terriajs | lib/ThirdParty/sdmxjsonlib.js | function(v, i) {
if (v === undefined || v === null) return;
failed += !iterator.call(context, v, type, level, i);
} | javascript | function(v, i) {
if (v === undefined || v === null) return;
failed += !iterator.call(context, v, type, level, i);
} | [
"function",
"(",
"v",
",",
"i",
")",
"{",
"if",
"(",
"v",
"===",
"undefined",
"||",
"v",
"===",
"null",
")",
"return",
";",
"failed",
"+=",
"!",
"iterator",
".",
"call",
"(",
"context",
",",
"v",
",",
"type",
",",
"level",
",",
"i",
")",
";",
"}"
] | Value iterator function. Gets the value and index as arguments. Collects boolean results. | [
"Value",
"iterator",
"function",
".",
"Gets",
"the",
"value",
"and",
"index",
"as",
"arguments",
".",
"Collects",
"boolean",
"results",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/ThirdParty/sdmxjsonlib.js#L598-L601 |
|
7,093 | TerriaJS/terriajs | lib/Core/updateFromJson.js | updateFromJson | function updateFromJson(target, json, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
var promises = [];
for (var propertyName in target) {
if (
target.hasOwnProperty(propertyName) &&
shouldBeUpdated(target, propertyName, json)
) {
if (target.updaters && target.updaters[propertyName]) {
promises.push(
target.updaters[propertyName](target, json, propertyName, options)
);
} else {
target[propertyName] = json[propertyName];
}
}
}
return when.all(promises);
} | javascript | function updateFromJson(target, json, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
var promises = [];
for (var propertyName in target) {
if (
target.hasOwnProperty(propertyName) &&
shouldBeUpdated(target, propertyName, json)
) {
if (target.updaters && target.updaters[propertyName]) {
promises.push(
target.updaters[propertyName](target, json, propertyName, options)
);
} else {
target[propertyName] = json[propertyName];
}
}
}
return when.all(promises);
} | [
"function",
"updateFromJson",
"(",
"target",
",",
"json",
",",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"var",
"promises",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"propertyName",
"in",
"target",
")",
"{",
"if",
"(",
"target",
".",
"hasOwnProperty",
"(",
"propertyName",
")",
"&&",
"shouldBeUpdated",
"(",
"target",
",",
"propertyName",
",",
"json",
")",
")",
"{",
"if",
"(",
"target",
".",
"updaters",
"&&",
"target",
".",
"updaters",
"[",
"propertyName",
"]",
")",
"{",
"promises",
".",
"push",
"(",
"target",
".",
"updaters",
"[",
"propertyName",
"]",
"(",
"target",
",",
"json",
",",
"propertyName",
",",
"options",
")",
")",
";",
"}",
"else",
"{",
"target",
"[",
"propertyName",
"]",
"=",
"json",
"[",
"propertyName",
"]",
";",
"}",
"}",
"}",
"return",
"when",
".",
"all",
"(",
"promises",
")",
";",
"}"
] | Updates an object from a JSON representation of the object. Only properties that actually exist on the object are read from the JSON,
and the object has the opportunity to inject specialized deserialization logic by providing an `updaters` property.
@param {Object} target The object to update from the JSON.
@param {Object} json The JSON description. The JSON should be in the form of an object literal, not a string.
@param {Object} [options] Optional parameters to custom updaters.
@return {Promise} A promise that resolves when the update completes. | [
"Updates",
"an",
"object",
"from",
"a",
"JSON",
"representation",
"of",
"the",
"object",
".",
"Only",
"properties",
"that",
"actually",
"exist",
"on",
"the",
"object",
"are",
"read",
"from",
"the",
"JSON",
"and",
"the",
"object",
"has",
"the",
"opportunity",
"to",
"inject",
"specialized",
"deserialization",
"logic",
"by",
"providing",
"an",
"updaters",
"property",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/updateFromJson.js#L15-L36 |
7,094 | TerriaJS/terriajs | lib/Core/updateFromJson.js | shouldBeUpdated | function shouldBeUpdated(target, propertyName, json) {
return (
json[propertyName] !== undefined && // Must have a value to update to
propertyName.length > 0 && // Must have a name to update
propertyName[0] !== "_" && // Must not be a private property
(propertyName !== "id" || !defined(target.id))
); // Must not be overwriting 'id'
} | javascript | function shouldBeUpdated(target, propertyName, json) {
return (
json[propertyName] !== undefined && // Must have a value to update to
propertyName.length > 0 && // Must have a name to update
propertyName[0] !== "_" && // Must not be a private property
(propertyName !== "id" || !defined(target.id))
); // Must not be overwriting 'id'
} | [
"function",
"shouldBeUpdated",
"(",
"target",
",",
"propertyName",
",",
"json",
")",
"{",
"return",
"(",
"json",
"[",
"propertyName",
"]",
"!==",
"undefined",
"&&",
"// Must have a value to update to",
"propertyName",
".",
"length",
">",
"0",
"&&",
"// Must have a name to update",
"propertyName",
"[",
"0",
"]",
"!==",
"\"_\"",
"&&",
"// Must not be a private property",
"(",
"propertyName",
"!==",
"\"id\"",
"||",
"!",
"defined",
"(",
"target",
".",
"id",
")",
")",
")",
";",
"// Must not be overwriting 'id'",
"}"
] | Determines whether this property is valid for updating. | [
"Determines",
"whether",
"this",
"property",
"is",
"valid",
"for",
"updating",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Core/updateFromJson.js#L41-L48 |
7,095 | TerriaJS/terriajs | lib/Models/CatalogItem.js | removeCurrentTimeSubscription | function removeCurrentTimeSubscription(catalogItem) {
if (defined(catalogItem._removeCurrentTimeChange)) {
catalogItem._removeCurrentTimeChange();
catalogItem._removeCurrentTimeChange = undefined;
}
} | javascript | function removeCurrentTimeSubscription(catalogItem) {
if (defined(catalogItem._removeCurrentTimeChange)) {
catalogItem._removeCurrentTimeChange();
catalogItem._removeCurrentTimeChange = undefined;
}
} | [
"function",
"removeCurrentTimeSubscription",
"(",
"catalogItem",
")",
"{",
"if",
"(",
"defined",
"(",
"catalogItem",
".",
"_removeCurrentTimeChange",
")",
")",
"{",
"catalogItem",
".",
"_removeCurrentTimeChange",
"(",
")",
";",
"catalogItem",
".",
"_removeCurrentTimeChange",
"=",
"undefined",
";",
"}",
"}"
] | Removes catalogItem.clock.definitionChanged subscriptions. | [
"Removes",
"catalogItem",
".",
"clock",
".",
"definitionChanged",
"subscriptions",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogItem.js#L1360-L1365 |
7,096 | TerriaJS/terriajs | lib/Models/CatalogItem.js | updateCurrentTime | function updateCurrentTime(catalogItem, updatedTime) {
if (defined(catalogItem.clock)) {
catalogItem.clock.currentTime = JulianDate.clone(updatedTime);
}
} | javascript | function updateCurrentTime(catalogItem, updatedTime) {
if (defined(catalogItem.clock)) {
catalogItem.clock.currentTime = JulianDate.clone(updatedTime);
}
} | [
"function",
"updateCurrentTime",
"(",
"catalogItem",
",",
"updatedTime",
")",
"{",
"if",
"(",
"defined",
"(",
"catalogItem",
".",
"clock",
")",
")",
"{",
"catalogItem",
".",
"clock",
".",
"currentTime",
"=",
"JulianDate",
".",
"clone",
"(",
"updatedTime",
")",
";",
"}",
"}"
] | Updates the item.clock.currentTime using the value provided.
This function does this so that all clients subscribed to the items clock with DataSourceClock.definitionChanged are notified.
@param catalogItem The CatalogItem to set the current time for.
@param updatedTime The new current time to use.
@private | [
"Updates",
"the",
"item",
".",
"clock",
".",
"currentTime",
"using",
"the",
"value",
"provided",
".",
"This",
"function",
"does",
"this",
"so",
"that",
"all",
"clients",
"subscribed",
"to",
"the",
"items",
"clock",
"with",
"DataSourceClock",
".",
"definitionChanged",
"are",
"notified",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogItem.js#L1551-L1555 |
7,097 | TerriaJS/terriajs | lib/Models/CatalogItem.js | useOwnClockChanged | function useOwnClockChanged(catalogItem) {
// If we are changing the state, copy the time from the clock that was in use to the clock that will be in use.
if (catalogItem._lastUseOwnClock !== catalogItem.useOwnClock) {
// Check that both clocks are defined before syncing the time (they may not both be defined during load due to construction order).
if (
defined(catalogItem.clock) &&
defined(catalogItem.terria) &&
defined(catalogItem.terria.clock) &&
defined(catalogItem.terria.clock.currentTime)
) {
if (catalogItem.useOwnClock) {
// This is probably not needed, since we should be doing it on update, but just do this here explicitly
// to be sure it is immediately current before we change.
updateCurrentTime(catalogItem, catalogItem.terria.clock.currentTime);
} else {
catalogItem.terria.clock.currentTime = JulianDate.clone(
catalogItem.clock.currentTime
);
}
catalogItem._lastUseOwnClock = catalogItem.useOwnClock;
catalogItem.useClock();
}
}
} | javascript | function useOwnClockChanged(catalogItem) {
// If we are changing the state, copy the time from the clock that was in use to the clock that will be in use.
if (catalogItem._lastUseOwnClock !== catalogItem.useOwnClock) {
// Check that both clocks are defined before syncing the time (they may not both be defined during load due to construction order).
if (
defined(catalogItem.clock) &&
defined(catalogItem.terria) &&
defined(catalogItem.terria.clock) &&
defined(catalogItem.terria.clock.currentTime)
) {
if (catalogItem.useOwnClock) {
// This is probably not needed, since we should be doing it on update, but just do this here explicitly
// to be sure it is immediately current before we change.
updateCurrentTime(catalogItem, catalogItem.terria.clock.currentTime);
} else {
catalogItem.terria.clock.currentTime = JulianDate.clone(
catalogItem.clock.currentTime
);
}
catalogItem._lastUseOwnClock = catalogItem.useOwnClock;
catalogItem.useClock();
}
}
} | [
"function",
"useOwnClockChanged",
"(",
"catalogItem",
")",
"{",
"// If we are changing the state, copy the time from the clock that was in use to the clock that will be in use.",
"if",
"(",
"catalogItem",
".",
"_lastUseOwnClock",
"!==",
"catalogItem",
".",
"useOwnClock",
")",
"{",
"// Check that both clocks are defined before syncing the time (they may not both be defined during load due to construction order).",
"if",
"(",
"defined",
"(",
"catalogItem",
".",
"clock",
")",
"&&",
"defined",
"(",
"catalogItem",
".",
"terria",
")",
"&&",
"defined",
"(",
"catalogItem",
".",
"terria",
".",
"clock",
")",
"&&",
"defined",
"(",
"catalogItem",
".",
"terria",
".",
"clock",
".",
"currentTime",
")",
")",
"{",
"if",
"(",
"catalogItem",
".",
"useOwnClock",
")",
"{",
"// This is probably not needed, since we should be doing it on update, but just do this here explicitly",
"// to be sure it is immediately current before we change.",
"updateCurrentTime",
"(",
"catalogItem",
",",
"catalogItem",
".",
"terria",
".",
"clock",
".",
"currentTime",
")",
";",
"}",
"else",
"{",
"catalogItem",
".",
"terria",
".",
"clock",
".",
"currentTime",
"=",
"JulianDate",
".",
"clone",
"(",
"catalogItem",
".",
"clock",
".",
"currentTime",
")",
";",
"}",
"catalogItem",
".",
"_lastUseOwnClock",
"=",
"catalogItem",
".",
"useOwnClock",
";",
"catalogItem",
".",
"useClock",
"(",
")",
";",
"}",
"}",
"}"
] | Syncs the time between the terria.clock and the catalogItem.clock.
The sync is performed in the direction that is required depending on the state change true->false / false->true of useOwnClock.
@param catalogItem The CatalogItem to sync the time for.
@private | [
"Syncs",
"the",
"time",
"between",
"the",
"terria",
".",
"clock",
"and",
"the",
"catalogItem",
".",
"clock",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/CatalogItem.js#L1565-L1590 |
7,098 | TerriaJS/terriajs | lib/Models/GeoJsonCatalogItem.js | describeWithoutUnderscores | function describeWithoutUnderscores(properties, nameProperty) {
var html = "";
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
if (key === nameProperty || simpleStyleIdentifiers.indexOf(key) !== -1) {
continue;
}
var value = properties[key];
if (typeof value === "object") {
value = describeWithoutUnderscores(value);
} else {
value = formatPropertyValue(value);
}
key = key.replace(/_/g, " ");
if (defined(value)) {
html += "<tr><th>" + key + "</th><td>" + value + "</td></tr>";
}
}
}
if (html.length > 0) {
html =
'<table class="cesium-infoBox-defaultTable"><tbody>' +
html +
"</tbody></table>";
}
return html;
} | javascript | function describeWithoutUnderscores(properties, nameProperty) {
var html = "";
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
if (key === nameProperty || simpleStyleIdentifiers.indexOf(key) !== -1) {
continue;
}
var value = properties[key];
if (typeof value === "object") {
value = describeWithoutUnderscores(value);
} else {
value = formatPropertyValue(value);
}
key = key.replace(/_/g, " ");
if (defined(value)) {
html += "<tr><th>" + key + "</th><td>" + value + "</td></tr>";
}
}
}
if (html.length > 0) {
html =
'<table class="cesium-infoBox-defaultTable"><tbody>' +
html +
"</tbody></table>";
}
return html;
} | [
"function",
"describeWithoutUnderscores",
"(",
"properties",
",",
"nameProperty",
")",
"{",
"var",
"html",
"=",
"\"\"",
";",
"for",
"(",
"var",
"key",
"in",
"properties",
")",
"{",
"if",
"(",
"properties",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"key",
"===",
"nameProperty",
"||",
"simpleStyleIdentifiers",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"{",
"continue",
";",
"}",
"var",
"value",
"=",
"properties",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"value",
"===",
"\"object\"",
")",
"{",
"value",
"=",
"describeWithoutUnderscores",
"(",
"value",
")",
";",
"}",
"else",
"{",
"value",
"=",
"formatPropertyValue",
"(",
"value",
")",
";",
"}",
"key",
"=",
"key",
".",
"replace",
"(",
"/",
"_",
"/",
"g",
",",
"\" \"",
")",
";",
"if",
"(",
"defined",
"(",
"value",
")",
")",
"{",
"html",
"+=",
"\"<tr><th>\"",
"+",
"key",
"+",
"\"</th><td>\"",
"+",
"value",
"+",
"\"</td></tr>\"",
";",
"}",
"}",
"}",
"if",
"(",
"html",
".",
"length",
">",
"0",
")",
"{",
"html",
"=",
"'<table class=\"cesium-infoBox-defaultTable\"><tbody>'",
"+",
"html",
"+",
"\"</tbody></table>\"",
";",
"}",
"return",
"html",
";",
"}"
] | This next function modelled on Cesium.geoJsonDataSource's defaultDescribe. | [
"This",
"next",
"function",
"modelled",
"on",
"Cesium",
".",
"geoJsonDataSource",
"s",
"defaultDescribe",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/GeoJsonCatalogItem.js#L159-L185 |
7,099 | TerriaJS/terriajs | lib/Models/GeoJsonCatalogItem.js | reprojectPointList | function reprojectPointList(pts, code) {
if (!(pts[0] instanceof Array)) {
return Reproject.reprojectPoint(pts, code, "EPSG:4326");
}
var pts_out = [];
for (var i = 0; i < pts.length; i++) {
pts_out.push(Reproject.reprojectPoint(pts[i], code, "EPSG:4326"));
}
return pts_out;
} | javascript | function reprojectPointList(pts, code) {
if (!(pts[0] instanceof Array)) {
return Reproject.reprojectPoint(pts, code, "EPSG:4326");
}
var pts_out = [];
for (var i = 0; i < pts.length; i++) {
pts_out.push(Reproject.reprojectPoint(pts[i], code, "EPSG:4326"));
}
return pts_out;
} | [
"function",
"reprojectPointList",
"(",
"pts",
",",
"code",
")",
"{",
"if",
"(",
"!",
"(",
"pts",
"[",
"0",
"]",
"instanceof",
"Array",
")",
")",
"{",
"return",
"Reproject",
".",
"reprojectPoint",
"(",
"pts",
",",
"code",
",",
"\"EPSG:4326\"",
")",
";",
"}",
"var",
"pts_out",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pts",
".",
"length",
";",
"i",
"++",
")",
"{",
"pts_out",
".",
"push",
"(",
"Reproject",
".",
"reprojectPoint",
"(",
"pts",
"[",
"i",
"]",
",",
"code",
",",
"\"EPSG:4326\"",
")",
")",
";",
"}",
"return",
"pts_out",
";",
"}"
] | Reproject a point list based on the supplied crs code. | [
"Reproject",
"a",
"point",
"list",
"based",
"on",
"the",
"supplied",
"crs",
"code",
"."
] | abcce28ff189f6fdbc0ee541a235ec6cabd90bd5 | https://github.com/TerriaJS/terriajs/blob/abcce28ff189f6fdbc0ee541a235ec6cabd90bd5/lib/Models/GeoJsonCatalogItem.js#L719-L728 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.