Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 5bdba48

Browse files
committed
Ability to supress tooltip coords message with the plot attribute
Figure gathers the tooltip from the axes (if they provide it)
1 parent cbae621 commit 5bdba48

File tree

6 files changed

+106
-16
lines changed

6 files changed

+106
-16
lines changed

RELEASE_NOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
### 1.5.19 (December 27, 2018)
2+
3+
New features:
4+
- Tooltip now shows the labels of label axis (in case of label axis depicts intervals)
5+
- Plot coordinates info can be suppressed in tooltip with `data-idd-suppress-tooltip-coords`
6+
7+
### 1.5.18 (December 21, 2018)
8+
- base64 data source is now suppoerted for specifing the data declaratively
9+
- Label axis data can be specified declaratively in the DOM before IDD plot initialization
10+
111
### 1.5.17 (December 13, 2018)
212

313
New features:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "interactive-data-display",
3-
"version": "1.5.18",
3+
"version": "1.5.19",
44
"license": "Apache-2.0",
55
"homepage": "https://github.com/predictionmachines/InteractiveDataDisplay/wiki",
66
"description": "A JavaScript visualization library for dynamic data",

samples/LabelledAxisDeclarative.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
<div id="bottom_axis1" data-idd-axis="labels" data-idd-placement="bottom" style="position: relative;">
4545
ticks labels
4646
1 a
47-
3 b
48-
8 c
49-
2 d
50-
4 e
47+
2 b
48+
3 c
49+
4 d
50+
5
5151
</div>
5252
<div id="left_axis1" data-idd-axis="numeric" data-idd-placement="left" style="position: relative;"></div>
5353
</div>

