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

Commit a433fff

Browse files
committed
specifying visible region with plot div attribute
1 parent f4a39a3 commit a433fff

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 1.5.16 (December 13, 2018)
2+
3+
New features:
4+
- "data-idd-visible-region" plot attribute can now define the visible are in data coordinates in format "xmin xmax ymin ymax". Specifying the attribute disables fit to view
5+
- "data-idd-padding" plot attribute can now override the padding (in pixels) added to the data region during calculation of visible region in case of active "fit to view" mode.
6+
17
### 1.5.15 (December 10, 2018)
28

39
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.15",
3+
"version": "1.5.16",
44
"license": "Apache-2.0",
55
"homepage": "https://github.com/predictionmachines/InteractiveDataDisplay/wiki",
66
"description": "A JavaScript visualization library for dynamic data",

samples/Visible region control.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.js"></script>
1515
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
1616
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
17-
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js"></script>
18-
<script src="../dist/idd_knockout.js"></script>
17+
<script src="../dist/idd.js"></script>
1918

2019
<script type="text/javascript">
2120
$(document).ready(function () {
2221
var plot1 = InteractiveDataDisplay.asPlot($("#figure1"));
2322
var plot2 = InteractiveDataDisplay.asPlot($("#figure2"));
24-
//var plot3 = InteractiveDataDisplay.asPlot($("#figure3"));
23+
var plot3 = InteractiveDataDisplay.asPlot($("#figure3"));
2524
});
2625
</script>
2726
</head>
@@ -76,6 +75,31 @@ <h3>Zero padding</h3>
7675
<div id="bottom_axis2" data-idd-axis="numeric" data-idd-placement="bottom" style="position: relative;"></div>
7776
<div id="left_axis2" data-idd-axis="numeric" data-idd-placement="left" style="position: relative;"></div>
7877
</div>
78+
79+
<h3>Visible region is set to x=[0.5;1.0] y=[0.2; 0.8]</h3>
80+
<div id="figure3" data-idd-plot="figure" style="width: 400px; height: 300px; float:left"
81+
data-idd-navigation-enabled="false" data-idd-legend-enabled="true" data-idd-padding="30" data-idd-visible-region="0.5 1.0 0.2 0.8">
82+
83+
<div id="grid3" data-idd-plot='grid' data-idd-placement='center' data-idd-style='stroke: DarkGray; thickness: 1px;'
84+
data-idd-xaxis='bottom_axis3' data-idd-yaxis='left_axis3'></div>
85+
86+
<div data-idd-plot="polyline" data-idd-style="stroke: red; thickness: 3" id="red line">
87+
x y
88+
0 0
89+
1 1
90+
2 2
91+
</div>
92+
<div data-idd-plot="polyline" data-idd-style="stroke: green; thickness: 3" id="green line">
93+
x y
94+
0 1
95+
1 0
96+
2 2
97+
</div>
98+
99+
<div id="bottom_axis3" data-idd-axis="numeric" data-idd-placement="bottom" style="position: relative;"></div>
100+
<div id="left_axis3" data-idd-axis="numeric" data-idd-placement="left" style="position: relative;"></div>
101+
</div>
102+
79103
</div>
80104

81105

src/idd/idd.base.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
280280

281281
var _plotRect;
282282

283+
// reading property overrides from attributes
284+
// Note: data-idd-visible-region attribute is handled at the end of the constructor, as it needs more plot objects to be defined and valid
283285
if (div) {
284286
_name = div.attr("data-idd-name") || div.attr("id") || "";
285287
if(div.attr("data-idd-ignored-by-fit-to-view")) {
@@ -1290,6 +1292,34 @@ var _initializeInteractiveDataDisplay = function () { // determines settings dep
12901292
}
12911293
};
12921294

1295+
if(div) {
1296+
if(div.attr("data-idd-visible-region")) {
1297+
var regionStr = div.attr("data-idd-visible-region")
1298+
div.removeAttr("data-idd-ignored-by-fit-to-view")
1299+
var values = regionStr.split(' ')
1300+
if(values.length != 4)
1301+
throw "data-idd-visible-region must contain exactly 4 numbers (xmin,xmax,ymin,ymax) separated by single space"
1302+
var xmin = Number(values[0])
1303+
var xmax = Number(values[1])
1304+
var ymin = Number(values[2])
1305+
var ymax = Number(values[3])
1306+
if(xmin>xmax)
1307+
throw "data-idd-visible-region attribute: xmax is less than xmin"
1308+
if(ymin>ymax)
1309+
throw "data-idd-visible-region attribute: ymax is less than ymin"
1310+
1311+
var dataToPlotX = this.xDataTransform && this.xDataTransform.dataToPlot;
1312+
var dataToPlotY = this.yDataTransform && this.yDataTransform.dataToPlot;
1313+
1314+
var plotXmin = dataToPlotX ? dataToPlotX(xmin) : xmin
1315+
var plotXmax = dataToPlotX ? dataToPlotX(xmax) : xmax
1316+
var plotYmin = dataToPlotY ? dataToPlotY(ymin) : ymin
1317+
var plotYmax = dataToPlotY ? dataToPlotY(ymax) : ymax
1318+
var plotRect = {x:plotXmin, width: plotXmax - plotXmin, y:plotYmin, height: plotYmax - plotYmin}
1319+
setVisibleRegion(plotRect) // this call will disable fit to view
1320+
}
1321+
}
1322+
12931323
//Disables IsAutoFitEnabled and fits all visible objects into screen with padding
12941324
this.fitToView = function () {
12951325
if (!_isMaster) {

0 commit comments

Comments
 (0)