The following are some helper functions useful when configuring a Syntool portal.
Type: capitalizeString(input: string) -> string
Returns the input string but with the first letter of each word capitalized.
function capitalizeString(input) {
return input.replace(
/(^|[^a-z])([a-z])(\w*)\b/ig,
function(_, p1, p2, p3) {
return p1 + p2.toUpperCase() + p3.toLowerCase();
}
);
}
Type: makeValuesTicks([[min: number,] max: number,] values: number[]) -> ColormapTick[]
Returns a list of ticks such that all values
are shown as ticks.
- If
min
is not given the first value will be used instead. - If
max
is not given the last value will be used instead.
function makeValuesTicks(min, max, values) {
if (Array.isArray(min)) {
values = min;
min = NaN;
max = NaN;
} else if (Array.isArray(max)) {
values = max;
max = NaN;
}
min = isNaN(min) ? values[0] : min;
max = isNaN(max) ? values[values.length - 1] : max;
return values.map(function(value) {
return [(value - min) / (max - min), Math.round(value * 1e2) / 1e2];
});
}
Type: makeDeltaTicks(min: number, max: number, delta: number, multiple: boolean = false) -> ColormapTick[]
Returns a list of ticks such that:
- The
min
value is included - The
max
value is included - If
multiple
is not set, allmin + n * delta < max
are included- except values that are visually too close to
max
- except values that are visually too close to
- If
multiple
is set, all multiples of delta betweenmin + delta
andmax
are included- except values that are visually too close to
max
- except values that are visually too close to
function makeDeltaTicks(min, max, delta, multiple) {
var start = min + delta;
if (multiple && start % delta !== 0) {
start = ODL.nextMultiple(start, delta);
}
var values = [];
values.push(min);
for (var value = start; (value - min) / (max - min) < 0.92; value += delta) {
values.push(value);
}
values.push(max);
return makeValuesTicks(min, max, values);
}
Type: makeMinMaxTicks(count: number) -> ColormapTick[]
Returns a list of ticks such that:
- The minimum tick is labeled "min"
- The maximum tick is labeled "max"
- There are in total
count
segments on the colormap
function makeMinMaxTicks(count) {
var ticks = [[0, 'min']];
for (var i = 1; i < count; i++) {
ticks.push([i / count, '']);
}
ticks.push([1, 'max']);
return ticks;
}