Skip to content

Commit

Permalink
Merge pull request #707 from fin-hypergrid/develop
Browse files Browse the repository at this point in the history
Merge develop (2.1.6) to master
  • Loading branch information
joneit authored Mar 22, 2018
2 parents 200b3bb + e99df2d commit 6161e8d
Show file tree
Hide file tree
Showing 29 changed files with 810 additions and 591 deletions.
5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/doc
/html/*.html
/images/**
!/images/index.js
!/images/images.js
/jsdoc-template-hypergrid
/src/jsdoc
Expand All @@ -18,10 +17,12 @@
/*.sh
/*.md

*.index.js
index.js
!/index.js
!/css/index.js
!/images/index.js
!/src/cellRenderers/index.js
!/src/cellEditors/index.js
!/src/dataModels/index.js
!/src/renderer/index.js
!/src/features/index.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ It also highlights a DOM-based custom external editor triggered via hypergrid ev
* [Roadmap](#roadmap)
* [Contributing](#contributors)

### Current Release (2.1.5 - 6 March 2018)
### Current Release (2.1.6 - 16 March 2018)

**Hypergrid 2.1.5** includes bug fixes.
**Hypergrid 2.1.6** includes bug fixes.

_For a complete list of changes, see the [release notes](https://github.com/fin-hypergrid/core/releases)._

Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</head>
<body>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.5 dev testbench</h1>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.6 dev testbench</h1>

<div id="tabs">
<div id="tab-dashboard">Dashboard</div>
Expand Down
18 changes: 13 additions & 5 deletions demo/js/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ window.onload = function() {
// convert field names containing underscore to camel case by overriding column enum decorator
Hypergrid.behaviors.JSON.prototype.columnEnumKey = Hypergrid.behaviors.JSON.columnEnumDecorators.toCamelCase;

var schema = Hypergrid.lib.fields.getSchema(people1);

// as of v2.1.6, column properties can also be initialized from custom schema (as well as from a grid state object).
// The following demonstrates this. Note that demo/setState.js also sets props of 'height' column. The setState
// call therein was changed to addState to accommodate (else schema props defined here would have been cleared).
Object.assign(schema.find(function(columnSchema) { return columnSchema.name === 'height'; }), {
halign: 'right',
// format: 'foot' --- for demo purposes, this prop being set in setState.js (see)
});

var gridOptions = {
data: people1,
margin: { bottom: '17px', right: '17px'},
schema: Hypergrid.lib.fields.getSchema(people1),
schema: schema,
plugins: require('fin-hypergrid-event-logger'),
state: { color: 'orange' }
},
Expand All @@ -45,11 +55,9 @@ window.onload = function() {
console.log('Indexes:'); console.dir(idx);

function setData(data, options) {
options = !data.length ? undefined : options || {
schema: Hypergrid.lib.fields.getSchema(data)
};
options = Object.assign({}, options);
options.schema = options.schema || [];
grid.setData(data, options);
behavior.reindex();
}

function reset() {
Expand Down
14 changes: 12 additions & 2 deletions demo/js/demo/setState.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,19 @@ module.exports = function(demo, grid) {
Add10: 'function(dataRow,columnName) { return dataRow[columnName] + 10; }'
},

// ANTI-PATTERNS FOLLOW
//
// Setting column, row, cell props here in a state object is a legacy feature.
// Developers may find it more useful to set column props in column schema (as of v2.1.6),
// row props in row metadata (as of v2.1.0), and cell props in column metadata (as of v2.0.2),
// which would then persist across setState calls which clear these properties objects
// before applying new values. In this demo, we have changed the setState call below to addState
// (which does not clear the properties object first) to show how to set a column prop here *and*
// a different prop on the same column in schema (in index.js).

columns: {
height: {
halign: 'right',
// halign: 'right', --- for demo purposes, this prop being set in index.js (see)
format: 'foot'
},

Expand Down Expand Up @@ -144,7 +154,7 @@ module.exports = function(demo, grid) {
}
};

grid.setState(state);
grid.addState(state); // changed from setState so 'height' props set with schema in index.js wouldn't be cleared

grid.takeFocus();

Expand Down
2 changes: 1 addition & 1 deletion demo/multiple-grids.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<style> body > div.hypergrid-container { width: 415px; margin-right: 10px; display: inline-block }</style>
</head>
<body>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.5 multiple grids demo</h1>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.6 multiple grids demo</h1>

<script src="build/fin-hypergrid.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion demo/row-props.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</style>
</head>
<body>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.5 performance workbench</h1>
<h1 style="margin:.5em; color:lightgrey">Hypergrid 2.1.6 performance workbench</h1>

<div id="controls" class="nowrap">
<label id="controller" title="Uncheck to hide other controls.">
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fin-hypergrid",
"version": "2.1.5",
"version": "2.1.6",
"description": "Canvas-based high-performance grid",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,7 @@
],
"dependencies": {
"chai": "^3.5.0",
"extend-me": "^2.3",
"extend-me": "^2.7.0",
"fin-hypergrid-data-source-base": "^0.4.10",
"fin-hypergrid-event-logger": "^1.0.3",
"finbars": "1.5.2",
Expand All @@ -25,7 +25,8 @@
"object-iterators": "1.3.0",
"overrider": "^0",
"rectangular": "1.0.1",
"sparse-boolean-array": "1.0.1"
"sparse-boolean-array": "1.0.1",
"synonomous": "^1.0.1"
},
"devDependencies": {
"browser-sync": "^2.10.0",
Expand Down
55 changes: 44 additions & 11 deletions src/Hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var SelectionModel = require('./lib/SelectionModel');
var Localization = require('./lib/Localization');
var Behavior = require('./behaviors/Behavior');
var behaviorJSON = require('./behaviors/JSON');
var CellRenderers = require('./cellRenderers');
var CellEditors = require('./cellEditors');
var cellRenderers = require('./cellRenderers');
var cellEditors = require('./cellEditors');

var EDGE_STYLES = ['top', 'bottom', 'left', 'right'],
RECT_STYLES = EDGE_STYLES.concat(['width', 'height', 'position']);
Expand Down Expand Up @@ -109,17 +109,19 @@ var Hypergrid = Base.extend('Hypergrid', {

/**
* @name cellRenderers
* @type {CellRenderer}
* @type {Registry}
* @memberOf Hypergrid#
*/
this.cellRenderers = new CellRenderers();
this.cellRenderers = cellRenderers;

