Skip to content

Commit

Permalink
Made all options external
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkiernander committed Feb 21, 2016
1 parent dda1e35 commit 3c77ba7
Show file tree
Hide file tree
Showing 45 changed files with 633 additions and 604 deletions.
374 changes: 192 additions & 182 deletions dist/scrollgrid.latest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scrollgrid.latest.min.js

Large diffs are not rendered by default.

374 changes: 192 additions & 182 deletions dist/scrollgrid.v0.1.12.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scrollgrid.v0.1.12.min.js

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions src/external/data.js
Expand Up @@ -5,7 +5,8 @@
Scrollgrid.prototype.data = function (data) {
"use strict";

var int = this.internal,
var self = this,
int = self.internal,
sizes = int.sizes,
physical = sizes.physical,
virtual = sizes.virtual,
Expand All @@ -16,32 +17,32 @@ Scrollgrid.prototype.data = function (data) {

// If the dataAdapter is an array, treat it as the data itself and instantiate with the default adapter
if (Object.prototype.toString.call(data) === '[object Array]') {
this.adapter = Scrollgrid.adapters.simple(data);
self.adapter = Scrollgrid.adapters.simple(data);
} else {
this.adapter = data;
self.adapter = data;
}
virtual.outerHeight = this.adapter.rowCount();
virtual.outerWidth = this.adapter.columnCount();
virtual.outerHeight = self.adapter.rowCount();
virtual.outerWidth = self.adapter.columnCount();

// Set up the columns
physical.initialiseColumns.call(this);
physical.initialiseColumns.call(self);

// If any of the columns have a sort it should be applied
for (c = 0; c < this.columns.length; c += 1) {
if (this.columns[c].sort === 'asc' || this.columns[c].sort === 'desc') {
interaction.sortColumn.call(this, c, false);
for (c = 0; c < self.columns.length; c += 1) {
if (self.columns[c].sort === 'asc' || self.columns[c].sort === 'desc') {
interaction.sortColumn.call(self, c, false);
}
}

// Calculate the bounds of the data displayable in the main grid
virtual.innerWidth = virtual.outerWidth - virtual.left - virtual.right;
virtual.innerHeight = virtual.outerHeight - virtual.top - virtual.bottom;
virtual.innerWidth = virtual.outerWidth - self.headerColumns - self.footerColumns;
virtual.innerHeight = virtual.outerHeight - self.headerRows - self.footerRows;

// Render the control
this.refresh(false);
self.refresh(false);

}

return this.adapter;
return self.adapter;

};
9 changes: 5 additions & 4 deletions src/external/refresh.js
Expand Up @@ -5,13 +5,14 @@
Scrollgrid.prototype.refresh = function (maintainCache) {
"use strict";

var int = this.internal,
var self = this,
int = self.internal,
render = int.render,
dom = int.dom;

// Call the instantiated layout refresh
dom.layoutDOM.call(this);
render.draw.call(this, !maintainCache);
dom.setScrollerSize.call(this);
dom.layoutDOM.call(self);
render.draw.call(self, !maintainCache);
dom.setScrollerSize.call(self);

};
54 changes: 25 additions & 29 deletions src/init.js
Expand Up @@ -35,13 +35,10 @@
// License: "https://github.com/PMSI-AlignAlytics/scrollgrid/blob/master/MIT-LICENSE.txt"
var Scrollgrid = function (options) {

var int = this.internal,
sizes = int.sizes,
interaction = int.interaction,
var self = this,
int = self.internal,
render = int.render,
dom = int.dom,
virtual = sizes.virtual,
physical = sizes.physical;
dom = int.dom;

options = options || {};

Expand All @@ -55,48 +52,47 @@
} else {

// Set the display options
this.rowHeight = physical.rowHeight = options.rowHeight || 30;
this.dragHandleWidth = physical.dragHandleWidth = options.dragHandleWidth || 8;
this.headerRowHeight = physical.headerRowHeight = options.headerRowHeight || physical.rowHeight;
this.footerRowHeight = physical.footerRowHeight = options.footerRowHeight || physical.rowHeight;
this.defaultColumnWidth = physical.defaultColumnWidth = options.defaultColumnWidth || 100;
this.cellPadding = physical.cellPadding = options.cellPadding || 6;
this.verticalAlignment = physical.verticalAlignment = options.verticalAlignment || 'top';
self.rowHeight = options.rowHeight || 30;
self.dragHandleWidth = options.dragHandleWidth || 8;
self.headerRowHeight = options.headerRowHeight || self.rowHeight;
self.footerRowHeight = options.footerRowHeight || self.rowHeight;
self.defaultColumnWidth = options.defaultColumnWidth || 100;
self.cellPadding = options.cellPadding || 6;
self.verticalAlignment = options.verticalAlignment || 'top';

// Set the interaction options
this.allowColumnResizing = interaction.allowColumnResizing = options.allowColumnResizing || true;
this.allowSorting = interaction.allowSorting = options.allowSorting || true;
self.allowColumnResizing = options.allowColumnResizing || true;
self.allowSorting = options.allowSorting || true;

// Set the number of header or footer rows or columns
this.headerRows = virtual.top = options.headerRows || 0;
this.footerRows = virtual.bottom = options.footerRows || 0;
this.headerColumns = virtual.left = options.headerColumns || 0;
this.footerColumns = virtual.right = options.footerColumns || 0;
self.headerRows = options.headerRows || 0;
self.footerRows = options.footerRows || 0;
self.headerColumns = options.headerColumns || 0;
self.footerColumns = options.footerColumns || 0;

// Set a reference to the parent object
this.target = options.target;
self.target = options.target;

render.setDefaultStyles.call(this);
this.formatRules = render.formatRules = options.formatRules || [];
this.cellWaitText = render.cellWaitText = options.cellWaitText || "loading...";
this.sortIconSize = render.sortIconSize = options.sortIconSize || 7;
render.setDefaultStyles.call(self);
self.formatRules = options.formatRules || [];
self.cellWaitText = options.cellWaitText || "loading...";
self.sortIconSize = options.sortIconSize || 7;

// Create the DOM shapes required
dom.populateDOM.call(this);
dom.populateDOM.call(self);

// Pass the data or adapter through to setData
this.data(options.data || options.adapter);
self.data(options.data || options.adapter);

if (options.autoResize) {
dom.setAutoResize.call(this);
dom.setAutoResize.call(self);
}
}
};

Scrollgrid.init = function (target, options) {
options.target = target;
var scrollgrid = new Scrollgrid(options);
return scrollgrid;
return new Scrollgrid(options);
};

// Build namespaces
Expand Down
8 changes: 3 additions & 5 deletions src/internal/dom/getTopMargin.js
Expand Up @@ -5,17 +5,15 @@
Scrollgrid.prototype.internal.dom.getTopMargin = function (containerSize, parent) {
"use strict";

var int = this.internal,
sizes = int.sizes,
physical = sizes.physical,
var self = this,
topMargin = 0,
parentHeight;

if (containerSize && containerSize.height && parent) {
parentHeight = parent.node().offsetHeight;
if (physical.verticalAlignment === 'middle') {
if (self.verticalAlignment === 'middle') {
topMargin = ((parentHeight - containerSize.height) / 2);
} else if (physical.verticalAlignment === 'bottom') {
} else if (self.verticalAlignment === 'bottom') {
topMargin = parentHeight - containerSize.height - 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/internal/dom/layoutDOM.js
Expand Up @@ -46,14 +46,14 @@ Scrollgrid.prototype.internal.dom.layoutDOM = function (fixedSize) {
dom.setRelativePosition.call(self, dom.main.viewport, physical.left, physical.visibleInnerWidth, physical.visibleInnerHeight, 'auto');
dom.setAbsolutePosition.call(self, dom.right.svg, physical.left + physical.visibleInnerWidth, physical.top + topMargin, physical.right, physical.visibleInnerHeight);
dom.setRelativePosition.call(self, dom.bottom.svg, physical.left, physical.visibleInnerWidth, physical.bottom, 'hidden');
dom.setAbsolutePosition.call(self, dom.top.left.svg, 0, topMargin, physical.left + physical.dragHandleWidth / 2, physical.top);
dom.setAbsolutePosition.call(self, dom.top.right.svg, physical.left + physical.visibleInnerWidth - physical.dragHandleWidth / 2, topMargin, physical.right + physical.dragHandleWidth / 2, physical.top);
dom.setAbsolutePosition.call(self, dom.top.left.svg, 0, topMargin, physical.left + self.dragHandleWidth / 2, physical.top);
dom.setAbsolutePosition.call(self, dom.top.right.svg, physical.left + physical.visibleInnerWidth - self.dragHandleWidth / 2, topMargin, physical.right + self.dragHandleWidth / 2, physical.top);
dom.setAbsolutePosition.call(self, dom.bottom.left.svg, 0, physical.top + physical.visibleInnerHeight + topMargin, physical.left, physical.bottom);
dom.setAbsolutePosition.call(self, dom.bottom.right.svg, physical.left + physical.visibleInnerWidth, physical.top + physical.visibleInnerHeight + topMargin, physical.right, physical.bottom);
dom.setAbsolutePosition.call(self, dom.main.svg, physical.left, physical.top + topMargin, physical.visibleInnerWidth, physical.visibleInnerHeight);

// Top right panel needs a small offset for the handle
dom.top.right.transform.attr('transform', 'translate(' + physical.dragHandleWidth / 2 + ', 0)');
dom.top.right.transform.attr('transform', 'translate(' + self.dragHandleWidth / 2 + ', 0)');

// Invoke draw on scroll
dom.main.viewport.on('scroll', function () { render.draw.call(self, false); });
Expand Down
25 changes: 13 additions & 12 deletions src/internal/dom/populateDOM.js
Expand Up @@ -5,29 +5,30 @@
Scrollgrid.prototype.internal.dom.populateDOM = function () {
"use strict";

var int = this.internal,
style = this.style,
var self = this,
int = self.internal,
style = self.style,
dom = int.dom;

// Get the parent container
dom.parent = d3.select(this.target);
dom.parent = d3.select(self.target);
// Add a container to the target which will house everything
dom.container = dom.parent.append('div');

// Populate the 5 regions of the control
dom.left = dom.populatePanel.call(this, style.left.panel);
dom.top = dom.populatePanel.call(this, style.top.panel);
dom.top.left = dom.populatePanel.call(this, style.top.left.panel);
dom.top.right = dom.populatePanel.call(this, style.top.right.panel);
dom.main = dom.populatePanel.call(this, style.main.panel);
dom.left = dom.populatePanel.call(self, style.left.panel);
dom.top = dom.populatePanel.call(self, style.top.panel);
dom.top.left = dom.populatePanel.call(self, style.top.left.panel);
dom.top.right = dom.populatePanel.call(self, style.top.right.panel);
dom.main = dom.populatePanel.call(self, style.main.panel);

// Add the viewport which is the fixed area with scroll bars
dom.main.viewport = dom.container.append('div');

dom.right = dom.populatePanel.call(this, style.right.panel);
dom.bottom = dom.populatePanel.call(this, style.bottom.panel);
dom.bottom.left = dom.populatePanel.call(this, style.bottom.left.panel);
dom.bottom.right = dom.populatePanel.call(this, style.bottom.right.panel);
dom.right = dom.populatePanel.call(self, style.right.panel);
dom.bottom = dom.populatePanel.call(self, style.bottom.panel);
dom.bottom.left = dom.populatePanel.call(self, style.bottom.left.panel);
dom.bottom.right = dom.populatePanel.call(self, style.bottom.right.panel);

// The scroller is going to be as large as the virtual size of
// the data (as if it had all been rendered) this is so that
Expand Down
3 changes: 2 additions & 1 deletion src/internal/dom/populatePanel.js
Expand Up @@ -5,7 +5,8 @@
Scrollgrid.prototype.internal.dom.populatePanel = function (css) {
"use strict";

var dom = this.internal.dom,
var self = this,
dom = self.internal.dom,
panel = {};

panel.svg = dom.container.append('svg');
Expand Down
3 changes: 2 additions & 1 deletion src/internal/dom/setScrollerSize.js
Expand Up @@ -5,7 +5,8 @@
Scrollgrid.prototype.internal.dom.setScrollerSize = function () {
"use strict";

var int = this.internal,
var self = this,
int = self.internal,
dom = int.dom,
sizes = int.sizes,
physical = sizes.physical;
Expand Down
6 changes: 3 additions & 3 deletions src/internal/interaction/addResizeHandles.js
Expand Up @@ -19,18 +19,18 @@ Scrollgrid.prototype.internal.interaction.addResizeHandles = function (target, b

target.content
.selectAll(".sg-no-style--handle-selector")
.data(this.columns.slice(bounds.left, bounds.right))
.data(self.columns.slice(bounds.left, bounds.right))
.enter()
.append("rect")
.attr("class", "sg-no-style--handle-selector " + style.resizeHandle)
.attr("transform", "translate(" + (-1 * physical.dragHandleWidth / 2) + ", 0)")
.attr("transform", "translate(" + (-1 * self.dragHandleWidth / 2) + ", 0)")
.attr("x", function (c) {
runningTotal += c.width;
c.x = runningTotal;
return c.x;
})
.attr("y", 0)
.attr("width", physical.dragHandleWidth)
.attr("width", self.dragHandleWidth)
.attr("height", physical.top)
.on("dblclick", function (c) { interaction.autoResizeColumn.call(self, c); })
.call(interaction.getColumnResizer.call(self));
Expand Down
7 changes: 4 additions & 3 deletions src/internal/interaction/autoResizeColumn.js
Expand Up @@ -5,7 +5,8 @@
Scrollgrid.prototype.internal.interaction.autoResizeColumn = function (column) {
"use strict";

var int = this.internal,
var self = this,
int = self.internal,
dom = int.dom,
sizes = int.sizes,
panels = [dom.top.left, dom.top, dom.top.right, dom.left, dom.main, dom.right, dom.bottom.left, dom.bottom, dom.bottom.right],
Expand All @@ -16,10 +17,10 @@ Scrollgrid.prototype.internal.interaction.autoResizeColumn = function (column) {

// Get the widest from the various panels (some panels may not apply to the given cell but those panels will return zero anyway)
for (i = 0; i < panels.length; i += 1) {
column.width = Math.max(column.width, sizes.getExistingTextBound.call(this, panels[i].svg, column.index).width);
column.width = Math.ceil(Math.max(column.width, sizes.getExistingTextBound.call(self, panels[i].svg, column.index).width));
}

// Update the container size because the width will have changed
this.refresh(true);
self.refresh(true);

};
4 changes: 3 additions & 1 deletion src/internal/interaction/columnResizing.js
Expand Up @@ -5,6 +5,8 @@
Scrollgrid.prototype.internal.interaction.columnResizing = function (shape, column) {
"use strict";

var self = this;

// Some resize handle should be inverted
column.width -= column.x - d3.event.x;

Expand All @@ -20,6 +22,6 @@ Scrollgrid.prototype.internal.interaction.columnResizing = function (shape, colu
shape.attr('x', column.x);

// Redraw
this.refresh(true);
self.refresh(true);

};
6 changes: 3 additions & 3 deletions src/internal/interaction/getColumnResizer.js
Expand Up @@ -5,9 +5,9 @@
Scrollgrid.prototype.internal.interaction.getColumnResizer = function () {
"use strict";

var int = this.internal,
interaction = int.interaction,
self = this;
var self = this,
int = self.internal,
interaction = int.interaction;

return d3.behavior.drag()
.origin(function (c) { return c; })
Expand Down
15 changes: 7 additions & 8 deletions src/internal/interaction/sortColumn.js
Expand Up @@ -5,23 +5,22 @@
Scrollgrid.prototype.internal.interaction.sortColumn = function (index, toggle) {
"use strict";

var int = this.internal,
var self = this,
int = self.internal,
interaction = int.interaction,
sizes = int.sizes,
virtual = sizes.virtual,
c;

// Clear existing sorts and set the new one
for (c = 0; c < this.columns.length; c += 1) {
for (c = 0; c < self.columns.length; c += 1) {
if (c !== index) {
delete this.columns[c].sort;
delete self.columns[c].sort;
} else if (toggle) {
this.columns[c].sort = (this.columns[c].sort === 'desc' ? 'asc' : 'desc');
self.columns[c].sort = (self.columns[c].sort === 'desc' ? 'asc' : 'desc');
}
}

// Instruct the adapter to perform a sort
this.adapter.sort(index, virtual.top, virtual.bottom, this.columns[index].sort === 'desc', this.columns[index].compareFunction || interaction.defaultComparer);
this.refresh(false);
self.adapter.sort(index, self.headerRows, self.footerRows, self.columns[index].sort === 'desc', self.columns[index].compareFunction || interaction.defaultComparer);
self.refresh(false);

};
4 changes: 3 additions & 1 deletion src/internal/raise.js
Expand Up @@ -5,7 +5,9 @@
Scrollgrid.prototype.internal.raise = function (err) {
"use strict";

var log = this.reporter || console;
var self = this,
log = self.reporter || console;

if (log && log.error) {
log.error(err);
} else {
Expand Down

0 comments on commit 3c77ba7

Please sign in to comment.