Skip to content

Commit

Permalink
Merge branch 'master' into fix-#253
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamberk authored Jan 27, 2020
2 parents bbc7638 + 109c121 commit daaef91
Show file tree
Hide file tree
Showing 22 changed files with 1,708 additions and 320 deletions.
8 changes: 2 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"presets": [
["@babel/preset-env", {
"targets": "> 0.1% or not dead"
}]
],
"plugins": ["css-modules-transform"]
"exclude": ["**/node_modules/**"],
"presets": [["vis-dev-utils/babel-preset", { "css": true }]]
}
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ npm-debug.log
# temporary files
.*.sw[op]
.commits.tmp
gen/
.nyc_output/
/examples/graph2d-generated/
/examples/graph2d/examples.css
/examples/graph2d/index.html
/examples/timeline-generated/
/examples/timeline/examples.css
/examples/timeline/index.html
coverage/
dist/
gen/
18 changes: 17 additions & 1 deletion docs/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,15 @@ <h2 id="Configuration_Options">Configuration Options</h2>
<td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
</tr>

<tr>
<td>longSelectPressTime</td>
<td>number</td>
<td><code>251</code></td>
<td>
The minimal press time in ms for an event to be considered a (long) press.
</td>
</tr>

<tr>
<td>moment</td>
<td>function</td>
Expand Down Expand Up @@ -1153,7 +1162,7 @@ <h2 id="Configuration_Options">Configuration Options</h2>
<td class="indent">cluster.titleTemplate</td>
<td>string or null</td>
<td><code>none</code></td>
<td>Cluster item tooltip</td>
<td>Cluster item tooltip, will replace <code>{count}</code> with the number of items in the cluster</td>
</tr>
<tr parent="cluster" class="hidden">
<td class="indent">cluster.clusterCriteria</td>
Expand Down Expand Up @@ -2209,6 +2218,13 @@ <h3 id="available-locales">Available locales</h3>
<code>ru_RU</code>
</td>
</tr>
<tr>
<td>Polish</td>
<td>
<code>pl</code><br>
<code>pl_PL</code>
</td>
</tr>
</table>


Expand Down
23 changes: 23 additions & 0 deletions generate-examples-index-graph2d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"base-url": "https://visjs.github.io/vis-timeline/",
"output-directory": "./examples/graph2d",

"assets-local-directory": "./examples/graph2d-generated",
"assets-web-directory": "../graph2d-generated",
"examples-local-directory": "./examples/graph2d",
"examples-web-directory": "./",
"pages-local-directory": "./examples/graph2d-generated",
"pages-web-directory": "../graph2d-generated",

"index": true,
"lint": true,
"playgrounds": true,
"screenshots": true,

"container-id": "visualization",
"format": "html",
"parallel": 6,
"screenshot-script": "./scripts/examples-index/screenshot-script.js",
"title": "Vis Graph2D Examples",
"verify": 100
}
23 changes: 23 additions & 0 deletions generate-examples-index-timeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"base-url": "https://visjs.github.io/vis-timeline/",
"output-directory": "./examples/timeline",

"assets-local-directory": "./examples/timeline-generated",
"assets-web-directory": "../timeline-generated",
"examples-local-directory": "./examples/timeline",
"examples-web-directory": "./",
"pages-local-directory": "./examples/timeline-generated",
"pages-web-directory": "../timeline-generated",

"index": true,
"lint": true,
"playgrounds": true,
"screenshots": true,

