mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 20:00:10 +00:00
new version of mergeData(...), now more flexible and general (needs testing)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b571f7d6c0
commit
23e5a1ff77
73
ui/data.js
73
ui/data.js
@ -718,38 +718,63 @@ function dataFromImages(images){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Merge two data objects
|
// Merge two or more data objects
|
||||||
//
|
//
|
||||||
|
// Each data object can be:
|
||||||
|
// - straight data object
|
||||||
|
// - array with ribbon shift at position 0 and the data at 1.
|
||||||
//
|
//
|
||||||
// (A) (B)
|
// The shift can be either positive or negative value. Positive shift
|
||||||
// oooooooooo -+-
|
// will shift the ribbons down (add padding to the top), while negative
|
||||||
// oooooooooooooooooo + shift
|
// will shift the ribbons up.
|
||||||
// oooooooooooooo -+- ooooooooooo
|
|
||||||
// oooooooooooooooooo ooooooooooooooooo
|
|
||||||
// ooooooooooooooo
|
|
||||||
//
|
//
|
||||||
// Negative shift moves (A) up while positive moves it down relative to (B)
|
// NOTE: if no shift is given it will default to 0, i.e. align by top
|
||||||
// In the diagram above the shift is -2
|
// ribbon.
|
||||||
|
// NOTE: shifting one set of ribbons up (negative shift) is the same as
|
||||||
|
// shifting every other set down by the same amount down (positive).
|
||||||
|
// e.g. these shifts:
|
||||||
|
// -1 0 2 -5 0 0
|
||||||
|
// will be normalized to, or are equivalent to:
|
||||||
|
// 4 5 7 0 5 5
|
||||||
|
// (we add abs max shift |-5| to each element, to align top to 0)
|
||||||
//
|
//
|
||||||
// XXX add ability to resort the data...
|
// XXX check version???
|
||||||
// ...should this be here???
|
function mergeData(a, b){
|
||||||
function mergeData(data_a, data_b, shift){
|
var order = []
|
||||||
var a = data_a.ribbons
|
var ribbon_sets = []
|
||||||
var b = data_b.ribbons
|
var shifts = []
|
||||||
// pad the head of the shifted array...
|
var min = 0
|
||||||
if(shift > 0){
|
|
||||||
a = new Array(shift).concat(a)
|
// build ribbon sets and shift bounds...
|
||||||
} else if(shift < 0) {
|
$.each(arguments, function(_, d){
|
||||||
b = new Array(Math.abs(shift)).concat(b)
|
if(typeof(d) == typeof([]) && d.constructor.name == 'Array'){
|
||||||
}
|
var s = d[0]
|
||||||
|
d = d[1]
|
||||||
|
shifts.push(s)
|
||||||
|
// NOTE: min shift (max negative shift) is needed so as to
|
||||||
|
// calculate the actual padding per each aligned ribbon
|
||||||
|
// set in the resulting structure...
|
||||||
|
min = Math.min(s, min)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
shifts.push(0)
|
||||||
|
}
|
||||||
|
ribbon_sets.push(d.ribbons)
|
||||||
|
order = order.concat(d.order)
|
||||||
|
})
|
||||||
|
var shift = Math.abs(min)
|
||||||
|
|
||||||
|
// normalize ribbons...
|
||||||
|
// NOTE: this will shift the ribbons to the required alignment...
|
||||||
|
$.each(shifts, function(i, s){
|
||||||
|
ribbon_sets[i] = new Array(shift + s).concat(ribbon_sets[i])
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: '2.0',
|
version: '2.0',
|
||||||
// XXX should we set this here???
|
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: concatZip(a, b),
|
ribbons: concatZip.apply(null, ribbon_sets),
|
||||||
// XXX should we sort this???
|
order: order,
|
||||||
order: data_a.order.concat(data_b.order),
|
|
||||||
image_file: null
|
image_file: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user