Skip to content

Commit

Permalink
Release 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed May 8, 2019
1 parent c2eb933 commit 37465c0
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "chartjs-chart-matrix",
"description": "Chart.js module for creating matrix charts",
"homepage": "https://github.com/kurkle/chartjs-chart-matrix#readme",
"license": "MIT",
"version": "0.1.1",
"main": "dist/chartjs-chart-matrix.js"
}
148 changes: 148 additions & 0 deletions dist/chartjs-chart-matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*!
* chartjs-chart-matrix v0.1.1
* https://github.com/kurkle/chartjs-chart-matrix#readme
* (c) 2019 Jukka Kurkela
* Released under the MIT license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js')) :
typeof define === 'function' && define.amd ? define(['chart.js'], factory) :
(global = global || self, factory(global.Chart));
}(this, function (Chart) { 'use strict';

Chart = Chart && Chart.hasOwnProperty('default') ? Chart['default'] : Chart;

var resolve = Chart.helpers.options.resolve;

var Controller = Chart.DatasetController.extend({

dataElementType: Chart.elements.Rectangle,

update: function(reset) {
var me = this;
var meta = me.getMeta();
var data = meta.data || [];
var i, ilen;

me._xScale = me.getScaleForId(meta.xAxisID);
me._yScale = me.getScaleForId(meta.yAxisID);

for (i = 0, ilen = data.length; i < ilen; ++i) {
me.updateElement(data[i], i, reset);
}
},

updateElement: function(item, index, reset) {
var me = this;
var dataset = me.getDataset();
var datasetIndex = me.index;
var value = dataset.data[index];
var xScale = me._xScale;
var yScale = me._yScale;
var options = me._resolveElementOptions(item, index);
var x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(value, index, datasetIndex);
var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(value, index, datasetIndex);
var h = options.height;
var w = options.width;
var halfH = h / 2;

item._xScale = xScale;
item._yScale = yScale;
item._options = options;
item._datasetIndex = datasetIndex;
item._index = index;

item._model = {
x: x,
base: y - halfH,
y: y + halfH,
width: w,
height: h,
backgroundColor: options.backgroundColor,
borderColor: options.borderColor,
borderSkipped: options.borderSkipped,
borderWidth: options.borderWidth
};

item.pivot();
},

draw: function() {
var me = this;
var data = me.getMeta().data || [];
var i, ilen;

for (i = 0, ilen = data.length; i < ilen; ++i) {
data[i].draw();
}
},

/**
* @private
*/
_resolveElementOptions: function(rectangle, index) {
var me = this;
var chart = me.chart;
var datasets = chart.data.datasets;
var dataset = datasets[me.index];
var options = chart.options.elements.rectangle;
var values = {};
var i, ilen, key;

// Scriptable options
var context = {
chart: chart,
dataIndex: index,
dataset: dataset,
datasetIndex: me.index
};

var keys = [
'backgroundColor',
'borderColor',
'borderSkipped',
'borderWidth',
'width',
'height'
];

for (i = 0, ilen = keys.length; i < ilen; ++i) {
key = keys[i];
values[key] = resolve([
dataset[key],
options[key]
], context, index);
}

return values;
}

});

Chart.controllers.matrix = Controller;
Chart.defaults.matrix = {
hover: {
mode: 'nearest',
intersect: true
},
tooltips: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
type: 'linear'
}],
yAxes: [{
type: 'linear'
}]
},
elements: {
rectangle: {
width: 20,
height: 20
}
}
};

}));
7 changes: 7 additions & 0 deletions dist/chartjs-chart-matrix.min.js

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

0 comments on commit 37465c0

Please sign in to comment.