heatmap overlay, add unbind events function
This commit is contained in:
parent
73cffb4396
commit
98e5280888
62
dist/frappe-charts.esm.js
vendored
62
dist/frappe-charts.esm.js
vendored
@ -230,10 +230,10 @@ const DEFAULT_CHAR_WIDTH = 7;
|
|||||||
const ANGLE_RATIO = Math.PI / 180;
|
const ANGLE_RATIO = Math.PI / 180;
|
||||||
const FULL_ANGLE = 360;
|
const FULL_ANGLE = 360;
|
||||||
|
|
||||||
/**
|
// Fixed 5-color theme,
|
||||||
* Returns the value of a number upto 2 decimal places.
|
// More colors are difficult to parse visually
|
||||||
* @param {Number} d Any number
|
const HEATMAP_DISTRIBUTION_SIZE = 5;
|
||||||
*/
|
|
||||||
function floatTwo(d) {
|
function floatTwo(d) {
|
||||||
return parseFloat(d.toFixed(2));
|
return parseFloat(d.toFixed(2));
|
||||||
}
|
}
|
||||||
@ -792,6 +792,25 @@ let makeOverlay = {
|
|||||||
overlay.setAttribute('fill', fill);
|
overlay.setAttribute('fill', fill);
|
||||||
overlay.style.opacity = '0.6';
|
overlay.style.opacity = '0.6';
|
||||||
|
|
||||||
|
if(transformValue) {
|
||||||
|
overlay.setAttribute('transform', transformValue);
|
||||||
|
}
|
||||||
|
return overlay;
|
||||||
|
},
|
||||||
|
|
||||||
|
'heat_square': (unit) => {
|
||||||
|
let transformValue;
|
||||||
|
if(unit.nodeName !== 'circle') {
|
||||||
|
transformValue = unit.getAttribute('transform');
|
||||||
|
unit = unit.childNodes[0];
|
||||||
|
}
|
||||||
|
let overlay = unit.cloneNode();
|
||||||
|
let radius = unit.getAttribute('r');
|
||||||
|
let fill = unit.getAttribute('fill');
|
||||||
|
overlay.setAttribute('r', parseInt(radius) + DOT_OVERLAY_SIZE_INCR);
|
||||||
|
overlay.setAttribute('fill', fill);
|
||||||
|
overlay.style.opacity = '0.6';
|
||||||
|
|
||||||
if(transformValue) {
|
if(transformValue) {
|
||||||
overlay.setAttribute('transform', transformValue);
|
overlay.setAttribute('transform', transformValue);
|
||||||
}
|
}
|
||||||
@ -834,7 +853,25 @@ let updateOverlay = {
|
|||||||
if(transformValue) {
|
if(transformValue) {
|
||||||
overlay.setAttribute('transform', transformValue);
|
overlay.setAttribute('transform', transformValue);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
'heat_square': (unit, overlay) => {
|
||||||
|
let transformValue;
|
||||||
|
if(unit.nodeName !== 'circle') {
|
||||||
|
transformValue = unit.getAttribute('transform');
|
||||||
|
unit = unit.childNodes[0];
|
||||||
|
}
|
||||||
|
let attributes = ['cx', 'cy'];
|
||||||
|
Object.values(unit.attributes)
|
||||||
|
.filter(attr => attributes.includes(attr.name) && attr.specified)
|
||||||
|
.map(attr => {
|
||||||
|
overlay.setAttribute(attr.name, attr.nodeValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(transformValue) {
|
||||||
|
overlay.setAttribute('transform', transformValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const PRESET_COLOR_MAP = {
|
const PRESET_COLOR_MAP = {
|
||||||
@ -1421,6 +1458,11 @@ class BaseChart {
|
|||||||
getDifferentChart(type) {
|
getDifferentChart(type) {
|
||||||
return getDifferentChart(type, this.type, this.parent, this.rawChartArgs);
|
return getDifferentChart(type, this.type, this.parent, this.rawChartArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unbindWindowEvents(){
|
||||||
|
window.removeEventListener('resize', () => this.draw(true));
|
||||||
|
window.removeEventListener('orientationchange', () => this.draw(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AggregationChart extends BaseChart {
|
class AggregationChart extends BaseChart {
|
||||||
@ -2332,11 +2374,8 @@ function getMaxCheckpoint(value, distribution) {
|
|||||||
class Heatmap extends BaseChart {
|
class Heatmap extends BaseChart {
|
||||||
constructor(parent, options) {
|
constructor(parent, options) {
|
||||||
super(parent, options);
|
super(parent, options);
|
||||||
|
|
||||||
this.type = 'heatmap';
|
this.type = 'heatmap';
|
||||||
|
|
||||||
this.domain = options.domain || '';
|
|
||||||
this.subdomain = options.subdomain || '';
|
|
||||||
this.data = options.data || {};
|
this.data = options.data || {};
|
||||||
this.discreteDomains = options.discreteDomains === 0 ? 0 : 1;
|
this.discreteDomains = options.discreteDomains === 0 ? 0 : 1;
|
||||||
this.countLabel = options.countLabel || '';
|
this.countLabel = options.countLabel || '';
|
||||||
@ -2349,10 +2388,6 @@ class Heatmap extends BaseChart {
|
|||||||
? legendColors
|
? legendColors
|
||||||
: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
|
: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
|
||||||
|
|
||||||
// Fixed 5-color theme,
|
|
||||||
// More colors are difficult to parse visually
|
|
||||||
this.distribution_size = 5;
|
|
||||||
|
|
||||||
this.translateX = 0;
|
this.translateX = 0;
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -2424,7 +2459,7 @@ class Heatmap extends BaseChart {
|
|||||||
calc() {
|
calc() {
|
||||||
|
|
||||||
let dataValues = Object.keys(this.data).map(key => this.data[key]);
|
let dataValues = Object.keys(this.data).map(key => this.data[key]);
|
||||||
this.distribution = calcDistribution(dataValues, this.distribution_size);
|
this.distribution = calcDistribution(dataValues, HEATMAP_DISTRIBUTION_SIZE);
|
||||||
|
|
||||||
this.monthNames = ["January", "February", "March", "April", "May", "June",
|
this.monthNames = ["January", "February", "March", "April", "May", "June",
|
||||||
"July", "August", "September", "October", "November", "December"
|
"July", "August", "September", "October", "November", "December"
|
||||||
@ -3256,7 +3291,6 @@ class AxisChart extends BaseChart {
|
|||||||
// removeDataPoint(index = 0) {}
|
// removeDataPoint(index = 0) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// import MultiAxisChart from './charts/MultiAxisChart';
|
|
||||||
const chartTypes = {
|
const chartTypes = {
|
||||||
// multiaxis: MultiAxisChart,
|
// multiaxis: MultiAxisChart,
|
||||||
percentage: PercentageChart,
|
percentage: PercentageChart,
|
||||||
|
|||||||
2
dist/frappe-charts.min.cjs.js
vendored
2
dist/frappe-charts.min.cjs.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-charts.min.esm.js
vendored
2
dist/frappe-charts.min.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-charts.min.iife.js
vendored
2
dist/frappe-charts.min.iife.js
vendored
File diff suppressed because one or more lines are too long
1
dist/frappe-charts.min.iife.js.map
vendored
1
dist/frappe-charts.min.iife.js.map
vendored
File diff suppressed because one or more lines are too long
2
docs/assets/js/frappe-charts.min.js
vendored
2
docs/assets/js/frappe-charts.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -438,6 +438,8 @@ events_chart.parent.addEventListener('data-select', (e) => {
|
|||||||
// Heatmap
|
// Heatmap
|
||||||
// ================================================================================
|
// ================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let heatmapData = {};
|
let heatmapData = {};
|
||||||
let current_date = new Date();
|
let current_date = new Date();
|
||||||
let timestamp = current_date.getTime()/1000;
|
let timestamp = current_date.getTime()/1000;
|
||||||
@ -447,7 +449,7 @@ for (var i = 0; i< 375; i++) {
|
|||||||
timestamp = Math.floor(timestamp - 86400).toFixed(1);
|
timestamp = Math.floor(timestamp - 86400).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
new frappe.Chart("#chart-heatmap", {
|
let heatmap = new frappe.Chart("#chart-heatmap", {
|
||||||
data: heatmapData,
|
data: heatmapData,
|
||||||
type: 'heatmap',
|
type: 'heatmap',
|
||||||
legendScale: [0, 1, 2, 4, 5],
|
legendScale: [0, 1, 2, 4, 5],
|
||||||
@ -456,7 +458,7 @@ new frappe.Chart("#chart-heatmap", {
|
|||||||
legendColors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c']
|
legendColors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c']
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log(heatmapData, heatmap);
|
console.log(heatmapData, heatmap);
|
||||||
|
|
||||||
Array.prototype.slice.call(
|
Array.prototype.slice.call(
|
||||||
document.querySelectorAll('.heatmap-mode-buttons button')
|
document.querySelectorAll('.heatmap-mode-buttons button')
|
||||||
|
|||||||
@ -279,4 +279,9 @@ export default class BaseChart {
|
|||||||
getDifferentChart(type) {
|
getDifferentChart(type) {
|
||||||
return getDifferentChart(type, this.type, this.parent, this.rawChartArgs);
|
return getDifferentChart(type, this.type, this.parent, this.rawChartArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unbindWindowEvents(){
|
||||||
|
window.removeEventListener('resize', () => this.draw(true));
|
||||||
|
window.removeEventListener('orientationchange', () => this.draw(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,15 +3,13 @@ import { makeSVGGroup, makeHeatSquare, makeText } from '../utils/draw';
|
|||||||
import { addDays, getDdMmYyyy, getWeeksBetween } from '../utils/date-utils';
|
import { addDays, getDdMmYyyy, getWeeksBetween } from '../utils/date-utils';
|
||||||
import { calcDistribution, getMaxCheckpoint } from '../utils/intervals';
|
import { calcDistribution, getMaxCheckpoint } from '../utils/intervals';
|
||||||
import { isValidColor } from '../utils/colors';
|
import { isValidColor } from '../utils/colors';
|
||||||
|
import { HEATMAP_DISTRIBUTION_SIZE } from '../utils/constants';
|
||||||
|
|
||||||
export default class Heatmap extends BaseChart {
|
export default class Heatmap extends BaseChart {
|
||||||
constructor(parent, options) {
|
constructor(parent, options) {
|
||||||
super(parent, options);
|
super(parent, options);
|
||||||
|
|
||||||
this.type = 'heatmap';
|
this.type = 'heatmap';
|
||||||
|
|
||||||
this.domain = options.domain || '';
|
|
||||||
this.subdomain = options.subdomain || '';
|
|
||||||
this.data = options.data || {};
|
this.data = options.data || {};
|
||||||
this.discreteDomains = options.discreteDomains === 0 ? 0 : 1;
|
this.discreteDomains = options.discreteDomains === 0 ? 0 : 1;
|
||||||
this.countLabel = options.countLabel || '';
|
this.countLabel = options.countLabel || '';
|
||||||
@ -24,10 +22,6 @@ export default class Heatmap extends BaseChart {
|
|||||||
? legendColors
|
? legendColors
|
||||||
: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
|
: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
|
||||||
|
|
||||||
// Fixed 5-color theme,
|
|
||||||
// More colors are difficult to parse visually
|
|
||||||
this.distribution_size = 5;
|
|
||||||
|
|
||||||
this.translateX = 0;
|
this.translateX = 0;
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -99,7 +93,7 @@ export default class Heatmap extends BaseChart {
|
|||||||
calc() {
|
calc() {
|
||||||
|
|
||||||
let dataValues = Object.keys(this.data).map(key => this.data[key]);
|
let dataValues = Object.keys(this.data).map(key => this.data[key]);
|
||||||
this.distribution = calcDistribution(dataValues, this.distribution_size);
|
this.distribution = calcDistribution(dataValues, HEATMAP_DISTRIBUTION_SIZE);
|
||||||
|
|
||||||
this.monthNames = ["January", "February", "March", "April", "May", "June",
|
this.monthNames = ["January", "February", "March", "April", "May", "June",
|
||||||
"July", "August", "September", "October", "November", "December"
|
"July", "August", "September", "October", "November", "December"
|
||||||
|
|||||||
@ -21,3 +21,7 @@ export const DEFAULT_CHAR_WIDTH = 7;
|
|||||||
// Universal constants
|
// Universal constants
|
||||||
export const ANGLE_RATIO = Math.PI / 180;
|
export const ANGLE_RATIO = Math.PI / 180;
|
||||||
export const FULL_ANGLE = 360;
|
export const FULL_ANGLE = 360;
|
||||||
|
|
||||||
|
// Fixed 5-color theme,
|
||||||
|
// More colors are difficult to parse visually
|
||||||
|
export const HEATMAP_DISTRIBUTION_SIZE = 5;
|
||||||
@ -490,6 +490,25 @@ export let makeOverlay = {
|
|||||||
overlay.setAttribute('fill', fill);
|
overlay.setAttribute('fill', fill);
|
||||||
overlay.style.opacity = '0.6';
|
overlay.style.opacity = '0.6';
|
||||||
|
|
||||||
|
if(transformValue) {
|
||||||
|
overlay.setAttribute('transform', transformValue);
|
||||||
|
}
|
||||||
|
return overlay;
|
||||||
|
},
|
||||||
|
|
||||||
|
'heat_square': (unit) => {
|
||||||
|
let transformValue;
|
||||||
|
if(unit.nodeName !== 'circle') {
|
||||||
|
transformValue = unit.getAttribute('transform');
|
||||||
|
unit = unit.childNodes[0];
|
||||||
|
}
|
||||||
|
let overlay = unit.cloneNode();
|
||||||
|
let radius = unit.getAttribute('r');
|
||||||
|
let fill = unit.getAttribute('fill');
|
||||||
|
overlay.setAttribute('r', parseInt(radius) + DOT_OVERLAY_SIZE_INCR);
|
||||||
|
overlay.setAttribute('fill', fill);
|
||||||
|
overlay.style.opacity = '0.6';
|
||||||
|
|
||||||
if(transformValue) {
|
if(transformValue) {
|
||||||
overlay.setAttribute('transform', transformValue);
|
overlay.setAttribute('transform', transformValue);
|
||||||
}
|
}
|
||||||
@ -532,5 +551,23 @@ export let updateOverlay = {
|
|||||||
if(transformValue) {
|
if(transformValue) {
|
||||||
overlay.setAttribute('transform', transformValue);
|
overlay.setAttribute('transform', transformValue);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
'heat_square': (unit, overlay) => {
|
||||||
|
let transformValue;
|
||||||
|
if(unit.nodeName !== 'circle') {
|
||||||
|
transformValue = unit.getAttribute('transform');
|
||||||
|
unit = unit.childNodes[0];
|
||||||
|
}
|
||||||
|
let attributes = ['cx', 'cy'];
|
||||||
|
Object.values(unit.attributes)
|
||||||
|
.filter(attr => attributes.includes(attr.name) && attr.specified)
|
||||||
|
.map(attr => {
|
||||||
|
overlay.setAttribute(attr.name, attr.nodeValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(transformValue) {
|
||||||
|
overlay.setAttribute('transform', transformValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user