/**
* Private version of cell editors registry with a bound `create` method for use by `getCellEditorAt`.
* @name cellEditors
* @type {CellEditor}
* @type {Registry}
* @memberOf Hypergrid#
*/
this.cellEditors = new CellEditors({ grid: this });
this.cellEditors = Object.create(cellEditors);
Object.defineProperty(this.cellEditors, 'create', { value: createCellEditor.bind(this) });

this.initCanvas();

Expand Down Expand Up @@ -302,7 +304,7 @@ var Hypergrid = Base.extend('Hypergrid', {
var: { value: new Var() }
});

// For all all default props of object type, if a dynamic prop, invoke setter; else deep clone it so changes
// For all default props of object type, if a dynamic prop, invoke setter; else deep clone it so changes
// made to inner props won't go to object on theme or defaults layers which are shared by other instances.
Object.keys(defaults).forEach(function(key) {
var value = defaults[key];
Expand Down Expand Up @@ -609,7 +611,16 @@ var Hypergrid = Base.extend('Hypergrid', {
* @see [Memento pattern](http://en.wikipedia.org/wiki/Memento_pattern)
*/
setState: function(state) {
this.behavior.setState(state);
this.addState(state, true);
},

/**
* @memberOf Hypergrid#
* @desc Add to the state object.
* @param {object} state
*/
addState: function(state, settingState) {
this.behavior.addState(state, settingState);
this.refreshProperties();
this.behaviorChanged();
},
Expand All @@ -636,7 +647,10 @@ var Hypergrid = Base.extend('Hypergrid', {

var space = options.space === undefined ? '\t' : options.space,
properties = this.properties,
calculators = properties.calculators;
calculators = properties.calculators,
blacklist = options.blacklist = options.blacklist || [];

blacklist.push('columnProperties'); // Never output this synonym of 'columns'

if (calculators) {
if (options.compact) {
Expand All @@ -654,8 +668,8 @@ var Hypergrid = Base.extend('Hypergrid', {
this.headerify = options.headerify;

var json = JSON.stringify(properties, function(key, value) {
if (options.blacklist && this === properties && options.blacklist.indexOf(key) >= 0) {
value = undefined;
if (this === properties && options.blacklist.indexOf(key) >= 0) {
value = undefined; // JSON.stringify ignores undefined props
} else if (key === 'calculator') {
if (calculators) {
// convert function reference to registry key
Expand Down Expand Up @@ -828,6 +842,13 @@ var Hypergrid = Base.extend('Hypergrid', {
this.renderer.setInfo(messages);
},

/**
* @memberOf Behavior#
*/
reindex: function() {
this.needsReindex = this.needsShapeChanged = true;
},

/**
* @memberOf Hypergrid#
* @summary _(See {@link Hypergrid.prototype#setData}.)_
Expand Down Expand Up @@ -889,6 +910,11 @@ var Hypergrid = Base.extend('Hypergrid', {
* Called from renderer/index.js
*/
deferredBehaviorChange: function() {
if (this.needsReindex) {
this.behavior.reindex();
this.needsReindex = false;
}

if (this.needsShapeChanged) {
if (this.divCanvas) {
this.synchronizeScrollingBoundaries(); // calls computeCellsBounds and repaint (state change)
Expand Down Expand Up @@ -1946,6 +1972,13 @@ function deepClone(object) {
return result;
}

function createCellEditor(name, props) {
var CellEditor = cellEditors.get(name);
if (CellEditor) {
return new CellEditor(this, props);
}
}

/**
* @name plugins
* @memberOf Hypergrid
Expand Down
Loading

0 comments on commit 6161e8d

Please sign in to comment.