[event-binding] chart.unbindWindowEvents()
This commit is contained in:
parent
1ba567dc24
commit
ffc50d41c2
32
dist/frappe-charts.esm.js
vendored
32
dist/frappe-charts.esm.js
vendored
@ -298,10 +298,6 @@ class SvgTip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value of a number upto 2 decimal places.
|
|
||||||
* @param {Number} d Any number
|
|
||||||
*/
|
|
||||||
function floatTwo(d) {
|
function floatTwo(d) {
|
||||||
return parseFloat(d.toFixed(2));
|
return parseFloat(d.toFixed(2));
|
||||||
}
|
}
|
||||||
@ -1342,6 +1338,8 @@ function prepareForExport(svg) {
|
|||||||
return container.innerHTML;
|
return container.innerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let BOUND_DRAW_FN;
|
||||||
|
|
||||||
class BaseChart {
|
class BaseChart {
|
||||||
constructor(parent, options) {
|
constructor(parent, options) {
|
||||||
|
|
||||||
@ -1422,8 +1420,18 @@ class BaseChart {
|
|||||||
this.height = height - getExtraHeight(this.measures);
|
this.height = height - getExtraHeight(this.measures);
|
||||||
|
|
||||||
// Bind window events
|
// Bind window events
|
||||||
window.addEventListener('resize', () => this.draw(true));
|
BOUND_DRAW_FN = this.boundDrawFn.bind(this);
|
||||||
window.addEventListener('orientationchange', () => this.draw(true));
|
window.addEventListener('resize', BOUND_DRAW_FN);
|
||||||
|
window.addEventListener('orientationchange', this.boundDrawFn.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
boundDrawFn() {
|
||||||
|
this.draw(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
unbindWindowEvents() {
|
||||||
|
window.removeEventListener('resize', BOUND_DRAW_FN);
|
||||||
|
window.removeEventListener('orientationchange', this.boundDrawFn.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has to be called manually
|
// Has to be called manually
|
||||||
@ -1632,15 +1640,6 @@ class BaseChart {
|
|||||||
|
|
||||||
updateDataset() {}
|
updateDataset() {}
|
||||||
|
|
||||||
boundDrawFn() {
|
|
||||||
this.draw(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
unbindWindowEvents(){
|
|
||||||
window.removeEventListener('resize', () => this.boundDrawFn.bind(this));
|
|
||||||
window.removeEventListener('orientationchange', () => this.boundDrawFn.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
export() {
|
||||||
let chartSvg = prepareForExport(this.svg);
|
let chartSvg = prepareForExport(this.svg);
|
||||||
downloadFile(this.title || 'Chart', [chartSvg]);
|
downloadFile(this.title || 'Chart', [chartSvg]);
|
||||||
@ -2253,7 +2252,7 @@ class PercentageChart extends AggregationChart {
|
|||||||
|
|
||||||
m.paddings.right = 30;
|
m.paddings.right = 30;
|
||||||
m.legendHeight = 80;
|
m.legendHeight = 80;
|
||||||
m.baseHeight = b.height * 10 + b.depth * 0.5;
|
m.baseHeight = (b.height + b.depth * 0.5) * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupComponents() {
|
setupComponents() {
|
||||||
@ -3673,7 +3672,6 @@ class AxisChart extends BaseChart {
|
|||||||
// removeDataPoint(index = 0) {}
|
// removeDataPoint(index = 0) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// import MultiAxisChart from './charts/MultiAxisChart';
|
|
||||||
const chartTypes = {
|
const chartTypes = {
|
||||||
bar: AxisChart,
|
bar: AxisChart,
|
||||||
line: AxisChart,
|
line: AxisChart,
|
||||||
|
|||||||
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
2
dist/frappe-charts.min.iife.js.map
vendored
2
dist/frappe-charts.min.iife.js.map
vendored
File diff suppressed because one or more lines are too long
@ -14,6 +14,7 @@ export const lineCompositeData = {
|
|||||||
{
|
{
|
||||||
label: "Average 100 reports/month",
|
label: "Average 100 reports/month",
|
||||||
value: 1200,
|
value: 1200,
|
||||||
|
options: { labelPos: 'left' }
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
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
12
docs/assets/js/index.min.js
vendored
12
docs/assets/js/index.min.js
vendored
@ -46,12 +46,6 @@ var HEATMAP_COLORS_YELLOW = ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001
|
|||||||
|
|
||||||
// Universal constants
|
// Universal constants
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value of a number upto 2 decimal places.
|
|
||||||
* @param {Number} d Any number
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not two given arrays are equal.
|
* Returns whether or not two given arrays are equal.
|
||||||
* @param {Array} arr1 First array
|
* @param {Array} arr1 First array
|
||||||
@ -120,6 +114,7 @@ var MONTH_NAMES_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/11252167/6495043
|
||||||
|
|
||||||
|
|
||||||
function clone(date) {
|
function clone(date) {
|
||||||
@ -169,7 +164,8 @@ var lineCompositeData = {
|
|||||||
|
|
||||||
yMarkers: [{
|
yMarkers: [{
|
||||||
label: "Average 100 reports/month",
|
label: "Average 100 reports/month",
|
||||||
value: 1200
|
value: 1200,
|
||||||
|
options: { labelPos: 'left' }
|
||||||
}],
|
}],
|
||||||
|
|
||||||
datasets: [{
|
datasets: [{
|
||||||
@ -299,8 +295,6 @@ var heatmapData = {
|
|||||||
end: end
|
end: end
|
||||||
};
|
};
|
||||||
|
|
||||||
// ================================================================================
|
|
||||||
|
|
||||||
var c1 = document.querySelector("#chart-composite-1");
|
var c1 = document.querySelector("#chart-composite-1");
|
||||||
var c2 = document.querySelector("#chart-composite-2");
|
var c2 = document.querySelector("#chart-composite-2");
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -255,6 +255,7 @@
|
|||||||
isNavigable: 1, // default: 0
|
isNavigable: 1, // default: 0
|
||||||
valuesOverPoints: 1, // default: 0
|
valuesOverPoints: 1, // default: 0
|
||||||
barOptions: {
|
barOptions: {
|
||||||
|
spaceRatio: 1 // default: 0.5
|
||||||
stacked: 1 // default: 0
|
stacked: 1 // default: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,15 +275,17 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Pie/Percentage charts
|
// Pie/Percentage charts
|
||||||
|
|
||||||
maxLegendPoints: 6, // default: 20
|
maxLegendPoints: 6, // default: 20
|
||||||
maxSlices: 10, // default: 20
|
maxSlices: 10, // default: 20
|
||||||
|
|
||||||
// Heatmap
|
// Percentage chart
|
||||||
|
barOptions: {
|
||||||
|
height: 15 // default: 20
|
||||||
|
depth: 5 // default: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heatmap
|
||||||
discreteDomains: 1, // default: 1
|
discreteDomains: 1, // default: 1
|
||||||
start: startDate, // Date object
|
|
||||||
colors: []
|
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -297,6 +300,9 @@
|
|||||||
// Exporting
|
// Exporting
|
||||||
chart.export();
|
chart.export();
|
||||||
|
|
||||||
|
// Unbind window-resize events
|
||||||
|
chart.unbindWindowEvents();
|
||||||
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import { getColor, isValidColor } from '../utils/colors';
|
|||||||
import { runSMILAnimation } from '../utils/animation';
|
import { runSMILAnimation } from '../utils/animation';
|
||||||
import { downloadFile, prepareForExport } from '../utils/export';
|
import { downloadFile, prepareForExport } from '../utils/export';
|
||||||
|
|
||||||
|
let BOUND_DRAW_FN;
|
||||||
|
|
||||||
export default class BaseChart {
|
export default class BaseChart {
|
||||||
constructor(parent, options) {
|
constructor(parent, options) {
|
||||||
|
|
||||||
@ -87,8 +89,18 @@ export default class BaseChart {
|
|||||||
this.height = height - getExtraHeight(this.measures);
|
this.height = height - getExtraHeight(this.measures);
|
||||||
|
|
||||||
// Bind window events
|
// Bind window events
|
||||||
window.addEventListener('resize', () => this.draw(true));
|
BOUND_DRAW_FN = this.boundDrawFn.bind(this);
|
||||||
window.addEventListener('orientationchange', () => this.draw(true));
|
window.addEventListener('resize', BOUND_DRAW_FN);
|
||||||
|
window.addEventListener('orientationchange', this.boundDrawFn.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
boundDrawFn() {
|
||||||
|
this.draw(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
unbindWindowEvents() {
|
||||||
|
window.removeEventListener('resize', BOUND_DRAW_FN);
|
||||||
|
window.removeEventListener('orientationchange', this.boundDrawFn.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has to be called manually
|
// Has to be called manually
|
||||||
@ -297,15 +309,6 @@ export default class BaseChart {
|
|||||||
|
|
||||||
updateDataset() {}
|
updateDataset() {}
|
||||||
|
|
||||||
boundDrawFn() {
|
|
||||||
this.draw(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
unbindWindowEvents(){
|
|
||||||
window.removeEventListener('resize', () => this.boundDrawFn.bind(this));
|
|
||||||
window.removeEventListener('orientationchange', () => this.boundDrawFn.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
export() {
|
||||||
let chartSvg = prepareForExport(this.svg);
|
let chartSvg = prepareForExport(this.svg);
|
||||||
downloadFile(this.title || 'Chart', [chartSvg]);
|
downloadFile(this.title || 'Chart', [chartSvg]);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export default class PercentageChart extends AggregationChart {
|
|||||||
|
|
||||||
m.paddings.right = 30;
|
m.paddings.right = 30;
|
||||||
m.legendHeight = 80;
|
m.legendHeight = 80;
|
||||||
m.baseHeight = b.height * 10 + b.depth * 0.5;
|
m.baseHeight = (b.height + b.depth * 0.5) * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupComponents() {
|
setupComponents() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user