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
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,000 | louischatriot/nedb | browser-version/out/nedb.js | getRandomArray | function getRandomArray (n) {
var res, next;
if (n === 0) { return []; }
if (n === 1) { return [0]; }
res = getRandomArray(n - 1);
next = Math.floor(Math.random() * n);
res.splice(next, 0, n - 1); // Add n-1 at a random position in the array
return res;
} | javascript | function getRandomArray (n) {
var res, next;
if (n === 0) { return []; }
if (n === 1) { return [0]; }
res = getRandomArray(n - 1);
next = Math.floor(Math.random() * n);
res.splice(next, 0, n - 1); // Add n-1 at a random position in the array
return res;
} | [
"function",
"getRandomArray",
"(",
"n",
")",
"{",
"var",
"res",
",",
"next",
";",
"if",
"(",
"n",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"n",
"===",
"1",
")",
"{",
"return",
"[",
"0",
"]",
";",
"}",
"res",
"=",
"getRandomArray",
"(",
"n",
"-",
"1",
")",
";",
"next",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"n",
")",
";",
"res",
".",
"splice",
"(",
"next",
",",
"0",
",",
"n",
"-",
"1",
")",
";",
"// Add n-1 at a random position in the array",
"return",
"res",
";",
"}"
] | Return an array with the numbers from 0 to n-1, in a random order | [
"Return",
"an",
"array",
"with",
"the",
"numbers",
"from",
"0",
"to",
"n",
"-",
"1",
"in",
"a",
"random",
"order"
] | aa3302e5dcefa471431901a8f3fe63e532a5a7b2 | https://github.com/louischatriot/nedb/blob/aa3302e5dcefa471431901a8f3fe63e532a5a7b2/browser-version/out/nedb.js#L5368-L5379 |
6,001 | louischatriot/nedb | browser-version/out/nedb.js | Promise | function Promise(resolver) {
if (!isFunction(resolver)) {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
if (!(this instanceof Promise)) {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}
this._subscribers = [];
invokeResolver(resolver, this);
} | javascript | function Promise(resolver) {
if (!isFunction(resolver)) {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
if (!(this instanceof Promise)) {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}
this._subscribers = [];
invokeResolver(resolver, this);
} | [
"function",
"Promise",
"(",
"resolver",
")",
"{",
"if",
"(",
"!",
"isFunction",
"(",
"resolver",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'You must pass a resolver function as the first argument to the promise constructor'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Promise",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.\"",
")",
";",
"}",
"this",
".",
"_subscribers",
"=",
"[",
"]",
";",
"invokeResolver",
"(",
"resolver",
",",
"this",
")",
";",
"}"
] | default async is asap; | [
"default",
"async",
"is",
"asap",
";"
] | aa3302e5dcefa471431901a8f3fe63e532a5a7b2 | https://github.com/louischatriot/nedb/blob/aa3302e5dcefa471431901a8f3fe63e532a5a7b2/browser-version/out/nedb.js#L5711-L5723 |
6,002 | Blizzard/node-rdkafka | lib/kafka-consumer-stream.js | KafkaConsumerStream | function KafkaConsumerStream(consumer, options) {
if (!(this instanceof KafkaConsumerStream)) {
return new KafkaConsumerStream(consumer, options);
}
if (options === undefined) {
options = { waitInterval: 1000 };
} else if (typeof options === 'number') {
options = { waitInterval: options };
} else if (options === null || typeof options !== 'object') {
throw new TypeError('"options" argument must be a number or an object');
}
var topics = options.topics;
if (typeof topics === 'function') {
// Just ignore the rest of the checks here
} else if (!Array.isArray(topics)) {
if (typeof topics !== 'string' && !(topics instanceof RegExp)) {
throw new TypeError('"topics" argument must be a string, regex, or an array');
} else {
topics = [topics];
}
}
options = Object.create(options);
var fetchSize = options.fetchSize || 1;
// Run in object mode by default.
if (options.objectMode === null || options.objectMode === undefined) {
options.objectMode = true;
// If they did not explicitly set high water mark, and we are running
// in object mode, set it to the fetch size + 2 to ensure there is room
// for a standard fetch
if (!options.highWaterMark) {
options.highWaterMark = fetchSize + 2;
}
}
if (options.objectMode !== true) {
this._read = this._read_buffer;
} else {
this._read = this._read_message;
}
Readable.call(this, options);
this.consumer = consumer;
this.topics = topics;
this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
this.waitInterval = options.waitInterval === undefined ? 1000 : options.waitInterval;
this.fetchSize = fetchSize;
this.connectOptions = options.connectOptions || {};
this.streamAsBatch = options.streamAsBatch || false;
// Hold the messages in here
this.messages = [];
var self = this;
this.consumer
.on('unsubscribed', function() {
// Invalidate the stream when we unsubscribe
self.push(null);
});
// Call connect. Handles potentially being connected already
this.connect(this.connectOptions);
this.once('end', function() {
if (this.autoClose) {
this.destroy();
}
});
} | javascript | function KafkaConsumerStream(consumer, options) {
if (!(this instanceof KafkaConsumerStream)) {
return new KafkaConsumerStream(consumer, options);
}
if (options === undefined) {
options = { waitInterval: 1000 };
} else if (typeof options === 'number') {
options = { waitInterval: options };
} else if (options === null || typeof options !== 'object') {
throw new TypeError('"options" argument must be a number or an object');
}
var topics = options.topics;
if (typeof topics === 'function') {
// Just ignore the rest of the checks here
} else if (!Array.isArray(topics)) {
if (typeof topics !== 'string' && !(topics instanceof RegExp)) {
throw new TypeError('"topics" argument must be a string, regex, or an array');
} else {
topics = [topics];
}
}
options = Object.create(options);
var fetchSize = options.fetchSize || 1;
// Run in object mode by default.
if (options.objectMode === null || options.objectMode === undefined) {
options.objectMode = true;
// If they did not explicitly set high water mark, and we are running
// in object mode, set it to the fetch size + 2 to ensure there is room
// for a standard fetch
if (!options.highWaterMark) {
options.highWaterMark = fetchSize + 2;
}
}
if (options.objectMode !== true) {
this._read = this._read_buffer;
} else {
this._read = this._read_message;
}
Readable.call(this, options);
this.consumer = consumer;
this.topics = topics;
this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
this.waitInterval = options.waitInterval === undefined ? 1000 : options.waitInterval;
this.fetchSize = fetchSize;
this.connectOptions = options.connectOptions || {};
this.streamAsBatch = options.streamAsBatch || false;
// Hold the messages in here
this.messages = [];
var self = this;
this.consumer
.on('unsubscribed', function() {
// Invalidate the stream when we unsubscribe
self.push(null);
});
// Call connect. Handles potentially being connected already
this.connect(this.connectOptions);
this.once('end', function() {
if (this.autoClose) {
this.destroy();
}
});
} | [
"function",
"KafkaConsumerStream",
"(",
"consumer",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"KafkaConsumerStream",
")",
")",
"{",
"return",
"new",
"KafkaConsumerStream",
"(",
"consumer",
",",
"options",
")",
";",
"}",
"if",
"(",
"options",
"===",
"undefined",
")",
"{",
"options",
"=",
"{",
"waitInterval",
":",
"1000",
"}",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"'number'",
")",
"{",
"options",
"=",
"{",
"waitInterval",
":",
"options",
"}",
";",
"}",
"else",
"if",
"(",
"options",
"===",
"null",
"||",
"typeof",
"options",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"options\" argument must be a number or an object'",
")",
";",
"}",
"var",
"topics",
"=",
"options",
".",
"topics",
";",
"if",
"(",
"typeof",
"topics",
"===",
"'function'",
")",
"{",
"// Just ignore the rest of the checks here",
"}",
"else",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"topics",
")",
")",
"{",
"if",
"(",
"typeof",
"topics",
"!==",
"'string'",
"&&",
"!",
"(",
"topics",
"instanceof",
"RegExp",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"topics\" argument must be a string, regex, or an array'",
")",
";",
"}",
"else",
"{",
"topics",
"=",
"[",
"topics",
"]",
";",
"}",
"}",
"options",
"=",
"Object",
".",
"create",
"(",
"options",
")",
";",
"var",
"fetchSize",
"=",
"options",
".",
"fetchSize",
"||",
"1",
";",
"// Run in object mode by default.",
"if",
"(",
"options",
".",
"objectMode",
"===",
"null",
"||",
"options",
".",
"objectMode",
"===",
"undefined",
")",
"{",
"options",
".",
"objectMode",
"=",
"true",
";",
"// If they did not explicitly set high water mark, and we are running",
"// in object mode, set it to the fetch size + 2 to ensure there is room",
"// for a standard fetch",
"if",
"(",
"!",
"options",
".",
"highWaterMark",
")",
"{",
"options",
".",
"highWaterMark",
"=",
"fetchSize",
"+",
"2",
";",
"}",
"}",
"if",
"(",
"options",
".",
"objectMode",
"!==",
"true",
")",
"{",
"this",
".",
"_read",
"=",
"this",
".",
"_read_buffer",
";",
"}",
"else",
"{",
"this",
".",
"_read",
"=",
"this",
".",
"_read_message",
";",
"}",
"Readable",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"consumer",
"=",
"consumer",
";",
"this",
".",
"topics",
"=",
"topics",
";",
"this",
".",
"autoClose",
"=",
"options",
".",
"autoClose",
"===",
"undefined",
"?",
"true",
":",
"!",
"!",
"options",
".",
"autoClose",
";",
"this",
".",
"waitInterval",
"=",
"options",
".",
"waitInterval",
"===",
"undefined",
"?",
"1000",
":",
"options",
".",
"waitInterval",
";",
"this",
".",
"fetchSize",
"=",
"fetchSize",
";",
"this",
".",
"connectOptions",
"=",
"options",
".",
"connectOptions",
"||",
"{",
"}",
";",
"this",
".",
"streamAsBatch",
"=",
"options",
".",
"streamAsBatch",
"||",
"false",
";",
"// Hold the messages in here",
"this",
".",
"messages",
"=",
"[",
"]",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"consumer",
".",
"on",
"(",
"'unsubscribed'",
",",
"function",
"(",
")",
"{",
"// Invalidate the stream when we unsubscribe",
"self",
".",
"push",
"(",
"null",
")",
";",
"}",
")",
";",
"// Call connect. Handles potentially being connected already",
"this",
".",
"connect",
"(",
"this",
".",
"connectOptions",
")",
";",
"this",
".",
"once",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"autoClose",
")",
"{",
"this",
".",
"destroy",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | ReadableStream integrating with the Kafka Consumer.
This class is used to read data off of Kafka in a streaming way. It is
useful if you'd like to have a way to pipe Kafka into other systems. You
should generally not make this class yourself, as it is not even exposed
as part of module.exports. Instead, you should KafkaConsumer.createReadStream.
The stream implementation is slower than the continuous subscribe callback.
If you don't care so much about backpressure and would rather squeeze
out performance, use that method. Using the stream will ensure you read only
as fast as you write.
The stream detects if Kafka is already connected. If it is, it will begin
reading. If it is not, it will connect and read when it is ready.
This stream operates in objectMode. It streams {Consumer~Message}
@param {Consumer} consumer - The Kafka Consumer object.
@param {object} options - Options to configure the stream.
@param {number} options.waitInterval - Number of ms to wait if Kafka reports
that it has timed out or that we are out of messages (right now).
@param {array} options.topics - Array of topics, or a function that parses
metadata into an array of topics
@constructor
@extends stream.Readable
@see Consumer~Message | [
"ReadableStream",
"integrating",
"with",
"the",
"Kafka",
"Consumer",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/kafka-consumer-stream.js#L47-L124 |
6,003 | Blizzard/node-rdkafka | lib/kafka-consumer-stream.js | retry | function retry() {
if (!self.waitInterval) {
setImmediate(function() {
self._read(size);
});
} else {
setTimeout(function() {
self._read(size);
}, self.waitInterval * Math.random()).unref();
}
} | javascript | function retry() {
if (!self.waitInterval) {
setImmediate(function() {
self._read(size);
});
} else {
setTimeout(function() {
self._read(size);
}, self.waitInterval * Math.random()).unref();
}
} | [
"function",
"retry",
"(",
")",
"{",
"if",
"(",
"!",
"self",
".",
"waitInterval",
")",
"{",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"self",
".",
"_read",
"(",
"size",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"_read",
"(",
"size",
")",
";",
"}",
",",
"self",
".",
"waitInterval",
"*",
"Math",
".",
"random",
"(",
")",
")",
".",
"unref",
"(",
")",
";",
"}",
"}"
] | Retry function. Will wait up to the wait interval, with some random noise if one is provided. Otherwise, will go immediately. | [
"Retry",
"function",
".",
"Will",
"wait",
"up",
"to",
"the",
"wait",
"interval",
"with",
"some",
"random",
"noise",
"if",
"one",
"is",
"provided",
".",
"Otherwise",
"will",
"go",
"immediately",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/kafka-consumer-stream.js#L166-L176 |
6,004 | Blizzard/node-rdkafka | lib/tools/ref-counter.js | RefCounter | function RefCounter(onActive, onPassive) {
this.context = {};
this.onActive = onActive;
this.onPassive = onPassive;
this.currentValue = 0;
this.isRunning = false;
} | javascript | function RefCounter(onActive, onPassive) {
this.context = {};
this.onActive = onActive;
this.onPassive = onPassive;
this.currentValue = 0;
this.isRunning = false;
} | [
"function",
"RefCounter",
"(",
"onActive",
",",
"onPassive",
")",
"{",
"this",
".",
"context",
"=",
"{",
"}",
";",
"this",
".",
"onActive",
"=",
"onActive",
";",
"this",
".",
"onPassive",
"=",
"onPassive",
";",
"this",
".",
"currentValue",
"=",
"0",
";",
"this",
".",
"isRunning",
"=",
"false",
";",
"}"
] | Ref counter class.
Is used to basically determine active/inactive and allow callbacks that
hook into each.
For the producer, it is used to begin rapid polling after a produce until
the delivery report is dispatched. | [
"Ref",
"counter",
"class",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/tools/ref-counter.js#L21-L27 |
6,005 | Blizzard/node-rdkafka | lib/client.js | Client | function Client(globalConf, SubClientType, topicConf) {
if (!(this instanceof Client)) {
return new Client(globalConf, SubClientType, topicConf);
}
Emitter.call(this);
// This superclass must be initialized with the Kafka.{Producer,Consumer}
// @example var client = new Client({}, Kafka.Producer);
// remember this is a superclass so this will get taken care of in
// the producer and consumer main wrappers
var no_event_cb = globalConf.event_cb === false;
topicConf = topicConf || {};
// delete this because librdkafka will complain since this particular
// key is a real conf value
delete globalConf.event_cb;
this._client = new SubClientType(globalConf, topicConf);
// primitive callbacks from c++ wrapper
// need binds on them if we want to broadcast the event via the emitter
// However, the C++ wrapper lazy processes callbacks.
// If we want to improve performance, removing this line is a good way to do it.
// we need to do this on creation of the object
// thats why we did some processing on config
// Self required because we are inside an async callback function scope
if (!no_event_cb) {
this._client.onEvent(function eventHandler(eventType, eventData) {
switch (eventType) {
case 'error':
self.emit('event.error', LibrdKafkaError.create(eventData));
break;
case 'stats':
self.emit('event.stats', eventData);
break;
case 'log':
self.emit('event.log', eventData);
break;
default:
self.emit('event.event', eventData);
self.emit('event.' + eventType, eventData);
}
});
}
this.metrics = {};
this._isConnected = false;
this.errorCounter = 0;
/**
* Metadata object. Starts out empty but will be filled with information after
* the initial connect.
*
* @type {Client~Metadata}
*/
this._metadata = {};
var self = this;
this.on('ready', function(info) {
self.metrics.connectionOpened = Date.now();
self.name = info.name;
})
.on('disconnected', function() {
// reset metrics
self.metrics = {};
self._isConnected = false;
// keep the metadata. it still may be useful
})
.on('event.error', function(err) {
self.lastError = err;
++self.errorCounter;
});
} | javascript | function Client(globalConf, SubClientType, topicConf) {
if (!(this instanceof Client)) {
return new Client(globalConf, SubClientType, topicConf);
}
Emitter.call(this);
// This superclass must be initialized with the Kafka.{Producer,Consumer}
// @example var client = new Client({}, Kafka.Producer);
// remember this is a superclass so this will get taken care of in
// the producer and consumer main wrappers
var no_event_cb = globalConf.event_cb === false;
topicConf = topicConf || {};
// delete this because librdkafka will complain since this particular
// key is a real conf value
delete globalConf.event_cb;
this._client = new SubClientType(globalConf, topicConf);
// primitive callbacks from c++ wrapper
// need binds on them if we want to broadcast the event via the emitter
// However, the C++ wrapper lazy processes callbacks.
// If we want to improve performance, removing this line is a good way to do it.
// we need to do this on creation of the object
// thats why we did some processing on config
// Self required because we are inside an async callback function scope
if (!no_event_cb) {
this._client.onEvent(function eventHandler(eventType, eventData) {
switch (eventType) {
case 'error':
self.emit('event.error', LibrdKafkaError.create(eventData));
break;
case 'stats':
self.emit('event.stats', eventData);
break;
case 'log':
self.emit('event.log', eventData);
break;
default:
self.emit('event.event', eventData);
self.emit('event.' + eventType, eventData);
}
});
}
this.metrics = {};
this._isConnected = false;
this.errorCounter = 0;
/**
* Metadata object. Starts out empty but will be filled with information after
* the initial connect.
*
* @type {Client~Metadata}
*/
this._metadata = {};
var self = this;
this.on('ready', function(info) {
self.metrics.connectionOpened = Date.now();
self.name = info.name;
})
.on('disconnected', function() {
// reset metrics
self.metrics = {};
self._isConnected = false;
// keep the metadata. it still may be useful
})
.on('event.error', function(err) {
self.lastError = err;
++self.errorCounter;
});
} | [
"function",
"Client",
"(",
"globalConf",
",",
"SubClientType",
",",
"topicConf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Client",
")",
")",
"{",
"return",
"new",
"Client",
"(",
"globalConf",
",",
"SubClientType",
",",
"topicConf",
")",
";",
"}",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"// This superclass must be initialized with the Kafka.{Producer,Consumer}",
"// @example var client = new Client({}, Kafka.Producer);",
"// remember this is a superclass so this will get taken care of in",
"// the producer and consumer main wrappers",
"var",
"no_event_cb",
"=",
"globalConf",
".",
"event_cb",
"===",
"false",
";",
"topicConf",
"=",
"topicConf",
"||",
"{",
"}",
";",
"// delete this because librdkafka will complain since this particular",
"// key is a real conf value",
"delete",
"globalConf",
".",
"event_cb",
";",
"this",
".",
"_client",
"=",
"new",
"SubClientType",
"(",
"globalConf",
",",
"topicConf",
")",
";",
"// primitive callbacks from c++ wrapper",
"// need binds on them if we want to broadcast the event via the emitter",
"// However, the C++ wrapper lazy processes callbacks.",
"// If we want to improve performance, removing this line is a good way to do it.",
"// we need to do this on creation of the object",
"// thats why we did some processing on config",
"// Self required because we are inside an async callback function scope",
"if",
"(",
"!",
"no_event_cb",
")",
"{",
"this",
".",
"_client",
".",
"onEvent",
"(",
"function",
"eventHandler",
"(",
"eventType",
",",
"eventData",
")",
"{",
"switch",
"(",
"eventType",
")",
"{",
"case",
"'error'",
":",
"self",
".",
"emit",
"(",
"'event.error'",
",",
"LibrdKafkaError",
".",
"create",
"(",
"eventData",
")",
")",
";",
"break",
";",
"case",
"'stats'",
":",
"self",
".",
"emit",
"(",
"'event.stats'",
",",
"eventData",
")",
";",
"break",
";",
"case",
"'log'",
":",
"self",
".",
"emit",
"(",
"'event.log'",
",",
"eventData",
")",
";",
"break",
";",
"default",
":",
"self",
".",
"emit",
"(",
"'event.event'",
",",
"eventData",
")",
";",
"self",
".",
"emit",
"(",
"'event.'",
"+",
"eventType",
",",
"eventData",
")",
";",
"}",
"}",
")",
";",
"}",
"this",
".",
"metrics",
"=",
"{",
"}",
";",
"this",
".",
"_isConnected",
"=",
"false",
";",
"this",
".",
"errorCounter",
"=",
"0",
";",
"/**\n * Metadata object. Starts out empty but will be filled with information after\n * the initial connect.\n *\n * @type {Client~Metadata}\n */",
"this",
".",
"_metadata",
"=",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"on",
"(",
"'ready'",
",",
"function",
"(",
"info",
")",
"{",
"self",
".",
"metrics",
".",
"connectionOpened",
"=",
"Date",
".",
"now",
"(",
")",
";",
"self",
".",
"name",
"=",
"info",
".",
"name",
";",
"}",
")",
".",
"on",
"(",
"'disconnected'",
",",
"function",
"(",
")",
"{",
"// reset metrics",
"self",
".",
"metrics",
"=",
"{",
"}",
";",
"self",
".",
"_isConnected",
"=",
"false",
";",
"// keep the metadata. it still may be useful",
"}",
")",
".",
"on",
"(",
"'event.error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"lastError",
"=",
"err",
";",
"++",
"self",
".",
"errorCounter",
";",
"}",
")",
";",
"}"
] | Base class for Consumer and Producer
This should not be created independently, but rather is
the base class on which both producer and consumer
get their common functionality.
@param {object} globalConf - Global configuration in key value pairs.
@param {function} SubClientType - The function representing the subclient
type. In C++ land this needs to be a class that inherits from Connection.
@param {object} topicConf - Topic configuration in key value pairs
@constructor
@extends Emitter | [
"Base",
"class",
"for",
"Consumer",
"and",
"Producer"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/client.js#L35-L113 |
6,006 | Blizzard/node-rdkafka | lib/topic-partition.js | TopicPartition | function TopicPartition(topic, partition, offset) {
if (!(this instanceof TopicPartition)) {
return new TopicPartition(topic, partition, offset);
}
// Validate that the elements we are iterating over are actual topic partition
// js objects. They do not need an offset, but they do need partition
if (!topic) {
throw new TypeError('"topic" must be a string and must be set');
}
if (partition === null || partition === undefined) {
throw new TypeError('"partition" must be a number and must set');
}
// We can just set topic and partition as they stand.
this.topic = topic;
this.partition = partition;
if (offset === undefined || offset === null) {
this.offset = Topic.OFFSET_STORED;
} else if (typeof offset === 'string') {
switch (offset.toLowerCase()) {
case 'earliest':
case 'beginning':
this.offset = Topic.OFFSET_BEGINNING;
break;
case 'latest':
case 'end':
this.offset = Topic.OFFSET_END;
break;
case 'stored':
this.offset = Topic.OFFSET_STORED;
break;
default:
throw new TypeError('"offset", if provided as a string, must be beginning, end, or stored.');
}
} else if (typeof offset === 'number') {
this.offset = offset;
} else {
throw new TypeError('"offset" must be a special string or number if it is set');
}
} | javascript | function TopicPartition(topic, partition, offset) {
if (!(this instanceof TopicPartition)) {
return new TopicPartition(topic, partition, offset);
}
// Validate that the elements we are iterating over are actual topic partition
// js objects. They do not need an offset, but they do need partition
if (!topic) {
throw new TypeError('"topic" must be a string and must be set');
}
if (partition === null || partition === undefined) {
throw new TypeError('"partition" must be a number and must set');
}
// We can just set topic and partition as they stand.
this.topic = topic;
this.partition = partition;
if (offset === undefined || offset === null) {
this.offset = Topic.OFFSET_STORED;
} else if (typeof offset === 'string') {
switch (offset.toLowerCase()) {
case 'earliest':
case 'beginning':
this.offset = Topic.OFFSET_BEGINNING;
break;
case 'latest':
case 'end':
this.offset = Topic.OFFSET_END;
break;
case 'stored':
this.offset = Topic.OFFSET_STORED;
break;
default:
throw new TypeError('"offset", if provided as a string, must be beginning, end, or stored.');
}
} else if (typeof offset === 'number') {
this.offset = offset;
} else {
throw new TypeError('"offset" must be a special string or number if it is set');
}
} | [
"function",
"TopicPartition",
"(",
"topic",
",",
"partition",
",",
"offset",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"TopicPartition",
")",
")",
"{",
"return",
"new",
"TopicPartition",
"(",
"topic",
",",
"partition",
",",
"offset",
")",
";",
"}",
"// Validate that the elements we are iterating over are actual topic partition",
"// js objects. They do not need an offset, but they do need partition",
"if",
"(",
"!",
"topic",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"topic\" must be a string and must be set'",
")",
";",
"}",
"if",
"(",
"partition",
"===",
"null",
"||",
"partition",
"===",
"undefined",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"partition\" must be a number and must set'",
")",
";",
"}",
"// We can just set topic and partition as they stand.",
"this",
".",
"topic",
"=",
"topic",
";",
"this",
".",
"partition",
"=",
"partition",
";",
"if",
"(",
"offset",
"===",
"undefined",
"||",
"offset",
"===",
"null",
")",
"{",
"this",
".",
"offset",
"=",
"Topic",
".",
"OFFSET_STORED",
";",
"}",
"else",
"if",
"(",
"typeof",
"offset",
"===",
"'string'",
")",
"{",
"switch",
"(",
"offset",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'earliest'",
":",
"case",
"'beginning'",
":",
"this",
".",
"offset",
"=",
"Topic",
".",
"OFFSET_BEGINNING",
";",
"break",
";",
"case",
"'latest'",
":",
"case",
"'end'",
":",
"this",
".",
"offset",
"=",
"Topic",
".",
"OFFSET_END",
";",
"break",
";",
"case",
"'stored'",
":",
"this",
".",
"offset",
"=",
"Topic",
".",
"OFFSET_STORED",
";",
"break",
";",
"default",
":",
"throw",
"new",
"TypeError",
"(",
"'\"offset\", if provided as a string, must be beginning, end, or stored.'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"offset",
"===",
"'number'",
")",
"{",
"this",
".",
"offset",
"=",
"offset",
";",
"}",
"else",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"offset\" must be a special string or number if it is set'",
")",
";",
"}",
"}"
] | Create a topic partition. Just does some validation and decoration
on topic partitions provided.
Goal is still to behave like a plain javascript object but with validation
and potentially some extra methods | [
"Create",
"a",
"topic",
"partition",
".",
"Just",
"does",
"some",
"validation",
"and",
"decoration",
"on",
"topic",
"partitions",
"provided",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/topic-partition.js#L46-L88 |
6,007 | Blizzard/node-rdkafka | lib/kafka-consumer.js | KafkaConsumer | function KafkaConsumer(conf, topicConf) {
if (!(this instanceof KafkaConsumer)) {
return new KafkaConsumer(conf, topicConf);
}
conf = shallowCopy(conf);
topicConf = shallowCopy(topicConf);
var onRebalance = conf.rebalance_cb;
var self = this;
// If rebalance is undefined we don't want any part of this
if (onRebalance && typeof onRebalance === 'boolean') {
conf.rebalance_cb = function(err, assignment) {
// Create the librdkafka error
err = LibrdKafkaError.create(err);
// Emit the event
self.emit('rebalance', err, assignment);
// That's it
try {
if (err.code === -175 /*ERR__ASSIGN_PARTITIONS*/) {
self.assign(assignment);
} else if (err.code === -174 /*ERR__REVOKE_PARTITIONS*/) {
self.unassign();
}
} catch (e) {
// Ignore exceptions if we are not connected
if (self.isConnected()) {
self.emit('rebalance.error', e);
}
}
};
} else if (onRebalance && typeof onRebalance === 'function') {
/*
* Once this is opted in to, that's it. It's going to manually rebalance
* forever. There is no way to unset config values in librdkafka, just
* a way to override them.
*/
conf.rebalance_cb = function(err, assignment) {
// Create the librdkafka error
err = err ? LibrdKafkaError.create(err) : undefined;
self.emit('rebalance', err, assignment);
onRebalance.call(self, err, assignment);
};
}
// Same treatment for offset_commit_cb
var onOffsetCommit = conf.offset_commit_cb;
if (onOffsetCommit && typeof onOffsetCommit === 'boolean') {
conf.offset_commit_cb = function(err, offsets) {
// Emit the event
self.emit('offset.commit', offsets);
};
} else if (onOffsetCommit && typeof onOffsetCommit === 'function') {
conf.offset_commit_cb = function(err, offsets) {
// Emit the event
self.emit('offset.commit', offsets);
onOffsetCommit.call(self, err, offsets);
};
}
/**
* KafkaConsumer message.
*
* This is the representation of a message read from Kafka.
*
* @typedef {object} KafkaConsumer~Message
* @property {buffer} value - the message buffer from Kafka.
* @property {string} topic - the topic name
* @property {number} partition - the partition on the topic the
* message was on
* @property {number} offset - the offset of the message
* @property {string} key - the message key
* @property {number} size - message size, in bytes.
* @property {number} timestamp - message timestamp
*/
Client.call(this, conf, Kafka.KafkaConsumer, topicConf);
this.globalConfig = conf;
this.topicConfig = topicConf;
this._consumeTimeout = 1000;
} | javascript | function KafkaConsumer(conf, topicConf) {
if (!(this instanceof KafkaConsumer)) {
return new KafkaConsumer(conf, topicConf);
}
conf = shallowCopy(conf);
topicConf = shallowCopy(topicConf);
var onRebalance = conf.rebalance_cb;
var self = this;
// If rebalance is undefined we don't want any part of this
if (onRebalance && typeof onRebalance === 'boolean') {
conf.rebalance_cb = function(err, assignment) {
// Create the librdkafka error
err = LibrdKafkaError.create(err);
// Emit the event
self.emit('rebalance', err, assignment);
// That's it
try {
if (err.code === -175 /*ERR__ASSIGN_PARTITIONS*/) {
self.assign(assignment);
} else if (err.code === -174 /*ERR__REVOKE_PARTITIONS*/) {
self.unassign();
}
} catch (e) {
// Ignore exceptions if we are not connected
if (self.isConnected()) {
self.emit('rebalance.error', e);
}
}
};
} else if (onRebalance && typeof onRebalance === 'function') {
/*
* Once this is opted in to, that's it. It's going to manually rebalance
* forever. There is no way to unset config values in librdkafka, just
* a way to override them.
*/
conf.rebalance_cb = function(err, assignment) {
// Create the librdkafka error
err = err ? LibrdKafkaError.create(err) : undefined;
self.emit('rebalance', err, assignment);
onRebalance.call(self, err, assignment);
};
}
// Same treatment for offset_commit_cb
var onOffsetCommit = conf.offset_commit_cb;
if (onOffsetCommit && typeof onOffsetCommit === 'boolean') {
conf.offset_commit_cb = function(err, offsets) {
// Emit the event
self.emit('offset.commit', offsets);
};
} else if (onOffsetCommit && typeof onOffsetCommit === 'function') {
conf.offset_commit_cb = function(err, offsets) {
// Emit the event
self.emit('offset.commit', offsets);
onOffsetCommit.call(self, err, offsets);
};
}
/**
* KafkaConsumer message.
*
* This is the representation of a message read from Kafka.
*
* @typedef {object} KafkaConsumer~Message
* @property {buffer} value - the message buffer from Kafka.
* @property {string} topic - the topic name
* @property {number} partition - the partition on the topic the
* message was on
* @property {number} offset - the offset of the message
* @property {string} key - the message key
* @property {number} size - message size, in bytes.
* @property {number} timestamp - message timestamp
*/
Client.call(this, conf, Kafka.KafkaConsumer, topicConf);
this.globalConfig = conf;
this.topicConfig = topicConf;
this._consumeTimeout = 1000;
} | [
"function",
"KafkaConsumer",
"(",
"conf",
",",
"topicConf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"KafkaConsumer",
")",
")",
"{",
"return",
"new",
"KafkaConsumer",
"(",
"conf",
",",
"topicConf",
")",
";",
"}",
"conf",
"=",
"shallowCopy",
"(",
"conf",
")",
";",
"topicConf",
"=",
"shallowCopy",
"(",
"topicConf",
")",
";",
"var",
"onRebalance",
"=",
"conf",
".",
"rebalance_cb",
";",
"var",
"self",
"=",
"this",
";",
"// If rebalance is undefined we don't want any part of this",
"if",
"(",
"onRebalance",
"&&",
"typeof",
"onRebalance",
"===",
"'boolean'",
")",
"{",
"conf",
".",
"rebalance_cb",
"=",
"function",
"(",
"err",
",",
"assignment",
")",
"{",
"// Create the librdkafka error",
"err",
"=",
"LibrdKafkaError",
".",
"create",
"(",
"err",
")",
";",
"// Emit the event",
"self",
".",
"emit",
"(",
"'rebalance'",
",",
"err",
",",
"assignment",
")",
";",
"// That's it",
"try",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"-",
"175",
"/*ERR__ASSIGN_PARTITIONS*/",
")",
"{",
"self",
".",
"assign",
"(",
"assignment",
")",
";",
"}",
"else",
"if",
"(",
"err",
".",
"code",
"===",
"-",
"174",
"/*ERR__REVOKE_PARTITIONS*/",
")",
"{",
"self",
".",
"unassign",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"// Ignore exceptions if we are not connected",
"if",
"(",
"self",
".",
"isConnected",
"(",
")",
")",
"{",
"self",
".",
"emit",
"(",
"'rebalance.error'",
",",
"e",
")",
";",
"}",
"}",
"}",
";",
"}",
"else",
"if",
"(",
"onRebalance",
"&&",
"typeof",
"onRebalance",
"===",
"'function'",
")",
"{",
"/*\n * Once this is opted in to, that's it. It's going to manually rebalance\n * forever. There is no way to unset config values in librdkafka, just\n * a way to override them.\n */",
"conf",
".",
"rebalance_cb",
"=",
"function",
"(",
"err",
",",
"assignment",
")",
"{",
"// Create the librdkafka error",
"err",
"=",
"err",
"?",
"LibrdKafkaError",
".",
"create",
"(",
"err",
")",
":",
"undefined",
";",
"self",
".",
"emit",
"(",
"'rebalance'",
",",
"err",
",",
"assignment",
")",
";",
"onRebalance",
".",
"call",
"(",
"self",
",",
"err",
",",
"assignment",
")",
";",
"}",
";",
"}",
"// Same treatment for offset_commit_cb",
"var",
"onOffsetCommit",
"=",
"conf",
".",
"offset_commit_cb",
";",
"if",
"(",
"onOffsetCommit",
"&&",
"typeof",
"onOffsetCommit",
"===",
"'boolean'",
")",
"{",
"conf",
".",
"offset_commit_cb",
"=",
"function",
"(",
"err",
",",
"offsets",
")",
"{",
"// Emit the event",
"self",
".",
"emit",
"(",
"'offset.commit'",
",",
"offsets",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"onOffsetCommit",
"&&",
"typeof",
"onOffsetCommit",
"===",
"'function'",
")",
"{",
"conf",
".",
"offset_commit_cb",
"=",
"function",
"(",
"err",
",",
"offsets",
")",
"{",
"// Emit the event",
"self",
".",
"emit",
"(",
"'offset.commit'",
",",
"offsets",
")",
";",
"onOffsetCommit",
".",
"call",
"(",
"self",
",",
"err",
",",
"offsets",
")",
";",
"}",
";",
"}",
"/**\n * KafkaConsumer message.\n *\n * This is the representation of a message read from Kafka.\n *\n * @typedef {object} KafkaConsumer~Message\n * @property {buffer} value - the message buffer from Kafka.\n * @property {string} topic - the topic name\n * @property {number} partition - the partition on the topic the\n * message was on\n * @property {number} offset - the offset of the message\n * @property {string} key - the message key\n * @property {number} size - message size, in bytes.\n * @property {number} timestamp - message timestamp\n */",
"Client",
".",
"call",
"(",
"this",
",",
"conf",
",",
"Kafka",
".",
"KafkaConsumer",
",",
"topicConf",
")",
";",
"this",
".",
"globalConfig",
"=",
"conf",
";",
"this",
".",
"topicConfig",
"=",
"topicConf",
";",
"this",
".",
"_consumeTimeout",
"=",
"1000",
";",
"}"
] | KafkaConsumer class for reading messages from Kafka
This is the main entry point for reading data from Kafka. You
configure this like you do any other client, with a global
configuration and default topic configuration.
Once you instantiate this object, connecting will open a socket.
Data will not be read until you tell the consumer what topics
you want to read from.
@param {object} conf - Key value pairs to configure the consumer
@param {object} topicConf - Key value pairs to create a default
topic configuration
@extends Client
@constructor | [
"KafkaConsumer",
"class",
"for",
"reading",
"messages",
"from",
"Kafka"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/kafka-consumer.js#L40-L128 |
6,008 | Blizzard/node-rdkafka | lib/producer/high-level-producer.js | createSerializer | function createSerializer(serializer) {
var applyFn = function serializationWrapper(v, cb) {
try {
return cb ? serializer(v, cb) : serializer(v);
} catch (e) {
var modifiedError = new Error('Could not serialize value: ' + e.message);
modifiedError.value = v;
modifiedError.serializer = serializer;
throw modifiedError;
}
};
// We can check how many parameters the function has and activate the asynchronous
// operation if the number of parameters the function accepts is > 1
return {
apply: applyFn,
async: serializer.length > 1
};
} | javascript | function createSerializer(serializer) {
var applyFn = function serializationWrapper(v, cb) {
try {
return cb ? serializer(v, cb) : serializer(v);
} catch (e) {
var modifiedError = new Error('Could not serialize value: ' + e.message);
modifiedError.value = v;
modifiedError.serializer = serializer;
throw modifiedError;
}
};
// We can check how many parameters the function has and activate the asynchronous
// operation if the number of parameters the function accepts is > 1
return {
apply: applyFn,
async: serializer.length > 1
};
} | [
"function",
"createSerializer",
"(",
"serializer",
")",
"{",
"var",
"applyFn",
"=",
"function",
"serializationWrapper",
"(",
"v",
",",
"cb",
")",
"{",
"try",
"{",
"return",
"cb",
"?",
"serializer",
"(",
"v",
",",
"cb",
")",
":",
"serializer",
"(",
"v",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"modifiedError",
"=",
"new",
"Error",
"(",
"'Could not serialize value: '",
"+",
"e",
".",
"message",
")",
";",
"modifiedError",
".",
"value",
"=",
"v",
";",
"modifiedError",
".",
"serializer",
"=",
"serializer",
";",
"throw",
"modifiedError",
";",
"}",
"}",
";",
"// We can check how many parameters the function has and activate the asynchronous",
"// operation if the number of parameters the function accepts is > 1",
"return",
"{",
"apply",
":",
"applyFn",
",",
"async",
":",
"serializer",
".",
"length",
">",
"1",
"}",
";",
"}"
] | Create a serializer
Method simply wraps a serializer provided by a user
so it adds context to the error
@returns {function} Serialization function | [
"Create",
"a",
"serializer"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/producer/high-level-producer.js#L34-L52 |
6,009 | Blizzard/node-rdkafka | lib/producer/high-level-producer.js | HighLevelProducer | function HighLevelProducer(conf, topicConf) {
if (!(this instanceof HighLevelProducer)) {
return new HighLevelProducer(conf, topicConf);
}
// Force this to be true for the high level producer
conf = shallowCopy(conf);
conf.dr_cb = true;
// producer is an initialized consumer object
// @see NodeKafka::Producer::Init
Producer.call(this, conf, topicConf);
var self = this;
// Add a delivery emitter to the producer
this._hl = {
deliveryEmitter: new EventEmitter(),
messageId: 0,
// Special logic for polling. We use a reference counter to know when we need
// to be doing it and when we can stop. This means when we go into fast polling
// mode we don't need to do multiple calls to poll since they all will yield
// the same result
pollingRefTimeout: null,
};
// Add the polling ref counter to the class which ensures we poll when we go active
this._hl.pollingRef = new RefCounter(function() {
self._hl.pollingRefTimeout = setInterval(function() {
try {
self.poll();
} catch (e) {
if (!self._isConnected) {
// If we got disconnected for some reason there is no point
// in polling anymore
clearInterval(self._hl.pollingRefTimeout);
}
}
}, 1);
}, function() {
clearInterval(self._hl.pollingRefTimeout);
});
// Default poll interval. More sophisticated polling is also done in create rule method
this.setPollInterval(1000);
// Listen to all delivery reports to propagate elements with a _message_id to the emitter
this.on('delivery-report', function(err, report) {
if (report.opaque && report.opaque.__message_id !== undefined) {
self._hl.deliveryEmitter.emit(report.opaque.__message_id, err, report.offset);
}
});
// Save old produce here since we are making some modifications for it
this._oldProduce = this.produce;
this.produce = this._modifiedProduce;
// Serializer information
this.keySerializer = noopSerializer;
this.valueSerializer = noopSerializer;
} | javascript | function HighLevelProducer(conf, topicConf) {
if (!(this instanceof HighLevelProducer)) {
return new HighLevelProducer(conf, topicConf);
}
// Force this to be true for the high level producer
conf = shallowCopy(conf);
conf.dr_cb = true;
// producer is an initialized consumer object
// @see NodeKafka::Producer::Init
Producer.call(this, conf, topicConf);
var self = this;
// Add a delivery emitter to the producer
this._hl = {
deliveryEmitter: new EventEmitter(),
messageId: 0,
// Special logic for polling. We use a reference counter to know when we need
// to be doing it and when we can stop. This means when we go into fast polling
// mode we don't need to do multiple calls to poll since they all will yield
// the same result
pollingRefTimeout: null,
};
// Add the polling ref counter to the class which ensures we poll when we go active
this._hl.pollingRef = new RefCounter(function() {
self._hl.pollingRefTimeout = setInterval(function() {
try {
self.poll();
} catch (e) {
if (!self._isConnected) {
// If we got disconnected for some reason there is no point
// in polling anymore
clearInterval(self._hl.pollingRefTimeout);
}
}
}, 1);
}, function() {
clearInterval(self._hl.pollingRefTimeout);
});
// Default poll interval. More sophisticated polling is also done in create rule method
this.setPollInterval(1000);
// Listen to all delivery reports to propagate elements with a _message_id to the emitter
this.on('delivery-report', function(err, report) {
if (report.opaque && report.opaque.__message_id !== undefined) {
self._hl.deliveryEmitter.emit(report.opaque.__message_id, err, report.offset);
}
});
// Save old produce here since we are making some modifications for it
this._oldProduce = this.produce;
this.produce = this._modifiedProduce;
// Serializer information
this.keySerializer = noopSerializer;
this.valueSerializer = noopSerializer;
} | [
"function",
"HighLevelProducer",
"(",
"conf",
",",
"topicConf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"HighLevelProducer",
")",
")",
"{",
"return",
"new",
"HighLevelProducer",
"(",
"conf",
",",
"topicConf",
")",
";",
"}",
"// Force this to be true for the high level producer",
"conf",
"=",
"shallowCopy",
"(",
"conf",
")",
";",
"conf",
".",
"dr_cb",
"=",
"true",
";",
"// producer is an initialized consumer object",
"// @see NodeKafka::Producer::Init",
"Producer",
".",
"call",
"(",
"this",
",",
"conf",
",",
"topicConf",
")",
";",
"var",
"self",
"=",
"this",
";",
"// Add a delivery emitter to the producer",
"this",
".",
"_hl",
"=",
"{",
"deliveryEmitter",
":",
"new",
"EventEmitter",
"(",
")",
",",
"messageId",
":",
"0",
",",
"// Special logic for polling. We use a reference counter to know when we need",
"// to be doing it and when we can stop. This means when we go into fast polling",
"// mode we don't need to do multiple calls to poll since they all will yield",
"// the same result",
"pollingRefTimeout",
":",
"null",
",",
"}",
";",
"// Add the polling ref counter to the class which ensures we poll when we go active",
"this",
".",
"_hl",
".",
"pollingRef",
"=",
"new",
"RefCounter",
"(",
"function",
"(",
")",
"{",
"self",
".",
"_hl",
".",
"pollingRefTimeout",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"try",
"{",
"self",
".",
"poll",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"self",
".",
"_isConnected",
")",
"{",
"// If we got disconnected for some reason there is no point",
"// in polling anymore",
"clearInterval",
"(",
"self",
".",
"_hl",
".",
"pollingRefTimeout",
")",
";",
"}",
"}",
"}",
",",
"1",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"clearInterval",
"(",
"self",
".",
"_hl",
".",
"pollingRefTimeout",
")",
";",
"}",
")",
";",
"// Default poll interval. More sophisticated polling is also done in create rule method",
"this",
".",
"setPollInterval",
"(",
"1000",
")",
";",
"// Listen to all delivery reports to propagate elements with a _message_id to the emitter",
"this",
".",
"on",
"(",
"'delivery-report'",
",",
"function",
"(",
"err",
",",
"report",
")",
"{",
"if",
"(",
"report",
".",
"opaque",
"&&",
"report",
".",
"opaque",
".",
"__message_id",
"!==",
"undefined",
")",
"{",
"self",
".",
"_hl",
".",
"deliveryEmitter",
".",
"emit",
"(",
"report",
".",
"opaque",
".",
"__message_id",
",",
"err",
",",
"report",
".",
"offset",
")",
";",
"}",
"}",
")",
";",
"// Save old produce here since we are making some modifications for it",
"this",
".",
"_oldProduce",
"=",
"this",
".",
"produce",
";",
"this",
".",
"produce",
"=",
"this",
".",
"_modifiedProduce",
";",
"// Serializer information",
"this",
".",
"keySerializer",
"=",
"noopSerializer",
";",
"this",
".",
"valueSerializer",
"=",
"noopSerializer",
";",
"}"
] | Producer class for sending messages to Kafka in a higher level fashion
This is the main entry point for writing data to Kafka if you want more
functionality than librdkafka supports out of the box. You
configure this like you do any other client, with a global
configuration and default topic configuration.
Once you instantiate this object, you need to connect to it first.
This allows you to get the metadata and make sure the connection
can be made before you depend on it. After that, problems with
the connection will by brought down by using poll, which automatically
runs when a transaction is made on the object.
This has a few restrictions, so it is not for free!
1. You may not define opaque tokens
The higher level producer is powered by opaque tokens.
2. Every message ack will dispatch an event on the node thread.
3. Will use a ref counter to determine if there are outgoing produces.
This will return the new object you should use instead when doing your
produce calls
@param {object} conf - Key value pairs to configure the producer
@param {object} topicConf - Key value pairs to create a default
topic configuration
@extends Producer
@constructor | [
"Producer",
"class",
"for",
"sending",
"messages",
"to",
"Kafka",
"in",
"a",
"higher",
"level",
"fashion"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/producer/high-level-producer.js#L84-L143 |
6,010 | Blizzard/node-rdkafka | lib/producer/high-level-producer.js | doProduce | function doProduce(v, k) {
try {
var r = self._oldProduce(topic, partition,
v, k,
timestamp, opaque);
self._hl.deliveryEmitter.once(opaque.__message_id, function(err, offset) {
self._hl.pollingRef.decrement();
setImmediate(function() {
// Offset must be greater than or equal to 0 otherwise it is a null offset
// Possibly because we have acks off
callback(err, offset >= 0 ? offset : null);
});
});
return r;
} catch (e) {
callback(e);
}
} | javascript | function doProduce(v, k) {
try {
var r = self._oldProduce(topic, partition,
v, k,
timestamp, opaque);
self._hl.deliveryEmitter.once(opaque.__message_id, function(err, offset) {
self._hl.pollingRef.decrement();
setImmediate(function() {
// Offset must be greater than or equal to 0 otherwise it is a null offset
// Possibly because we have acks off
callback(err, offset >= 0 ? offset : null);
});
});
return r;
} catch (e) {
callback(e);
}
} | [
"function",
"doProduce",
"(",
"v",
",",
"k",
")",
"{",
"try",
"{",
"var",
"r",
"=",
"self",
".",
"_oldProduce",
"(",
"topic",
",",
"partition",
",",
"v",
",",
"k",
",",
"timestamp",
",",
"opaque",
")",
";",
"self",
".",
"_hl",
".",
"deliveryEmitter",
".",
"once",
"(",
"opaque",
".",
"__message_id",
",",
"function",
"(",
"err",
",",
"offset",
")",
"{",
"self",
".",
"_hl",
".",
"pollingRef",
".",
"decrement",
"(",
")",
";",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"// Offset must be greater than or equal to 0 otherwise it is a null offset",
"// Possibly because we have acks off",
"callback",
"(",
"err",
",",
"offset",
">=",
"0",
"?",
"offset",
":",
"null",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"r",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
")",
";",
"}",
"}"
] | Actually do the produce with new key and value based on deserialized results | [
"Actually",
"do",
"the",
"produce",
"with",
"new",
"key",
"and",
"value",
"based",
"on",
"deserialized",
"results"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/producer/high-level-producer.js#L180-L199 |
6,011 | Blizzard/node-rdkafka | lib/error.js | LibrdKafkaError | function LibrdKafkaError(e) {
if (!(this instanceof LibrdKafkaError)) {
return new LibrdKafkaError(e);
}
if (typeof e === 'number') {
this.message = librdkafka.err2str(e);
this.code = e;
this.errno = e;
if (e >= LibrdKafkaError.codes.ERR__END) {
this.origin = 'local';
} else {
this.origin = 'kafka';
}
Error.captureStackTrace(this, this.constructor);
} else if (!util.isError(e)) {
// This is the better way
this.message = e.message;
this.code = e.code;
this.errno = e.code;
if (e.code >= LibrdKafkaError.codes.ERR__END) {
this.origin = 'local';
} else {
this.origin = 'kafka';
}
Error.captureStackTrace(this, this.constructor);
} else {
var message = e.message;
var parsedMessage = message.split(': ');
var origin, msg;
if (parsedMessage.length > 1) {
origin = parsedMessage[0].toLowerCase();
msg = parsedMessage[1].toLowerCase();
} else {
origin = 'unknown';
msg = message.toLowerCase();
}
// special cases
if (msg === 'consumer is disconnected' || msg === 'producer is disconnected') {
this.origin = 'local';
this.code = LibrdKafkaError.codes.ERR__STATE;
this.errno = this.code;
this.message = msg;
} else {
this.origin = origin;
this.message = msg;
this.code = typeof e.code === 'number' ? e.code : -1;
this.errno = this.code;
this.stack = e.stack;
}
}
} | javascript | function LibrdKafkaError(e) {
if (!(this instanceof LibrdKafkaError)) {
return new LibrdKafkaError(e);
}
if (typeof e === 'number') {
this.message = librdkafka.err2str(e);
this.code = e;
this.errno = e;
if (e >= LibrdKafkaError.codes.ERR__END) {
this.origin = 'local';
} else {
this.origin = 'kafka';
}
Error.captureStackTrace(this, this.constructor);
} else if (!util.isError(e)) {
// This is the better way
this.message = e.message;
this.code = e.code;
this.errno = e.code;
if (e.code >= LibrdKafkaError.codes.ERR__END) {
this.origin = 'local';
} else {
this.origin = 'kafka';
}
Error.captureStackTrace(this, this.constructor);
} else {
var message = e.message;
var parsedMessage = message.split(': ');
var origin, msg;
if (parsedMessage.length > 1) {
origin = parsedMessage[0].toLowerCase();
msg = parsedMessage[1].toLowerCase();
} else {
origin = 'unknown';
msg = message.toLowerCase();
}
// special cases
if (msg === 'consumer is disconnected' || msg === 'producer is disconnected') {
this.origin = 'local';
this.code = LibrdKafkaError.codes.ERR__STATE;
this.errno = this.code;
this.message = msg;
} else {
this.origin = origin;
this.message = msg;
this.code = typeof e.code === 'number' ? e.code : -1;
this.errno = this.code;
this.stack = e.stack;
}
}
} | [
"function",
"LibrdKafkaError",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"LibrdKafkaError",
")",
")",
"{",
"return",
"new",
"LibrdKafkaError",
"(",
"e",
")",
";",
"}",
"if",
"(",
"typeof",
"e",
"===",
"'number'",
")",
"{",
"this",
".",
"message",
"=",
"librdkafka",
".",
"err2str",
"(",
"e",
")",
";",
"this",
".",
"code",
"=",
"e",
";",
"this",
".",
"errno",
"=",
"e",
";",
"if",
"(",
"e",
">=",
"LibrdKafkaError",
".",
"codes",
".",
"ERR__END",
")",
"{",
"this",
".",
"origin",
"=",
"'local'",
";",
"}",
"else",
"{",
"this",
".",
"origin",
"=",
"'kafka'",
";",
"}",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"}",
"else",
"if",
"(",
"!",
"util",
".",
"isError",
"(",
"e",
")",
")",
"{",
"// This is the better way",
"this",
".",
"message",
"=",
"e",
".",
"message",
";",
"this",
".",
"code",
"=",
"e",
".",
"code",
";",
"this",
".",
"errno",
"=",
"e",
".",
"code",
";",
"if",
"(",
"e",
".",
"code",
">=",
"LibrdKafkaError",
".",
"codes",
".",
"ERR__END",
")",
"{",
"this",
".",
"origin",
"=",
"'local'",
";",
"}",
"else",
"{",
"this",
".",
"origin",
"=",
"'kafka'",
";",
"}",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"}",
"else",
"{",
"var",
"message",
"=",
"e",
".",
"message",
";",
"var",
"parsedMessage",
"=",
"message",
".",
"split",
"(",
"': '",
")",
";",
"var",
"origin",
",",
"msg",
";",
"if",
"(",
"parsedMessage",
".",
"length",
">",
"1",
")",
"{",
"origin",
"=",
"parsedMessage",
"[",
"0",
"]",
".",
"toLowerCase",
"(",
")",
";",
"msg",
"=",
"parsedMessage",
"[",
"1",
"]",
".",
"toLowerCase",
"(",
")",
";",
"}",
"else",
"{",
"origin",
"=",
"'unknown'",
";",
"msg",
"=",
"message",
".",
"toLowerCase",
"(",
")",
";",
"}",
"// special cases",
"if",
"(",
"msg",
"===",
"'consumer is disconnected'",
"||",
"msg",
"===",
"'producer is disconnected'",
")",
"{",
"this",
".",
"origin",
"=",
"'local'",
";",
"this",
".",
"code",
"=",
"LibrdKafkaError",
".",
"codes",
".",
"ERR__STATE",
";",
"this",
".",
"errno",
"=",
"this",
".",
"code",
";",
"this",
".",
"message",
"=",
"msg",
";",
"}",
"else",
"{",
"this",
".",
"origin",
"=",
"origin",
";",
"this",
".",
"message",
"=",
"msg",
";",
"this",
".",
"code",
"=",
"typeof",
"e",
".",
"code",
"===",
"'number'",
"?",
"e",
".",
"code",
":",
"-",
"1",
";",
"this",
".",
"errno",
"=",
"this",
".",
"code",
";",
"this",
".",
"stack",
"=",
"e",
".",
"stack",
";",
"}",
"}",
"}"
] | Representation of a librdkafka error
This can be created by giving either another error
to piggy-back on. In this situation it tries to parse
the error string to figure out the intent. However, more usually,
it is constructed by an error object created by a C++ Baton.
@param {object|error} e - An object or error to wrap
@property {string} message - The error message
@property {number} code - The error code.
@property {string} origin - The origin, whether it is local or remote
@constructor | [
"Representation",
"of",
"a",
"librdkafka",
"error"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/error.js#L275-L331 |
6,012 | Blizzard/node-rdkafka | lib/producer.js | Producer | function Producer(conf, topicConf) {
if (!(this instanceof Producer)) {
return new Producer(conf, topicConf);
}
conf = shallowCopy(conf);
topicConf = shallowCopy(topicConf);
/**
* Producer message. This is sent to the wrapper, not received from it
*
* @typedef {object} Producer~Message
* @property {string|buffer} message - The buffer to send to Kafka.
* @property {Topic} topic - The Kafka topic to produce to.
* @property {number} partition - The partition to produce to. Defaults to
* the partitioner
* @property {string} key - The key string to use for the message.
* @see Consumer~Message
*/
var gTopic = conf.topic || false;
var gPart = conf.partition || null;
var dr_cb = conf.dr_cb || null;
var dr_msg_cb = conf.dr_msg_cb || null;
// delete keys we don't want to pass on
delete conf.topic;
delete conf.partition;
delete conf.dr_cb;
delete conf.dr_msg_cb;
// client is an initialized consumer object
// @see NodeKafka::Producer::Init
Client.call(this, conf, Kafka.Producer, topicConf);
var self = this;
// Delete these keys after saving them in vars
this.globalConfig = conf;
this.topicConfig = topicConf;
this.defaultTopic = gTopic || null;
this.defaultPartition = gPart == null ? -1 : gPart;
this.sentMessages = 0;
this.pollInterval = undefined;
if (dr_msg_cb || dr_cb) {
this._client.onDeliveryReport(function onDeliveryReport(err, report) {
if (err) {
err = LibrdKafkaError.create(err);
}
self.emit('delivery-report', err, report);
}, !!dr_msg_cb);
if (typeof dr_cb === 'function') {
self.on('delivery-report', dr_cb);
}
}
} | javascript | function Producer(conf, topicConf) {
if (!(this instanceof Producer)) {
return new Producer(conf, topicConf);
}
conf = shallowCopy(conf);
topicConf = shallowCopy(topicConf);
/**
* Producer message. This is sent to the wrapper, not received from it
*
* @typedef {object} Producer~Message
* @property {string|buffer} message - The buffer to send to Kafka.
* @property {Topic} topic - The Kafka topic to produce to.
* @property {number} partition - The partition to produce to. Defaults to
* the partitioner
* @property {string} key - The key string to use for the message.
* @see Consumer~Message
*/
var gTopic = conf.topic || false;
var gPart = conf.partition || null;
var dr_cb = conf.dr_cb || null;
var dr_msg_cb = conf.dr_msg_cb || null;
// delete keys we don't want to pass on
delete conf.topic;
delete conf.partition;
delete conf.dr_cb;
delete conf.dr_msg_cb;
// client is an initialized consumer object
// @see NodeKafka::Producer::Init
Client.call(this, conf, Kafka.Producer, topicConf);
var self = this;
// Delete these keys after saving them in vars
this.globalConfig = conf;
this.topicConfig = topicConf;
this.defaultTopic = gTopic || null;
this.defaultPartition = gPart == null ? -1 : gPart;
this.sentMessages = 0;
this.pollInterval = undefined;
if (dr_msg_cb || dr_cb) {
this._client.onDeliveryReport(function onDeliveryReport(err, report) {
if (err) {
err = LibrdKafkaError.create(err);
}
self.emit('delivery-report', err, report);
}, !!dr_msg_cb);
if (typeof dr_cb === 'function') {
self.on('delivery-report', dr_cb);
}
}
} | [
"function",
"Producer",
"(",
"conf",
",",
"topicConf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Producer",
")",
")",
"{",
"return",
"new",
"Producer",
"(",
"conf",
",",
"topicConf",
")",
";",
"}",
"conf",
"=",
"shallowCopy",
"(",
"conf",
")",
";",
"topicConf",
"=",
"shallowCopy",
"(",
"topicConf",
")",
";",
"/**\n * Producer message. This is sent to the wrapper, not received from it\n *\n * @typedef {object} Producer~Message\n * @property {string|buffer} message - The buffer to send to Kafka.\n * @property {Topic} topic - The Kafka topic to produce to.\n * @property {number} partition - The partition to produce to. Defaults to\n * the partitioner\n * @property {string} key - The key string to use for the message.\n * @see Consumer~Message\n */",
"var",
"gTopic",
"=",
"conf",
".",
"topic",
"||",
"false",
";",
"var",
"gPart",
"=",
"conf",
".",
"partition",
"||",
"null",
";",
"var",
"dr_cb",
"=",
"conf",
".",
"dr_cb",
"||",
"null",
";",
"var",
"dr_msg_cb",
"=",
"conf",
".",
"dr_msg_cb",
"||",
"null",
";",
"// delete keys we don't want to pass on",
"delete",
"conf",
".",
"topic",
";",
"delete",
"conf",
".",
"partition",
";",
"delete",
"conf",
".",
"dr_cb",
";",
"delete",
"conf",
".",
"dr_msg_cb",
";",
"// client is an initialized consumer object",
"// @see NodeKafka::Producer::Init",
"Client",
".",
"call",
"(",
"this",
",",
"conf",
",",
"Kafka",
".",
"Producer",
",",
"topicConf",
")",
";",
"var",
"self",
"=",
"this",
";",
"// Delete these keys after saving them in vars",
"this",
".",
"globalConfig",
"=",
"conf",
";",
"this",
".",
"topicConfig",
"=",
"topicConf",
";",
"this",
".",
"defaultTopic",
"=",
"gTopic",
"||",
"null",
";",
"this",
".",
"defaultPartition",
"=",
"gPart",
"==",
"null",
"?",
"-",
"1",
":",
"gPart",
";",
"this",
".",
"sentMessages",
"=",
"0",
";",
"this",
".",
"pollInterval",
"=",
"undefined",
";",
"if",
"(",
"dr_msg_cb",
"||",
"dr_cb",
")",
"{",
"this",
".",
"_client",
".",
"onDeliveryReport",
"(",
"function",
"onDeliveryReport",
"(",
"err",
",",
"report",
")",
"{",
"if",
"(",
"err",
")",
"{",
"err",
"=",
"LibrdKafkaError",
".",
"create",
"(",
"err",
")",
";",
"}",
"self",
".",
"emit",
"(",
"'delivery-report'",
",",
"err",
",",
"report",
")",
";",
"}",
",",
"!",
"!",
"dr_msg_cb",
")",
";",
"if",
"(",
"typeof",
"dr_cb",
"===",
"'function'",
")",
"{",
"self",
".",
"on",
"(",
"'delivery-report'",
",",
"dr_cb",
")",
";",
"}",
"}",
"}"
] | Producer class for sending messages to Kafka
This is the main entry point for writing data to Kafka. You
configure this like you do any other client, with a global
configuration and default topic configuration.
Once you instantiate this object, you need to connect to it first.
This allows you to get the metadata and make sure the connection
can be made before you depend on it. After that, problems with
the connection will by brought down by using poll, which automatically
runs when a transaction is made on the object.
@param {object} conf - Key value pairs to configure the producer
@param {object} topicConf - Key value pairs to create a default
topic configuration
@extends Client
@constructor | [
"Producer",
"class",
"for",
"sending",
"messages",
"to",
"Kafka"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/producer.js#L41-L101 |
6,013 | Blizzard/node-rdkafka | lib/producer-stream.js | ProducerStream | function ProducerStream(producer, options) {
if (!(this instanceof ProducerStream)) {
return new ProducerStream(producer, options);
}
if (options === undefined) {
options = {};
} else if (typeof options === 'string') {
options = { encoding: options };
} else if (options === null || typeof options !== 'object') {
throw new TypeError('"streamOptions" argument must be a string or an object');
}
if (!options.objectMode && !options.topic) {
throw new TypeError('ProducerStreams not using objectMode must provide a topic to produce to.');
}
if (options.objectMode !== true) {
this._write = this._write_buffer;
} else {
this._write = this._write_message;
}
Writable.call(this, options);
this.producer = producer;
this.topicName = options.topic;
this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
this.connectOptions = options.connectOptions || {};
this.producer.setPollInterval(options.pollInterval || 1000);
if (options.encoding) {
this.setDefaultEncoding(options.encoding);
}
// Connect to the producer. Unless we are already connected
if (!this.producer.isConnected()) {
this.connect(this.connectOptions);
}
var self = this;
this.once('finish', function() {
if (this.autoClose) {
this.close();
}
});
} | javascript | function ProducerStream(producer, options) {
if (!(this instanceof ProducerStream)) {
return new ProducerStream(producer, options);
}
if (options === undefined) {
options = {};
} else if (typeof options === 'string') {
options = { encoding: options };
} else if (options === null || typeof options !== 'object') {
throw new TypeError('"streamOptions" argument must be a string or an object');
}
if (!options.objectMode && !options.topic) {
throw new TypeError('ProducerStreams not using objectMode must provide a topic to produce to.');
}
if (options.objectMode !== true) {
this._write = this._write_buffer;
} else {
this._write = this._write_message;
}
Writable.call(this, options);
this.producer = producer;
this.topicName = options.topic;
this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
this.connectOptions = options.connectOptions || {};
this.producer.setPollInterval(options.pollInterval || 1000);
if (options.encoding) {
this.setDefaultEncoding(options.encoding);
}
// Connect to the producer. Unless we are already connected
if (!this.producer.isConnected()) {
this.connect(this.connectOptions);
}
var self = this;
this.once('finish', function() {
if (this.autoClose) {
this.close();
}
});
} | [
"function",
"ProducerStream",
"(",
"producer",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ProducerStream",
")",
")",
"{",
"return",
"new",
"ProducerStream",
"(",
"producer",
",",
"options",
")",
";",
"}",
"if",
"(",
"options",
"===",
"undefined",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"{",
"options",
"=",
"{",
"encoding",
":",
"options",
"}",
";",
"}",
"else",
"if",
"(",
"options",
"===",
"null",
"||",
"typeof",
"options",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"streamOptions\" argument must be a string or an object'",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"objectMode",
"&&",
"!",
"options",
".",
"topic",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'ProducerStreams not using objectMode must provide a topic to produce to.'",
")",
";",
"}",
"if",
"(",
"options",
".",
"objectMode",
"!==",
"true",
")",
"{",
"this",
".",
"_write",
"=",
"this",
".",
"_write_buffer",
";",
"}",
"else",
"{",
"this",
".",
"_write",
"=",
"this",
".",
"_write_message",
";",
"}",
"Writable",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"producer",
"=",
"producer",
";",
"this",
".",
"topicName",
"=",
"options",
".",
"topic",
";",
"this",
".",
"autoClose",
"=",
"options",
".",
"autoClose",
"===",
"undefined",
"?",
"true",
":",
"!",
"!",
"options",
".",
"autoClose",
";",
"this",
".",
"connectOptions",
"=",
"options",
".",
"connectOptions",
"||",
"{",
"}",
";",
"this",
".",
"producer",
".",
"setPollInterval",
"(",
"options",
".",
"pollInterval",
"||",
"1000",
")",
";",
"if",
"(",
"options",
".",
"encoding",
")",
"{",
"this",
".",
"setDefaultEncoding",
"(",
"options",
".",
"encoding",
")",
";",
"}",
"// Connect to the producer. Unless we are already connected",
"if",
"(",
"!",
"this",
".",
"producer",
".",
"isConnected",
"(",
")",
")",
"{",
"this",
".",
"connect",
"(",
"this",
".",
"connectOptions",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"this",
".",
"once",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"autoClose",
")",
"{",
"this",
".",
"close",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Writable stream integrating with the Kafka Producer.
This class is used to write data to Kafka in a streaming way. It takes
buffers of data and puts them into the appropriate Kafka topic. If you need
finer control over partitions or keys, this is probably not the class for
you. In that situation just use the Producer itself.
The stream detects if Kafka is already connected. You can safely begin
writing right away.
This stream does not operate in Object mode and can only be given buffers.
@param {Producer} producer - The Kafka Producer object.
@param {array} topics - Array of topics
@param {object} options - Topic configuration.
@constructor
@extends stream.Writable | [
"Writable",
"stream",
"integrating",
"with",
"the",
"Kafka",
"Producer",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/producer-stream.js#L39-L89 |
6,014 | Blizzard/node-rdkafka | lib/admin.js | createAdminClient | function createAdminClient(conf) {
var client = new AdminClient(conf);
// Wrap the error so we throw if it failed with some context
LibrdKafkaError.wrap(client.connect(), true);
// Return the client if we succeeded
return client;
} | javascript | function createAdminClient(conf) {
var client = new AdminClient(conf);
// Wrap the error so we throw if it failed with some context
LibrdKafkaError.wrap(client.connect(), true);
// Return the client if we succeeded
return client;
} | [
"function",
"createAdminClient",
"(",
"conf",
")",
"{",
"var",
"client",
"=",
"new",
"AdminClient",
"(",
"conf",
")",
";",
"// Wrap the error so we throw if it failed with some context",
"LibrdKafkaError",
".",
"wrap",
"(",
"client",
".",
"connect",
"(",
")",
",",
"true",
")",
";",
"// Return the client if we succeeded",
"return",
"client",
";",
"}"
] | Create a new AdminClient for making topics, partitions, and more.
This is a factory method because it immediately starts an
active handle with the brokers. | [
"Create",
"a",
"new",
"AdminClient",
"for",
"making",
"topics",
"partitions",
"and",
"more",
"."
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/admin.js#L28-L36 |
6,015 | Blizzard/node-rdkafka | lib/admin.js | AdminClient | function AdminClient(conf) {
if (!(this instanceof AdminClient)) {
return new AdminClient(conf);
}
conf = shallowCopy(conf);
/**
* NewTopic model.
*
* This is the representation of a new message that is requested to be made
* using the Admin client.
*
* @typedef {object} AdminClient~NewTopic
* @property {string} topic - the topic name to create
* @property {number} num_partitions - the number of partitions to give the topic
* @property {number} replication_factor - the replication factor of the topic
* @property {object} config - a list of key values to be passed as configuration
* for the topic.
*/
this._client = new Kafka.AdminClient(conf);
this._isConnected = false;
this.globalConfig = conf;
} | javascript | function AdminClient(conf) {
if (!(this instanceof AdminClient)) {
return new AdminClient(conf);
}
conf = shallowCopy(conf);
/**
* NewTopic model.
*
* This is the representation of a new message that is requested to be made
* using the Admin client.
*
* @typedef {object} AdminClient~NewTopic
* @property {string} topic - the topic name to create
* @property {number} num_partitions - the number of partitions to give the topic
* @property {number} replication_factor - the replication factor of the topic
* @property {object} config - a list of key values to be passed as configuration
* for the topic.
*/
this._client = new Kafka.AdminClient(conf);
this._isConnected = false;
this.globalConfig = conf;
} | [
"function",
"AdminClient",
"(",
"conf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"AdminClient",
")",
")",
"{",
"return",
"new",
"AdminClient",
"(",
"conf",
")",
";",
"}",
"conf",
"=",
"shallowCopy",
"(",
"conf",
")",
";",
"/**\n * NewTopic model.\n *\n * This is the representation of a new message that is requested to be made\n * using the Admin client.\n *\n * @typedef {object} AdminClient~NewTopic\n * @property {string} topic - the topic name to create\n * @property {number} num_partitions - the number of partitions to give the topic\n * @property {number} replication_factor - the replication factor of the topic\n * @property {object} config - a list of key values to be passed as configuration\n * for the topic.\n */",
"this",
".",
"_client",
"=",
"new",
"Kafka",
".",
"AdminClient",
"(",
"conf",
")",
";",
"this",
".",
"_isConnected",
"=",
"false",
";",
"this",
".",
"globalConfig",
"=",
"conf",
";",
"}"
] | AdminClient class for administering Kafka
This client is the way you can interface with the Kafka Admin APIs.
This class should not be made using the constructor, but instead
should be made using the factory method.
<code>
var client = AdminClient.create({ ... });
</code>
Once you instantiate this object, it will have a handle to the kafka broker.
Unlike the other node-rdkafka classes, this class does not ensure that
it is connected to the upstream broker. Instead, making an action will
validate that.
@param {object} conf - Key value pairs to configure the admin client
topic configuration
@constructor | [
"AdminClient",
"class",
"for",
"administering",
"Kafka"
] | 50f99ab46c4a475678b94af07c2ea02e1ba353ff | https://github.com/Blizzard/node-rdkafka/blob/50f99ab46c4a475678b94af07c2ea02e1ba353ff/lib/admin.js#L58-L82 |
6,016 | nhn/tui.grid | src/js/view/clipboard.js | function(ev) {
var gridEvent;
if (this.isLocked) {
ev.preventDefault();
return;
}
gridEvent = keyEvent.generate(ev);
if (!gridEvent) {
return;
}
this._lock();
if (shouldPreventDefault(gridEvent)) {
ev.preventDefault();
}
if (!isPasteEvent(gridEvent)) {
this.domEventBus.trigger(gridEvent.type, gridEvent);
}
} | javascript | function(ev) {
var gridEvent;
if (this.isLocked) {
ev.preventDefault();
return;
}
gridEvent = keyEvent.generate(ev);
if (!gridEvent) {
return;
}
this._lock();
if (shouldPreventDefault(gridEvent)) {
ev.preventDefault();
}
if (!isPasteEvent(gridEvent)) {
this.domEventBus.trigger(gridEvent.type, gridEvent);
}
} | [
"function",
"(",
"ev",
")",
"{",
"var",
"gridEvent",
";",
"if",
"(",
"this",
".",
"isLocked",
")",
"{",
"ev",
".",
"preventDefault",
"(",
")",
";",
"return",
";",
"}",
"gridEvent",
"=",
"keyEvent",
".",
"generate",
"(",
"ev",
")",
";",
"if",
"(",
"!",
"gridEvent",
")",
"{",
"return",
";",
"}",
"this",
".",
"_lock",
"(",
")",
";",
"if",
"(",
"shouldPreventDefault",
"(",
"gridEvent",
")",
")",
"{",
"ev",
".",
"preventDefault",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isPasteEvent",
"(",
"gridEvent",
")",
")",
"{",
"this",
".",
"domEventBus",
".",
"trigger",
"(",
"gridEvent",
".",
"type",
",",
"gridEvent",
")",
";",
"}",
"}"
] | Event handler for the keydown event
@param {Event} ev - Event
@private | [
"Event",
"handler",
"for",
"the",
"keydown",
"event"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/clipboard.js#L104-L128 |
|
6,017 | nhn/tui.grid | src/js/view/clipboard.js | function(ev) {
var clipboardData = (ev.originalEvent || ev).clipboardData || window.clipboardData;
if (!isEdge && !supportWindowClipboardData) {
ev.preventDefault();
this._pasteInOtherBrowsers(clipboardData);
} else {
this._pasteInMSBrowsers(clipboardData);
}
} | javascript | function(ev) {
var clipboardData = (ev.originalEvent || ev).clipboardData || window.clipboardData;
if (!isEdge && !supportWindowClipboardData) {
ev.preventDefault();
this._pasteInOtherBrowsers(clipboardData);
} else {
this._pasteInMSBrowsers(clipboardData);
}
} | [
"function",
"(",
"ev",
")",
"{",
"var",
"clipboardData",
"=",
"(",
"ev",
".",
"originalEvent",
"||",
"ev",
")",
".",
"clipboardData",
"||",
"window",
".",
"clipboardData",
";",
"if",
"(",
"!",
"isEdge",
"&&",
"!",
"supportWindowClipboardData",
")",
"{",
"ev",
".",
"preventDefault",
"(",
")",
";",
"this",
".",
"_pasteInOtherBrowsers",
"(",
"clipboardData",
")",
";",
"}",
"else",
"{",
"this",
".",
"_pasteInMSBrowsers",
"(",
"clipboardData",
")",
";",
"}",
"}"
] | onpaste event handler
The original 'paste' event should be prevented on browsers except MS
to block that copied data is appending on contenteditable element.
@param {jQueryEvent} ev - Event object
@private | [
"onpaste",
"event",
"handler",
"The",
"original",
"paste",
"event",
"should",
"be",
"prevented",
"on",
"browsers",
"except",
"MS",
"to",
"block",
"that",
"copied",
"data",
"is",
"appending",
"on",
"contenteditable",
"element",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/clipboard.js#L159-L168 |
|
6,018 | nhn/tui.grid | src/js/common/i18n.js | flattenMessageMap | function flattenMessageMap(data) {
var obj = {};
var newKey;
_.each(data, function(groupMessages, key) {
_.each(groupMessages, function(message, subKey) {
newKey = [key, subKey].join('.');
obj[newKey] = message;
});
}, this);
return obj;
} | javascript | function flattenMessageMap(data) {
var obj = {};
var newKey;
_.each(data, function(groupMessages, key) {
_.each(groupMessages, function(message, subKey) {
newKey = [key, subKey].join('.');
obj[newKey] = message;
});
}, this);
return obj;
} | [
"function",
"flattenMessageMap",
"(",
"data",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
";",
"var",
"newKey",
";",
"_",
".",
"each",
"(",
"data",
",",
"function",
"(",
"groupMessages",
",",
"key",
")",
"{",
"_",
".",
"each",
"(",
"groupMessages",
",",
"function",
"(",
"message",
",",
"subKey",
")",
"{",
"newKey",
"=",
"[",
"key",
",",
"subKey",
"]",
".",
"join",
"(",
"'.'",
")",
";",
"obj",
"[",
"newKey",
"]",
"=",
"message",
";",
"}",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"obj",
";",
"}"
] | Flatten message map
@param {object} data - Messages
@returns {object} Flatten message object (key foramt is 'key.subKey')
@ignore | [
"Flatten",
"message",
"map"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/i18n.js#L60-L72 |
6,019 | nhn/tui.grid | src/js/theme/styleGenerator.js | bgTextRuleString | function bgTextRuleString(className, options) {
return classRule(className)
.bg(options.background)
.text(options.text)
.build();
} | javascript | function bgTextRuleString(className, options) {
return classRule(className)
.bg(options.background)
.text(options.text)
.build();
} | [
"function",
"bgTextRuleString",
"(",
"className",
",",
"options",
")",
"{",
"return",
"classRule",
"(",
"className",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"text",
"(",
"options",
".",
"text",
")",
".",
"build",
"(",
")",
";",
"}"
] | Creates a rule string for background and text colors.
@param {String} className - class name
@param {Objecr} options - options
@returns {String}
@ignore | [
"Creates",
"a",
"rule",
"string",
"for",
"background",
"and",
"text",
"colors",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L32-L37 |
6,020 | nhn/tui.grid | src/js/theme/styleGenerator.js | bgBorderRuleString | function bgBorderRuleString(className, options) {
return classRule(className)
.bg(options.background)
.border(options.border)
.build();
} | javascript | function bgBorderRuleString(className, options) {
return classRule(className)
.bg(options.background)
.border(options.border)
.build();
} | [
"function",
"bgBorderRuleString",
"(",
"className",
",",
"options",
")",
"{",
"return",
"classRule",
"(",
"className",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
".",
"build",
"(",
")",
";",
"}"
] | Creates a rule string for background and border colors.
@param {String} className - class name
@param {Objecr} options - options
@returns {String}
@ignore | [
"Creates",
"a",
"rule",
"string",
"for",
"background",
"and",
"border",
"colors",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L46-L51 |
6,021 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
var borderTopRule = classRule(classNameConst.BORDER_TOP).bg(options.border);
var borderBottomRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_X,
classNameConst.BORDER_BOTTOM
]).bg(options.border);
var rules = [
borderTopRule,
borderBottomRule
];
var borderLeftRule, borderRightRule;
if (options.showVerticalBorder) {
borderLeftRule = classRule(classNameConst.BORDER_LEFT).bg(options.border);
borderRightRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_Y,
classNameConst.BORDER_RIGHT
]).bg(options.border);
rules = rules.concat([borderLeftRule, borderRightRule]);
}
return builder.buildAll(rules);
} | javascript | function(options) {
var borderTopRule = classRule(classNameConst.BORDER_TOP).bg(options.border);
var borderBottomRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_X,
classNameConst.BORDER_BOTTOM
]).bg(options.border);
var rules = [
borderTopRule,
borderBottomRule
];
var borderLeftRule, borderRightRule;
if (options.showVerticalBorder) {
borderLeftRule = classRule(classNameConst.BORDER_LEFT).bg(options.border);
borderRightRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_Y,
classNameConst.BORDER_RIGHT
]).bg(options.border);
rules = rules.concat([borderLeftRule, borderRightRule]);
}
return builder.buildAll(rules);
} | [
"function",
"(",
"options",
")",
"{",
"var",
"borderTopRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"BORDER_TOP",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"borderBottomRule",
"=",
"classComposeRule",
"(",
"' .'",
",",
"[",
"classNameConst",
".",
"NO_SCROLL_X",
",",
"classNameConst",
".",
"BORDER_BOTTOM",
"]",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"rules",
"=",
"[",
"borderTopRule",
",",
"borderBottomRule",
"]",
";",
"var",
"borderLeftRule",
",",
"borderRightRule",
";",
"if",
"(",
"options",
".",
"showVerticalBorder",
")",
"{",
"borderLeftRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"BORDER_LEFT",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"borderRightRule",
"=",
"classComposeRule",
"(",
"' .'",
",",
"[",
"classNameConst",
".",
"NO_SCROLL_Y",
",",
"classNameConst",
".",
"BORDER_RIGHT",
"]",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"rules",
"=",
"rules",
".",
"concat",
"(",
"[",
"borderLeftRule",
",",
"borderRightRule",
"]",
")",
";",
"}",
"return",
"builder",
".",
"buildAll",
"(",
"rules",
")",
";",
"}"
] | Generates a css string for grid outline.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"grid",
"outline",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L59-L82 |
|
6,022 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
var webkitScrollbarRules = builder.createWebkitScrollbarRules('.' + classNameConst.CONTAINER, options);
var ieScrollbarRule = builder.createIEScrollbarRule('.' + classNameConst.CONTAINER, options);
var xInnerBorderRule = classRule(classNameConst.BORDER_BOTTOM).bg(options.border);
var xOuterBorderRule = classRule(classNameConst.CONTENT_AREA).border(options.border);
var yInnerBorderRule = classRule(classNameConst.SCROLLBAR_Y_INNER_BORDER).bg(options.border);
var yOuterBorderRule = classRule(classNameConst.SCROLLBAR_Y_OUTER_BORDER).bg(options.border);
var spaceRightTopRule = classRule(classNameConst.SCROLLBAR_RIGHT_TOP)
.bg(options.emptySpace)
.border(options.border);
var spaceRightBottomRule = classRule(classNameConst.SCROLLBAR_RIGHT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var spaceLeftBottomRule = classRule(classNameConst.SCROLLBAR_LEFT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var frozenBorderRule = classRule(classNameConst.SCROLLBAR_FROZEN_BORDER)
.bg(options.emptySpace)
.border(options.border);
return builder.buildAll(webkitScrollbarRules.concat([
ieScrollbarRule,
xInnerBorderRule,
xOuterBorderRule,
yInnerBorderRule,
yOuterBorderRule,
spaceRightTopRule,
spaceRightBottomRule,
spaceLeftBottomRule,
frozenBorderRule
]));
} | javascript | function(options) {
var webkitScrollbarRules = builder.createWebkitScrollbarRules('.' + classNameConst.CONTAINER, options);
var ieScrollbarRule = builder.createIEScrollbarRule('.' + classNameConst.CONTAINER, options);
var xInnerBorderRule = classRule(classNameConst.BORDER_BOTTOM).bg(options.border);
var xOuterBorderRule = classRule(classNameConst.CONTENT_AREA).border(options.border);
var yInnerBorderRule = classRule(classNameConst.SCROLLBAR_Y_INNER_BORDER).bg(options.border);
var yOuterBorderRule = classRule(classNameConst.SCROLLBAR_Y_OUTER_BORDER).bg(options.border);
var spaceRightTopRule = classRule(classNameConst.SCROLLBAR_RIGHT_TOP)
.bg(options.emptySpace)
.border(options.border);
var spaceRightBottomRule = classRule(classNameConst.SCROLLBAR_RIGHT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var spaceLeftBottomRule = classRule(classNameConst.SCROLLBAR_LEFT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var frozenBorderRule = classRule(classNameConst.SCROLLBAR_FROZEN_BORDER)
.bg(options.emptySpace)
.border(options.border);
return builder.buildAll(webkitScrollbarRules.concat([
ieScrollbarRule,
xInnerBorderRule,
xOuterBorderRule,
yInnerBorderRule,
yOuterBorderRule,
spaceRightTopRule,
spaceRightBottomRule,
spaceLeftBottomRule,
frozenBorderRule
]));
} | [
"function",
"(",
"options",
")",
"{",
"var",
"webkitScrollbarRules",
"=",
"builder",
".",
"createWebkitScrollbarRules",
"(",
"'.'",
"+",
"classNameConst",
".",
"CONTAINER",
",",
"options",
")",
";",
"var",
"ieScrollbarRule",
"=",
"builder",
".",
"createIEScrollbarRule",
"(",
"'.'",
"+",
"classNameConst",
".",
"CONTAINER",
",",
"options",
")",
";",
"var",
"xInnerBorderRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"BORDER_BOTTOM",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"xOuterBorderRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"CONTENT_AREA",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"var",
"yInnerBorderRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_Y_INNER_BORDER",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"yOuterBorderRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_Y_OUTER_BORDER",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"spaceRightTopRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_RIGHT_TOP",
")",
".",
"bg",
"(",
"options",
".",
"emptySpace",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"var",
"spaceRightBottomRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_RIGHT_BOTTOM",
")",
".",
"bg",
"(",
"options",
".",
"emptySpace",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"var",
"spaceLeftBottomRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_LEFT_BOTTOM",
")",
".",
"bg",
"(",
"options",
".",
"emptySpace",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"var",
"frozenBorderRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SCROLLBAR_FROZEN_BORDER",
")",
".",
"bg",
"(",
"options",
".",
"emptySpace",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"return",
"builder",
".",
"buildAll",
"(",
"webkitScrollbarRules",
".",
"concat",
"(",
"[",
"ieScrollbarRule",
",",
"xInnerBorderRule",
",",
"xOuterBorderRule",
",",
"yInnerBorderRule",
",",
"yOuterBorderRule",
",",
"spaceRightTopRule",
",",
"spaceRightBottomRule",
",",
"spaceLeftBottomRule",
",",
"frozenBorderRule",
"]",
")",
")",
";",
"}"
] | Generates a css string for scrollbars.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"scrollbars",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L100-L131 |
|
6,023 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
return classRule(classNameConst.HEAD_AREA)
.bg(options.background)
.border(options.border)
.build();
} | javascript | function(options) {
return classRule(classNameConst.HEAD_AREA)
.bg(options.background)
.border(options.border)
.build();
} | [
"function",
"(",
"options",
")",
"{",
"return",
"classRule",
"(",
"classNameConst",
".",
"HEAD_AREA",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
".",
"build",
"(",
")",
";",
"}"
] | Generates a css string for head area.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"head",
"area",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L165-L170 |
|
6,024 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
var contentAreaRule = classRule(classNameConst.SUMMARY_AREA)
.bg(options.background)
.border(options.border);
var bodyAreaRule = classComposeRule(' .', [
classNameConst.HAS_SUMMARY_TOP,
classNameConst.BODY_AREA
]).border(options.border);
return builder.buildAll([
contentAreaRule,
bodyAreaRule
]);
} | javascript | function(options) {
var contentAreaRule = classRule(classNameConst.SUMMARY_AREA)
.bg(options.background)
.border(options.border);
var bodyAreaRule = classComposeRule(' .', [
classNameConst.HAS_SUMMARY_TOP,
classNameConst.BODY_AREA
]).border(options.border);
return builder.buildAll([
contentAreaRule,
bodyAreaRule
]);
} | [
"function",
"(",
"options",
")",
"{",
"var",
"contentAreaRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"SUMMARY_AREA",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"var",
"bodyAreaRule",
"=",
"classComposeRule",
"(",
"' .'",
",",
"[",
"classNameConst",
".",
"HAS_SUMMARY_TOP",
",",
"classNameConst",
".",
"BODY_AREA",
"]",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"return",
"builder",
".",
"buildAll",
"(",
"[",
"contentAreaRule",
",",
"bodyAreaRule",
"]",
")",
";",
"}"
] | Generates a css string for summary area.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"summary",
"area",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L188-L201 |
|
6,025 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
return classRule(classNameConst.CELL)
.bg(options.background)
.border(options.border)
.borderWidth(options)
.text(options.text)
.build();
} | javascript | function(options) {
return classRule(classNameConst.CELL)
.bg(options.background)
.border(options.border)
.borderWidth(options)
.text(options.text)
.build();
} | [
"function",
"(",
"options",
")",
"{",
"return",
"classRule",
"(",
"classNameConst",
".",
"CELL",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
".",
"borderWidth",
"(",
"options",
")",
".",
"text",
"(",
"options",
".",
"text",
")",
".",
"build",
"(",
")",
";",
"}"
] | Generates a css string for table cells.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"table",
"cells",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L208-L215 |
|
6,026 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
return classComposeRule('.', [
classNameConst.CELL_HEAD,
classNameConst.CELL_SELECTED
]).bg(options.background)
.text(options.text)
.build();
} | javascript | function(options) {
return classComposeRule('.', [
classNameConst.CELL_HEAD,
classNameConst.CELL_SELECTED
]).bg(options.background)
.text(options.text)
.build();
} | [
"function",
"(",
"options",
")",
"{",
"return",
"classComposeRule",
"(",
"'.'",
",",
"[",
"classNameConst",
".",
"CELL_HEAD",
",",
"classNameConst",
".",
"CELL_SELECTED",
"]",
")",
".",
"bg",
"(",
"options",
".",
"background",
")",
".",
"text",
"(",
"options",
".",
"text",
")",
".",
"build",
"(",
")",
";",
"}"
] | Generates a css string for selected head cells.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"selected",
"head",
"cells",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L319-L326 |
|
6,027 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
var focusLayerRule = classRule(classNameConst.LAYER_FOCUS_BORDER).bg(options.border);
var editingLayerRule = classRule(classNameConst.LAYER_EDITING).border(options.border);
return builder.buildAll([focusLayerRule, editingLayerRule]);
} | javascript | function(options) {
var focusLayerRule = classRule(classNameConst.LAYER_FOCUS_BORDER).bg(options.border);
var editingLayerRule = classRule(classNameConst.LAYER_EDITING).border(options.border);
return builder.buildAll([focusLayerRule, editingLayerRule]);
} | [
"function",
"(",
"options",
")",
"{",
"var",
"focusLayerRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"LAYER_FOCUS_BORDER",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
";",
"var",
"editingLayerRule",
"=",
"classRule",
"(",
"classNameConst",
".",
"LAYER_EDITING",
")",
".",
"border",
"(",
"options",
".",
"border",
")",
";",
"return",
"builder",
".",
"buildAll",
"(",
"[",
"focusLayerRule",
",",
"editingLayerRule",
"]",
")",
";",
"}"
] | Generates a css string for focused cell.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"focused",
"cell",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L347-L352 |
|
6,028 | nhn/tui.grid | src/js/theme/styleGenerator.js | function(options) {
return classComposeRule(' .', [
classNameConst.LAYER_FOCUS_DEACTIVE,
classNameConst.LAYER_FOCUS_BORDER
]).bg(options.border).build();
} | javascript | function(options) {
return classComposeRule(' .', [
classNameConst.LAYER_FOCUS_DEACTIVE,
classNameConst.LAYER_FOCUS_BORDER
]).bg(options.border).build();
} | [
"function",
"(",
"options",
")",
"{",
"return",
"classComposeRule",
"(",
"' .'",
",",
"[",
"classNameConst",
".",
"LAYER_FOCUS_DEACTIVE",
",",
"classNameConst",
".",
"LAYER_FOCUS_BORDER",
"]",
")",
".",
"bg",
"(",
"options",
".",
"border",
")",
".",
"build",
"(",
")",
";",
"}"
] | Generates a css string for focus inactive cell.
@param {Object} options - options
@returns {String} | [
"Generates",
"a",
"css",
"string",
"for",
"focus",
"inactive",
"cell",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/styleGenerator.js#L359-L364 |
|
6,029 | nhn/tui.grid | src/js/common/clipboardUtil.js | setDataInSpanRange | function setDataInSpanRange(value, data, colspanRange, rowspanRange) {
var startColspan = colspanRange[0];
var endColspan = colspanRange[1];
var startRowspan = rowspanRange[0];
var endRowspan = rowspanRange[1];
var cIndex, rIndex;
for (rIndex = startRowspan; rIndex < endRowspan; rIndex += 1) {
for (cIndex = startColspan; cIndex < endColspan; cIndex += 1) {
data[rIndex][cIndex] = ((startRowspan === rIndex) &&
(startColspan === cIndex)) ? value : ' ';
}
}
} | javascript | function setDataInSpanRange(value, data, colspanRange, rowspanRange) {
var startColspan = colspanRange[0];
var endColspan = colspanRange[1];
var startRowspan = rowspanRange[0];
var endRowspan = rowspanRange[1];
var cIndex, rIndex;
for (rIndex = startRowspan; rIndex < endRowspan; rIndex += 1) {
for (cIndex = startColspan; cIndex < endColspan; cIndex += 1) {
data[rIndex][cIndex] = ((startRowspan === rIndex) &&
(startColspan === cIndex)) ? value : ' ';
}
}
} | [
"function",
"setDataInSpanRange",
"(",
"value",
",",
"data",
",",
"colspanRange",
",",
"rowspanRange",
")",
"{",
"var",
"startColspan",
"=",
"colspanRange",
"[",
"0",
"]",
";",
"var",
"endColspan",
"=",
"colspanRange",
"[",
"1",
"]",
";",
"var",
"startRowspan",
"=",
"rowspanRange",
"[",
"0",
"]",
";",
"var",
"endRowspan",
"=",
"rowspanRange",
"[",
"1",
"]",
";",
"var",
"cIndex",
",",
"rIndex",
";",
"for",
"(",
"rIndex",
"=",
"startRowspan",
";",
"rIndex",
"<",
"endRowspan",
";",
"rIndex",
"+=",
"1",
")",
"{",
"for",
"(",
"cIndex",
"=",
"startColspan",
";",
"cIndex",
"<",
"endColspan",
";",
"cIndex",
"+=",
"1",
")",
"{",
"data",
"[",
"rIndex",
"]",
"[",
"cIndex",
"]",
"=",
"(",
"(",
"startRowspan",
"===",
"rIndex",
")",
"&&",
"(",
"startColspan",
"===",
"cIndex",
")",
")",
"?",
"value",
":",
"' '",
";",
"}",
"}",
"}"
] | Set to the data matrix as colspan & rowspan range
@param {string} value - Text from getting td element
@param {array} data - Data matrix to set value
@param {array} colspanRange - colspan range (ex: [start,Index endIndex])
@param {array} rowspanRange - rowspan range (ex: [start,Index endIndex])
@private | [
"Set",
"to",
"the",
"data",
"matrix",
"as",
"colspan",
"&",
"rowspan",
"range"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/clipboardUtil.js#L27-L40 |
6,030 | nhn/tui.grid | src/js/common/clipboardUtil.js | function(table) {
var data = [];
var rows = table.rows;
var index = 0;
var length = rows.length;
var columnIndex, colspanRange, rowspanRange;
// Step 1: Init the data matrix
for (; index < length; index += 1) {
data[index] = [];
}
// Step 2: Traverse the table
_.each(rows, function(tr, rowIndex) {
columnIndex = 0;
_.each(tr.cells, function(td) {
var text = td.textContent || td.innerText;
while (data[rowIndex][columnIndex]) {
columnIndex += 1;
}
colspanRange = [columnIndex, columnIndex + (td.colSpan || 1)];
rowspanRange = [rowIndex, rowIndex + (td.rowSpan || 1)];
// Step 3: Set the value of td element to the data matrix as colspan and rowspan ranges
setDataInSpanRange(text, data, colspanRange, rowspanRange);
columnIndex = colspanRange[1];
});
});
return data;
} | javascript | function(table) {
var data = [];
var rows = table.rows;
var index = 0;
var length = rows.length;
var columnIndex, colspanRange, rowspanRange;
// Step 1: Init the data matrix
for (; index < length; index += 1) {
data[index] = [];
}
// Step 2: Traverse the table
_.each(rows, function(tr, rowIndex) {
columnIndex = 0;
_.each(tr.cells, function(td) {
var text = td.textContent || td.innerText;
while (data[rowIndex][columnIndex]) {
columnIndex += 1;
}
colspanRange = [columnIndex, columnIndex + (td.colSpan || 1)];
rowspanRange = [rowIndex, rowIndex + (td.rowSpan || 1)];
// Step 3: Set the value of td element to the data matrix as colspan and rowspan ranges
setDataInSpanRange(text, data, colspanRange, rowspanRange);
columnIndex = colspanRange[1];
});
});
return data;
} | [
"function",
"(",
"table",
")",
"{",
"var",
"data",
"=",
"[",
"]",
";",
"var",
"rows",
"=",
"table",
".",
"rows",
";",
"var",
"index",
"=",
"0",
";",
"var",
"length",
"=",
"rows",
".",
"length",
";",
"var",
"columnIndex",
",",
"colspanRange",
",",
"rowspanRange",
";",
"// Step 1: Init the data matrix",
"for",
"(",
";",
"index",
"<",
"length",
";",
"index",
"+=",
"1",
")",
"{",
"data",
"[",
"index",
"]",
"=",
"[",
"]",
";",
"}",
"// Step 2: Traverse the table",
"_",
".",
"each",
"(",
"rows",
",",
"function",
"(",
"tr",
",",
"rowIndex",
")",
"{",
"columnIndex",
"=",
"0",
";",
"_",
".",
"each",
"(",
"tr",
".",
"cells",
",",
"function",
"(",
"td",
")",
"{",
"var",
"text",
"=",
"td",
".",
"textContent",
"||",
"td",
".",
"innerText",
";",
"while",
"(",
"data",
"[",
"rowIndex",
"]",
"[",
"columnIndex",
"]",
")",
"{",
"columnIndex",
"+=",
"1",
";",
"}",
"colspanRange",
"=",
"[",
"columnIndex",
",",
"columnIndex",
"+",
"(",
"td",
".",
"colSpan",
"||",
"1",
")",
"]",
";",
"rowspanRange",
"=",
"[",
"rowIndex",
",",
"rowIndex",
"+",
"(",
"td",
".",
"rowSpan",
"||",
"1",
")",
"]",
";",
"// Step 3: Set the value of td element to the data matrix as colspan and rowspan ranges",
"setDataInSpanRange",
"(",
"text",
",",
"data",
",",
"colspanRange",
",",
"rowspanRange",
")",
";",
"columnIndex",
"=",
"colspanRange",
"[",
"1",
"]",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"data",
";",
"}"
] | Convert cell data of table to clipboard data
@param {HTMLElement} table - Table element
@returns {array} clipboard data (2*2 matrix) | [
"Convert",
"cell",
"data",
"of",
"table",
"to",
"clipboard",
"data"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/clipboardUtil.js#L52-L86 |
|
6,031 | nhn/tui.grid | src/js/common/clipboardUtil.js | function(text) {
// Each newline cell data is wrapping double quotes in the text and
// newline characters should be replaced with substitution characters temporarily
// before spliting the text by newline characters.
text = clipboardUtil.replaceNewlineToSubchar(text);
return _.map(text.split(/\r?\n/), function(row) {
return _.map(row.split('\t'), function(column) {
column = clipboardUtil.removeDoubleQuotes(column);
return column.replace(CUSTOM_LF_REGEXP, LF)
.replace(CUSTOM_CR_REGEXP, CR);
});
});
} | javascript | function(text) {
// Each newline cell data is wrapping double quotes in the text and
// newline characters should be replaced with substitution characters temporarily
// before spliting the text by newline characters.
text = clipboardUtil.replaceNewlineToSubchar(text);
return _.map(text.split(/\r?\n/), function(row) {
return _.map(row.split('\t'), function(column) {
column = clipboardUtil.removeDoubleQuotes(column);
return column.replace(CUSTOM_LF_REGEXP, LF)
.replace(CUSTOM_CR_REGEXP, CR);
});
});
} | [
"function",
"(",
"text",
")",
"{",
"// Each newline cell data is wrapping double quotes in the text and",
"// newline characters should be replaced with substitution characters temporarily",
"// before spliting the text by newline characters.",
"text",
"=",
"clipboardUtil",
".",
"replaceNewlineToSubchar",
"(",
"text",
")",
";",
"return",
"_",
".",
"map",
"(",
"text",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
")",
",",
"function",
"(",
"row",
")",
"{",
"return",
"_",
".",
"map",
"(",
"row",
".",
"split",
"(",
"'\\t'",
")",
",",
"function",
"(",
"column",
")",
"{",
"column",
"=",
"clipboardUtil",
".",
"removeDoubleQuotes",
"(",
"column",
")",
";",
"return",
"column",
".",
"replace",
"(",
"CUSTOM_LF_REGEXP",
",",
"LF",
")",
".",
"replace",
"(",
"CUSTOM_CR_REGEXP",
",",
"CR",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Convert plain text to clipboard data
@param {string} text - Copied plain text
@returns {array} clipboard data (2*2 matrix) | [
"Convert",
"plain",
"text",
"to",
"clipboard",
"data"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/clipboardUtil.js#L93-L107 |
|
6,032 | nhn/tui.grid | src/js/common/clipboardUtil.js | function(text) {
if (text.match(CUSTOM_LF_REGEXP)) {
text = text.substring(1, text.length - 1)
.replace(/""/g, '"');
}
return text;
} | javascript | function(text) {
if (text.match(CUSTOM_LF_REGEXP)) {
text = text.substring(1, text.length - 1)
.replace(/""/g, '"');
}
return text;
} | [
"function",
"(",
"text",
")",
"{",
"if",
"(",
"text",
".",
"match",
"(",
"CUSTOM_LF_REGEXP",
")",
")",
"{",
"text",
"=",
"text",
".",
"substring",
"(",
"1",
",",
"text",
".",
"length",
"-",
"1",
")",
".",
"replace",
"(",
"/",
"\"\"",
"/",
"g",
",",
"'\"'",
")",
";",
"}",
"return",
"text",
";",
"}"
] | Remove double quetes on text when including substitution characters
@param {string} text - Original text
@returns {string} Replaced text | [
"Remove",
"double",
"quetes",
"on",
"text",
"when",
"including",
"substitution",
"characters"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/clipboardUtil.js#L127-L134 |
|
6,033 | nhn/tui.grid | src/js/common/clipboardUtil.js | function(text) {
return text.replace(/"([^"]|"")*"/g, function(value) {
return value.replace(LF, CUSTOM_LF_SUBCHAR)
.replace(CR, CUSTOM_CR_SUBCHAR);
});
} | javascript | function(text) {
return text.replace(/"([^"]|"")*"/g, function(value) {
return value.replace(LF, CUSTOM_LF_SUBCHAR)
.replace(CR, CUSTOM_CR_SUBCHAR);
});
} | [
"function",
"(",
"text",
")",
"{",
"return",
"text",
".",
"replace",
"(",
"/",
"\"([^\"]|\"\")*\"",
"/",
"g",
",",
"function",
"(",
"value",
")",
"{",
"return",
"value",
".",
"replace",
"(",
"LF",
",",
"CUSTOM_LF_SUBCHAR",
")",
".",
"replace",
"(",
"CR",
",",
"CUSTOM_CR_SUBCHAR",
")",
";",
"}",
")",
";",
"}"
] | Replace newline characters to substitution characters
@param {string} text - Original text
@returns {string} Replaced text | [
"Replace",
"newline",
"characters",
"to",
"substitution",
"characters"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/clipboardUtil.js#L141-L146 |
|
6,034 | nhn/tui.grid | src/js/view/layout/frame-rside.js | function() {
var dimensionModel, height;
if (this.$scrollBorder) {
dimensionModel = this.dimensionModel;
height = dimensionModel.get('bodyHeight') - dimensionModel.getScrollXHeight();
this.$scrollBorder.height(height);
}
} | javascript | function() {
var dimensionModel, height;
if (this.$scrollBorder) {
dimensionModel = this.dimensionModel;
height = dimensionModel.get('bodyHeight') - dimensionModel.getScrollXHeight();
this.$scrollBorder.height(height);
}
} | [
"function",
"(",
")",
"{",
"var",
"dimensionModel",
",",
"height",
";",
"if",
"(",
"this",
".",
"$scrollBorder",
")",
"{",
"dimensionModel",
"=",
"this",
".",
"dimensionModel",
";",
"height",
"=",
"dimensionModel",
".",
"get",
"(",
"'bodyHeight'",
")",
"-",
"dimensionModel",
".",
"getScrollXHeight",
"(",
")",
";",
"this",
".",
"$scrollBorder",
".",
"height",
"(",
"height",
")",
";",
"}",
"}"
] | Resets the height of a vertical scroll-bar border
@private | [
"Resets",
"the",
"height",
"of",
"a",
"vertical",
"scroll",
"-",
"bar",
"border"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/frame-rside.js#L96-L104 |
|
6,035 | nhn/tui.grid | src/js/view/layout/frame-rside.js | function() {
var dimensionModel = this.dimensionModel;
var scrollX = dimensionModel.get('scrollX');
var scrollY = dimensionModel.get('scrollY');
var spaceHeights = this._getSpaceHeights(scrollX, scrollY);
this._setScrollbar(scrollX, scrollY, spaceHeights);
if (dimensionModel.get('frozenBorderWidth')) {
this._setFrozenBorder(scrollX);
}
this._resetScrollBorderHeight();
} | javascript | function() {
var dimensionModel = this.dimensionModel;
var scrollX = dimensionModel.get('scrollX');
var scrollY = dimensionModel.get('scrollY');
var spaceHeights = this._getSpaceHeights(scrollX, scrollY);
this._setScrollbar(scrollX, scrollY, spaceHeights);
if (dimensionModel.get('frozenBorderWidth')) {
this._setFrozenBorder(scrollX);
}
this._resetScrollBorderHeight();
} | [
"function",
"(",
")",
"{",
"var",
"dimensionModel",
"=",
"this",
".",
"dimensionModel",
";",
"var",
"scrollX",
"=",
"dimensionModel",
".",
"get",
"(",
"'scrollX'",
")",
";",
"var",
"scrollY",
"=",
"dimensionModel",
".",
"get",
"(",
"'scrollY'",
")",
";",
"var",
"spaceHeights",
"=",
"this",
".",
"_getSpaceHeights",
"(",
"scrollX",
",",
"scrollY",
")",
";",
"this",
".",
"_setScrollbar",
"(",
"scrollX",
",",
"scrollY",
",",
"spaceHeights",
")",
";",
"if",
"(",
"dimensionModel",
".",
"get",
"(",
"'frozenBorderWidth'",
")",
")",
"{",
"this",
".",
"_setFrozenBorder",
"(",
"scrollX",
")",
";",
"}",
"this",
".",
"_resetScrollBorderHeight",
"(",
")",
";",
"}"
] | To be called at the end of the 'render' method.
@override | [
"To",
"be",
"called",
"at",
"the",
"end",
"of",
"the",
"render",
"method",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/frame-rside.js#L119-L132 |
|
6,036 | nhn/tui.grid | src/js/view/layout/frame-rside.js | function(scrollX, scrollY) {
var dimensionModel = this.dimensionModel;
var summaryHeight = dimensionModel.get('summaryHeight');
var summaryPosition = dimensionModel.get('summaryPosition');
var topHeight = dimensionModel.get('headerHeight');
var bottomHeight = scrollX ? dimensionConst.SCROLLBAR_WIDTH : 0;
if (scrollY && summaryHeight) {
if (summaryPosition === summaryPositionConst.TOP) {
topHeight += summaryHeight + dimensionConst.TABLE_BORDER_WIDTH;
} else {
bottomHeight += summaryHeight;
}
}
return {
top: topHeight,
bottom: bottomHeight
};
} | javascript | function(scrollX, scrollY) {
var dimensionModel = this.dimensionModel;
var summaryHeight = dimensionModel.get('summaryHeight');
var summaryPosition = dimensionModel.get('summaryPosition');
var topHeight = dimensionModel.get('headerHeight');
var bottomHeight = scrollX ? dimensionConst.SCROLLBAR_WIDTH : 0;
if (scrollY && summaryHeight) {
if (summaryPosition === summaryPositionConst.TOP) {
topHeight += summaryHeight + dimensionConst.TABLE_BORDER_WIDTH;
} else {
bottomHeight += summaryHeight;
}
}
return {
top: topHeight,
bottom: bottomHeight
};
} | [
"function",
"(",
"scrollX",
",",
"scrollY",
")",
"{",
"var",
"dimensionModel",
"=",
"this",
".",
"dimensionModel",
";",
"var",
"summaryHeight",
"=",
"dimensionModel",
".",
"get",
"(",
"'summaryHeight'",
")",
";",
"var",
"summaryPosition",
"=",
"dimensionModel",
".",
"get",
"(",
"'summaryPosition'",
")",
";",
"var",
"topHeight",
"=",
"dimensionModel",
".",
"get",
"(",
"'headerHeight'",
")",
";",
"var",
"bottomHeight",
"=",
"scrollX",
"?",
"dimensionConst",
".",
"SCROLLBAR_WIDTH",
":",
"0",
";",
"if",
"(",
"scrollY",
"&&",
"summaryHeight",
")",
"{",
"if",
"(",
"summaryPosition",
"===",
"summaryPositionConst",
".",
"TOP",
")",
"{",
"topHeight",
"+=",
"summaryHeight",
"+",
"dimensionConst",
".",
"TABLE_BORDER_WIDTH",
";",
"}",
"else",
"{",
"bottomHeight",
"+=",
"summaryHeight",
";",
"}",
"}",
"return",
"{",
"top",
":",
"topHeight",
",",
"bottom",
":",
"bottomHeight",
"}",
";",
"}"
] | Get height values of top, bottom space on scroll area
@param {boolean} scrollX - Whether the grid has x-scroll or not
@param {boolean} scrollY - Whether the grid has y-scroll or not
@returns {object} Heighs value
@private | [
"Get",
"height",
"values",
"of",
"top",
"bottom",
"space",
"on",
"scroll",
"area"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/frame-rside.js#L141-L160 |
|
6,037 | nhn/tui.grid | src/js/view/layout/frame-rside.js | function(scrollX, scrollY, spaceHeights) {
var $yInnerBorder, $yOuterBorder, $spaceRightTop, $spaceRightBottom, $frozenBorder;
if (scrollX) {
$frozenBorder = createDiv(classNameConst.SCROLLBAR_FROZEN_BORDER, {
height: dimensionConst.SCROLLBAR_WIDTH
});
}
if (scrollY) {
// subtract 2px for border-width (top and bottom)
$spaceRightTop = createDiv(classNameConst.SCROLLBAR_RIGHT_TOP, {
height: spaceHeights.top - 2
});
$yInnerBorder = createDiv(classNameConst.SCROLLBAR_Y_INNER_BORDER, {
top: spaceHeights.top
});
$yOuterBorder = createDiv(classNameConst.SCROLLBAR_Y_OUTER_BORDER);
}
if (scrollX || scrollY) {
$spaceRightBottom = createDiv(classNameConst.SCROLLBAR_RIGHT_BOTTOM, {
height: spaceHeights.bottom
});
}
this.$el.append(
$yInnerBorder,
$yOuterBorder,
$spaceRightTop,
$spaceRightBottom,
$frozenBorder
);
this.$scrollBorder = $yInnerBorder;
} | javascript | function(scrollX, scrollY, spaceHeights) {
var $yInnerBorder, $yOuterBorder, $spaceRightTop, $spaceRightBottom, $frozenBorder;
if (scrollX) {
$frozenBorder = createDiv(classNameConst.SCROLLBAR_FROZEN_BORDER, {
height: dimensionConst.SCROLLBAR_WIDTH
});
}
if (scrollY) {
// subtract 2px for border-width (top and bottom)
$spaceRightTop = createDiv(classNameConst.SCROLLBAR_RIGHT_TOP, {
height: spaceHeights.top - 2
});
$yInnerBorder = createDiv(classNameConst.SCROLLBAR_Y_INNER_BORDER, {
top: spaceHeights.top
});
$yOuterBorder = createDiv(classNameConst.SCROLLBAR_Y_OUTER_BORDER);
}
if (scrollX || scrollY) {
$spaceRightBottom = createDiv(classNameConst.SCROLLBAR_RIGHT_BOTTOM, {
height: spaceHeights.bottom
});
}
this.$el.append(
$yInnerBorder,
$yOuterBorder,
$spaceRightTop,
$spaceRightBottom,
$frozenBorder
);
this.$scrollBorder = $yInnerBorder;
} | [
"function",
"(",
"scrollX",
",",
"scrollY",
",",
"spaceHeights",
")",
"{",
"var",
"$yInnerBorder",
",",
"$yOuterBorder",
",",
"$spaceRightTop",
",",
"$spaceRightBottom",
",",
"$frozenBorder",
";",
"if",
"(",
"scrollX",
")",
"{",
"$frozenBorder",
"=",
"createDiv",
"(",
"classNameConst",
".",
"SCROLLBAR_FROZEN_BORDER",
",",
"{",
"height",
":",
"dimensionConst",
".",
"SCROLLBAR_WIDTH",
"}",
")",
";",
"}",
"if",
"(",
"scrollY",
")",
"{",
"// subtract 2px for border-width (top and bottom)",
"$spaceRightTop",
"=",
"createDiv",
"(",
"classNameConst",
".",
"SCROLLBAR_RIGHT_TOP",
",",
"{",
"height",
":",
"spaceHeights",
".",
"top",
"-",
"2",
"}",
")",
";",
"$yInnerBorder",
"=",
"createDiv",
"(",
"classNameConst",
".",
"SCROLLBAR_Y_INNER_BORDER",
",",
"{",
"top",
":",
"spaceHeights",
".",
"top",
"}",
")",
";",
"$yOuterBorder",
"=",
"createDiv",
"(",
"classNameConst",
".",
"SCROLLBAR_Y_OUTER_BORDER",
")",
";",
"}",
"if",
"(",
"scrollX",
"||",
"scrollY",
")",
"{",
"$spaceRightBottom",
"=",
"createDiv",
"(",
"classNameConst",
".",
"SCROLLBAR_RIGHT_BOTTOM",
",",
"{",
"height",
":",
"spaceHeights",
".",
"bottom",
"}",
")",
";",
"}",
"this",
".",
"$el",
".",
"append",
"(",
"$yInnerBorder",
",",
"$yOuterBorder",
",",
"$spaceRightTop",
",",
"$spaceRightBottom",
",",
"$frozenBorder",
")",
";",
"this",
".",
"$scrollBorder",
"=",
"$yInnerBorder",
";",
"}"
] | Create scrollbar area and set styles
@param {boolean} scrollX - Whether the grid has x-scroll or not
@param {boolean} scrollY - Whether the grid has y-scroll or not
@param {object} spaceHeights - Height values of top, bottom space on scroll area
@private | [
"Create",
"scrollbar",
"area",
"and",
"set",
"styles"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/frame-rside.js#L169-L204 |
|
6,038 | nhn/tui.grid | src/js/view/layout/frame-rside.js | function() {
var dimensionModel = this.dimensionModel;
var headerHeight = dimensionModel.get('headerHeight');
var frozenBorderWidth = dimensionModel.get('frozenBorderWidth');
var resizeHandleView = this.viewFactory.createHeaderResizeHandle(frameConst.L, [headerHeight], true);
var $resizeHanlder = resizeHandleView.render().$el;
var $frozenBorder = createDiv(classNameConst.FROZEN_BORDER, {
marginLeft: -frozenBorderWidth,
width: frozenBorderWidth
});
this.$el.append($resizeHanlder, $frozenBorder)
.find('.' + classNameConst.SCROLLBAR_FROZEN_BORDER)
.css({
marginLeft: -(frozenBorderWidth + CELL_BORDER_WIDTH),
width: frozenBorderWidth
});
} | javascript | function() {
var dimensionModel = this.dimensionModel;
var headerHeight = dimensionModel.get('headerHeight');
var frozenBorderWidth = dimensionModel.get('frozenBorderWidth');
var resizeHandleView = this.viewFactory.createHeaderResizeHandle(frameConst.L, [headerHeight], true);
var $resizeHanlder = resizeHandleView.render().$el;
var $frozenBorder = createDiv(classNameConst.FROZEN_BORDER, {
marginLeft: -frozenBorderWidth,
width: frozenBorderWidth
});
this.$el.append($resizeHanlder, $frozenBorder)
.find('.' + classNameConst.SCROLLBAR_FROZEN_BORDER)
.css({
marginLeft: -(frozenBorderWidth + CELL_BORDER_WIDTH),
width: frozenBorderWidth
});
} | [
"function",
"(",
")",
"{",
"var",
"dimensionModel",
"=",
"this",
".",
"dimensionModel",
";",
"var",
"headerHeight",
"=",
"dimensionModel",
".",
"get",
"(",
"'headerHeight'",
")",
";",
"var",
"frozenBorderWidth",
"=",
"dimensionModel",
".",
"get",
"(",
"'frozenBorderWidth'",
")",
";",
"var",
"resizeHandleView",
"=",
"this",
".",
"viewFactory",
".",
"createHeaderResizeHandle",
"(",
"frameConst",
".",
"L",
",",
"[",
"headerHeight",
"]",
",",
"true",
")",
";",
"var",
"$resizeHanlder",
"=",
"resizeHandleView",
".",
"render",
"(",
")",
".",
"$el",
";",
"var",
"$frozenBorder",
"=",
"createDiv",
"(",
"classNameConst",
".",
"FROZEN_BORDER",
",",
"{",
"marginLeft",
":",
"-",
"frozenBorderWidth",
",",
"width",
":",
"frozenBorderWidth",
"}",
")",
";",
"this",
".",
"$el",
".",
"append",
"(",
"$resizeHanlder",
",",
"$frozenBorder",
")",
".",
"find",
"(",
"'.'",
"+",
"classNameConst",
".",
"SCROLLBAR_FROZEN_BORDER",
")",
".",
"css",
"(",
"{",
"marginLeft",
":",
"-",
"(",
"frozenBorderWidth",
"+",
"CELL_BORDER_WIDTH",
")",
",",
"width",
":",
"frozenBorderWidth",
"}",
")",
";",
"}"
] | Create frozen border and set styles
@param {boolean} scrollX - Whether the grid has x-scroll or not
@private | [
"Create",
"frozen",
"border",
"and",
"set",
"styles"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/frame-rside.js#L211-L228 |
|
6,039 | nhn/tui.grid | src/js/event/keyEvent.js | getKeyStrokeString | function getKeyStrokeString(ev) {
var keys = [];
if (ev.ctrlKey || ev.metaKey) {
keys.push('ctrl');
}
if (ev.shiftKey) {
keys.push('shift');
}
keys.push(keyNameMap[ev.keyCode]);
return keys.join('-');
} | javascript | function getKeyStrokeString(ev) {
var keys = [];
if (ev.ctrlKey || ev.metaKey) {
keys.push('ctrl');
}
if (ev.shiftKey) {
keys.push('shift');
}
keys.push(keyNameMap[ev.keyCode]);
return keys.join('-');
} | [
"function",
"getKeyStrokeString",
"(",
"ev",
")",
"{",
"var",
"keys",
"=",
"[",
"]",
";",
"if",
"(",
"ev",
".",
"ctrlKey",
"||",
"ev",
".",
"metaKey",
")",
"{",
"keys",
".",
"push",
"(",
"'ctrl'",
")",
";",
"}",
"if",
"(",
"ev",
".",
"shiftKey",
")",
"{",
"keys",
".",
"push",
"(",
"'shift'",
")",
";",
"}",
"keys",
".",
"push",
"(",
"keyNameMap",
"[",
"ev",
".",
"keyCode",
"]",
")",
";",
"return",
"keys",
".",
"join",
"(",
"'-'",
")",
";",
"}"
] | Returns the keyStroke string
@param {Event} ev - Keyboard event
@returns {String}
@ignore | [
"Returns",
"the",
"keyStroke",
"string"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/event/keyEvent.js#L78-L90 |
6,040 | nhn/tui.grid | src/js/theme/manager.js | buildCssString | function buildCssString(options) {
var styles = [
styleGen.outline(options.outline),
styleGen.frozenBorder(options.frozenBorder),
styleGen.scrollbar(options.scrollbar),
styleGen.heightResizeHandle(options.heightResizeHandle),
styleGen.pagination(options.pagination),
styleGen.selection(options.selection)
];
var area = options.area;
var cell = options.cell;
styles = styles.concat([
styleGen.headArea(area.header),
styleGen.bodyArea(area.body),
styleGen.summaryArea(area.summary)
]);
if (cell) {
styles = styles.concat([
styleGen.cell(cell.normal),
styleGen.cellDummy(cell.dummy),
styleGen.cellEditable(cell.editable),
styleGen.cellHead(cell.head),
styleGen.cellRowHead(cell.rowHead),
styleGen.cellSummary(cell.summary),
styleGen.cellOddRow(cell.oddRow),
styleGen.cellEvenRow(cell.evenRow),
styleGen.cellRequired(cell.required),
styleGen.cellDisabled(cell.disabled),
styleGen.cellInvalid(cell.invalid),
styleGen.cellCurrentRow(cell.currentRow),
styleGen.cellSelectedHead(cell.selectedHead),
styleGen.cellSelectedRowHead(cell.selectedRowHead),
styleGen.cellFocused(cell.focused),
styleGen.cellFocusedInactive(cell.focusedInactive)
]);
}
return styles.join('');
} | javascript | function buildCssString(options) {
var styles = [
styleGen.outline(options.outline),
styleGen.frozenBorder(options.frozenBorder),
styleGen.scrollbar(options.scrollbar),
styleGen.heightResizeHandle(options.heightResizeHandle),
styleGen.pagination(options.pagination),
styleGen.selection(options.selection)
];
var area = options.area;
var cell = options.cell;
styles = styles.concat([
styleGen.headArea(area.header),
styleGen.bodyArea(area.body),
styleGen.summaryArea(area.summary)
]);
if (cell) {
styles = styles.concat([
styleGen.cell(cell.normal),
styleGen.cellDummy(cell.dummy),
styleGen.cellEditable(cell.editable),
styleGen.cellHead(cell.head),
styleGen.cellRowHead(cell.rowHead),
styleGen.cellSummary(cell.summary),
styleGen.cellOddRow(cell.oddRow),
styleGen.cellEvenRow(cell.evenRow),
styleGen.cellRequired(cell.required),
styleGen.cellDisabled(cell.disabled),
styleGen.cellInvalid(cell.invalid),
styleGen.cellCurrentRow(cell.currentRow),
styleGen.cellSelectedHead(cell.selectedHead),
styleGen.cellSelectedRowHead(cell.selectedRowHead),
styleGen.cellFocused(cell.focused),
styleGen.cellFocusedInactive(cell.focusedInactive)
]);
}
return styles.join('');
} | [
"function",
"buildCssString",
"(",
"options",
")",
"{",
"var",
"styles",
"=",
"[",
"styleGen",
".",
"outline",
"(",
"options",
".",
"outline",
")",
",",
"styleGen",
".",
"frozenBorder",
"(",
"options",
".",
"frozenBorder",
")",
",",
"styleGen",
".",
"scrollbar",
"(",
"options",
".",
"scrollbar",
")",
",",
"styleGen",
".",
"heightResizeHandle",
"(",
"options",
".",
"heightResizeHandle",
")",
",",
"styleGen",
".",
"pagination",
"(",
"options",
".",
"pagination",
")",
",",
"styleGen",
".",
"selection",
"(",
"options",
".",
"selection",
")",
"]",
";",
"var",
"area",
"=",
"options",
".",
"area",
";",
"var",
"cell",
"=",
"options",
".",
"cell",
";",
"styles",
"=",
"styles",
".",
"concat",
"(",
"[",
"styleGen",
".",
"headArea",
"(",
"area",
".",
"header",
")",
",",
"styleGen",
".",
"bodyArea",
"(",
"area",
".",
"body",
")",
",",
"styleGen",
".",
"summaryArea",
"(",
"area",
".",
"summary",
")",
"]",
")",
";",
"if",
"(",
"cell",
")",
"{",
"styles",
"=",
"styles",
".",
"concat",
"(",
"[",
"styleGen",
".",
"cell",
"(",
"cell",
".",
"normal",
")",
",",
"styleGen",
".",
"cellDummy",
"(",
"cell",
".",
"dummy",
")",
",",
"styleGen",
".",
"cellEditable",
"(",
"cell",
".",
"editable",
")",
",",
"styleGen",
".",
"cellHead",
"(",
"cell",
".",
"head",
")",
",",
"styleGen",
".",
"cellRowHead",
"(",
"cell",
".",
"rowHead",
")",
",",
"styleGen",
".",
"cellSummary",
"(",
"cell",
".",
"summary",
")",
",",
"styleGen",
".",
"cellOddRow",
"(",
"cell",
".",
"oddRow",
")",
",",
"styleGen",
".",
"cellEvenRow",
"(",
"cell",
".",
"evenRow",
")",
",",
"styleGen",
".",
"cellRequired",
"(",
"cell",
".",
"required",
")",
",",
"styleGen",
".",
"cellDisabled",
"(",
"cell",
".",
"disabled",
")",
",",
"styleGen",
".",
"cellInvalid",
"(",
"cell",
".",
"invalid",
")",
",",
"styleGen",
".",
"cellCurrentRow",
"(",
"cell",
".",
"currentRow",
")",
",",
"styleGen",
".",
"cellSelectedHead",
"(",
"cell",
".",
"selectedHead",
")",
",",
"styleGen",
".",
"cellSelectedRowHead",
"(",
"cell",
".",
"selectedRowHead",
")",
",",
"styleGen",
".",
"cellFocused",
"(",
"cell",
".",
"focused",
")",
",",
"styleGen",
".",
"cellFocusedInactive",
"(",
"cell",
".",
"focusedInactive",
")",
"]",
")",
";",
"}",
"return",
"styles",
".",
"join",
"(",
"''",
")",
";",
"}"
] | build css string with given options.
@param {Object} options - options
@returns {String}
@ignore | [
"build",
"css",
"string",
"with",
"given",
"options",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/manager.js#L26-L66 |
6,041 | nhn/tui.grid | src/js/theme/manager.js | setDocumentStyle | function setDocumentStyle(options) {
var cssString = buildCssString(options);
$('#' + STYLE_ELEMENT_ID).remove();
util.appendStyleElement(STYLE_ELEMENT_ID, cssString);
} | javascript | function setDocumentStyle(options) {
var cssString = buildCssString(options);
$('#' + STYLE_ELEMENT_ID).remove();
util.appendStyleElement(STYLE_ELEMENT_ID, cssString);
} | [
"function",
"setDocumentStyle",
"(",
"options",
")",
"{",
"var",
"cssString",
"=",
"buildCssString",
"(",
"options",
")",
";",
"$",
"(",
"'#'",
"+",
"STYLE_ELEMENT_ID",
")",
".",
"remove",
"(",
")",
";",
"util",
".",
"appendStyleElement",
"(",
"STYLE_ELEMENT_ID",
",",
"cssString",
")",
";",
"}"
] | Set document style with given options.
@param {Object} options - options
@ignore | [
"Set",
"document",
"style",
"with",
"given",
"options",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/manager.js#L73-L78 |
6,042 | nhn/tui.grid | src/js/theme/manager.js | function(themeName, extOptions) {
var options = presetOptions[themeName];
if (!options) {
options = presetOptions[themeNameConst.DEFAULT];
}
options = $.extend(true, {}, options, extOptions);
setDocumentStyle(options);
} | javascript | function(themeName, extOptions) {
var options = presetOptions[themeName];
if (!options) {
options = presetOptions[themeNameConst.DEFAULT];
}
options = $.extend(true, {}, options, extOptions);
setDocumentStyle(options);
} | [
"function",
"(",
"themeName",
",",
"extOptions",
")",
"{",
"var",
"options",
"=",
"presetOptions",
"[",
"themeName",
"]",
";",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"presetOptions",
"[",
"themeNameConst",
".",
"DEFAULT",
"]",
";",
"}",
"options",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"options",
",",
"extOptions",
")",
";",
"setDocumentStyle",
"(",
"options",
")",
";",
"}"
] | Creates a style element using theme options identified by given name,
and appends it to the document.
@param {String} themeName - preset theme name
@param {Object} extOptions - if exist, extend preset theme options with it. | [
"Creates",
"a",
"style",
"element",
"using",
"theme",
"options",
"identified",
"by",
"given",
"name",
"and",
"appends",
"it",
"to",
"the",
"document",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/theme/manager.js#L87-L95 |
|
6,043 | nhn/tui.grid | src/js/view/layout/header.js | getSameColumnCount | function getSameColumnCount(currentColumn, prevColumn) {
var index = 0;
var len = Math.min(currentColumn.length, prevColumn.length);
for (; index < len; index += 1) {
if (currentColumn[index].name !== prevColumn[index].name) {
break;
}
}
return index;
} | javascript | function getSameColumnCount(currentColumn, prevColumn) {
var index = 0;
var len = Math.min(currentColumn.length, prevColumn.length);
for (; index < len; index += 1) {
if (currentColumn[index].name !== prevColumn[index].name) {
break;
}
}
return index;
} | [
"function",
"getSameColumnCount",
"(",
"currentColumn",
",",
"prevColumn",
")",
"{",
"var",
"index",
"=",
"0",
";",
"var",
"len",
"=",
"Math",
".",
"min",
"(",
"currentColumn",
".",
"length",
",",
"prevColumn",
".",
"length",
")",
";",
"for",
"(",
";",
"index",
"<",
"len",
";",
"index",
"+=",
"1",
")",
"{",
"if",
"(",
"currentColumn",
"[",
"index",
"]",
".",
"name",
"!==",
"prevColumn",
"[",
"index",
"]",
".",
"name",
")",
"{",
"break",
";",
"}",
"}",
"return",
"index",
";",
"}"
] | Get count of same columns in complex columns
@param {array} currentColumn - Current column's model
@param {array} prevColumn - Previous column's model
@returns {number} Count of same columns
@ignore | [
"Get",
"count",
"of",
"same",
"columns",
"in",
"complex",
"columns"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L37-L48 |
6,044 | nhn/tui.grid | src/js/view/layout/header.js | function() {
var columnRange = this.selectionModel.get('range').column;
var visibleColumns = this.columnModel.getVisibleColumns();
var selectedColumns = visibleColumns.slice(columnRange[0], columnRange[1] + 1);
return _.pluck(selectedColumns, 'name');
} | javascript | function() {
var columnRange = this.selectionModel.get('range').column;
var visibleColumns = this.columnModel.getVisibleColumns();
var selectedColumns = visibleColumns.slice(columnRange[0], columnRange[1] + 1);
return _.pluck(selectedColumns, 'name');
} | [
"function",
"(",
")",
"{",
"var",
"columnRange",
"=",
"this",
".",
"selectionModel",
".",
"get",
"(",
"'range'",
")",
".",
"column",
";",
"var",
"visibleColumns",
"=",
"this",
".",
"columnModel",
".",
"getVisibleColumns",
"(",
")",
";",
"var",
"selectedColumns",
"=",
"visibleColumns",
".",
"slice",
"(",
"columnRange",
"[",
"0",
"]",
",",
"columnRange",
"[",
"1",
"]",
"+",
"1",
")",
";",
"return",
"_",
".",
"pluck",
"(",
"selectedColumns",
",",
"'name'",
")",
";",
"}"
] | Returns an array of names of columns in selection range.
@private
@returns {Array.<String>} | [
"Returns",
"an",
"array",
"of",
"names",
"of",
"columns",
"in",
"selection",
"range",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L175-L181 |
|
6,045 | nhn/tui.grid | src/js/view/layout/header.js | function(columnNames) {
var columnModel = this.columnModel;
var mergedColumnNames = _.pluck(columnModel.get('complexHeaderColumns'), 'name');
return _.filter(mergedColumnNames, function(mergedColumnName) {
var unitColumnNames = columnModel.getUnitColumnNamesIfMerged(mergedColumnName);
return _.every(unitColumnNames, function(name) {
return _.contains(columnNames, name);
});
});
} | javascript | function(columnNames) {
var columnModel = this.columnModel;
var mergedColumnNames = _.pluck(columnModel.get('complexHeaderColumns'), 'name');
return _.filter(mergedColumnNames, function(mergedColumnName) {
var unitColumnNames = columnModel.getUnitColumnNamesIfMerged(mergedColumnName);
return _.every(unitColumnNames, function(name) {
return _.contains(columnNames, name);
});
});
} | [
"function",
"(",
"columnNames",
")",
"{",
"var",
"columnModel",
"=",
"this",
".",
"columnModel",
";",
"var",
"mergedColumnNames",
"=",
"_",
".",
"pluck",
"(",
"columnModel",
".",
"get",
"(",
"'complexHeaderColumns'",
")",
",",
"'name'",
")",
";",
"return",
"_",
".",
"filter",
"(",
"mergedColumnNames",
",",
"function",
"(",
"mergedColumnName",
")",
"{",
"var",
"unitColumnNames",
"=",
"columnModel",
".",
"getUnitColumnNamesIfMerged",
"(",
"mergedColumnName",
")",
";",
"return",
"_",
".",
"every",
"(",
"unitColumnNames",
",",
"function",
"(",
"name",
")",
"{",
"return",
"_",
".",
"contains",
"(",
"columnNames",
",",
"name",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Returns an array of names of merged-column which contains every column name in the given array.
@param {Array.<String>} columnNames - an array of column names to test
@returns {Array.<String>}
@private | [
"Returns",
"an",
"array",
"of",
"names",
"of",
"merged",
"-",
"column",
"which",
"contains",
"every",
"column",
"name",
"in",
"the",
"given",
"array",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L198-L209 |
|
6,046 | nhn/tui.grid | src/js/view/layout/header.js | function(ev) {
var $target = $(ev.target);
var columnName;
if (!this._triggerPublicMousedown(ev)) {
return;
}
if ($target.hasClass(classNameConst.BTN_SORT)) {
return;
}
columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
if (columnName) {
this.dragEmitter.start(ev, {
columnName: columnName
});
}
} | javascript | function(ev) {
var $target = $(ev.target);
var columnName;
if (!this._triggerPublicMousedown(ev)) {
return;
}
if ($target.hasClass(classNameConst.BTN_SORT)) {
return;
}
columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
if (columnName) {
this.dragEmitter.start(ev, {
columnName: columnName
});
}
} | [
"function",
"(",
"ev",
")",
"{",
"var",
"$target",
"=",
"$",
"(",
"ev",
".",
"target",
")",
";",
"var",
"columnName",
";",
"if",
"(",
"!",
"this",
".",
"_triggerPublicMousedown",
"(",
"ev",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$target",
".",
"hasClass",
"(",
"classNameConst",
".",
"BTN_SORT",
")",
")",
"{",
"return",
";",
"}",
"columnName",
"=",
"$target",
".",
"closest",
"(",
"'th'",
")",
".",
"attr",
"(",
"ATTR_COLUMN_NAME",
")",
";",
"if",
"(",
"columnName",
")",
"{",
"this",
".",
"dragEmitter",
".",
"start",
"(",
"ev",
",",
"{",
"columnName",
":",
"columnName",
"}",
")",
";",
"}",
"}"
] | Mousedown event handler
@param {jQuery.Event} ev - MouseDown event
@private | [
"Mousedown",
"event",
"handler"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L251-L269 |
|
6,047 | nhn/tui.grid | src/js/view/layout/header.js | function(ev) {
var $target = $(ev.target);
var columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
var eventData = new GridEvent(ev);
if (columnName === '_button' && $target.is('input')) {
eventData.setData({
checked: $target.prop('checked')
});
this.domEventBus.trigger('click:headerCheck', eventData);
} else if ($target.is('a.' + classNameConst.BTN_SORT)) {
eventData.setData({
columnName: columnName
});
this.domEventBus.trigger('click:headerSort', eventData);
}
} | javascript | function(ev) {
var $target = $(ev.target);
var columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
var eventData = new GridEvent(ev);
if (columnName === '_button' && $target.is('input')) {
eventData.setData({
checked: $target.prop('checked')
});
this.domEventBus.trigger('click:headerCheck', eventData);
} else if ($target.is('a.' + classNameConst.BTN_SORT)) {
eventData.setData({
columnName: columnName
});
this.domEventBus.trigger('click:headerSort', eventData);
}
} | [
"function",
"(",
"ev",
")",
"{",
"var",
"$target",
"=",
"$",
"(",
"ev",
".",
"target",
")",
";",
"var",
"columnName",
"=",
"$target",
".",
"closest",
"(",
"'th'",
")",
".",
"attr",
"(",
"ATTR_COLUMN_NAME",
")",
";",
"var",
"eventData",
"=",
"new",
"GridEvent",
"(",
"ev",
")",
";",
"if",
"(",
"columnName",
"===",
"'_button'",
"&&",
"$target",
".",
"is",
"(",
"'input'",
")",
")",
"{",
"eventData",
".",
"setData",
"(",
"{",
"checked",
":",
"$target",
".",
"prop",
"(",
"'checked'",
")",
"}",
")",
";",
"this",
".",
"domEventBus",
".",
"trigger",
"(",
"'click:headerCheck'",
",",
"eventData",
")",
";",
"}",
"else",
"if",
"(",
"$target",
".",
"is",
"(",
"'a.'",
"+",
"classNameConst",
".",
"BTN_SORT",
")",
")",
"{",
"eventData",
".",
"setData",
"(",
"{",
"columnName",
":",
"columnName",
"}",
")",
";",
"this",
".",
"domEventBus",
".",
"trigger",
"(",
"'click:headerSort'",
",",
"eventData",
")",
";",
"}",
"}"
] | Event handler for click event
@param {jQuery.Event} ev - MouseEvent
@private | [
"Event",
"handler",
"for",
"click",
"event"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L368-L384 |
|
6,048 | nhn/tui.grid | src/js/view/layout/header.js | function() {
var hierarchyList = this._getColumnHierarchyList();
var maxRowCount = this._getHierarchyMaxRowCount(hierarchyList);
var rowHeight = util.getRowHeight(maxRowCount, this.headerHeight) - 1;
var handleHeights = [];
var index = 1;
var coulmnLen = hierarchyList.length;
var sameColumnCount, handleHeight;
for (; index < coulmnLen; index += 1) {
sameColumnCount = getSameColumnCount(hierarchyList[index], hierarchyList[index - 1]);
handleHeight = rowHeight * (maxRowCount - sameColumnCount);
handleHeights.push(handleHeight);
}
handleHeights.push(rowHeight * maxRowCount); // last resize handle
return handleHeights;
} | javascript | function() {
var hierarchyList = this._getColumnHierarchyList();
var maxRowCount = this._getHierarchyMaxRowCount(hierarchyList);
var rowHeight = util.getRowHeight(maxRowCount, this.headerHeight) - 1;
var handleHeights = [];
var index = 1;
var coulmnLen = hierarchyList.length;
var sameColumnCount, handleHeight;
for (; index < coulmnLen; index += 1) {
sameColumnCount = getSameColumnCount(hierarchyList[index], hierarchyList[index - 1]);
handleHeight = rowHeight * (maxRowCount - sameColumnCount);
handleHeights.push(handleHeight);
}
handleHeights.push(rowHeight * maxRowCount); // last resize handle
return handleHeights;
} | [
"function",
"(",
")",
"{",
"var",
"hierarchyList",
"=",
"this",
".",
"_getColumnHierarchyList",
"(",
")",
";",
"var",
"maxRowCount",
"=",
"this",
".",
"_getHierarchyMaxRowCount",
"(",
"hierarchyList",
")",
";",
"var",
"rowHeight",
"=",
"util",
".",
"getRowHeight",
"(",
"maxRowCount",
",",
"this",
".",
"headerHeight",
")",
"-",
"1",
";",
"var",
"handleHeights",
"=",
"[",
"]",
";",
"var",
"index",
"=",
"1",
";",
"var",
"coulmnLen",
"=",
"hierarchyList",
".",
"length",
";",
"var",
"sameColumnCount",
",",
"handleHeight",
";",
"for",
"(",
";",
"index",
"<",
"coulmnLen",
";",
"index",
"+=",
"1",
")",
"{",
"sameColumnCount",
"=",
"getSameColumnCount",
"(",
"hierarchyList",
"[",
"index",
"]",
",",
"hierarchyList",
"[",
"index",
"-",
"1",
"]",
")",
";",
"handleHeight",
"=",
"rowHeight",
"*",
"(",
"maxRowCount",
"-",
"sameColumnCount",
")",
";",
"handleHeights",
".",
"push",
"(",
"handleHeight",
")",
";",
"}",
"handleHeights",
".",
"push",
"(",
"rowHeight",
"*",
"maxRowCount",
")",
";",
"// last resize handle",
"return",
"handleHeights",
";",
"}"
] | Get height values of resize handlers
@returns {array} Height values of resize handles | [
"Get",
"height",
"values",
"of",
"resize",
"handlers"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/header.js#L578-L597 |
|
6,049 | nhn/tui.grid | karma.conf.js | setConfig | function setConfig(defaultConfig, server) {
if (server === 'ne') {
defaultConfig.captureTimeout = 100000;
defaultConfig.customLaunchers = {
'IE8': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '8'
},
'IE9': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '9'
},
'IE10': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '10'
},
'IE11': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '11'
},
'Edge': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'MicrosoftEdge'
},
'Chrome-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'chrome'
},
'Firefox-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'firefox'
},
'Safari-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'safari'
}
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'IE8',
'IE9',
'IE10',
'IE11',
'Edge',
'Chrome-WebDriver',
'Firefox-WebDriver'
// 'Safari-WebDriver' // active only when safari test is needed
];
defaultConfig.webpack.module.preLoaders = [{
test: /\.js$/,
include: path.resolve('./src/js'),
loader: 'istanbul-instrumenter'
}];
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
defaultConfig.reporters = [
'dots',
'coverage',
'junit'
];
// optionally, configure the reporter
defaultConfig.coverageReporter = {
dir: 'report/coverage/',
reporters: [
{
type: 'html',
subdir: function(browser) {
return 'report-html/' + browser;
}
},
{
type: 'cobertura',
subdir: function(browser) {
return 'report-cobertura/' + browser;
},
file: 'cobertura.txt'
}
]
};
defaultConfig.junitReporter = {
outputDir: 'report/junit',
suite: ''
};
} else {
defaultConfig.captureTimeout = 60000;
defaultConfig.reporters = [
'karmaSimpleReporter'
];
defaultConfig.specReporter = {
suppressPassed: true,
suppressSkipped: true,
suppressErrorSummary: true
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'ChromeHeadless'
];
}
} | javascript | function setConfig(defaultConfig, server) {
if (server === 'ne') {
defaultConfig.captureTimeout = 100000;
defaultConfig.customLaunchers = {
'IE8': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '8'
},
'IE9': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '9'
},
'IE10': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '10'
},
'IE11': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '11'
},
'Edge': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'MicrosoftEdge'
},
'Chrome-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'chrome'
},
'Firefox-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'firefox'
},
'Safari-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'safari'
}
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'IE8',
'IE9',
'IE10',
'IE11',
'Edge',
'Chrome-WebDriver',
'Firefox-WebDriver'
// 'Safari-WebDriver' // active only when safari test is needed
];
defaultConfig.webpack.module.preLoaders = [{
test: /\.js$/,
include: path.resolve('./src/js'),
loader: 'istanbul-instrumenter'
}];
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
defaultConfig.reporters = [
'dots',
'coverage',
'junit'
];
// optionally, configure the reporter
defaultConfig.coverageReporter = {
dir: 'report/coverage/',
reporters: [
{
type: 'html',
subdir: function(browser) {
return 'report-html/' + browser;
}
},
{
type: 'cobertura',
subdir: function(browser) {
return 'report-cobertura/' + browser;
},
file: 'cobertura.txt'
}
]
};
defaultConfig.junitReporter = {
outputDir: 'report/junit',
suite: ''
};
} else {
defaultConfig.captureTimeout = 60000;
defaultConfig.reporters = [
'karmaSimpleReporter'
];
defaultConfig.specReporter = {
suppressPassed: true,
suppressSkipped: true,
suppressErrorSummary: true
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'ChromeHeadless'
];
}
} | [
"function",
"setConfig",
"(",
"defaultConfig",
",",
"server",
")",
"{",
"if",
"(",
"server",
"===",
"'ne'",
")",
"{",
"defaultConfig",
".",
"captureTimeout",
"=",
"100000",
";",
"defaultConfig",
".",
"customLaunchers",
"=",
"{",
"'IE8'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'internet explorer'",
",",
"version",
":",
"'8'",
"}",
",",
"'IE9'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'internet explorer'",
",",
"version",
":",
"'9'",
"}",
",",
"'IE10'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'internet explorer'",
",",
"version",
":",
"'10'",
"}",
",",
"'IE11'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'internet explorer'",
",",
"version",
":",
"'11'",
"}",
",",
"'Edge'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'MicrosoftEdge'",
"}",
",",
"'Chrome-WebDriver'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'chrome'",
"}",
",",
"'Firefox-WebDriver'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'firefox'",
"}",
",",
"'Safari-WebDriver'",
":",
"{",
"base",
":",
"'WebDriver'",
",",
"config",
":",
"webdriverConfig",
",",
"browserName",
":",
"'safari'",
"}",
"}",
";",
"// start these browsers",
"// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher",
"defaultConfig",
".",
"browsers",
"=",
"[",
"'IE8'",
",",
"'IE9'",
",",
"'IE10'",
",",
"'IE11'",
",",
"'Edge'",
",",
"'Chrome-WebDriver'",
",",
"'Firefox-WebDriver'",
"// 'Safari-WebDriver' // active only when safari test is needed",
"]",
";",
"defaultConfig",
".",
"webpack",
".",
"module",
".",
"preLoaders",
"=",
"[",
"{",
"test",
":",
"/",
"\\.js$",
"/",
",",
"include",
":",
"path",
".",
"resolve",
"(",
"'./src/js'",
")",
",",
"loader",
":",
"'istanbul-instrumenter'",
"}",
"]",
";",
"// test results reporter to use",
"// possible values: 'dots', 'progress'",
"// available reporters: https://npmjs.org/browse/keyword/karma-reporter",
"defaultConfig",
".",
"reporters",
"=",
"[",
"'dots'",
",",
"'coverage'",
",",
"'junit'",
"]",
";",
"// optionally, configure the reporter",
"defaultConfig",
".",
"coverageReporter",
"=",
"{",
"dir",
":",
"'report/coverage/'",
",",
"reporters",
":",
"[",
"{",
"type",
":",
"'html'",
",",
"subdir",
":",
"function",
"(",
"browser",
")",
"{",
"return",
"'report-html/'",
"+",
"browser",
";",
"}",
"}",
",",
"{",
"type",
":",
"'cobertura'",
",",
"subdir",
":",
"function",
"(",
"browser",
")",
"{",
"return",
"'report-cobertura/'",
"+",
"browser",
";",
"}",
",",
"file",
":",
"'cobertura.txt'",
"}",
"]",
"}",
";",
"defaultConfig",
".",
"junitReporter",
"=",
"{",
"outputDir",
":",
"'report/junit'",
",",
"suite",
":",
"''",
"}",
";",
"}",
"else",
"{",
"defaultConfig",
".",
"captureTimeout",
"=",
"60000",
";",
"defaultConfig",
".",
"reporters",
"=",
"[",
"'karmaSimpleReporter'",
"]",
";",
"defaultConfig",
".",
"specReporter",
"=",
"{",
"suppressPassed",
":",
"true",
",",
"suppressSkipped",
":",
"true",
",",
"suppressErrorSummary",
":",
"true",
"}",
";",
"// start these browsers",
"// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher",
"defaultConfig",
".",
"browsers",
"=",
"[",
"'ChromeHeadless'",
"]",
";",
"}",
"}"
] | Set config by environment
@param {object} defaultConfig - default config
@param {string} server - server type ('ne' or local) | [
"Set",
"config",
"by",
"environment"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/karma.conf.js#L20-L142 |
6,050 | nhn/tui.grid | src/js/common/util.js | function(arr) {
return {
min: Math.min.apply(null, arr),
max: Math.max.apply(null, arr)
};
} | javascript | function(arr) {
return {
min: Math.min.apply(null, arr),
max: Math.max.apply(null, arr)
};
} | [
"function",
"(",
"arr",
")",
"{",
"return",
"{",
"min",
":",
"Math",
".",
"min",
".",
"apply",
"(",
"null",
",",
"arr",
")",
",",
"max",
":",
"Math",
".",
"max",
".",
"apply",
"(",
"null",
",",
"arr",
")",
"}",
";",
"}"
] | Returns the minimum value and the maximum value of the values in array.
@param {Array} arr - Target array
@returns {{min: number, max: number}} Min and Max
@see {@link http://jsperf.com/getminmax} | [
"Returns",
"the",
"minimum",
"value",
"and",
"the",
"maximum",
"value",
"of",
"the",
"values",
"in",
"array",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L94-L99 |
|
6,051 | nhn/tui.grid | src/js/common/util.js | function(obj) {
var pruned = {};
_.each(obj, function(value, key) {
if (!_.isUndefined(value) && !_.isNull(value)) {
pruned[key] = value;
}
});
return pruned;
} | javascript | function(obj) {
var pruned = {};
_.each(obj, function(value, key) {
if (!_.isUndefined(value) && !_.isNull(value)) {
pruned[key] = value;
}
});
return pruned;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"pruned",
"=",
"{",
"}",
";",
"_",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"value",
")",
"&&",
"!",
"_",
".",
"isNull",
"(",
"value",
")",
")",
"{",
"pruned",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"return",
"pruned",
";",
"}"
] | Omits all undefined or null properties of given object.
@param {Object} obj - object
@returns {Object} | [
"Omits",
"all",
"undefined",
"or",
"null",
"properties",
"of",
"given",
"object",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L118-L127 |
|
6,052 | nhn/tui.grid | src/js/common/util.js | function(targetObj, distObj) {
var result = false;
snippet.forEach(targetObj, function(item, key) {
result = (item === distObj[key]);
return result;
});
return result;
} | javascript | function(targetObj, distObj) {
var result = false;
snippet.forEach(targetObj, function(item, key) {
result = (item === distObj[key]);
return result;
});
return result;
} | [
"function",
"(",
"targetObj",
",",
"distObj",
")",
"{",
"var",
"result",
"=",
"false",
";",
"snippet",
".",
"forEach",
"(",
"targetObj",
",",
"function",
"(",
"item",
",",
"key",
")",
"{",
"result",
"=",
"(",
"item",
"===",
"distObj",
"[",
"key",
"]",
")",
";",
"return",
"result",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | eslint-disable-line complexity | [
"eslint",
"-",
"disable",
"-",
"line",
"complexity"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L180-L190 |
|
6,053 | nhn/tui.grid | src/js/common/util.js | function(target) {
if (_.isString(target)) {
return !target.length;
}
return _.isUndefined(target) || _.isNull(target);
} | javascript | function(target) {
if (_.isString(target)) {
return !target.length;
}
return _.isUndefined(target) || _.isNull(target);
} | [
"function",
"(",
"target",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"target",
")",
")",
"{",
"return",
"!",
"target",
".",
"length",
";",
"}",
"return",
"_",
".",
"isUndefined",
"(",
"target",
")",
"||",
"_",
".",
"isNull",
"(",
"target",
")",
";",
"}"
] | Returns whether the string blank.
@memberof module:util
@param {*} target - target object
@returns {boolean} True if target is undefined or null or '' | [
"Returns",
"whether",
"the",
"string",
"blank",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L215-L221 |
|
6,054 | nhn/tui.grid | src/js/common/util.js | function(id, cssString) {
var style = document.createElement('style');
style.type = 'text/css';
style.id = id;
if (style.styleSheet) {
style.styleSheet.cssText = cssString;
} else {
style.appendChild(document.createTextNode(cssString));
}
document.getElementsByTagName('head')[0].appendChild(style);
} | javascript | function(id, cssString) {
var style = document.createElement('style');
style.type = 'text/css';
style.id = id;
if (style.styleSheet) {
style.styleSheet.cssText = cssString;
} else {
style.appendChild(document.createTextNode(cssString));
}
document.getElementsByTagName('head')[0].appendChild(style);
} | [
"function",
"(",
"id",
",",
"cssString",
")",
"{",
"var",
"style",
"=",
"document",
".",
"createElement",
"(",
"'style'",
")",
";",
"style",
".",
"type",
"=",
"'text/css'",
";",
"style",
".",
"id",
"=",
"id",
";",
"if",
"(",
"style",
".",
"styleSheet",
")",
"{",
"style",
".",
"styleSheet",
".",
"cssText",
"=",
"cssString",
";",
"}",
"else",
"{",
"style",
".",
"appendChild",
"(",
"document",
".",
"createTextNode",
"(",
"cssString",
")",
")",
";",
"}",
"document",
".",
"getElementsByTagName",
"(",
"'head'",
")",
"[",
"0",
"]",
".",
"appendChild",
"(",
"style",
")",
";",
"}"
] | create style element and append it into the head element.
@param {String} id - element id
@param {String} cssString - css string | [
"create",
"style",
"element",
"and",
"append",
"it",
"into",
"the",
"head",
"element",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L390-L403 |
|
6,055 | nhn/tui.grid | src/js/common/util.js | function(ev) {
var rightClick;
ev = ev || window.event;
if (ev.which) {
rightClick = ev.which === 3;
} else if (ev.button) {
rightClick = ev.button === 2;
}
return rightClick;
} | javascript | function(ev) {
var rightClick;
ev = ev || window.event;
if (ev.which) {
rightClick = ev.which === 3;
} else if (ev.button) {
rightClick = ev.button === 2;
}
return rightClick;
} | [
"function",
"(",
"ev",
")",
"{",
"var",
"rightClick",
";",
"ev",
"=",
"ev",
"||",
"window",
".",
"event",
";",
"if",
"(",
"ev",
".",
"which",
")",
"{",
"rightClick",
"=",
"ev",
".",
"which",
"===",
"3",
";",
"}",
"else",
"if",
"(",
"ev",
".",
"button",
")",
"{",
"rightClick",
"=",
"ev",
".",
"button",
"===",
"2",
";",
"}",
"return",
"rightClick",
";",
"}"
] | Detect right button by mouse event
@param {object} ev - Mouse event
@returns {boolean} State | [
"Detect",
"right",
"button",
"by",
"mouse",
"event"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/common/util.js#L434-L446 |
|
6,056 | nhn/tui.grid | src/js/view/layout/content-area.js | function() {
var factory = this.viewFactory;
this._addChildren([
factory.createFrame(frameConst.L),
factory.createFrame(frameConst.R)
]);
} | javascript | function() {
var factory = this.viewFactory;
this._addChildren([
factory.createFrame(frameConst.L),
factory.createFrame(frameConst.R)
]);
} | [
"function",
"(",
")",
"{",
"var",
"factory",
"=",
"this",
".",
"viewFactory",
";",
"this",
".",
"_addChildren",
"(",
"[",
"factory",
".",
"createFrame",
"(",
"frameConst",
".",
"L",
")",
",",
"factory",
".",
"createFrame",
"(",
"frameConst",
".",
"R",
")",
"]",
")",
";",
"}"
] | Creates Frame views and add them as children.
@private | [
"Creates",
"Frame",
"views",
"and",
"add",
"them",
"as",
"children",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/layout/content-area.js#L49-L56 |
|
6,057 | nhn/tui.grid | src/js/view/datePickerLayer.js | function() {
var datePickerMap = {};
var columnModelMap = this.columnModel.get('columnModelMap');
_.each(columnModelMap, function(columnModel) {
var name = columnModel.name;
var component = columnModel.component;
var options;
if (component && component.name === 'datePicker') {
options = component.options || {};
datePickerMap[name] = new DatePicker(this.$el, options);
this._bindEventOnDatePicker(datePickerMap[name]);
}
}, this);
return datePickerMap;
} | javascript | function() {
var datePickerMap = {};
var columnModelMap = this.columnModel.get('columnModelMap');
_.each(columnModelMap, function(columnModel) {
var name = columnModel.name;
var component = columnModel.component;
var options;
if (component && component.name === 'datePicker') {
options = component.options || {};
datePickerMap[name] = new DatePicker(this.$el, options);
this._bindEventOnDatePicker(datePickerMap[name]);
}
}, this);
return datePickerMap;
} | [
"function",
"(",
")",
"{",
"var",
"datePickerMap",
"=",
"{",
"}",
";",
"var",
"columnModelMap",
"=",
"this",
".",
"columnModel",
".",
"get",
"(",
"'columnModelMap'",
")",
";",
"_",
".",
"each",
"(",
"columnModelMap",
",",
"function",
"(",
"columnModel",
")",
"{",
"var",
"name",
"=",
"columnModel",
".",
"name",
";",
"var",
"component",
"=",
"columnModel",
".",
"component",
";",
"var",
"options",
";",
"if",
"(",
"component",
"&&",
"component",
".",
"name",
"===",
"'datePicker'",
")",
"{",
"options",
"=",
"component",
".",
"options",
"||",
"{",
"}",
";",
"datePickerMap",
"[",
"name",
"]",
"=",
"new",
"DatePicker",
"(",
"this",
".",
"$el",
",",
"options",
")",
";",
"this",
".",
"_bindEventOnDatePicker",
"(",
"datePickerMap",
"[",
"name",
"]",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"datePickerMap",
";",
"}"
] | Creates instances map of 'tui-date-picker'
@returns {Object.<string, DatePicker>}
@private | [
"Creates",
"instances",
"map",
"of",
"tui",
"-",
"date",
"-",
"picker"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/datePickerLayer.js#L63-L82 |
|
6,058 | nhn/tui.grid | src/js/view/datePickerLayer.js | function(datePicker) {
var self = this;
datePicker.on('open', function() {
self.textPainter.blockFocusingOut();
});
datePicker.on('close', function() {
var focusModel = self.focusModel;
var address = focusModel.which();
var rowKey = address.rowKey;
var columnName = address.columnName;
var changedValue = self.$focusedInput.val();
self.textPainter.unblockFocusingOut();
// when the datePicker layer is closed, selected date must set on input element.
if (focusModel.isEditingCell(rowKey, columnName)) {
focusModel.dataModel.setValue(rowKey, columnName, changedValue);
}
focusModel.finishEditing();
});
} | javascript | function(datePicker) {
var self = this;
datePicker.on('open', function() {
self.textPainter.blockFocusingOut();
});
datePicker.on('close', function() {
var focusModel = self.focusModel;
var address = focusModel.which();
var rowKey = address.rowKey;
var columnName = address.columnName;
var changedValue = self.$focusedInput.val();
self.textPainter.unblockFocusingOut();
// when the datePicker layer is closed, selected date must set on input element.
if (focusModel.isEditingCell(rowKey, columnName)) {
focusModel.dataModel.setValue(rowKey, columnName, changedValue);
}
focusModel.finishEditing();
});
} | [
"function",
"(",
"datePicker",
")",
"{",
"var",
"self",
"=",
"this",
";",
"datePicker",
".",
"on",
"(",
"'open'",
",",
"function",
"(",
")",
"{",
"self",
".",
"textPainter",
".",
"blockFocusingOut",
"(",
")",
";",
"}",
")",
";",
"datePicker",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"var",
"focusModel",
"=",
"self",
".",
"focusModel",
";",
"var",
"address",
"=",
"focusModel",
".",
"which",
"(",
")",
";",
"var",
"rowKey",
"=",
"address",
".",
"rowKey",
";",
"var",
"columnName",
"=",
"address",
".",
"columnName",
";",
"var",
"changedValue",
"=",
"self",
".",
"$focusedInput",
".",
"val",
"(",
")",
";",
"self",
".",
"textPainter",
".",
"unblockFocusingOut",
"(",
")",
";",
"// when the datePicker layer is closed, selected date must set on input element.",
"if",
"(",
"focusModel",
".",
"isEditingCell",
"(",
"rowKey",
",",
"columnName",
")",
")",
"{",
"focusModel",
".",
"dataModel",
".",
"setValue",
"(",
"rowKey",
",",
"columnName",
",",
"changedValue",
")",
";",
"}",
"focusModel",
".",
"finishEditing",
"(",
")",
";",
"}",
")",
";",
"}"
] | Bind custom event on the DatePicker instance
@param {DatePicker} datePicker - instance of DatePicker
@private | [
"Bind",
"custom",
"event",
"on",
"the",
"DatePicker",
"instance"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/datePickerLayer.js#L89-L111 |
|
6,059 | nhn/tui.grid | src/js/view/datePickerLayer.js | function(options, $input, columnName) {
var datePicker = this.datePickerMap[columnName];
var format = options.format || DEFAULT_DATE_FORMAT;
var date = options.date || (new Date());
var selectableRanges = options.selectableRanges;
datePicker.setInput($input, {
format: format,
syncFromInput: true
});
if (selectableRanges) {
datePicker.setRanges(selectableRanges);
} else {
datePicker.setRanges(FULL_RANGES);
}
if ($input.val() === '') {
datePicker.setDate(date);
$input.val('');
}
} | javascript | function(options, $input, columnName) {
var datePicker = this.datePickerMap[columnName];
var format = options.format || DEFAULT_DATE_FORMAT;
var date = options.date || (new Date());
var selectableRanges = options.selectableRanges;
datePicker.setInput($input, {
format: format,
syncFromInput: true
});
if (selectableRanges) {
datePicker.setRanges(selectableRanges);
} else {
datePicker.setRanges(FULL_RANGES);
}
if ($input.val() === '') {
datePicker.setDate(date);
$input.val('');
}
} | [
"function",
"(",
"options",
",",
"$input",
",",
"columnName",
")",
"{",
"var",
"datePicker",
"=",
"this",
".",
"datePickerMap",
"[",
"columnName",
"]",
";",
"var",
"format",
"=",
"options",
".",
"format",
"||",
"DEFAULT_DATE_FORMAT",
";",
"var",
"date",
"=",
"options",
".",
"date",
"||",
"(",
"new",
"Date",
"(",
")",
")",
";",
"var",
"selectableRanges",
"=",
"options",
".",
"selectableRanges",
";",
"datePicker",
".",
"setInput",
"(",
"$input",
",",
"{",
"format",
":",
"format",
",",
"syncFromInput",
":",
"true",
"}",
")",
";",
"if",
"(",
"selectableRanges",
")",
"{",
"datePicker",
".",
"setRanges",
"(",
"selectableRanges",
")",
";",
"}",
"else",
"{",
"datePicker",
".",
"setRanges",
"(",
"FULL_RANGES",
")",
";",
"}",
"if",
"(",
"$input",
".",
"val",
"(",
")",
"===",
"''",
")",
"{",
"datePicker",
".",
"setDate",
"(",
"date",
")",
";",
"$input",
".",
"val",
"(",
"''",
")",
";",
"}",
"}"
] | Resets date picker options
@param {Object} options - datePicker options
@param {jQuery} $input - target input element
@param {string} columnName - name to find the DatePicker instance created on each column
@private | [
"Resets",
"date",
"picker",
"options"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/datePickerLayer.js#L120-L141 |
|
6,060 | nhn/tui.grid | src/js/view/datePickerLayer.js | function($input) {
var inputOffset = $input.offset();
var inputHeight = $input.outerHeight();
var wrapperOffset = this.domState.getOffset();
return {
top: inputOffset.top - wrapperOffset.top + inputHeight,
left: inputOffset.left - wrapperOffset.left
};
} | javascript | function($input) {
var inputOffset = $input.offset();
var inputHeight = $input.outerHeight();
var wrapperOffset = this.domState.getOffset();
return {
top: inputOffset.top - wrapperOffset.top + inputHeight,
left: inputOffset.left - wrapperOffset.left
};
} | [
"function",
"(",
"$input",
")",
"{",
"var",
"inputOffset",
"=",
"$input",
".",
"offset",
"(",
")",
";",
"var",
"inputHeight",
"=",
"$input",
".",
"outerHeight",
"(",
")",
";",
"var",
"wrapperOffset",
"=",
"this",
".",
"domState",
".",
"getOffset",
"(",
")",
";",
"return",
"{",
"top",
":",
"inputOffset",
".",
"top",
"-",
"wrapperOffset",
".",
"top",
"+",
"inputHeight",
",",
"left",
":",
"inputOffset",
".",
"left",
"-",
"wrapperOffset",
".",
"left",
"}",
";",
"}"
] | Calculates the position of the layer and returns the object that contains css properties.
@param {jQuery} $input - input element
@returns {Object}
@private | [
"Calculates",
"the",
"position",
"of",
"the",
"layer",
"and",
"returns",
"the",
"object",
"that",
"contains",
"css",
"properties",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/datePickerLayer.js#L149-L158 |
|
6,061 | nhn/tui.grid | src/js/view/datePickerLayer.js | function() {
var name = this.focusModel.which().columnName;
var datePicker = this.datePickerMap[name];
if (datePicker && datePicker.isOpened()) {
datePicker.close();
}
} | javascript | function() {
var name = this.focusModel.which().columnName;
var datePicker = this.datePickerMap[name];
if (datePicker && datePicker.isOpened()) {
datePicker.close();
}
} | [
"function",
"(",
")",
"{",
"var",
"name",
"=",
"this",
".",
"focusModel",
".",
"which",
"(",
")",
".",
"columnName",
";",
"var",
"datePicker",
"=",
"this",
".",
"datePickerMap",
"[",
"name",
"]",
";",
"if",
"(",
"datePicker",
"&&",
"datePicker",
".",
"isOpened",
"(",
")",
")",
"{",
"datePicker",
".",
"close",
"(",
")",
";",
"}",
"}"
] | Close the date picker layer that is already opend
@private | [
"Close",
"the",
"date",
"picker",
"layer",
"that",
"is",
"already",
"opend"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/view/datePickerLayer.js#L187-L194 |
|
6,062 | nhn/tui.grid | src/js/painter/controller.js | function(address, force) {
var result;
if (force) {
this.focusModel.finishEditing();
}
result = this.focusModel.startEditing(address.rowKey, address.columnName);
if (result) {
this.selectionModel.end();
}
return result;
} | javascript | function(address, force) {
var result;
if (force) {
this.focusModel.finishEditing();
}
result = this.focusModel.startEditing(address.rowKey, address.columnName);
if (result) {
this.selectionModel.end();
}
return result;
} | [
"function",
"(",
"address",
",",
"force",
")",
"{",
"var",
"result",
";",
"if",
"(",
"force",
")",
"{",
"this",
".",
"focusModel",
".",
"finishEditing",
"(",
")",
";",
"}",
"result",
"=",
"this",
".",
"focusModel",
".",
"startEditing",
"(",
"address",
".",
"rowKey",
",",
"address",
".",
"columnName",
")",
";",
"if",
"(",
"result",
")",
"{",
"this",
".",
"selectionModel",
".",
"end",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Starts editing a cell identified by a given address, and returns the result.
@param {{rowKey:String, columnName:String}} address - cell address
@param {Boolean} force - if set to true, finish current editing before start.
@returns {Boolean} true if succeeded, false otherwise | [
"Starts",
"editing",
"a",
"cell",
"identified",
"by",
"a",
"given",
"address",
"and",
"returns",
"the",
"result",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L34-L48 |
|
6,063 | nhn/tui.grid | src/js/painter/controller.js | function(columnName, value) {
var column = this.columnModel.getColumnModel(columnName);
var maxLength = snippet.pick(column, 'editOptions', 'maxLength');
if (maxLength > 0 && value.length > maxLength) {
return value.substring(0, maxLength);
}
return value;
} | javascript | function(columnName, value) {
var column = this.columnModel.getColumnModel(columnName);
var maxLength = snippet.pick(column, 'editOptions', 'maxLength');
if (maxLength > 0 && value.length > maxLength) {
return value.substring(0, maxLength);
}
return value;
} | [
"function",
"(",
"columnName",
",",
"value",
")",
"{",
"var",
"column",
"=",
"this",
".",
"columnModel",
".",
"getColumnModel",
"(",
"columnName",
")",
";",
"var",
"maxLength",
"=",
"snippet",
".",
"pick",
"(",
"column",
",",
"'editOptions'",
",",
"'maxLength'",
")",
";",
"if",
"(",
"maxLength",
">",
"0",
"&&",
"value",
".",
"length",
">",
"maxLength",
")",
"{",
"return",
"value",
".",
"substring",
"(",
"0",
",",
"maxLength",
")",
";",
"}",
"return",
"value",
";",
"}"
] | Check if given column has 'maxLength' property and returns the substring limited by maxLength.
@param {string} columnName - columnName
@param {string} value - value
@returns {string}
@private | [
"Check",
"if",
"given",
"column",
"has",
"maxLength",
"property",
"and",
"returns",
"the",
"substring",
"limited",
"by",
"maxLength",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L57-L66 |
|
6,064 | nhn/tui.grid | src/js/painter/controller.js | function(address, shouldBlur, value) {
var focusModel = this.focusModel;
var row, currentValue;
if (!focusModel.isEditingCell(address.rowKey, address.columnName)) {
return false;
}
this.selectionModel.enable();
if (!_.isUndefined(value)) {
row = this.dataModel.get(address.rowKey);
currentValue = row.get(address.columnName);
if (!(util.isBlank(value) && util.isBlank(currentValue))) {
this.setValue(address, this._checkMaxLength(address.columnName, value));
}
}
focusModel.finishEditing();
if (shouldBlur) {
focusModel.focusClipboard();
} else {
_.defer(function() {
focusModel.refreshState();
});
}
return true;
} | javascript | function(address, shouldBlur, value) {
var focusModel = this.focusModel;
var row, currentValue;
if (!focusModel.isEditingCell(address.rowKey, address.columnName)) {
return false;
}
this.selectionModel.enable();
if (!_.isUndefined(value)) {
row = this.dataModel.get(address.rowKey);
currentValue = row.get(address.columnName);
if (!(util.isBlank(value) && util.isBlank(currentValue))) {
this.setValue(address, this._checkMaxLength(address.columnName, value));
}
}
focusModel.finishEditing();
if (shouldBlur) {
focusModel.focusClipboard();
} else {
_.defer(function() {
focusModel.refreshState();
});
}
return true;
} | [
"function",
"(",
"address",
",",
"shouldBlur",
",",
"value",
")",
"{",
"var",
"focusModel",
"=",
"this",
".",
"focusModel",
";",
"var",
"row",
",",
"currentValue",
";",
"if",
"(",
"!",
"focusModel",
".",
"isEditingCell",
"(",
"address",
".",
"rowKey",
",",
"address",
".",
"columnName",
")",
")",
"{",
"return",
"false",
";",
"}",
"this",
".",
"selectionModel",
".",
"enable",
"(",
")",
";",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"value",
")",
")",
"{",
"row",
"=",
"this",
".",
"dataModel",
".",
"get",
"(",
"address",
".",
"rowKey",
")",
";",
"currentValue",
"=",
"row",
".",
"get",
"(",
"address",
".",
"columnName",
")",
";",
"if",
"(",
"!",
"(",
"util",
".",
"isBlank",
"(",
"value",
")",
"&&",
"util",
".",
"isBlank",
"(",
"currentValue",
")",
")",
")",
"{",
"this",
".",
"setValue",
"(",
"address",
",",
"this",
".",
"_checkMaxLength",
"(",
"address",
".",
"columnName",
",",
"value",
")",
")",
";",
"}",
"}",
"focusModel",
".",
"finishEditing",
"(",
")",
";",
"if",
"(",
"shouldBlur",
")",
"{",
"focusModel",
".",
"focusClipboard",
"(",
")",
";",
"}",
"else",
"{",
"_",
".",
"defer",
"(",
"function",
"(",
")",
"{",
"focusModel",
".",
"refreshState",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Ends editing a cell identified by a given address, and returns the result.
@param {{rowKey:String, columnName:String}} address - cell address
@param {Boolean} shouldBlur - if set to true, make the current input lose focus.
@param {String} [value] - if exists, set the value of the data model to this value.
@returns {Boolean} - true if succeeded, false otherwise | [
"Ends",
"editing",
"a",
"cell",
"identified",
"by",
"a",
"given",
"address",
"and",
"returns",
"the",
"result",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L75-L104 |
|
6,065 | nhn/tui.grid | src/js/painter/controller.js | function(reverse) {
var focusModel = this.focusModel;
var address = reverse ? focusModel.prevAddress() : focusModel.nextAddress();
focusModel.focusIn(address.rowKey, address.columnName, true);
} | javascript | function(reverse) {
var focusModel = this.focusModel;
var address = reverse ? focusModel.prevAddress() : focusModel.nextAddress();
focusModel.focusIn(address.rowKey, address.columnName, true);
} | [
"function",
"(",
"reverse",
")",
"{",
"var",
"focusModel",
"=",
"this",
".",
"focusModel",
";",
"var",
"address",
"=",
"reverse",
"?",
"focusModel",
".",
"prevAddress",
"(",
")",
":",
"focusModel",
".",
"nextAddress",
"(",
")",
";",
"focusModel",
".",
"focusIn",
"(",
"address",
".",
"rowKey",
",",
"address",
".",
"columnName",
",",
"true",
")",
";",
"}"
] | Moves focus to the next cell, and starts editing the cell.
@param {Boolean} reverse - if set to true, find the previous cell instead of next cell | [
"Moves",
"focus",
"to",
"the",
"next",
"cell",
"and",
"starts",
"editing",
"the",
"cell",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L110-L115 |
|
6,066 | nhn/tui.grid | src/js/painter/controller.js | function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (_.isString(value)) {
value = $.trim(value);
}
if (columnModel.validation && columnModel.validation.dataType === 'number') {
value = convertToNumber(value);
}
if (columnModel.name === '_button') {
if (value) {
this.dataModel.check(address.rowKey);
} else {
this.dataModel.uncheck(address.rowKey);
}
} else {
this.dataModel.setValue(address.rowKey, address.columnName, value);
}
} | javascript | function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (_.isString(value)) {
value = $.trim(value);
}
if (columnModel.validation && columnModel.validation.dataType === 'number') {
value = convertToNumber(value);
}
if (columnModel.name === '_button') {
if (value) {
this.dataModel.check(address.rowKey);
} else {
this.dataModel.uncheck(address.rowKey);
}
} else {
this.dataModel.setValue(address.rowKey, address.columnName, value);
}
} | [
"function",
"(",
"address",
",",
"value",
")",
"{",
"var",
"columnModel",
"=",
"this",
".",
"columnModel",
".",
"getColumnModel",
"(",
"address",
".",
"columnName",
")",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"value",
")",
")",
"{",
"value",
"=",
"$",
".",
"trim",
"(",
"value",
")",
";",
"}",
"if",
"(",
"columnModel",
".",
"validation",
"&&",
"columnModel",
".",
"validation",
".",
"dataType",
"===",
"'number'",
")",
"{",
"value",
"=",
"convertToNumber",
"(",
"value",
")",
";",
"}",
"if",
"(",
"columnModel",
".",
"name",
"===",
"'_button'",
")",
"{",
"if",
"(",
"value",
")",
"{",
"this",
".",
"dataModel",
".",
"check",
"(",
"address",
".",
"rowKey",
")",
";",
"}",
"else",
"{",
"this",
".",
"dataModel",
".",
"uncheck",
"(",
"address",
".",
"rowKey",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"dataModel",
".",
"setValue",
"(",
"address",
".",
"rowKey",
",",
"address",
".",
"columnName",
",",
"value",
")",
";",
"}",
"}"
] | Sets the value of the given cell.
@param {{rowKey:String, columnName:String}} address - cell address
@param {(Number|String|Boolean)} value - value | [
"Sets",
"the",
"value",
"of",
"the",
"given",
"cell",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L153-L171 |
|
6,067 | nhn/tui.grid | src/js/painter/controller.js | function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (!snippet.pick(columnModel, 'editOptions', 'useViewMode')) {
this.setValue(address, value);
}
} | javascript | function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (!snippet.pick(columnModel, 'editOptions', 'useViewMode')) {
this.setValue(address, value);
}
} | [
"function",
"(",
"address",
",",
"value",
")",
"{",
"var",
"columnModel",
"=",
"this",
".",
"columnModel",
".",
"getColumnModel",
"(",
"address",
".",
"columnName",
")",
";",
"if",
"(",
"!",
"snippet",
".",
"pick",
"(",
"columnModel",
",",
"'editOptions'",
",",
"'useViewMode'",
")",
")",
"{",
"this",
".",
"setValue",
"(",
"address",
",",
"value",
")",
";",
"}",
"}"
] | Sets the value of the given cell, if the given column is not using view-mode.
@param {{rowKey:String, columnName:String}} address - cell address
@param {(Number|String|Boolean)} value - value | [
"Sets",
"the",
"value",
"of",
"the",
"given",
"cell",
"if",
"the",
"given",
"column",
"is",
"not",
"using",
"view",
"-",
"mode",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L178-L184 |
|
6,068 | nhn/tui.grid | src/js/painter/controller.js | convertToNumber | function convertToNumber(value) {
if (_.isString(value)) {
value = value.replace(/,/g, '');
}
if (_.isNumber(value) || isNaN(value) || util.isBlank(value)) {
return value;
}
return Number(value);
} | javascript | function convertToNumber(value) {
if (_.isString(value)) {
value = value.replace(/,/g, '');
}
if (_.isNumber(value) || isNaN(value) || util.isBlank(value)) {
return value;
}
return Number(value);
} | [
"function",
"convertToNumber",
"(",
"value",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"value",
")",
")",
"{",
"value",
"=",
"value",
".",
"replace",
"(",
"/",
",",
"/",
"g",
",",
"''",
")",
";",
"}",
"if",
"(",
"_",
".",
"isNumber",
"(",
"value",
")",
"||",
"isNaN",
"(",
"value",
")",
"||",
"util",
".",
"isBlank",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"return",
"Number",
"(",
"value",
")",
";",
"}"
] | Converts given value to a number type and returns it.
If the value is not a number type, returns the original value.
@param {*} value - value
@returns {*} | [
"Converts",
"given",
"value",
"to",
"a",
"number",
"type",
"and",
"returns",
"it",
".",
"If",
"the",
"value",
"is",
"not",
"a",
"number",
"type",
"returns",
"the",
"original",
"value",
"."
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/src/js/painter/controller.js#L206-L216 |
6,069 | nhn/tui.grid | wdio.conf.js | getScreenshotName | function getScreenshotName(basePath) {
return function(context) {
var testName = context.test.title.replace(/\s+/g, '-');
var browserName = context.browser.name;
var browserVersion = parseInt(context.browser.version, 10);
var subDir = browserName + '_v' + browserVersion;
var fileName = testName + '.png';
return path.join(basePath, subDir, fileName);
};
} | javascript | function getScreenshotName(basePath) {
return function(context) {
var testName = context.test.title.replace(/\s+/g, '-');
var browserName = context.browser.name;
var browserVersion = parseInt(context.browser.version, 10);
var subDir = browserName + '_v' + browserVersion;
var fileName = testName + '.png';
return path.join(basePath, subDir, fileName);
};
} | [
"function",
"getScreenshotName",
"(",
"basePath",
")",
"{",
"return",
"function",
"(",
"context",
")",
"{",
"var",
"testName",
"=",
"context",
".",
"test",
".",
"title",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'-'",
")",
";",
"var",
"browserName",
"=",
"context",
".",
"browser",
".",
"name",
";",
"var",
"browserVersion",
"=",
"parseInt",
"(",
"context",
".",
"browser",
".",
"version",
",",
"10",
")",
";",
"var",
"subDir",
"=",
"browserName",
"+",
"'_v'",
"+",
"browserVersion",
";",
"var",
"fileName",
"=",
"testName",
"+",
"'.png'",
";",
"return",
"path",
".",
"join",
"(",
"basePath",
",",
"subDir",
",",
"fileName",
")",
";",
"}",
";",
"}"
] | Returns the screenshot name
@param {String} basePath - base path
@returns {String} | [
"Returns",
"the",
"screenshot",
"name"
] | 9f66e339485e505bb85490c03a6a2db8dd599e0a | https://github.com/nhn/tui.grid/blob/9f66e339485e505bb85490c03a6a2db8dd599e0a/wdio.conf.js#L11-L21 |
6,070 | jacomyal/sigma.js | src/classes/sigma.classes.configurable.js | function(a1, a2) {
var o,
i,
l,
k;
if (arguments.length === 1 && typeof a1 === 'string') {
if (data[a1] !== undefined)
return data[a1];
for (i = 0, l = datas.length; i < l; i++)
if (datas[i][a1] !== undefined)
return datas[i][a1];
return undefined;
} else if (typeof a1 === 'object' && typeof a2 === 'string') {
return (a1 || {})[a2] !== undefined ? a1[a2] : settings(a2);
} else {
o = (typeof a1 === 'object' && a2 === undefined) ? a1 : {};
if (typeof a1 === 'string')
o[a1] = a2;
for (i = 0, k = Object.keys(o), l = k.length; i < l; i++)
data[k[i]] = o[k[i]];
return this;
}
} | javascript | function(a1, a2) {
var o,
i,
l,
k;
if (arguments.length === 1 && typeof a1 === 'string') {
if (data[a1] !== undefined)
return data[a1];
for (i = 0, l = datas.length; i < l; i++)
if (datas[i][a1] !== undefined)
return datas[i][a1];
return undefined;
} else if (typeof a1 === 'object' && typeof a2 === 'string') {
return (a1 || {})[a2] !== undefined ? a1[a2] : settings(a2);
} else {
o = (typeof a1 === 'object' && a2 === undefined) ? a1 : {};
if (typeof a1 === 'string')
o[a1] = a2;
for (i = 0, k = Object.keys(o), l = k.length; i < l; i++)
data[k[i]] = o[k[i]];
return this;
}
} | [
"function",
"(",
"a1",
",",
"a2",
")",
"{",
"var",
"o",
",",
"i",
",",
"l",
",",
"k",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
"&&",
"typeof",
"a1",
"===",
"'string'",
")",
"{",
"if",
"(",
"data",
"[",
"a1",
"]",
"!==",
"undefined",
")",
"return",
"data",
"[",
"a1",
"]",
";",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"datas",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"if",
"(",
"datas",
"[",
"i",
"]",
"[",
"a1",
"]",
"!==",
"undefined",
")",
"return",
"datas",
"[",
"i",
"]",
"[",
"a1",
"]",
";",
"return",
"undefined",
";",
"}",
"else",
"if",
"(",
"typeof",
"a1",
"===",
"'object'",
"&&",
"typeof",
"a2",
"===",
"'string'",
")",
"{",
"return",
"(",
"a1",
"||",
"{",
"}",
")",
"[",
"a2",
"]",
"!==",
"undefined",
"?",
"a1",
"[",
"a2",
"]",
":",
"settings",
"(",
"a2",
")",
";",
"}",
"else",
"{",
"o",
"=",
"(",
"typeof",
"a1",
"===",
"'object'",
"&&",
"a2",
"===",
"undefined",
")",
"?",
"a1",
":",
"{",
"}",
";",
"if",
"(",
"typeof",
"a1",
"===",
"'string'",
")",
"o",
"[",
"a1",
"]",
"=",
"a2",
";",
"for",
"(",
"i",
"=",
"0",
",",
"k",
"=",
"Object",
".",
"keys",
"(",
"o",
")",
",",
"l",
"=",
"k",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"data",
"[",
"k",
"[",
"i",
"]",
"]",
"=",
"o",
"[",
"k",
"[",
"i",
"]",
"]",
";",
"return",
"this",
";",
"}",
"}"
] | The method to use to set or get any property of this instance.
@param {string|object} a1 If it is a string and if a2 is undefined,
then it will return the corresponding
property. If it is a string and if a2 is
set, then it will set a2 as the property
corresponding to a1, and return this. If
it is an object, then each pair string +
object(or any other type) will be set as a
property.
@param {*?} a2 The new property corresponding to a1 if a1
is a string.
@return {*|configurable} Returns itself or the corresponding
property.
Polymorphism:
*************
Here are some basic use examples:
> settings = new configurable();
> settings('mySetting', 42);
> settings('mySetting'); // Logs: 42
> settings('mySetting', 123);
> settings('mySetting'); // Logs: 123
> settings({mySetting: 456});
> settings('mySetting'); // Logs: 456
Also, it is possible to use the function as a fallback:
> settings({mySetting: 'abc'}, 'mySetting'); // Logs: 'abc'
> settings({hisSetting: 'abc'}, 'mySetting'); // Logs: 456 | [
"The",
"method",
"to",
"use",
"to",
"set",
"or",
"get",
"any",
"property",
"of",
"this",
"instance",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.configurable.js#L51-L77 |
|
6,071 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(n) {
return {
x1: n.x - n.size,
y1: n.y - n.size,
x2: n.x + n.size,
y2: n.y - n.size,
height: n.size * 2
};
} | javascript | function(n) {
return {
x1: n.x - n.size,
y1: n.y - n.size,
x2: n.x + n.size,
y2: n.y - n.size,
height: n.size * 2
};
} | [
"function",
"(",
"n",
")",
"{",
"return",
"{",
"x1",
":",
"n",
".",
"x",
"-",
"n",
".",
"size",
",",
"y1",
":",
"n",
".",
"y",
"-",
"n",
".",
"size",
",",
"x2",
":",
"n",
".",
"x",
"+",
"n",
".",
"size",
",",
"y2",
":",
"n",
".",
"y",
"-",
"n",
".",
"size",
",",
"height",
":",
"n",
".",
"size",
"*",
"2",
"}",
";",
"}"
] | Transforms a graph node with x, y and size into an
axis-aligned square.
@param {object} A graph node with at least a point (x, y) and a size.
@return {object} A square: two points (x1, y1), (x2, y2) and height. | [
"Transforms",
"a",
"graph",
"node",
"with",
"x",
"y",
"and",
"size",
"into",
"an",
"axis",
"-",
"aligned",
"square",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L31-L39 |
|
6,072 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(e) {
if (e.y1 < e.y2) {
// (e.x1, e.y1) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y1 - e.size,
x2: e.x2 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x1, e.y1) on right
return {
x1: e.x2 - e.size,
y1: e.y1 - e.size,
x2: e.x1 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x2, e.y2) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y2 - e.size,
x2: e.x2 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
}
// (e.x2, e.y2) on right
return {
x1: e.x2 - e.size,
y1: e.y2 - e.size,
x2: e.x1 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
} | javascript | function(e) {
if (e.y1 < e.y2) {
// (e.x1, e.y1) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y1 - e.size,
x2: e.x2 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x1, e.y1) on right
return {
x1: e.x2 - e.size,
y1: e.y1 - e.size,
x2: e.x1 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x2, e.y2) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y2 - e.size,
x2: e.x2 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
}
// (e.x2, e.y2) on right
return {
x1: e.x2 - e.size,
y1: e.y2 - e.size,
x2: e.x1 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"y1",
"<",
"e",
".",
"y2",
")",
"{",
"// (e.x1, e.y1) on top",
"if",
"(",
"e",
".",
"x1",
"<",
"e",
".",
"x2",
")",
"{",
"// (e.x1, e.y1) on left",
"return",
"{",
"x1",
":",
"e",
".",
"x1",
"-",
"e",
".",
"size",
",",
"y1",
":",
"e",
".",
"y1",
"-",
"e",
".",
"size",
",",
"x2",
":",
"e",
".",
"x2",
"+",
"e",
".",
"size",
",",
"y2",
":",
"e",
".",
"y1",
"-",
"e",
".",
"size",
",",
"height",
":",
"e",
".",
"y2",
"-",
"e",
".",
"y1",
"+",
"e",
".",
"size",
"*",
"2",
"}",
";",
"}",
"// (e.x1, e.y1) on right",
"return",
"{",
"x1",
":",
"e",
".",
"x2",
"-",
"e",
".",
"size",
",",
"y1",
":",
"e",
".",
"y1",
"-",
"e",
".",
"size",
",",
"x2",
":",
"e",
".",
"x1",
"+",
"e",
".",
"size",
",",
"y2",
":",
"e",
".",
"y1",
"-",
"e",
".",
"size",
",",
"height",
":",
"e",
".",
"y2",
"-",
"e",
".",
"y1",
"+",
"e",
".",
"size",
"*",
"2",
"}",
";",
"}",
"// (e.x2, e.y2) on top",
"if",
"(",
"e",
".",
"x1",
"<",
"e",
".",
"x2",
")",
"{",
"// (e.x1, e.y1) on left",
"return",
"{",
"x1",
":",
"e",
".",
"x1",
"-",
"e",
".",
"size",
",",
"y1",
":",
"e",
".",
"y2",
"-",
"e",
".",
"size",
",",
"x2",
":",
"e",
".",
"x2",
"+",
"e",
".",
"size",
",",
"y2",
":",
"e",
".",
"y2",
"-",
"e",
".",
"size",
",",
"height",
":",
"e",
".",
"y1",
"-",
"e",
".",
"y2",
"+",
"e",
".",
"size",
"*",
"2",
"}",
";",
"}",
"// (e.x2, e.y2) on right",
"return",
"{",
"x1",
":",
"e",
".",
"x2",
"-",
"e",
".",
"size",
",",
"y1",
":",
"e",
".",
"y2",
"-",
"e",
".",
"size",
",",
"x2",
":",
"e",
".",
"x1",
"+",
"e",
".",
"size",
",",
"y2",
":",
"e",
".",
"y2",
"-",
"e",
".",
"size",
",",
"height",
":",
"e",
".",
"y1",
"-",
"e",
".",
"y2",
"+",
"e",
".",
"size",
"*",
"2",
"}",
";",
"}"
] | Transforms a graph edge with x1, y1, x2, y2 and size into an
axis-aligned square.
@param {object} A graph edge with at least two points
(x1, y1), (x2, y2) and a size.
@return {object} A square: two points (x1, y1), (x2, y2) and height. | [
"Transforms",
"a",
"graph",
"edge",
"with",
"x1",
"y1",
"x2",
"y2",
"and",
"size",
"into",
"an",
"axis",
"-",
"aligned",
"square",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L49-L91 |
|
6,073 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(e, cp) {
var pt = sigma.utils.getPointOnQuadraticCurve(
0.5,
e.x1,
e.y1,
e.x2,
e.y2,
cp.x,
cp.y
);
// Bounding box of the two points and the point at the middle of the
// curve:
var minX = Math.min(e.x1, e.x2, pt.x),
maxX = Math.max(e.x1, e.x2, pt.x),
minY = Math.min(e.y1, e.y2, pt.y),
maxY = Math.max(e.y1, e.y2, pt.y);
return {
x1: minX - e.size,
y1: minY - e.size,
x2: maxX + e.size,
y2: minY - e.size,
height: maxY - minY + e.size * 2
};
} | javascript | function(e, cp) {
var pt = sigma.utils.getPointOnQuadraticCurve(
0.5,
e.x1,
e.y1,
e.x2,
e.y2,
cp.x,
cp.y
);
// Bounding box of the two points and the point at the middle of the
// curve:
var minX = Math.min(e.x1, e.x2, pt.x),
maxX = Math.max(e.x1, e.x2, pt.x),
minY = Math.min(e.y1, e.y2, pt.y),
maxY = Math.max(e.y1, e.y2, pt.y);
return {
x1: minX - e.size,
y1: minY - e.size,
x2: maxX + e.size,
y2: minY - e.size,
height: maxY - minY + e.size * 2
};
} | [
"function",
"(",
"e",
",",
"cp",
")",
"{",
"var",
"pt",
"=",
"sigma",
".",
"utils",
".",
"getPointOnQuadraticCurve",
"(",
"0.5",
",",
"e",
".",
"x1",
",",
"e",
".",
"y1",
",",
"e",
".",
"x2",
",",
"e",
".",
"y2",
",",
"cp",
".",
"x",
",",
"cp",
".",
"y",
")",
";",
"// Bounding box of the two points and the point at the middle of the",
"// curve:",
"var",
"minX",
"=",
"Math",
".",
"min",
"(",
"e",
".",
"x1",
",",
"e",
".",
"x2",
",",
"pt",
".",
"x",
")",
",",
"maxX",
"=",
"Math",
".",
"max",
"(",
"e",
".",
"x1",
",",
"e",
".",
"x2",
",",
"pt",
".",
"x",
")",
",",
"minY",
"=",
"Math",
".",
"min",
"(",
"e",
".",
"y1",
",",
"e",
".",
"y2",
",",
"pt",
".",
"y",
")",
",",
"maxY",
"=",
"Math",
".",
"max",
"(",
"e",
".",
"y1",
",",
"e",
".",
"y2",
",",
"pt",
".",
"y",
")",
";",
"return",
"{",
"x1",
":",
"minX",
"-",
"e",
".",
"size",
",",
"y1",
":",
"minY",
"-",
"e",
".",
"size",
",",
"x2",
":",
"maxX",
"+",
"e",
".",
"size",
",",
"y2",
":",
"minY",
"-",
"e",
".",
"size",
",",
"height",
":",
"maxY",
"-",
"minY",
"+",
"e",
".",
"size",
"*",
"2",
"}",
";",
"}"
] | Transforms a graph edge of type 'curve' with x1, y1, x2, y2,
control point and size into an axis-aligned square.
@param {object} e A graph edge with at least two points
(x1, y1), (x2, y2) and a size.
@param {object} cp A control point (x,y).
@return {object} A square: two points (x1, y1), (x2, y2) and height. | [
"Transforms",
"a",
"graph",
"edge",
"of",
"type",
"curve",
"with",
"x1",
"y1",
"x2",
"y2",
"control",
"point",
"and",
"size",
"into",
"an",
"axis",
"-",
"aligned",
"square",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L102-L127 |
|
6,074 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(n) {
// Fitting to the curve is too costly, we compute a larger bounding box
// using the control points:
var cp = sigma.utils.getSelfLoopControlPoints(n.x, n.y, n.size);
// Bounding box of the point and the two control points:
var minX = Math.min(n.x, cp.x1, cp.x2),
maxX = Math.max(n.x, cp.x1, cp.x2),
minY = Math.min(n.y, cp.y1, cp.y2),
maxY = Math.max(n.y, cp.y1, cp.y2);
return {
x1: minX - n.size,
y1: minY - n.size,
x2: maxX + n.size,
y2: minY - n.size,
height: maxY - minY + n.size * 2
};
} | javascript | function(n) {
// Fitting to the curve is too costly, we compute a larger bounding box
// using the control points:
var cp = sigma.utils.getSelfLoopControlPoints(n.x, n.y, n.size);
// Bounding box of the point and the two control points:
var minX = Math.min(n.x, cp.x1, cp.x2),
maxX = Math.max(n.x, cp.x1, cp.x2),
minY = Math.min(n.y, cp.y1, cp.y2),
maxY = Math.max(n.y, cp.y1, cp.y2);
return {
x1: minX - n.size,
y1: minY - n.size,
x2: maxX + n.size,
y2: minY - n.size,
height: maxY - minY + n.size * 2
};
} | [
"function",
"(",
"n",
")",
"{",
"// Fitting to the curve is too costly, we compute a larger bounding box",
"// using the control points:",
"var",
"cp",
"=",
"sigma",
".",
"utils",
".",
"getSelfLoopControlPoints",
"(",
"n",
".",
"x",
",",
"n",
".",
"y",
",",
"n",
".",
"size",
")",
";",
"// Bounding box of the point and the two control points:",
"var",
"minX",
"=",
"Math",
".",
"min",
"(",
"n",
".",
"x",
",",
"cp",
".",
"x1",
",",
"cp",
".",
"x2",
")",
",",
"maxX",
"=",
"Math",
".",
"max",
"(",
"n",
".",
"x",
",",
"cp",
".",
"x1",
",",
"cp",
".",
"x2",
")",
",",
"minY",
"=",
"Math",
".",
"min",
"(",
"n",
".",
"y",
",",
"cp",
".",
"y1",
",",
"cp",
".",
"y2",
")",
",",
"maxY",
"=",
"Math",
".",
"max",
"(",
"n",
".",
"y",
",",
"cp",
".",
"y1",
",",
"cp",
".",
"y2",
")",
";",
"return",
"{",
"x1",
":",
"minX",
"-",
"n",
".",
"size",
",",
"y1",
":",
"minY",
"-",
"n",
".",
"size",
",",
"x2",
":",
"maxX",
"+",
"n",
".",
"size",
",",
"y2",
":",
"minY",
"-",
"n",
".",
"size",
",",
"height",
":",
"maxY",
"-",
"minY",
"+",
"n",
".",
"size",
"*",
"2",
"}",
";",
"}"
] | Transforms a graph self loop into an axis-aligned square.
@param {object} n A graph node with a point (x, y) and a size.
@return {object} A square: two points (x1, y1), (x2, y2) and height. | [
"Transforms",
"a",
"graph",
"self",
"loop",
"into",
"an",
"axis",
"-",
"aligned",
"square",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L135-L153 |
|
6,075 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(r) {
var width = (
Math.sqrt(
Math.pow(r.x2 - r.x1, 2) +
Math.pow(r.y2 - r.y1, 2)
)
);
return {
x: r.x1 - (r.y2 - r.y1) * r.height / width,
y: r.y1 + (r.x2 - r.x1) * r.height / width
};
} | javascript | function(r) {
var width = (
Math.sqrt(
Math.pow(r.x2 - r.x1, 2) +
Math.pow(r.y2 - r.y1, 2)
)
);
return {
x: r.x1 - (r.y2 - r.y1) * r.height / width,
y: r.y1 + (r.x2 - r.x1) * r.height / width
};
} | [
"function",
"(",
"r",
")",
"{",
"var",
"width",
"=",
"(",
"Math",
".",
"sqrt",
"(",
"Math",
".",
"pow",
"(",
"r",
".",
"x2",
"-",
"r",
".",
"x1",
",",
"2",
")",
"+",
"Math",
".",
"pow",
"(",
"r",
".",
"y2",
"-",
"r",
".",
"y1",
",",
"2",
")",
")",
")",
";",
"return",
"{",
"x",
":",
"r",
".",
"x1",
"-",
"(",
"r",
".",
"y2",
"-",
"r",
".",
"y1",
")",
"*",
"r",
".",
"height",
"/",
"width",
",",
"y",
":",
"r",
".",
"y1",
"+",
"(",
"r",
".",
"x2",
"-",
"r",
".",
"x1",
")",
"*",
"r",
".",
"height",
"/",
"width",
"}",
";",
"}"
] | Get coordinates of a rectangle's lower left corner from its top points.
@param {object} A rectangle defined by two points (x1, y1) and (x2, y2).
@return {object} Coordinates of the corner (x, y). | [
"Get",
"coordinates",
"of",
"a",
"rectangle",
"s",
"lower",
"left",
"corner",
"from",
"its",
"top",
"points",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L211-L223 |
|
6,076 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(r, llc) {
return {
x: llc.x - r.x1 + r.x2,
y: llc.y - r.y1 + r.y2
};
} | javascript | function(r, llc) {
return {
x: llc.x - r.x1 + r.x2,
y: llc.y - r.y1 + r.y2
};
} | [
"function",
"(",
"r",
",",
"llc",
")",
"{",
"return",
"{",
"x",
":",
"llc",
".",
"x",
"-",
"r",
".",
"x1",
"+",
"r",
".",
"x2",
",",
"y",
":",
"llc",
".",
"y",
"-",
"r",
".",
"y1",
"+",
"r",
".",
"y2",
"}",
";",
"}"
] | Get coordinates of a rectangle's lower right corner from its top points
and its lower left corner.
@param {object} A rectangle defined by two points (x1, y1) and (x2, y2).
@param {object} A corner's coordinates (x, y).
@return {object} Coordinates of the corner (x, y). | [
"Get",
"coordinates",
"of",
"a",
"rectangle",
"s",
"lower",
"right",
"corner",
"from",
"its",
"top",
"points",
"and",
"its",
"lower",
"left",
"corner",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L233-L238 |
|
6,077 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(r) {
var llc = this.lowerLeftCoor(r),
lrc = this.lowerRightCoor(r, llc);
return [
{x: r.x1, y: r.y1},
{x: r.x2, y: r.y2},
{x: llc.x, y: llc.y},
{x: lrc.x, y: lrc.y}
];
} | javascript | function(r) {
var llc = this.lowerLeftCoor(r),
lrc = this.lowerRightCoor(r, llc);
return [
{x: r.x1, y: r.y1},
{x: r.x2, y: r.y2},
{x: llc.x, y: llc.y},
{x: lrc.x, y: lrc.y}
];
} | [
"function",
"(",
"r",
")",
"{",
"var",
"llc",
"=",
"this",
".",
"lowerLeftCoor",
"(",
"r",
")",
",",
"lrc",
"=",
"this",
".",
"lowerRightCoor",
"(",
"r",
",",
"llc",
")",
";",
"return",
"[",
"{",
"x",
":",
"r",
".",
"x1",
",",
"y",
":",
"r",
".",
"y1",
"}",
",",
"{",
"x",
":",
"r",
".",
"x2",
",",
"y",
":",
"r",
".",
"y2",
"}",
",",
"{",
"x",
":",
"llc",
".",
"x",
",",
"y",
":",
"llc",
".",
"y",
"}",
",",
"{",
"x",
":",
"lrc",
".",
"x",
",",
"y",
":",
"lrc",
".",
"y",
"}",
"]",
";",
"}"
] | Get the coordinates of all the corners of a rectangle from its top point.
@param {object} A rectangle defined by two points (x1, y1) and (x2, y2).
@return {array} An array of the four corners' coordinates (x, y). | [
"Get",
"the",
"coordinates",
"of",
"all",
"the",
"corners",
"of",
"a",
"rectangle",
"from",
"its",
"top",
"point",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L246-L256 |
|
6,078 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(b) {
return [
[
{x: b.x, y: b.y},
{x: b.x + b.width / 2, y: b.y},
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2}
],
[
{x: b.x + b.width / 2, y: b.y},
{x: b.x + b.width, y: b.y},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2}
],
[
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x, y: b.y + b.height},
{x: b.x + b.width / 2, y: b.y + b.height}
],
[
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height},
{x: b.x + b.width, y: b.y + b.height}
]
];
} | javascript | function(b) {
return [
[
{x: b.x, y: b.y},
{x: b.x + b.width / 2, y: b.y},
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2}
],
[
{x: b.x + b.width / 2, y: b.y},
{x: b.x + b.width, y: b.y},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2}
],
[
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x, y: b.y + b.height},
{x: b.x + b.width / 2, y: b.y + b.height}
],
[
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height},
{x: b.x + b.width, y: b.y + b.height}
]
];
} | [
"function",
"(",
"b",
")",
"{",
"return",
"[",
"[",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"b",
".",
"y",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
"]",
",",
"[",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
",",
"y",
":",
"b",
".",
"y",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
"]",
",",
"[",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"}",
"]",
",",
"[",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
"+",
"b",
".",
"width",
",",
"y",
":",
"b",
".",
"y",
"+",
"b",
".",
"height",
"}",
"]",
"]",
";",
"}"
] | Split a square defined by its boundaries into four.
@param {object} Boundaries of the square (x, y, width, height).
@return {array} An array containing the four new squares, themselves
defined by an array of their four corners (x, y). | [
"Split",
"a",
"square",
"defined",
"by",
"its",
"boundaries",
"into",
"four",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L265-L292 |
|
6,079 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(c1, c2) {
return [
{x: c1[1].x - c1[0].x, y: c1[1].y - c1[0].y},
{x: c1[1].x - c1[3].x, y: c1[1].y - c1[3].y},
{x: c2[0].x - c2[2].x, y: c2[0].y - c2[2].y},
{x: c2[0].x - c2[1].x, y: c2[0].y - c2[1].y}
];
} | javascript | function(c1, c2) {
return [
{x: c1[1].x - c1[0].x, y: c1[1].y - c1[0].y},
{x: c1[1].x - c1[3].x, y: c1[1].y - c1[3].y},
{x: c2[0].x - c2[2].x, y: c2[0].y - c2[2].y},
{x: c2[0].x - c2[1].x, y: c2[0].y - c2[1].y}
];
} | [
"function",
"(",
"c1",
",",
"c2",
")",
"{",
"return",
"[",
"{",
"x",
":",
"c1",
"[",
"1",
"]",
".",
"x",
"-",
"c1",
"[",
"0",
"]",
".",
"x",
",",
"y",
":",
"c1",
"[",
"1",
"]",
".",
"y",
"-",
"c1",
"[",
"0",
"]",
".",
"y",
"}",
",",
"{",
"x",
":",
"c1",
"[",
"1",
"]",
".",
"x",
"-",
"c1",
"[",
"3",
"]",
".",
"x",
",",
"y",
":",
"c1",
"[",
"1",
"]",
".",
"y",
"-",
"c1",
"[",
"3",
"]",
".",
"y",
"}",
",",
"{",
"x",
":",
"c2",
"[",
"0",
"]",
".",
"x",
"-",
"c2",
"[",
"2",
"]",
".",
"x",
",",
"y",
":",
"c2",
"[",
"0",
"]",
".",
"y",
"-",
"c2",
"[",
"2",
"]",
".",
"y",
"}",
",",
"{",
"x",
":",
"c2",
"[",
"0",
"]",
".",
"x",
"-",
"c2",
"[",
"1",
"]",
".",
"x",
",",
"y",
":",
"c2",
"[",
"0",
"]",
".",
"y",
"-",
"c2",
"[",
"1",
"]",
".",
"y",
"}",
"]",
";",
"}"
] | Compute the four axis between corners of rectangle A and corners of
rectangle B. This is needed later to check an eventual collision.
@param {array} An array of rectangle A's four corners (x, y).
@param {array} An array of rectangle B's four corners (x, y).
@return {array} An array of four axis defined by their coordinates (x,y). | [
"Compute",
"the",
"four",
"axis",
"between",
"corners",
"of",
"rectangle",
"A",
"and",
"corners",
"of",
"rectangle",
"B",
".",
"This",
"is",
"needed",
"later",
"to",
"check",
"an",
"eventual",
"collision",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L302-L309 |
|
6,080 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(c, a) {
var l = (
(c.x * a.x + c.y * a.y) /
(Math.pow(a.x, 2) + Math.pow(a.y, 2))
);
return {
x: l * a.x,
y: l * a.y
};
} | javascript | function(c, a) {
var l = (
(c.x * a.x + c.y * a.y) /
(Math.pow(a.x, 2) + Math.pow(a.y, 2))
);
return {
x: l * a.x,
y: l * a.y
};
} | [
"function",
"(",
"c",
",",
"a",
")",
"{",
"var",
"l",
"=",
"(",
"(",
"c",
".",
"x",
"*",
"a",
".",
"x",
"+",
"c",
".",
"y",
"*",
"a",
".",
"y",
")",
"/",
"(",
"Math",
".",
"pow",
"(",
"a",
".",
"x",
",",
"2",
")",
"+",
"Math",
".",
"pow",
"(",
"a",
".",
"y",
",",
"2",
")",
")",
")",
";",
"return",
"{",
"x",
":",
"l",
"*",
"a",
".",
"x",
",",
"y",
":",
"l",
"*",
"a",
".",
"y",
"}",
";",
"}"
] | Project a rectangle's corner on an axis.
@param {object} Coordinates of a corner (x, y).
@param {object} Coordinates of an axis (x, y).
@return {object} The projection defined by coordinates (x, y). | [
"Project",
"a",
"rectangle",
"s",
"corner",
"on",
"an",
"axis",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L318-L328 |
|
6,081 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(a, c1, c2) {
var sc1 = [],
sc2 = [];
for (var ci = 0; ci < 4; ci++) {
var p1 = this.projection(c1[ci], a),
p2 = this.projection(c2[ci], a);
sc1.push(p1.x * a.x + p1.y * a.y);
sc2.push(p2.x * a.x + p2.y * a.y);
}
var maxc1 = Math.max.apply(Math, sc1),
maxc2 = Math.max.apply(Math, sc2),
minc1 = Math.min.apply(Math, sc1),
minc2 = Math.min.apply(Math, sc2);
return (minc2 <= maxc1 && maxc2 >= minc1);
} | javascript | function(a, c1, c2) {
var sc1 = [],
sc2 = [];
for (var ci = 0; ci < 4; ci++) {
var p1 = this.projection(c1[ci], a),
p2 = this.projection(c2[ci], a);
sc1.push(p1.x * a.x + p1.y * a.y);
sc2.push(p2.x * a.x + p2.y * a.y);
}
var maxc1 = Math.max.apply(Math, sc1),
maxc2 = Math.max.apply(Math, sc2),
minc1 = Math.min.apply(Math, sc1),
minc2 = Math.min.apply(Math, sc2);
return (minc2 <= maxc1 && maxc2 >= minc1);
} | [
"function",
"(",
"a",
",",
"c1",
",",
"c2",
")",
"{",
"var",
"sc1",
"=",
"[",
"]",
",",
"sc2",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"ci",
"=",
"0",
";",
"ci",
"<",
"4",
";",
"ci",
"++",
")",
"{",
"var",
"p1",
"=",
"this",
".",
"projection",
"(",
"c1",
"[",
"ci",
"]",
",",
"a",
")",
",",
"p2",
"=",
"this",
".",
"projection",
"(",
"c2",
"[",
"ci",
"]",
",",
"a",
")",
";",
"sc1",
".",
"push",
"(",
"p1",
".",
"x",
"*",
"a",
".",
"x",
"+",
"p1",
".",
"y",
"*",
"a",
".",
"y",
")",
";",
"sc2",
".",
"push",
"(",
"p2",
".",
"x",
"*",
"a",
".",
"x",
"+",
"p2",
".",
"y",
"*",
"a",
".",
"y",
")",
";",
"}",
"var",
"maxc1",
"=",
"Math",
".",
"max",
".",
"apply",
"(",
"Math",
",",
"sc1",
")",
",",
"maxc2",
"=",
"Math",
".",
"max",
".",
"apply",
"(",
"Math",
",",
"sc2",
")",
",",
"minc1",
"=",
"Math",
".",
"min",
".",
"apply",
"(",
"Math",
",",
"sc1",
")",
",",
"minc2",
"=",
"Math",
".",
"min",
".",
"apply",
"(",
"Math",
",",
"sc2",
")",
";",
"return",
"(",
"minc2",
"<=",
"maxc1",
"&&",
"maxc2",
">=",
"minc1",
")",
";",
"}"
] | Check whether two rectangles collide on one particular axis.
@param {object} An axis' coordinates (x, y).
@param {array} Rectangle A's corners.
@param {array} Rectangle B's corners.
@return {boolean} True if the rectangles collide on the axis. | [
"Check",
"whether",
"two",
"rectangles",
"collide",
"on",
"one",
"particular",
"axis",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L338-L356 |
|
6,082 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | function(c1, c2) {
var axis = this.axis(c1, c2),
col = true;
for (var i = 0; i < 4; i++)
col = col && this.axisCollision(axis[i], c1, c2);
return col;
} | javascript | function(c1, c2) {
var axis = this.axis(c1, c2),
col = true;
for (var i = 0; i < 4; i++)
col = col && this.axisCollision(axis[i], c1, c2);
return col;
} | [
"function",
"(",
"c1",
",",
"c2",
")",
"{",
"var",
"axis",
"=",
"this",
".",
"axis",
"(",
"c1",
",",
"c2",
")",
",",
"col",
"=",
"true",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"col",
"=",
"col",
"&&",
"this",
".",
"axisCollision",
"(",
"axis",
"[",
"i",
"]",
",",
"c1",
",",
"c2",
")",
";",
"return",
"col",
";",
"}"
] | Check whether two rectangles collide on each one of their four axis. If
all axis collide, then the two rectangles do collide on the plane.
@param {array} Rectangle A's corners.
@param {array} Rectangle B's corners.
@return {boolean} True if the rectangles collide. | [
"Check",
"whether",
"two",
"rectangles",
"collide",
"on",
"each",
"one",
"of",
"their",
"four",
"axis",
".",
"If",
"all",
"axis",
"collide",
"then",
"the",
"two",
"rectangles",
"do",
"collide",
"on",
"the",
"plane",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L366-L374 |
|
6,083 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadIndexes | function _quadIndexes(rectangle, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if ((rectangle.x2 >= quadCorners[i][0].x) &&
(rectangle.x1 <= quadCorners[i][1].x) &&
(rectangle.y1 + rectangle.height >= quadCorners[i][0].y) &&
(rectangle.y1 <= quadCorners[i][2].y))
indexes.push(i);
return indexes;
} | javascript | function _quadIndexes(rectangle, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if ((rectangle.x2 >= quadCorners[i][0].x) &&
(rectangle.x1 <= quadCorners[i][1].x) &&
(rectangle.y1 + rectangle.height >= quadCorners[i][0].y) &&
(rectangle.y1 <= quadCorners[i][2].y))
indexes.push(i);
return indexes;
} | [
"function",
"_quadIndexes",
"(",
"rectangle",
",",
"quadCorners",
")",
"{",
"var",
"indexes",
"=",
"[",
"]",
";",
"// Iterating through quads",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"if",
"(",
"(",
"rectangle",
".",
"x2",
">=",
"quadCorners",
"[",
"i",
"]",
"[",
"0",
"]",
".",
"x",
")",
"&&",
"(",
"rectangle",
".",
"x1",
"<=",
"quadCorners",
"[",
"i",
"]",
"[",
"1",
"]",
".",
"x",
")",
"&&",
"(",
"rectangle",
".",
"y1",
"+",
"rectangle",
".",
"height",
">=",
"quadCorners",
"[",
"i",
"]",
"[",
"0",
"]",
".",
"y",
")",
"&&",
"(",
"rectangle",
".",
"y1",
"<=",
"quadCorners",
"[",
"i",
"]",
"[",
"2",
"]",
".",
"y",
")",
")",
"indexes",
".",
"push",
"(",
"i",
")",
";",
"return",
"indexes",
";",
"}"
] | Get a list of indexes of nodes containing an axis-aligned rectangle
@param {object} rectangle A rectangle defined by two points (x1, y1),
(x2, y2) and height.
@param {array} quadCorners An array of the quad nodes' corners.
@return {array} An array of indexes containing one to
four integers. | [
"Get",
"a",
"list",
"of",
"indexes",
"of",
"nodes",
"containing",
"an",
"axis",
"-",
"aligned",
"rectangle"
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L431-L443 |
6,084 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadCollision | function _quadCollision(corners, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if (_geom.collision(corners, quadCorners[i]))
indexes.push(i);
return indexes;
} | javascript | function _quadCollision(corners, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if (_geom.collision(corners, quadCorners[i]))
indexes.push(i);
return indexes;
} | [
"function",
"_quadCollision",
"(",
"corners",
",",
"quadCorners",
")",
"{",
"var",
"indexes",
"=",
"[",
"]",
";",
"// Iterating through quads",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"if",
"(",
"_geom",
".",
"collision",
"(",
"corners",
",",
"quadCorners",
"[",
"i",
"]",
")",
")",
"indexes",
".",
"push",
"(",
"i",
")",
";",
"return",
"indexes",
";",
"}"
] | Get a list of indexes of nodes containing a non-axis-aligned rectangle
@param {array} corners An array containing each corner of the
rectangle defined by its coordinates (x, y).
@param {array} quadCorners An array of the quad nodes' corners.
@return {array} An array of indexes containing one to
four integers. | [
"Get",
"a",
"list",
"of",
"indexes",
"of",
"nodes",
"containing",
"a",
"non",
"-",
"axis",
"-",
"aligned",
"rectangle"
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L454-L463 |
6,085 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadSubdivide | function _quadSubdivide(index, quad) {
var next = quad.level + 1,
subw = Math.round(quad.bounds.width / 2),
subh = Math.round(quad.bounds.height / 2),
qx = Math.round(quad.bounds.x),
qy = Math.round(quad.bounds.y),
x,
y;
switch (index) {
case 0:
x = qx;
y = qy;
break;
case 1:
x = qx + subw;
y = qy;
break;
case 2:
x = qx;
y = qy + subh;
break;
case 3:
x = qx + subw;
y = qy + subh;
break;
}
return _quadTree(
{x: x, y: y, width: subw, height: subh},
next,
quad.maxElements,
quad.maxLevel
);
} | javascript | function _quadSubdivide(index, quad) {
var next = quad.level + 1,
subw = Math.round(quad.bounds.width / 2),
subh = Math.round(quad.bounds.height / 2),
qx = Math.round(quad.bounds.x),
qy = Math.round(quad.bounds.y),
x,
y;
switch (index) {
case 0:
x = qx;
y = qy;
break;
case 1:
x = qx + subw;
y = qy;
break;
case 2:
x = qx;
y = qy + subh;
break;
case 3:
x = qx + subw;
y = qy + subh;
break;
}
return _quadTree(
{x: x, y: y, width: subw, height: subh},
next,
quad.maxElements,
quad.maxLevel
);
} | [
"function",
"_quadSubdivide",
"(",
"index",
",",
"quad",
")",
"{",
"var",
"next",
"=",
"quad",
".",
"level",
"+",
"1",
",",
"subw",
"=",
"Math",
".",
"round",
"(",
"quad",
".",
"bounds",
".",
"width",
"/",
"2",
")",
",",
"subh",
"=",
"Math",
".",
"round",
"(",
"quad",
".",
"bounds",
".",
"height",
"/",
"2",
")",
",",
"qx",
"=",
"Math",
".",
"round",
"(",
"quad",
".",
"bounds",
".",
"x",
")",
",",
"qy",
"=",
"Math",
".",
"round",
"(",
"quad",
".",
"bounds",
".",
"y",
")",
",",
"x",
",",
"y",
";",
"switch",
"(",
"index",
")",
"{",
"case",
"0",
":",
"x",
"=",
"qx",
";",
"y",
"=",
"qy",
";",
"break",
";",
"case",
"1",
":",
"x",
"=",
"qx",
"+",
"subw",
";",
"y",
"=",
"qy",
";",
"break",
";",
"case",
"2",
":",
"x",
"=",
"qx",
";",
"y",
"=",
"qy",
"+",
"subh",
";",
"break",
";",
"case",
"3",
":",
"x",
"=",
"qx",
"+",
"subw",
";",
"y",
"=",
"qy",
"+",
"subh",
";",
"break",
";",
"}",
"return",
"_quadTree",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"width",
":",
"subw",
",",
"height",
":",
"subh",
"}",
",",
"next",
",",
"quad",
".",
"maxElements",
",",
"quad",
".",
"maxLevel",
")",
";",
"}"
] | Subdivide a quad by creating a node at a precise index. The function does
not generate all four nodes not to potentially create unused nodes.
@param {integer} index The index of the node to create.
@param {object} quad The quad object to subdivide.
@return {object} A new quad representing the node created. | [
"Subdivide",
"a",
"quad",
"by",
"creating",
"a",
"node",
"at",
"a",
"precise",
"index",
".",
"The",
"function",
"does",
"not",
"generate",
"all",
"four",
"nodes",
"not",
"to",
"potentially",
"create",
"unused",
"nodes",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L473-L507 |
6,086 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadInsert | function _quadInsert(el, sizedPoint, quad) {
if (quad.level < quad.maxLevel) {
// Searching appropriate quads
var indexes = _quadIndexes(sizedPoint, quad.corners);
// Iterating
for (var i = 0, l = indexes.length; i < l; i++) {
// Subdividing if necessary
if (quad.nodes[indexes[i]] === undefined)
quad.nodes[indexes[i]] = _quadSubdivide(indexes[i], quad);
// Recursion
_quadInsert(el, sizedPoint, quad.nodes[indexes[i]]);
}
}
else {
// Pushing the element in a leaf node
quad.elements.push(el);
}
} | javascript | function _quadInsert(el, sizedPoint, quad) {
if (quad.level < quad.maxLevel) {
// Searching appropriate quads
var indexes = _quadIndexes(sizedPoint, quad.corners);
// Iterating
for (var i = 0, l = indexes.length; i < l; i++) {
// Subdividing if necessary
if (quad.nodes[indexes[i]] === undefined)
quad.nodes[indexes[i]] = _quadSubdivide(indexes[i], quad);
// Recursion
_quadInsert(el, sizedPoint, quad.nodes[indexes[i]]);
}
}
else {
// Pushing the element in a leaf node
quad.elements.push(el);
}
} | [
"function",
"_quadInsert",
"(",
"el",
",",
"sizedPoint",
",",
"quad",
")",
"{",
"if",
"(",
"quad",
".",
"level",
"<",
"quad",
".",
"maxLevel",
")",
"{",
"// Searching appropriate quads",
"var",
"indexes",
"=",
"_quadIndexes",
"(",
"sizedPoint",
",",
"quad",
".",
"corners",
")",
";",
"// Iterating",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"indexes",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"// Subdividing if necessary",
"if",
"(",
"quad",
".",
"nodes",
"[",
"indexes",
"[",
"i",
"]",
"]",
"===",
"undefined",
")",
"quad",
".",
"nodes",
"[",
"indexes",
"[",
"i",
"]",
"]",
"=",
"_quadSubdivide",
"(",
"indexes",
"[",
"i",
"]",
",",
"quad",
")",
";",
"// Recursion",
"_quadInsert",
"(",
"el",
",",
"sizedPoint",
",",
"quad",
".",
"nodes",
"[",
"indexes",
"[",
"i",
"]",
"]",
")",
";",
"}",
"}",
"else",
"{",
"// Pushing the element in a leaf node",
"quad",
".",
"elements",
".",
"push",
"(",
"el",
")",
";",
"}",
"}"
] | Recursively insert an element into the quadtree. Only points
with size, i.e. axis-aligned squares, may be inserted with this
method.
@param {object} el The element to insert in the quadtree.
@param {object} sizedPoint A sized point defined by two top points
(x1, y1), (x2, y2) and height.
@param {object} quad The quad in which to insert the element.
@return {undefined} The function does not return anything. | [
"Recursively",
"insert",
"an",
"element",
"into",
"the",
"quadtree",
".",
"Only",
"points",
"with",
"size",
"i",
".",
"e",
".",
"axis",
"-",
"aligned",
"squares",
"may",
"be",
"inserted",
"with",
"this",
"method",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L520-L542 |
6,087 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadRetrievePoint | function _quadRetrievePoint(point, quad) {
if (quad.level < quad.maxLevel) {
var index = _quadIndex(point, quad.bounds);
// If node does not exist we return an empty list
if (quad.nodes[index] !== undefined) {
return _quadRetrievePoint(point, quad.nodes[index]);
}
else {
return [];
}
}
else {
return quad.elements;
}
} | javascript | function _quadRetrievePoint(point, quad) {
if (quad.level < quad.maxLevel) {
var index = _quadIndex(point, quad.bounds);
// If node does not exist we return an empty list
if (quad.nodes[index] !== undefined) {
return _quadRetrievePoint(point, quad.nodes[index]);
}
else {
return [];
}
}
else {
return quad.elements;
}
} | [
"function",
"_quadRetrievePoint",
"(",
"point",
",",
"quad",
")",
"{",
"if",
"(",
"quad",
".",
"level",
"<",
"quad",
".",
"maxLevel",
")",
"{",
"var",
"index",
"=",
"_quadIndex",
"(",
"point",
",",
"quad",
".",
"bounds",
")",
";",
"// If node does not exist we return an empty list",
"if",
"(",
"quad",
".",
"nodes",
"[",
"index",
"]",
"!==",
"undefined",
")",
"{",
"return",
"_quadRetrievePoint",
"(",
"point",
",",
"quad",
".",
"nodes",
"[",
"index",
"]",
")",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"else",
"{",
"return",
"quad",
".",
"elements",
";",
"}",
"}"
] | Recursively retrieve every elements held by the node containing the
searched point.
@param {object} point The searched point (x, y).
@param {object} quad The searched quad.
@return {array} An array of elements contained in the relevant
node. | [
"Recursively",
"retrieve",
"every",
"elements",
"held",
"by",
"the",
"node",
"containing",
"the",
"searched",
"point",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L553-L568 |
6,088 | jacomyal/sigma.js | src/classes/sigma.classes.edgequad.js | _quadRetrieveArea | function _quadRetrieveArea(rectData, quad, collisionFunc, els) {
els = els || {};
if (quad.level < quad.maxLevel) {
var indexes = collisionFunc(rectData, quad.corners);
for (var i = 0, l = indexes.length; i < l; i++)
if (quad.nodes[indexes[i]] !== undefined)
_quadRetrieveArea(
rectData,
quad.nodes[indexes[i]],
collisionFunc,
els
);
} else
for (var j = 0, m = quad.elements.length; j < m; j++)
if (els[quad.elements[j].id] === undefined)
els[quad.elements[j].id] = quad.elements[j];
return els;
} | javascript | function _quadRetrieveArea(rectData, quad, collisionFunc, els) {
els = els || {};
if (quad.level < quad.maxLevel) {
var indexes = collisionFunc(rectData, quad.corners);
for (var i = 0, l = indexes.length; i < l; i++)
if (quad.nodes[indexes[i]] !== undefined)
_quadRetrieveArea(
rectData,
quad.nodes[indexes[i]],
collisionFunc,
els
);
} else
for (var j = 0, m = quad.elements.length; j < m; j++)
if (els[quad.elements[j].id] === undefined)
els[quad.elements[j].id] = quad.elements[j];
return els;
} | [
"function",
"_quadRetrieveArea",
"(",
"rectData",
",",
"quad",
",",
"collisionFunc",
",",
"els",
")",
"{",
"els",
"=",
"els",
"||",
"{",
"}",
";",
"if",
"(",
"quad",
".",
"level",
"<",
"quad",
".",
"maxLevel",
")",
"{",
"var",
"indexes",
"=",
"collisionFunc",
"(",
"rectData",
",",
"quad",
".",
"corners",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"indexes",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"if",
"(",
"quad",
".",
"nodes",
"[",
"indexes",
"[",
"i",
"]",
"]",
"!==",
"undefined",
")",
"_quadRetrieveArea",
"(",
"rectData",
",",
"quad",
".",
"nodes",
"[",
"indexes",
"[",
"i",
"]",
"]",
",",
"collisionFunc",
",",
"els",
")",
";",
"}",
"else",
"for",
"(",
"var",
"j",
"=",
"0",
",",
"m",
"=",
"quad",
".",
"elements",
".",
"length",
";",
"j",
"<",
"m",
";",
"j",
"++",
")",
"if",
"(",
"els",
"[",
"quad",
".",
"elements",
"[",
"j",
"]",
".",
"id",
"]",
"===",
"undefined",
")",
"els",
"[",
"quad",
".",
"elements",
"[",
"j",
"]",
".",
"id",
"]",
"=",
"quad",
".",
"elements",
"[",
"j",
"]",
";",
"return",
"els",
";",
"}"
] | Recursively retrieve every elements contained within an rectangular area
that may or may not be axis-aligned.
@param {object|array} rectData The searched area defined either by
an array of four corners (x, y) in
the case of a non-axis-aligned
rectangle or an object with two top
points (x1, y1), (x2, y2) and height.
@param {object} quad The searched quad.
@param {function} collisionFunc The collision function used to search
for node indexes.
@param {array?} els The retrieved elements.
@return {array} An array of elements contained in the
area. | [
"Recursively",
"retrieve",
"every",
"elements",
"contained",
"within",
"an",
"rectangular",
"area",
"that",
"may",
"or",
"may",
"not",
"be",
"axis",
"-",
"aligned",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.edgequad.js#L586-L606 |
6,089 | jacomyal/sigma.js | plugins/sigma.plugins.filter/sigma.plugins.filter.js | register | function register(fn, p, key) {
if (key != undefined && typeof key !== 'string')
throw 'The filter key "'+ key.toString() +'" must be a string.';
if (key != undefined && !key.length)
throw 'The filter key must be a non-empty string.';
if (typeof fn !== 'function')
throw 'The predicate of key "'+ key +'" must be a function.';
if ('undo' === key)
throw '"undo" is a reserved key.';
if (_keysIndex[key])
throw 'The filter "' + key + '" already exists.';
if (key)
_keysIndex[key] = true;
_chain.push({
'key': key,
'processor': fn,
'predicate': p
});
} | javascript | function register(fn, p, key) {
if (key != undefined && typeof key !== 'string')
throw 'The filter key "'+ key.toString() +'" must be a string.';
if (key != undefined && !key.length)
throw 'The filter key must be a non-empty string.';
if (typeof fn !== 'function')
throw 'The predicate of key "'+ key +'" must be a function.';
if ('undo' === key)
throw '"undo" is a reserved key.';
if (_keysIndex[key])
throw 'The filter "' + key + '" already exists.';
if (key)
_keysIndex[key] = true;
_chain.push({
'key': key,
'processor': fn,
'predicate': p
});
} | [
"function",
"register",
"(",
"fn",
",",
"p",
",",
"key",
")",
"{",
"if",
"(",
"key",
"!=",
"undefined",
"&&",
"typeof",
"key",
"!==",
"'string'",
")",
"throw",
"'The filter key \"'",
"+",
"key",
".",
"toString",
"(",
")",
"+",
"'\" must be a string.'",
";",
"if",
"(",
"key",
"!=",
"undefined",
"&&",
"!",
"key",
".",
"length",
")",
"throw",
"'The filter key must be a non-empty string.'",
";",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"throw",
"'The predicate of key \"'",
"+",
"key",
"+",
"'\" must be a function.'",
";",
"if",
"(",
"'undo'",
"===",
"key",
")",
"throw",
"'\"undo\" is a reserved key.'",
";",
"if",
"(",
"_keysIndex",
"[",
"key",
"]",
")",
"throw",
"'The filter \"'",
"+",
"key",
"+",
"'\" already exists.'",
";",
"if",
"(",
"key",
")",
"_keysIndex",
"[",
"key",
"]",
"=",
"true",
";",
"_chain",
".",
"push",
"(",
"{",
"'key'",
":",
"key",
",",
"'processor'",
":",
"fn",
",",
"'predicate'",
":",
"p",
"}",
")",
";",
"}"
] | This function adds a filter to the chain of filters.
@param {function} fn The filter (i.e. predicate processor).
@param {function} p The predicate.
@param {?string} key The key to identify the filter. | [
"This",
"function",
"adds",
"a",
"filter",
"to",
"the",
"chain",
"of",
"filters",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/plugins/sigma.plugins.filter/sigma.plugins.filter.js#L138-L162 |
6,090 | jacomyal/sigma.js | plugins/sigma.plugins.filter/sigma.plugins.filter.js | unregister | function unregister (o) {
_chain = _chain.filter(function(a) {
return !(a.key in o);
});
for(var key in o)
delete _keysIndex[key];
} | javascript | function unregister (o) {
_chain = _chain.filter(function(a) {
return !(a.key in o);
});
for(var key in o)
delete _keysIndex[key];
} | [
"function",
"unregister",
"(",
"o",
")",
"{",
"_chain",
"=",
"_chain",
".",
"filter",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"!",
"(",
"a",
".",
"key",
"in",
"o",
")",
";",
"}",
")",
";",
"for",
"(",
"var",
"key",
"in",
"o",
")",
"delete",
"_keysIndex",
"[",
"key",
"]",
";",
"}"
] | This function removes a set of filters from the chain.
@param {object} o The filter keys. | [
"This",
"function",
"removes",
"a",
"set",
"of",
"filters",
"from",
"the",
"chain",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/plugins/sigma.plugins.filter/sigma.plugins.filter.js#L169-L176 |
6,091 | jacomyal/sigma.js | plugins/sigma.plugins.filter/sigma.plugins.filter.js | deepCopy | function deepCopy(o) {
var copy = Object.create(null);
for (var i in o) {
if (typeof o[i] === "object" && o[i] !== null) {
copy[i] = deepCopy(o[i]);
}
else if (typeof o[i] === "function" && o[i] !== null) {
// clone function:
eval(" copy[i] = " + o[i].toString());
//copy[i] = o[i].bind(_g);
}
else
copy[i] = o[i];
}
return copy;
} | javascript | function deepCopy(o) {
var copy = Object.create(null);
for (var i in o) {
if (typeof o[i] === "object" && o[i] !== null) {
copy[i] = deepCopy(o[i]);
}
else if (typeof o[i] === "function" && o[i] !== null) {
// clone function:
eval(" copy[i] = " + o[i].toString());
//copy[i] = o[i].bind(_g);
}
else
copy[i] = o[i];
}
return copy;
} | [
"function",
"deepCopy",
"(",
"o",
")",
"{",
"var",
"copy",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"for",
"(",
"var",
"i",
"in",
"o",
")",
"{",
"if",
"(",
"typeof",
"o",
"[",
"i",
"]",
"===",
"\"object\"",
"&&",
"o",
"[",
"i",
"]",
"!==",
"null",
")",
"{",
"copy",
"[",
"i",
"]",
"=",
"deepCopy",
"(",
"o",
"[",
"i",
"]",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"o",
"[",
"i",
"]",
"===",
"\"function\"",
"&&",
"o",
"[",
"i",
"]",
"!==",
"null",
")",
"{",
"// clone function:",
"eval",
"(",
"\" copy[i] = \"",
"+",
"o",
"[",
"i",
"]",
".",
"toString",
"(",
")",
")",
";",
"//copy[i] = o[i].bind(_g);",
"}",
"else",
"copy",
"[",
"i",
"]",
"=",
"o",
"[",
"i",
"]",
";",
"}",
"return",
"copy",
";",
"}"
] | fast deep copy function | [
"fast",
"deep",
"copy",
"function"
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/plugins/sigma.plugins.filter/sigma.plugins.filter.js#L368-L384 |
6,092 | jacomyal/sigma.js | src/captors/sigma.captors.mouse.js | _upHandler | function _upHandler(e) {
if (_settings('mouseEnabled') && _isMouseDown) {
_isMouseDown = false;
if (_movingTimeoutId)
clearTimeout(_movingTimeoutId);
_camera.isMoving = false;
var x = sigma.utils.getX(e),
y = sigma.utils.getY(e);
if (_isMoving) {
sigma.misc.animation.killAll(_camera);
sigma.misc.animation.camera(
_camera,
{
x: _camera.x +
_settings('mouseInertiaRatio') * (_camera.x - _lastCameraX),
y: _camera.y +
_settings('mouseInertiaRatio') * (_camera.y - _lastCameraY)
},
{
easing: 'quadraticOut',
duration: _settings('mouseInertiaDuration')
}
);
} else if (
_startMouseX !== x ||
_startMouseY !== y
)
_camera.goTo({
x: _camera.x,
y: _camera.y
});
_self.dispatchEvent('mouseup',
sigma.utils.mouseCoords(e));
// Update _isMoving flag:
_isMoving = false;
}
} | javascript | function _upHandler(e) {
if (_settings('mouseEnabled') && _isMouseDown) {
_isMouseDown = false;
if (_movingTimeoutId)
clearTimeout(_movingTimeoutId);
_camera.isMoving = false;
var x = sigma.utils.getX(e),
y = sigma.utils.getY(e);
if (_isMoving) {
sigma.misc.animation.killAll(_camera);
sigma.misc.animation.camera(
_camera,
{
x: _camera.x +
_settings('mouseInertiaRatio') * (_camera.x - _lastCameraX),
y: _camera.y +
_settings('mouseInertiaRatio') * (_camera.y - _lastCameraY)
},
{
easing: 'quadraticOut',
duration: _settings('mouseInertiaDuration')
}
);
} else if (
_startMouseX !== x ||
_startMouseY !== y
)
_camera.goTo({
x: _camera.x,
y: _camera.y
});
_self.dispatchEvent('mouseup',
sigma.utils.mouseCoords(e));
// Update _isMoving flag:
_isMoving = false;
}
} | [
"function",
"_upHandler",
"(",
"e",
")",
"{",
"if",
"(",
"_settings",
"(",
"'mouseEnabled'",
")",
"&&",
"_isMouseDown",
")",
"{",
"_isMouseDown",
"=",
"false",
";",
"if",
"(",
"_movingTimeoutId",
")",
"clearTimeout",
"(",
"_movingTimeoutId",
")",
";",
"_camera",
".",
"isMoving",
"=",
"false",
";",
"var",
"x",
"=",
"sigma",
".",
"utils",
".",
"getX",
"(",
"e",
")",
",",
"y",
"=",
"sigma",
".",
"utils",
".",
"getY",
"(",
"e",
")",
";",
"if",
"(",
"_isMoving",
")",
"{",
"sigma",
".",
"misc",
".",
"animation",
".",
"killAll",
"(",
"_camera",
")",
";",
"sigma",
".",
"misc",
".",
"animation",
".",
"camera",
"(",
"_camera",
",",
"{",
"x",
":",
"_camera",
".",
"x",
"+",
"_settings",
"(",
"'mouseInertiaRatio'",
")",
"*",
"(",
"_camera",
".",
"x",
"-",
"_lastCameraX",
")",
",",
"y",
":",
"_camera",
".",
"y",
"+",
"_settings",
"(",
"'mouseInertiaRatio'",
")",
"*",
"(",
"_camera",
".",
"y",
"-",
"_lastCameraY",
")",
"}",
",",
"{",
"easing",
":",
"'quadraticOut'",
",",
"duration",
":",
"_settings",
"(",
"'mouseInertiaDuration'",
")",
"}",
")",
";",
"}",
"else",
"if",
"(",
"_startMouseX",
"!==",
"x",
"||",
"_startMouseY",
"!==",
"y",
")",
"_camera",
".",
"goTo",
"(",
"{",
"x",
":",
"_camera",
".",
"x",
",",
"y",
":",
"_camera",
".",
"y",
"}",
")",
";",
"_self",
".",
"dispatchEvent",
"(",
"'mouseup'",
",",
"sigma",
".",
"utils",
".",
"mouseCoords",
"(",
"e",
")",
")",
";",
"// Update _isMoving flag:",
"_isMoving",
"=",
"false",
";",
"}",
"}"
] | The handler listening to the 'up' mouse event. It will stop dragging the
graph.
@param {event} e A mouse event. | [
"The",
"handler",
"listening",
"to",
"the",
"up",
"mouse",
"event",
".",
"It",
"will",
"stop",
"dragging",
"the",
"graph",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/captors/sigma.captors.mouse.js#L151-L192 |
6,093 | jacomyal/sigma.js | src/captors/sigma.captors.mouse.js | _downHandler | function _downHandler(e) {
if (_settings('mouseEnabled')) {
_startCameraX = _camera.x;
_startCameraY = _camera.y;
_lastCameraX = _camera.x;
_lastCameraY = _camera.y;
_startMouseX = sigma.utils.getX(e);
_startMouseY = sigma.utils.getY(e);
_hasDragged = false;
_downStartTime = (new Date()).getTime();
switch (e.which) {
case 2:
// Middle mouse button pressed
// Do nothing.
break;
case 3:
// Right mouse button pressed
_self.dispatchEvent('rightclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
break;
// case 1:
default:
// Left mouse button pressed
_isMouseDown = true;
_self.dispatchEvent('mousedown',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
}
}
} | javascript | function _downHandler(e) {
if (_settings('mouseEnabled')) {
_startCameraX = _camera.x;
_startCameraY = _camera.y;
_lastCameraX = _camera.x;
_lastCameraY = _camera.y;
_startMouseX = sigma.utils.getX(e);
_startMouseY = sigma.utils.getY(e);
_hasDragged = false;
_downStartTime = (new Date()).getTime();
switch (e.which) {
case 2:
// Middle mouse button pressed
// Do nothing.
break;
case 3:
// Right mouse button pressed
_self.dispatchEvent('rightclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
break;
// case 1:
default:
// Left mouse button pressed
_isMouseDown = true;
_self.dispatchEvent('mousedown',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
}
}
} | [
"function",
"_downHandler",
"(",
"e",
")",
"{",
"if",
"(",
"_settings",
"(",
"'mouseEnabled'",
")",
")",
"{",
"_startCameraX",
"=",
"_camera",
".",
"x",
";",
"_startCameraY",
"=",
"_camera",
".",
"y",
";",
"_lastCameraX",
"=",
"_camera",
".",
"x",
";",
"_lastCameraY",
"=",
"_camera",
".",
"y",
";",
"_startMouseX",
"=",
"sigma",
".",
"utils",
".",
"getX",
"(",
"e",
")",
";",
"_startMouseY",
"=",
"sigma",
".",
"utils",
".",
"getY",
"(",
"e",
")",
";",
"_hasDragged",
"=",
"false",
";",
"_downStartTime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"switch",
"(",
"e",
".",
"which",
")",
"{",
"case",
"2",
":",
"// Middle mouse button pressed",
"// Do nothing.",
"break",
";",
"case",
"3",
":",
"// Right mouse button pressed",
"_self",
".",
"dispatchEvent",
"(",
"'rightclick'",
",",
"sigma",
".",
"utils",
".",
"mouseCoords",
"(",
"e",
",",
"_startMouseX",
",",
"_startMouseY",
")",
")",
";",
"break",
";",
"// case 1:",
"default",
":",
"// Left mouse button pressed",
"_isMouseDown",
"=",
"true",
";",
"_self",
".",
"dispatchEvent",
"(",
"'mousedown'",
",",
"sigma",
".",
"utils",
".",
"mouseCoords",
"(",
"e",
",",
"_startMouseX",
",",
"_startMouseY",
")",
")",
";",
"}",
"}",
"}"
] | The handler listening to the 'down' mouse event. It will start observing
the mouse position for dragging the graph.
@param {event} e A mouse event. | [
"The",
"handler",
"listening",
"to",
"the",
"down",
"mouse",
"event",
".",
"It",
"will",
"start",
"observing",
"the",
"mouse",
"position",
"for",
"dragging",
"the",
"graph",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/captors/sigma.captors.mouse.js#L200-L233 |
6,094 | jacomyal/sigma.js | src/captors/sigma.captors.mouse.js | _clickHandler | function _clickHandler(e) {
if (_settings('mouseEnabled')) {
var event = sigma.utils.mouseCoords(e);
event.isDragging =
(((new Date()).getTime() - _downStartTime) > 100) && _hasDragged;
_self.dispatchEvent('click', event);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
} | javascript | function _clickHandler(e) {
if (_settings('mouseEnabled')) {
var event = sigma.utils.mouseCoords(e);
event.isDragging =
(((new Date()).getTime() - _downStartTime) > 100) && _hasDragged;
_self.dispatchEvent('click', event);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
} | [
"function",
"_clickHandler",
"(",
"e",
")",
"{",
"if",
"(",
"_settings",
"(",
"'mouseEnabled'",
")",
")",
"{",
"var",
"event",
"=",
"sigma",
".",
"utils",
".",
"mouseCoords",
"(",
"e",
")",
";",
"event",
".",
"isDragging",
"=",
"(",
"(",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
"-",
"_downStartTime",
")",
">",
"100",
")",
"&&",
"_hasDragged",
";",
"_self",
".",
"dispatchEvent",
"(",
"'click'",
",",
"event",
")",
";",
"}",
"if",
"(",
"e",
".",
"preventDefault",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"else",
"e",
".",
"returnValue",
"=",
"false",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}"
] | The handler listening to the 'click' mouse event. It will redispatch the
click event, but with normalized X and Y coordinates.
@param {event} e A mouse event. | [
"The",
"handler",
"listening",
"to",
"the",
"click",
"mouse",
"event",
".",
"It",
"will",
"redispatch",
"the",
"click",
"event",
"but",
"with",
"normalized",
"X",
"and",
"Y",
"coordinates",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/captors/sigma.captors.mouse.js#L252-L267 |
6,095 | jacomyal/sigma.js | src/captors/sigma.captors.mouse.js | _doubleClickHandler | function _doubleClickHandler(e) {
var pos,
ratio,
animation;
if (_settings('mouseEnabled')) {
ratio = 1 / _settings('doubleClickZoomingRatio');
_self.dispatchEvent('doubleclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
if (_settings('doubleClickEnabled')) {
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('doubleClickZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
} | javascript | function _doubleClickHandler(e) {
var pos,
ratio,
animation;
if (_settings('mouseEnabled')) {
ratio = 1 / _settings('doubleClickZoomingRatio');
_self.dispatchEvent('doubleclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
if (_settings('doubleClickEnabled')) {
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('doubleClickZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
} | [
"function",
"_doubleClickHandler",
"(",
"e",
")",
"{",
"var",
"pos",
",",
"ratio",
",",
"animation",
";",
"if",
"(",
"_settings",
"(",
"'mouseEnabled'",
")",
")",
"{",
"ratio",
"=",
"1",
"/",
"_settings",
"(",
"'doubleClickZoomingRatio'",
")",
";",
"_self",
".",
"dispatchEvent",
"(",
"'doubleclick'",
",",
"sigma",
".",
"utils",
".",
"mouseCoords",
"(",
"e",
",",
"_startMouseX",
",",
"_startMouseY",
")",
")",
";",
"if",
"(",
"_settings",
"(",
"'doubleClickEnabled'",
")",
")",
"{",
"pos",
"=",
"_camera",
".",
"cameraPosition",
"(",
"sigma",
".",
"utils",
".",
"getX",
"(",
"e",
")",
"-",
"sigma",
".",
"utils",
".",
"getCenter",
"(",
"e",
")",
".",
"x",
",",
"sigma",
".",
"utils",
".",
"getY",
"(",
"e",
")",
"-",
"sigma",
".",
"utils",
".",
"getCenter",
"(",
"e",
")",
".",
"y",
",",
"true",
")",
";",
"animation",
"=",
"{",
"duration",
":",
"_settings",
"(",
"'doubleClickZoomDuration'",
")",
"}",
";",
"sigma",
".",
"utils",
".",
"zoomTo",
"(",
"_camera",
",",
"pos",
".",
"x",
",",
"pos",
".",
"y",
",",
"ratio",
",",
"animation",
")",
";",
"}",
"if",
"(",
"e",
".",
"preventDefault",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"else",
"e",
".",
"returnValue",
"=",
"false",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] | The handler listening to the double click custom event. It will
basically zoom into the graph.
@param {event} e A mouse event. | [
"The",
"handler",
"listening",
"to",
"the",
"double",
"click",
"custom",
"event",
".",
"It",
"will",
"basically",
"zoom",
"into",
"the",
"graph",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/captors/sigma.captors.mouse.js#L275-L308 |
6,096 | jacomyal/sigma.js | src/captors/sigma.captors.mouse.js | _wheelHandler | function _wheelHandler(e) {
var pos,
ratio,
animation,
wheelDelta = sigma.utils.getDelta(e);
if (_settings('mouseEnabled') && _settings('mouseWheelEnabled') && wheelDelta !== 0) {
ratio = wheelDelta > 0 ?
1 / _settings('zoomingRatio') :
_settings('zoomingRatio');
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('mouseZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
} | javascript | function _wheelHandler(e) {
var pos,
ratio,
animation,
wheelDelta = sigma.utils.getDelta(e);
if (_settings('mouseEnabled') && _settings('mouseWheelEnabled') && wheelDelta !== 0) {
ratio = wheelDelta > 0 ?
1 / _settings('zoomingRatio') :
_settings('zoomingRatio');
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('mouseZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
} | [
"function",
"_wheelHandler",
"(",
"e",
")",
"{",
"var",
"pos",
",",
"ratio",
",",
"animation",
",",
"wheelDelta",
"=",
"sigma",
".",
"utils",
".",
"getDelta",
"(",
"e",
")",
";",
"if",
"(",
"_settings",
"(",
"'mouseEnabled'",
")",
"&&",
"_settings",
"(",
"'mouseWheelEnabled'",
")",
"&&",
"wheelDelta",
"!==",
"0",
")",
"{",
"ratio",
"=",
"wheelDelta",
">",
"0",
"?",
"1",
"/",
"_settings",
"(",
"'zoomingRatio'",
")",
":",
"_settings",
"(",
"'zoomingRatio'",
")",
";",
"pos",
"=",
"_camera",
".",
"cameraPosition",
"(",
"sigma",
".",
"utils",
".",
"getX",
"(",
"e",
")",
"-",
"sigma",
".",
"utils",
".",
"getCenter",
"(",
"e",
")",
".",
"x",
",",
"sigma",
".",
"utils",
".",
"getY",
"(",
"e",
")",
"-",
"sigma",
".",
"utils",
".",
"getCenter",
"(",
"e",
")",
".",
"y",
",",
"true",
")",
";",
"animation",
"=",
"{",
"duration",
":",
"_settings",
"(",
"'mouseZoomDuration'",
")",
"}",
";",
"sigma",
".",
"utils",
".",
"zoomTo",
"(",
"_camera",
",",
"pos",
".",
"x",
",",
"pos",
".",
"y",
",",
"ratio",
",",
"animation",
")",
";",
"if",
"(",
"e",
".",
"preventDefault",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"else",
"e",
".",
"returnValue",
"=",
"false",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] | The handler listening to the 'wheel' mouse event. It will basically zoom
in or not into the graph.
@param {event} e A mouse event. | [
"The",
"handler",
"listening",
"to",
"the",
"wheel",
"mouse",
"event",
".",
"It",
"will",
"basically",
"zoom",
"in",
"or",
"not",
"into",
"the",
"graph",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/captors/sigma.captors.mouse.js#L316-L347 |
6,097 | jacomyal/sigma.js | src/classes/sigma.classes.graph.js | function(settings) {
var k,
fn,
data;
/**
* DATA:
* *****
* Every data that is callable from graph methods are stored in this "data"
* object. This object will be served as context for all these methods,
* and it is possible to add other type of data in it.
*/
data = {
/**
* SETTINGS FUNCTION:
* ******************
*/
settings: settings || _defaultSettingsFunction,
/**
* MAIN DATA:
* **********
*/
nodesArray: [],
edgesArray: [],
/**
* GLOBAL INDEXES:
* ***************
* These indexes just index data by ids.
*/
nodesIndex: Object.create(null),
edgesIndex: Object.create(null),
/**
* LOCAL INDEXES:
* **************
* These indexes refer from node to nodes. Each key is an id, and each
* value is the array of the ids of related nodes.
*/
inNeighborsIndex: Object.create(null),
outNeighborsIndex: Object.create(null),
allNeighborsIndex: Object.create(null),
inNeighborsCount: Object.create(null),
outNeighborsCount: Object.create(null),
allNeighborsCount: Object.create(null)
};
// Execute bindings:
for (k in _initBindings)
_initBindings[k].call(data);
// Add methods to both the scope and the data objects:
for (k in _methods) {
fn = __bindGraphMethod(k, data, _methods[k]);
this[k] = fn;
data[k] = fn;
}
} | javascript | function(settings) {
var k,
fn,
data;
/**
* DATA:
* *****
* Every data that is callable from graph methods are stored in this "data"
* object. This object will be served as context for all these methods,
* and it is possible to add other type of data in it.
*/
data = {
/**
* SETTINGS FUNCTION:
* ******************
*/
settings: settings || _defaultSettingsFunction,
/**
* MAIN DATA:
* **********
*/
nodesArray: [],
edgesArray: [],
/**
* GLOBAL INDEXES:
* ***************
* These indexes just index data by ids.
*/
nodesIndex: Object.create(null),
edgesIndex: Object.create(null),
/**
* LOCAL INDEXES:
* **************
* These indexes refer from node to nodes. Each key is an id, and each
* value is the array of the ids of related nodes.
*/
inNeighborsIndex: Object.create(null),
outNeighborsIndex: Object.create(null),
allNeighborsIndex: Object.create(null),
inNeighborsCount: Object.create(null),
outNeighborsCount: Object.create(null),
allNeighborsCount: Object.create(null)
};
// Execute bindings:
for (k in _initBindings)
_initBindings[k].call(data);
// Add methods to both the scope and the data objects:
for (k in _methods) {
fn = __bindGraphMethod(k, data, _methods[k]);
this[k] = fn;
data[k] = fn;
}
} | [
"function",
"(",
"settings",
")",
"{",
"var",
"k",
",",
"fn",
",",
"data",
";",
"/**\n * DATA:\n * *****\n * Every data that is callable from graph methods are stored in this \"data\"\n * object. This object will be served as context for all these methods,\n * and it is possible to add other type of data in it.\n */",
"data",
"=",
"{",
"/**\n * SETTINGS FUNCTION:\n * ******************\n */",
"settings",
":",
"settings",
"||",
"_defaultSettingsFunction",
",",
"/**\n * MAIN DATA:\n * **********\n */",
"nodesArray",
":",
"[",
"]",
",",
"edgesArray",
":",
"[",
"]",
",",
"/**\n * GLOBAL INDEXES:\n * ***************\n * These indexes just index data by ids.\n */",
"nodesIndex",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"edgesIndex",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"/**\n * LOCAL INDEXES:\n * **************\n * These indexes refer from node to nodes. Each key is an id, and each\n * value is the array of the ids of related nodes.\n */",
"inNeighborsIndex",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"outNeighborsIndex",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"allNeighborsIndex",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"inNeighborsCount",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"outNeighborsCount",
":",
"Object",
".",
"create",
"(",
"null",
")",
",",
"allNeighborsCount",
":",
"Object",
".",
"create",
"(",
"null",
")",
"}",
";",
"// Execute bindings:",
"for",
"(",
"k",
"in",
"_initBindings",
")",
"_initBindings",
"[",
"k",
"]",
".",
"call",
"(",
"data",
")",
";",
"// Add methods to both the scope and the data objects:",
"for",
"(",
"k",
"in",
"_methods",
")",
"{",
"fn",
"=",
"__bindGraphMethod",
"(",
"k",
",",
"data",
",",
"_methods",
"[",
"k",
"]",
")",
";",
"this",
"[",
"k",
"]",
"=",
"fn",
";",
"data",
"[",
"k",
"]",
"=",
"fn",
";",
"}",
"}"
] | The graph constructor. It initializes the data and the indexes, and binds
the custom indexes and methods to its own scope.
Recognized parameters:
**********************
Here is the exhaustive list of every accepted parameters in the settings
object:
{boolean} clone Indicates if the data have to be cloned in methods
to add nodes or edges.
{boolean} immutable Indicates if nodes "id" values and edges "id",
"source" and "target" values must be set as
immutable.
@param {?configurable} settings Eventually a settings function.
@return {graph} The new graph instance. | [
"The",
"graph",
"constructor",
".",
"It",
"initializes",
"the",
"data",
"and",
"the",
"indexes",
"and",
"binds",
"the",
"custom",
"indexes",
"and",
"methods",
"to",
"its",
"own",
"scope",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.graph.js#L35-L94 |
|
6,098 | jacomyal/sigma.js | src/classes/sigma.classes.graph.js | __bindGraphMethod | function __bindGraphMethod(methodName, scope, fn) {
var result = function() {
var k,
res;
// Execute "before" bound functions:
for (k in _methodBeforeBindings[methodName])
_methodBeforeBindings[methodName][k].apply(scope, arguments);
// Apply the method:
res = fn.apply(scope, arguments);
// Execute bound functions:
for (k in _methodBindings[methodName])
_methodBindings[methodName][k].apply(scope, arguments);
// Return res:
return res;
};
return result;
} | javascript | function __bindGraphMethod(methodName, scope, fn) {
var result = function() {
var k,
res;
// Execute "before" bound functions:
for (k in _methodBeforeBindings[methodName])
_methodBeforeBindings[methodName][k].apply(scope, arguments);
// Apply the method:
res = fn.apply(scope, arguments);
// Execute bound functions:
for (k in _methodBindings[methodName])
_methodBindings[methodName][k].apply(scope, arguments);
// Return res:
return res;
};
return result;
} | [
"function",
"__bindGraphMethod",
"(",
"methodName",
",",
"scope",
",",
"fn",
")",
"{",
"var",
"result",
"=",
"function",
"(",
")",
"{",
"var",
"k",
",",
"res",
";",
"// Execute \"before\" bound functions:",
"for",
"(",
"k",
"in",
"_methodBeforeBindings",
"[",
"methodName",
"]",
")",
"_methodBeforeBindings",
"[",
"methodName",
"]",
"[",
"k",
"]",
".",
"apply",
"(",
"scope",
",",
"arguments",
")",
";",
"// Apply the method:",
"res",
"=",
"fn",
".",
"apply",
"(",
"scope",
",",
"arguments",
")",
";",
"// Execute bound functions:",
"for",
"(",
"k",
"in",
"_methodBindings",
"[",
"methodName",
"]",
")",
"_methodBindings",
"[",
"methodName",
"]",
"[",
"k",
"]",
".",
"apply",
"(",
"scope",
",",
"arguments",
")",
";",
"// Return res:",
"return",
"res",
";",
"}",
";",
"return",
"result",
";",
"}"
] | A custom tool to bind methods such that function that are bound to it will
be executed anytime the method is called.
@param {string} methodName The name of the method to bind.
@param {object} scope The scope where the method must be executed.
@param {function} fn The method itself.
@return {function} The new method. | [
"A",
"custom",
"tool",
"to",
"bind",
"methods",
"such",
"that",
"function",
"that",
"are",
"bound",
"to",
"it",
"will",
"be",
"executed",
"anytime",
"the",
"method",
"is",
"called",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.graph.js#L108-L129 |
6,099 | jacomyal/sigma.js | src/classes/sigma.classes.quad.js | _quadTree | function _quadTree(bounds, level, maxElements, maxLevel) {
return {
level: level || 0,
bounds: bounds,
corners: _geom.splitSquare(bounds),
maxElements: maxElements || 20,
maxLevel: maxLevel || 4,
elements: [],
nodes: []
};
} | javascript | function _quadTree(bounds, level, maxElements, maxLevel) {
return {
level: level || 0,
bounds: bounds,
corners: _geom.splitSquare(bounds),
maxElements: maxElements || 20,
maxLevel: maxLevel || 4,
elements: [],
nodes: []
};
} | [
"function",
"_quadTree",
"(",
"bounds",
",",
"level",
",",
"maxElements",
",",
"maxLevel",
")",
"{",
"return",
"{",
"level",
":",
"level",
"||",
"0",
",",
"bounds",
":",
"bounds",
",",
"corners",
":",
"_geom",
".",
"splitSquare",
"(",
"bounds",
")",
",",
"maxElements",
":",
"maxElements",
"||",
"20",
",",
"maxLevel",
":",
"maxLevel",
"||",
"4",
",",
"elements",
":",
"[",
"]",
",",
"nodes",
":",
"[",
"]",
"}",
";",
"}"
] | Creates the quadtree object itself.
@param {object} bounds The boundaries of the quad defined by an
origin (x, y), width and heigth.
@param {integer} level The level of the quad in the tree.
@param {integer} maxElements The max number of element in a leaf node.
@param {integer} maxLevel The max recursion level of the tree.
@return {object} The quadtree object. | [
"Creates",
"the",
"quadtree",
"object",
"itself",
"."
] | c49589f2419ca98542fd21b82b926dea21bb9fef | https://github.com/jacomyal/sigma.js/blob/c49589f2419ca98542fd21b82b926dea21bb9fef/src/classes/sigma.classes.quad.js#L503-L513 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.