"container-id": "visualization",
"format": "html",
"parallel": 6,
"screenshot-script": "./scripts/examples-index/screenshot-script.js",
"title": "Vis Timeline Examples",
"verify": 100
}
15 changes: 10 additions & 5 deletions lib/DOMutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,15 @@ export function drawBar (x, y, width, height, className, JSONcontainer, svgConta
* @returns {string}
*/
export function getNavigatorLanguage() {
if (!navigator) return 'en';
if (navigator.languages && navigator.languages.length) {
return navigator.languages;
} else {
return navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
try {
if (!navigator) return 'en';
if (navigator.languages && navigator.languages.length) {
return navigator.languages;
} else {
return navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
}
}
catch(error) {
return 'en';
}
}
44 changes: 0 additions & 44 deletions lib/header.js

This file was deleted.

4 changes: 4 additions & 0 deletions lib/shared/Activator.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Activator.prototype.activate = function () {
* Overlay is displayed on top of the element
*/
Activator.prototype.deactivate = function () {
if (Activator.current === this) {
Activator.current = null;
}

this.active = false;
this.dom.overlay.style.display = '';
util.removeClassName(this.dom.container, 'vis-active');
Expand Down
19 changes: 15 additions & 4 deletions lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ class Core {
*/
function onMouseScrollSide(event) {
if (!me.options.verticalScroll) return;

if (me._isProgramaticallyScrolled) {
me._isProgramaticallyScrolled = false;
return;
}

event.preventDefault();
if (me.isActive()) {
const adjusted = -event.target.scrollTop;
Expand Down Expand Up @@ -404,10 +410,10 @@ class Core {
const fields = [
'width', 'height', 'minHeight', 'maxHeight', 'autoResize',
'start', 'end', 'clickToUse', 'dataAttributes', 'hiddenDates',
'locale', 'locales', 'moment', 'preferZoom', 'rtl', 'zoomKey', 'horizontalScroll', 'verticalScroll'
'locale', 'locales', 'moment', 'preferZoom', 'rtl', 'zoomKey',
'horizontalScroll', 'verticalScroll', 'longSelectPressTime'
];
util.selectiveExtend(fields, this.options, options);

util.selectiveExtend(fields, this.options, options);
this.dom.rollingModeBtn.style.visibility = 'hidden';

if (this.options.rtl) {
Expand Down Expand Up @@ -1044,6 +1050,11 @@ class Core {
direction: contentsOverflow ? Hammer.DIRECTION_ALL : Hammer.DIRECTION_HORIZONTAL
});

// set the long press time
this.hammer.get('press').set({
time: this.options.longSelectPressTime
});

// redraw all components
this.components.forEach(component => {
resized = component.redraw() || resized;
Expand Down Expand Up @@ -1355,7 +1366,7 @@ class Core {
this.dom.left.parentNode.scrollTop = -this.props.scrollTop;
this.dom.right.parentNode.scrollTop = -this.props.scrollTop;
}

this._isProgramaticallyScrolled = true;
return this.props.scrollTop;
}

Expand Down
17 changes: 8 additions & 9 deletions lib/timeline/Graph2d.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from '../module/moment';
import util from '../util';
import util, { typeCoerceDataSet } from '../util';
import { DataSet } from 'vis-data';
import { DataView } from 'vis-data';
import Range from './Range';
Expand Down Expand Up @@ -193,21 +193,20 @@ Graph2d.prototype.setItems = function(items) {
newDataSet = null;
}
else if (items instanceof DataSet || items instanceof DataView) {
newDataSet = items;
newDataSet = typeCoerceDataSet(items);
}
else {
// turn an array into a dataset
newDataSet = new DataSet(items, {
type: {
start: 'Date',
end: 'Date'
}
});
newDataSet = typeCoerceDataSet(new DataSet(items));
}

// set items
if (this.itemsData) {
// stop maintaining a coerced version of the old data set
this.itemsData.dispose()
}
this.itemsData = newDataSet;
this.linegraph && this.linegraph.setItems(newDataSet);
this.linegraph && this.linegraph.setItems(newDataSet != null ? newDataSet.rawDS : null);

if (initialLoad) {
if (this.options.start != undefined || this.options.end != undefined) {
Expand Down
39 changes: 16 additions & 23 deletions lib/timeline/Timeline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from '../module/moment';
import util from '../util';
import util, { typeCoerceDataSet } from '../util';
import { DataSet } from 'vis-data';
import { DataView } from 'vis-data';
import Range from './Range';
Expand Down Expand Up @@ -53,6 +53,7 @@ export default class Timeline extends Core {
const me = this;
this.defaultOptions = {
autoResize: true,
longSelectPressTime: 251,
orientation: {
axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both'
item: 'bottom' // not relevant
Expand Down Expand Up @@ -288,9 +289,9 @@ export default class Timeline extends Core {
const itemsData = this.itemsData;
if (itemsData) {
const selection = this.getSelection();
this.setItems(null); // remove all
this.setItems(itemsData); // add all
this.setSelection(selection); // restore selection
this.setItems(null); // remove all
this.setItems(itemsData.rawDS); // add all
this.setSelection(selection); // restore selection
}
}
}
Expand All @@ -309,21 +310,20 @@ export default class Timeline extends Core {
newDataSet = null;
}
else if (items instanceof DataSet || items instanceof DataView) {
newDataSet = items;
newDataSet = typeCoerceDataSet(items);
}
else {
// turn an array into a dataset
newDataSet = new DataSet(items, {
type: {
start: 'Date',
end: 'Date'
}
});
newDataSet = typeCoerceDataSet(new DataSet(items));
}

// set items
if (this.itemsData) {
// stop maintaining a coerced version of the old data set
this.itemsData.dispose();
}
this.itemsData = newDataSet;
this.itemSet && this.itemSet.setItems(newDataSet);
this.itemSet && this.itemSet.setItems(newDataSet != null ? newDataSet.rawDS : null);
}

/**
Expand Down Expand Up @@ -419,12 +419,7 @@ export default class Timeline extends Core {
const ids = Array.isArray(id) ? id : [id];

// get the specified item(s)
const itemsData = this.itemsData.getDataSet().get(ids, {
type: {
start: 'Date',
end: 'Date'
}
});
const itemsData = this.itemsData.get(ids);

// calculate minimum start and maximum end of specified items
let start = null;
Expand Down Expand Up @@ -533,8 +528,7 @@ export default class Timeline extends Core {
const animation = (options && options.animation !== undefined) ? options.animation : true;
let range;

const dataset = this.itemsData && this.itemsData.getDataSet();
if (dataset.length === 1 && dataset.get()[0].end === undefined) {
if (this.itemsData.length === 1 && this.itemsData.get()[0].end === undefined) {
// a single item -> don't fit, just show a range around the item from -4 to +3 days
range = this.getDataRange();
this.moveTo(range.min.valueOf(), {animation}, callback);
Expand Down Expand Up @@ -645,9 +639,8 @@ export default class Timeline extends Core {
let min = null;
let max = null;

const dataset = this.itemsData && this.itemsData.getDataSet();
if (dataset) {
dataset.forEach(item => {
if (this.itemsData) {
this.itemsData.forEach(item => {
const start = util.convert(item.start, 'Date').valueOf();
const end = util.convert(item.end != undefined ? item.end : item.start, 'Date').valueOf();
if (min === null || start < min) {
Expand Down
Loading

0 comments on commit daaef91

Please sign in to comment.