Browse Source

Refactored item selection

css_transitions
josdejong 10 years ago
parent
commit
8717aac332
9 changed files with 60 additions and 30 deletions
  1. +1
    -2
      docs/timeline.html
  2. +34
    -4
      src/timeline/Stack.js
  3. +6
    -12
      src/timeline/component/ItemSet.js
  4. +4
    -3
      src/timeline/component/css/item.css
  5. +2
    -2
      src/timeline/component/item/Item.js
  6. +3
    -3
      src/timeline/component/item/ItemBox.js
  7. +4
    -1
      src/timeline/component/item/ItemPoint.js
  8. +3
    -0
      src/timeline/component/item/ItemRange.js
  9. +3
    -3
      src/timeline/component/item/ItemRangeOverflow.js

+ 1
- 2
docs/timeline.html View File

@ -483,8 +483,7 @@ var options = {
<pre class="prettyprint lang-css"> <pre class="prettyprint lang-css">
.vis.timeline .item { .vis.timeline .item {
padding: 10px; padding: 10px;
}
</pre>
}</pre>
</td> </td>
</tr> </tr>

+ 34
- 4
src/timeline/Stack.js View File

@ -29,9 +29,6 @@ function Stack (itemset, options) {
return 1; return 1;
} }
else { else {
if (!a.data) {
throw new Error('hu')
}
return (a.data.start - b.data.start); return (a.data.start - b.data.start);
} }
} }
@ -60,7 +57,7 @@ Stack.prototype.setOptions = function setOptions (options) {
/** /**
* Order a map with items * Order a map with items
* @param {Object<String, Item>} items * @param {Object<String, Item>} items
* @return {Item[]} sorted items
* @return {{asc: Item[], desc: Item[]}} sorted items
*/ */
Stack.prototype.order = function order(items) { Stack.prototype.order = function order(items) {
var ordered = []; var ordered = [];
@ -70,13 +67,46 @@ Stack.prototype.order = function order(items) {
if (items.hasOwnProperty(id)) ordered.push(items[id]); if (items.hasOwnProperty(id)) ordered.push(items[id]);
} }
/* FIXME: fix option order
//order the items //order the items
var order = this.options.order || this.defaultOptions.order; var order = this.options.order || this.defaultOptions.order;
if (!(typeof order === 'function')) { if (!(typeof order === 'function')) {
throw new Error('Option order must be a function'); throw new Error('Option order must be a function');
} }
ordered.sort(order); ordered.sort(order);
*/
// TODO: fix ordering, doesn't work correctly for ItemRange
ordered.sort(function (a, b) {
var aCenter = ('end' in a.data) ? (a.data.start + a.data.end) / 2 : a.data.start,
bCenter = ('end' in b.data) ? (b.data.start + b.data.end) / 2 : b.data.start;
return aCenter - bCenter;
});
/* TODO: cleanup
var asc = array.concat(),
desc= array.concat();
// sort ascending
asc.sort(function (a, b) {
return a.data.start - b.data.start;
});
// sort descending
desc.sort(function (a, b) {
var aTime = 'end' in a.data ? a.data.end : a.data.start,
bTime = 'end' in b.data ? b.data.end : b.data.start;
return bTime - aTime;
});
return {
asc: asc,
desc: desc
};
*/
return ordered; return ordered;
}; };

+ 6
- 12
src/timeline/component/ItemSet.js View File

@ -45,19 +45,13 @@ function ItemSet(parent, depends, options) {
// data change listeners // data change listeners
this.listeners = { this.listeners = {
'add': function (event, params, senderId) { 'add': function (event, params, senderId) {
if (senderId != me.id) {
me._onAdd(params.items);
}
if (senderId != me.id) me._onAdd(params.items);
}, },
'update': function (event, params, senderId) { 'update': function (event, params, senderId) {
if (senderId != me.id) {
me._onUpdate(params.items);
}
if (senderId != me.id) me._onUpdate(params.items);
}, },
'remove': function (event, params, senderId) { 'remove': function (event, params, senderId) {
if (senderId != me.id) {
me._onRemove(params.items);
}
if (senderId != me.id) me._onRemove(params.items);
} }
}; };
@ -166,7 +160,7 @@ ItemSet.prototype.setRange = function setRange(range) {
* unselected. * unselected.
*/ */
ItemSet.prototype.setSelection = function setSelection(ids) { ItemSet.prototype.setSelection = function setSelection(ids) {
var i, ii, id, item, selection;
var i, ii, id, item;
if (ids) { if (ids) {
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
@ -764,7 +758,7 @@ ItemSet.prototype._onDrag = function (event) {
// TODO: implement dragging from one group to another // TODO: implement dragging from one group to another
this.requestReflow();
this.repaint();
event.stopPropagation(); event.stopPropagation();
} }
@ -808,7 +802,7 @@ ItemSet.prototype._onDragEnd = function (event) {
// restore original values // restore original values
if ('start' in props) props.item.data.start = props.start; if ('start' in props) props.item.data.start = props.start;
if ('end' in props) props.item.data.end = props.end; if ('end' in props) props.item.data.end = props.end;
me.requestReflow();
me.repaint();
} }
}); });
} }