src/idd/idd.axis.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ InteractiveDataDisplay.TicksRenderer = function (div, source) {
8080

8181
var _width, _height;
8282
var _size;
83-
var _deltaRange;
83+
var _deltaRange; // DG: seems to be a ratio between axis screen size and visible data range
8484
var _canvasHeight;
8585
var _rotateAngle;
8686

@@ -706,6 +706,9 @@ InteractiveDataDisplay.TicksRenderer = function (div, source) {
706706
InteractiveDataDisplay.NumericAxis = function (div) {
707707
this.base = InteractiveDataDisplay.TicksRenderer;
708708
div[0].axis = this;
709+
710+
// DG: seems to be data coord -> screen coord transform
711+
// ticks locations are transformed with this function to be put to screen
709712
this.getCoordinateFromTick = function (x) {
710713
var delta = this.deltaRange;
711714
if (isFinite(delta)) {
@@ -745,6 +748,8 @@ InteractiveDataDisplay.LabelledAxis = function (div, params) {
745748
this.base = InteractiveDataDisplay.TicksRenderer;
746749
var that = this;
747750

751+
// DG: seems to be data coord -> screen coord transform
752+
// ticks locations are transformed with this function to be put to screen
748753
this.getCoordinateFromTick = function (x) {
749754
var delta = this.deltaRange;
750755
if (isFinite(delta)) {
@@ -765,11 +770,45 @@ InteractiveDataDisplay.LabelledAxis = function (div, params) {
765770
};
766771

767772
if (params && params.rotate)
768-
this.rotateLabels = true;
773+
this.rotateLabels = true;
769774

770775
this.base(div, new InteractiveDataDisplay.LabelledTickSource(params));
771776
this.rotateAngle = params && params.rotateAngle ? params.rotateAngle : 0;
772777

778+
// returns the string, that depicts the supplied data coordinate (associated label)
779+
this.getToolTip = function(dataCoord) {
780+
// the function returns the tooltip only for the named intervals (e.g. when Ticks count is one more than labels count)
781+
var dataToPlot = function(x) { return that.dataTransform ? that.dataTransform(x) : x }
782+
var plotCoord = dataToPlot(dataCoord)
783+
784+
// finding "invisible" tick (tick hidden, label visible) after unlabeled visible tick
785+
var lessThanIndex = undefined
786+
var moreThanIndex = undefined
787+
for(var i=0; i<that.ticks.length; i++) {
788+
var curTick = that.ticks[i]
789+
if(curTick.text) // we skip labeled invisible ticks, analyzing only unlabled ones
790+
continue
791+
var curPlotCoord = dataToPlot(curTick.position)
792+
if(curPlotCoord>plotCoord && !moreThanIndex)
793+
moreThanIndex = i
794+
if(curPlotCoord<plotCoord)
795+
lessThanIndex = i
796+
}
797+
if(moreThanIndex && !lessThanIndex) {
798+
// left interval bound is out of visible region, right is inside
799+
if(that.ticks[moreThanIndex-1] && that.ticks[moreThanIndex-1].text)
800+
return that.ticks[moreThanIndex-1].text
801+
} else if (lessThanIndex && !moreThanIndex) {
802+
// right interval bound is out of visible region, left is inside
803+
if(that.ticks[lessThanIndex+1] && that.ticks[lessThanIndex+1].text)
804+
return that.ticks[lessThanIndex+1].text
805+
} else if (lessThanIndex && moreThanIndex && (moreThanIndex-lessThanIndex == 2)) {
806+
// left and right interval bounds are inside visible regions
807+
return that.ticks[lessThanIndex+1].text
808+
}
809+
return undefined
810+
}
811+
773812
return this;
774813
}
775814
InteractiveDataDisplay.LabelledAxis.prototype = new InteractiveDataDisplay.TicksRenderer;
@@ -1196,7 +1235,7 @@ InteractiveDataDisplay.LabelledTickSource = function (params) {
11961235
var that = this;
11971236

11981237
var _labels = [];
1199-
var _ticks = [];
1238+
var _ticks = []; // DG: Seems that it is in data coords, as the coords are later processed with getCoordinateFromTick
12001239

12011240
// if labels and ticks are defined - cash them
12021241
// if ticks are undefined - they are calculated as an array of integers from 0 to length of labels

src/idd/idd.base.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
277277
// I set this flag to suppress echo, i.e. I will not notify bound plots about my new visible rectangle.
278278
// The flag is reset when any other update request is received.
279279
var _suppressNotifyBoundPlots = false;
280+
var _tooltipSettings = undefined;
280281

281282
var _plotRect;
282283

@@ -300,6 +301,11 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
300301
_padding = Number(div.attr("data-idd-padding"))
301302
div.removeAttr("data-idd-padding");
302303
}
304+
if(div.attr("data-idd-suppress-tooltip-coords")) {
305+
div.removeAttr("data-idd-suppress-tooltip-coords");
306+
_tooltipSettings = _tooltipSettings || {}
307+
_tooltipSettings.showCursorCoordinates = false
308+
}
303309
div[0].plot = this; // adding a reference to the initialized DOM object of the plot, pointing to the plot instance.
304310

305311
// Disables user selection for this element:
@@ -499,8 +505,7 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
499505
configurable: false
500506
}
501507
);
502-
503-
var _tooltipSettings = undefined;
508+
504509
Object.defineProperty(this, "tooltipSettings",
505510
{
506511
get: function () { return _isMaster ? _tooltipSettings : _master.tooltipSettings; },
@@ -1375,6 +1380,10 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
13751380
// Implementation of this method for a particular plot should build and return
13761381
// a tooltip element for the point (xd,yd) in data coordinates, and (xp, yp) in plot coordinates.
13771382
// Method returns <div> element or undefined
1383+
this.getTooltip = function (xd, yd, xp, yp) {
1384+
return undefined;
1385+
};
1386+
13781387
var foreachDependentPlot = function (plot, f) {
13791388
var myChildren = plot.children;
13801389
var n = myChildren.length;
@@ -1384,9 +1393,6 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
13841393
}
13851394
f(plot);
13861395
};
1387-
this.getTooltip = function (xd, yd, xp, yp) {
1388-
return undefined;
1389-
};
13901396

13911397
if (_isMaster) {
13921398
var _tooltipTimer; // descriptor of the set timer to show the tooltip
@@ -1405,10 +1411,11 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
14051411
clearTooltip();
14061412

14071413
var getElements = function () {
1408-
var tooltips = [];
1409-
var xd, yd;
1414+
var tooltips = [];
14101415
var px = origin_p.x, py = origin_p.y;
1411-
1416+
1417+
var xd,yd;
1418+
14121419
foreachDependentPlot(that, function (child) {
14131420
var my_xd = child.xDataTransform ? child.xDataTransform.plotToData(px) : px;
14141421
var my_yd = child.yDataTransform ? child.yDataTransform.plotToData(py) : py;

src/idd/idd.figure.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,40 @@ InteractiveDataDisplay.Figure = function (div, master) {
287287
return jqDiv;
288288
}
289289

290+
// Builds a tooltip <div> for a point
291+
this.getTooltip = function (xd, yd, xp, yp) {
292+
// the Figure is responsible for producing the tooltips for the axes (e.g. label axis)
293+
// tooltip must show relevant informative information from the axes
294+
// thus, traversing axes, gathering labels that corespond to mouse position
295+
var axes = that.getAxes();
296+
var axisTooltipFound = false
297+
var labels = new Array()
298+
if (axes) {
299+
for (var i = 0; i < axes.length; i++) {
300+
// we build tooltip only for axes that are able to return tooltip
301+
var axis = axes[i]
302+
if(axis.getToolTip) {
303+
axisTooltipFound = true
304+
var coord;
305+
if (axes[i].mode=="left" || axes[i].mode=="right")
306+
coord = yd
307+
else
308+
coord = xd
309+
var tooltipValue = axes[i].getToolTip(coord)
310+
if(tooltipValue)
311+
labels.push(tooltipValue)
312+
}
313+
}
314+
}
315+
if(axisTooltipFound) {
316+
var $content = $("<div></div>").addClass('idd-tooltip-compositevalue');
317+
$content.append($("<div>"+labels.join(', ')+"</div>"));
318+
return $content
319+
}
320+
else
321+
return undefined
322+
}
323+
290324
var finalSize;
291325
this.measure = function (screenSize) {
292326

0 commit comments

Comments
 (0)