Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Add the source data to Point3d objects in Graph3D #1884

Merged
merged 3 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/graph3d/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ <h2 id="Configuration_Options">Configuration Options</h2>
The contents of the tooltip can be customized by providing a callback
function as <code>tooltip</code>. In this case the function is called
with an object containing parameters <code>x</code>,
<code>y</code>, and <code>z</code> argument,
<code>y</code>, <code>z</code>, and <code>data</code>
(the source JS object for the point) as an argument,
and must return a string which may contain HTML.
</td>
</tr>
Expand Down
14 changes: 10 additions & 4 deletions examples/graph3d/11_tooltips.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

// Create and populate a data table.
data = new vis.DataSet();
var extra_content = [
'Arbitrary information',
'You can access data from the point source object',
'Tooltip example content',
];

// create some nice looking data with sin/cos
var steps = 5; // number of datapoints will be steps*steps
Expand All @@ -34,10 +39,10 @@
var z = custom(x,y);
if (withValue) {
var value = (y - x);
data.add({x:x, y:y, z: z, style:value});
data.add({x:x, y:y, z: z, style:value, extra: extra_content[(x*y) % extra_content.length]});
}
else {
data.add({x:x, y:y, z: z});
data.add({x:x, y:y, z: z, extra: extra_content[(x*y) % extra_content.length]});
}
}
}
Expand All @@ -55,8 +60,9 @@
// Option tooltip can be true, false, or a function returning a string with HTML contents
//tooltip: true,
tooltip: function (point) {
// parameter point contains properties x, y, z
return 'value: <b>' + point.z + '</b>';
// parameter point contains properties x, y, z, and data
// data is the original object passed to the point constructor
return 'value: <b>' + point.z + '</b><br>' + point.data.extra;
},

keepAspectRatio: true,
Expand Down
5 changes: 3 additions & 2 deletions lib/graph3d/Graph3d.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Emitter = require('emitter-component');
var DataSet = require('../DataSet');
var Emitter = require('emitter-component'); var DataSet = require('../DataSet');
var DataView = require('../DataView');
var util = require('../util');
var Point3d = require('./Point3d');
Expand Down Expand Up @@ -561,6 +560,7 @@ Graph3d.prototype._getDataPoints = function (data) {
point3d.x = x;
point3d.y = y;
point3d.z = z;
point3d.data = data[i];

obj = {};
obj.point = point3d;
Expand Down Expand Up @@ -594,6 +594,7 @@ Graph3d.prototype._getDataPoints = function (data) {
point.x = data[i][this.colX] || 0;
point.y = data[i][this.colY] || 0;
point.z = data[i][this.colZ] || 0;
point.data = data[i];

if (this.colValue !== undefined) {
point.value = data[i][this.colValue] || 0;
Expand Down