+ 4
- 3
src/timeline/component/css/item.css View File

@ -7,8 +7,8 @@
display: inline-block; display: inline-block;
padding: 5px; padding: 5px;
-webkit-transition: top .4s, height .4s, background-color .4s, -webkit-transform .4s ease-in-out;
transition: top .4s, height .4s, background-color .4s, transform .4s ease-in-out;
-webkit-transition: top .4s ease-in-out, height .4s ease-in-out;
transition: top .4s ease-in-out, height .4s ease-in-out;
} }
.vis.timeline .item.selected { .vis.timeline .item.selected {
@ -25,7 +25,8 @@
background-color: #FFF785; background-color: #FFF785;
z-index: 999; z-index: 999;
} }
.vis.timeline .item.point.selected .dot {
.vis.timeline .item.point.selected .dot,
.vis.timeline .item.dot.selected {
border-color: #FFC200; border-color: #FFC200;
} }

+ 2
- 2
src/timeline/component/item/Item.js View File

@ -30,7 +30,7 @@ function Item (parent, data, options, defaultOptions) {
*/ */
Item.prototype.select = function select() { Item.prototype.select = function select() {
this.selected = true; this.selected = true;
if (this.visible) this.repaint();
if (this.displayed) this.repaint();
}; };
/** /**
@ -38,7 +38,7 @@ Item.prototype.select = function select() {
*/ */
Item.prototype.unselect = function unselect() { Item.prototype.unselect = function unselect() {
this.selected = false; this.selected = false;
if (this.visible) this.repaint();
if (this.displayed) this.repaint();
}; };
/** /**

+ 3
- 3
src/timeline/component/item/ItemBox.js View File

@ -160,11 +160,11 @@ ItemBox.prototype.hide = function hide() {
if (dom.line.parentNode) dom.line.parentNode.removeChild(dom.line); if (dom.line.parentNode) dom.line.parentNode.removeChild(dom.line);
if (dom.dot.parentNode) dom.dot.parentNode.removeChild(dom.dot); if (dom.dot.parentNode) dom.dot.parentNode.removeChild(dom.dot);
this.top = null;
this.left = null;
this.displayed = false; this.displayed = false;
} }
this.top = null;
this.left = null;
}; };
/** /**

+ 4
- 1
src/timeline/component/item/ItemPoint.js View File

@ -129,7 +129,7 @@ ItemPoint.prototype.repaint = function repaint() {
this.dirty = false; this.dirty = false;
} }
this._repaintDeleteButton(dom.box);
this._repaintDeleteButton(dom.point);
}; };
/** /**
@ -151,6 +151,9 @@ ItemPoint.prototype.hide = function hide() {
this.dom.point.parentNode.removeChild(this.dom.point); this.dom.point.parentNode.removeChild(this.dom.point);
} }
this.top = null;
this.left = null;
this.displayed = false; this.displayed = false;
} }
}; };

+ 3
- 0
src/timeline/component/item/ItemRange.js View File

@ -140,6 +140,9 @@ ItemRange.prototype.hide = function hide() {
box.parentNode.removeChild(box); box.parentNode.removeChild(box);
} }
this.top = null;
this.left = null;
this.displayed = false; this.displayed = false;
} }
}; };

+ 3
- 3
src/timeline/component/item/ItemRangeOverflow.js View File

@ -47,9 +47,9 @@ ItemRangeOverflow.prototype.repositionX = function repositionX() {
this.left = start; this.left = start;
var boxWidth = Math.max(end - start, 1); var boxWidth = Math.max(end - start, 1);
this.width = (this.props.content && boxWidth < this.props.content.width) ?
this.props.content.width :
boxWidth;
this.width = (this.props.content.width < boxWidth) ?
boxWidth :
start + contentLeft + this.props.content.width;
this.dom.box.style.left = this.left + 'px'; this.dom.box.style.left = this.left + 'px';
this.dom.box.style.width = boxWidth + 'px'; this.dom.box.style.width = boxWidth + 'px';

Loading…
Cancel
Save