Browse Source

Some fixes/improvements in calculating the height of the stacked items

css_transitions
josdejong 11 years ago
parent
commit
1dcd615626
6 changed files with 67 additions and 29 deletions
  1. +0
    -1
      package.json
  2. +7
    -9
      src/component/itemset.js
  3. +1
    -1
      src/util.js
  4. +6
    -3
      src/visualization/timeline.js
  5. +1
    -0
      test/timeline.html
  6. +52
    -15
      vis.js

+ 0
- 1
package.json View File

@ -28,7 +28,6 @@
"devDependencies": {
"jake": "latest",
"jake-utils": "latest",
"node-watch": "latest",
"moment": "latest"
}
}

+ 7
- 9
src/component/itemset.js View File

@ -312,21 +312,19 @@ ItemSet.prototype.reflow = function reflow () {
}
else {
// height is not specified, determine the height from the height and positioned items
height = 0;
var visibleItems = this.stack.ordered; // TODO: not so nice way to get the filtered items
if (options.orientation == 'top') {
if (visibleItems.length) {
var min = visibleItems[0].top;
var max = visibleItems[0].top + visibleItems[0].height;
util.forEach(visibleItems, function (item) {
height = Math.max(height, item.top + item.height);
min = Math.min(min, item.top);
max = Math.max(max, (item.top + item.height));
});
height = (max - min) + options.margin.axis + options.margin.item;
}
else {
// orientation == 'bottom'
var frameHeight = this.height;
util.forEach(visibleItems, function (item) {
height = Math.max(height, frameHeight - item.top);
});
height = options.margin.axis + options.margin.item;
}
height += options.margin.axis;
}
if (maxHeight != null) {
height = Math.min(height, maxHeight);

+ 1
- 1
src/util.js View File

@ -571,7 +571,7 @@ util.option.asNumber = function (value, defaultValue) {
}
if (value != null) {
return Number(value);
return Number(value) || defaultValue || null;
}
return defaultValue || null;

+ 6
- 3
src/visualization/timeline.js View File

@ -117,10 +117,13 @@ Timeline.prototype.setOptions = function (options) {
itemsHeight = null;
}
// TODO: maxHeight should be a string in px or %
if (options.maxHeight) {
// TODO: maxHeight should be a string in px or % (currently only accepts a number)
if (this.options.maxHeight) {
if (!util.isNumber(this.options.maxHeight)) {
throw new TypeError('Number expected for property maxHeight');
}
maxHeight = function () {
return options.maxHeight - me.timeaxis.height;
return me.options.maxHeight - me.timeaxis.height;
}
}

+ 1
- 0
test/timeline.html View File

@ -63,6 +63,7 @@
//end: now.clone().add('days', 7).valueOf(),
min: moment('2013-01-01').valueOf(),
max: moment('2013-12-31').valueOf(),
//maxHeight: 150,
zoomMin: 1000 * 60 * 60 * 24, // 1 day
zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
};

+ 52
- 15
vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 0.0.8
* @date 2013-05-03
* @date 2013-05-07
*
* @license
* Copyright (C) 2011-2013 Almende B.V, http://almende.com
@ -602,7 +602,7 @@ util.option.asNumber = function (value, defaultValue) {
}
if (value != null) {
return Number(value);
return Number(value) || defaultValue || null;
}
return defaultValue || null;
@ -1853,7 +1853,7 @@ DataSet.prototype.clear = function (senderId) {
/**
* Find the item with maximum value of a specified field
* @param {String} field
* @return {Object} item Item containing max value, or null if no items
* @return {Object | null} item Item containing max value, or null if no items
*/
DataSet.prototype.max = function (field) {
var data = this.data,
@ -1876,6 +1876,7 @@ DataSet.prototype.max = function (field) {
/**
* Find the item with minimum value of a specified field
* @param {String} field
* @return {Object | null} item Item containing max value, or null if no items
*/
DataSet.prototype.min = function (field) {
var data = this.data,
@ -1895,6 +1896,41 @@ DataSet.prototype.min = function (field) {
return min;
};
/**
* Find all distinct values of a specified field
* @param {String} field
* @return {Array} values Array containing all distinct values. If the data
* items do not contain the specified field, an array
* containing a single value undefined is returned.
* The returned array is unordered.
*/
DataSet.prototype.distinct = function (field) {
var data = this.data,
values = [],
fieldType = this.options.fieldTypes[field],
count = 0;
for (var prop in data) {
if (data.hasOwnProperty(prop)) {
var item = data[prop];
var value = util.cast(item[field], fieldType);
var exists = false;
for (var i = 0; i < count; i++) {
if (values[i] == value) {
exists = true;
break;
}
}
if (!exists) {
values[count] = value;
count++;
}
}
}
return values;
};
/**
* Add a single item
* @param {Object} item
@ -4219,21 +4255,19 @@ ItemSet.prototype.reflow = function reflow () {
}
else {
// height is not specified, determine the height from the height and positioned items
height = 0;
var visibleItems = this.stack.ordered; // TODO: not so nice way to get the filtered items
if (options.orientation == 'top') {
if (visibleItems.length) {
var min = visibleItems[0].top;
var max = visibleItems[0].top + visibleItems[0].height;
util.forEach(visibleItems, function (item) {
height = Math.max(height, item.top + item.height);
min = Math.min(min, item.top);
max = Math.max(max, (item.top + item.height));
});
height = (max - min) + options.margin.axis + options.margin.item;
}
else {
// orientation == 'bottom'
var frameHeight = this.height;
util.forEach(visibleItems, function (item) {
height = Math.max(height, frameHeight - item.top);
});
height = options.margin.axis + options.margin.item;
}
height += options.margin.axis;
}
if (maxHeight != null) {
height = Math.min(height, maxHeight);
@ -5437,10 +5471,13 @@ Timeline.prototype.setOptions = function (options) {
itemsHeight = null;
}
// TODO: maxHeight should be a string in px or %
if (options.maxHeight) {
// TODO: maxHeight should be a string in px or % (currently only accepts a number)
if (this.options.maxHeight) {
if (!util.isNumber(this.options.maxHeight)) {
throw new TypeError('Number expected for property maxHeight');
}
maxHeight = function () {
return options.maxHeight - me.timeaxis.height;
return me.options.maxHeight - me.timeaxis.height;
}
}

Loading…
Cancel
Save