Browse Source

[aggregation] add dot legend

tags/1.2.0
Prateeksha Singh 7 years ago
parent
commit
cf5985fd9a
13 changed files with 110 additions and 67 deletions
  1. +50
    -30
      dist/frappe-charts.esm.js
  2. +1
    -1
      dist/frappe-charts.min.cjs.js
  3. +1
    -1
      dist/frappe-charts.min.esm.js
  4. +1
    -1
      dist/frappe-charts.min.iife.js
  5. +1
    -1
      dist/frappe-charts.min.iife.js.map
  6. +1
    -1
      docs/assets/js/frappe-charts.min.js
  7. +1
    -1
      docs/assets/js/frappe-charts.min.js.map
  8. +1
    -0
      docs/assets/js/index.js
  9. +3
    -0
      docs/assets/js/index.min.js
  10. +1
    -1
      docs/assets/js/index.min.js.map
  11. +20
    -20
      src/js/charts/AggregationChart.js
  12. +0
    -10
      src/js/charts/PieChart.js
  13. +29
    -0
      src/js/utils/draw.js

+ 50
- 30
dist/frappe-charts.esm.js View File

@@ -591,6 +591,35 @@ function legendBar(x, y, size, fill='none', label) {
return group;
}

function legendDot(x, y, size, fill='none', label) {
let args = {
className: 'legend-dot',
cx: 0,
cy: 0,
r: size,
fill: fill
};
let text = createSVG('text', {
className: 'legend-dataset-text',
x: 0,
y: 0,
dx: (FONT_SIZE) + 'px',
dy: (FONT_SIZE/3) + 'px',
'font-size': (FONT_SIZE * 1.2) + 'px',
'text-anchor': 'start',
fill: FONT_FILL,
innerHTML: label
});

let group = createSVG('g', {
transform: `translate(${x}, ${y})`
});
group.appendChild(createSVG("circle", args));
group.appendChild(text);

return group;
}

function makeText(className, x, y, content, fontSize = FONT_SIZE) {
return createSVG('text', {
className: className,
@@ -1594,31 +1623,30 @@ class AggregationChart extends BaseChart {
});

s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0);

this.center = {
x: this.width / 2,
y: this.height / 2
};
}

renderLegend() {
// let s = this.state;

// this.statsWrapper.textContent = '';

// this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);

// let xValues = s.labels;
// this.legendTotals.map((d, i) => {
// if(d) {
// let stats = $.create('div', {
// className: 'stats',
// inside: this.statsWrapper
// });
// stats.innerHTML = `<span class="indicator">
// <i style="background: ${this.colors[i]}"></i>
// <span class="text-muted">${xValues[i]}:</span>
// ${d}
// </span>`;
// }
// });
let s = this.state;
this.legendArea.textContent = '';

//
this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);

this.legendTotals.map((d, i) => {
let barWidth = 110;
let rect = legendDot(
barWidth * i + 5,
'0',
5,
this.colors[i],
`${s.labels[i]}: ${d}`
);
this.legendArea.appendChild(rect);
});
}
}

@@ -2130,17 +2158,9 @@ class PieChart extends AggregationChart {

calc() {
super.calc();
this.center = {
x: this.width / 2,
y: this.height / 2
};
let s = this.state;
this.radius = (this.height > this.width ? this.center.x : this.center.y);

this.calcSlices();
}

calcSlices() {
let s = this.state;
const { radius, clockWise } = this;

const prevSlicesProperties = s.slicesProperties || [];


+ 1
- 1
dist/frappe-charts.min.cjs.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/frappe-charts.min.esm.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/frappe-charts.min.iife.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/frappe-charts.min.iife.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
docs/assets/js/frappe-charts.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
docs/assets/js/frappe-charts.min.js.map
File diff suppressed because it is too large
View File


+ 1
- 0
docs/assets/js/index.js View File

@@ -50,6 +50,7 @@ lineCompositeChart.parent.addEventListener('data-select', (e) => {
// ================================================================================

let args = {
title: "My Awesome Chart",
data: typeData,
type: 'axis-mixed',
height: 250,


+ 3
- 0
docs/assets/js/index.min.js View File

@@ -272,6 +272,8 @@ var heatmapData = {
end: end
};

// ================================================================================

var c1 = document.querySelector("#chart-composite-1");
var c2 = document.querySelector("#chart-composite-2");

@@ -316,6 +318,7 @@ lineCompositeChart.parent.addEventListener('data-select', function (e) {
// ================================================================================

var args = {
title: "My Awesome Chart",
data: typeData,
type: 'axis-mixed',
height: 250,


+ 1
- 1
docs/assets/js/index.min.js.map
File diff suppressed because it is too large
View File


+ 20
- 20
src/js/charts/AggregationChart.js View File

@@ -1,4 +1,5 @@
import BaseChart from './BaseChart';
import { legendDot } from '../utils/draw';

export default class AggregationChart extends BaseChart {
constructor(parent, args) {
@@ -46,30 +47,29 @@ export default class AggregationChart extends BaseChart {
});

s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0);

this.center = {
x: this.width / 2,
y: this.height / 2
};
}

renderLegend() {
// let s = this.state;

// this.statsWrapper.textContent = '';

// this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);
let s = this.state;
this.legendArea.textContent = '';

// let xValues = s.labels;
// this.legendTotals.map((d, i) => {
// if(d) {
// let stats = $.create('div', {
// className: 'stats',
// inside: this.statsWrapper
// });
// stats.innerHTML = `<span class="indicator">
// <i style="background: ${this.colors[i]}"></i>
// <span class="text-muted">${xValues[i]}:</span>
// ${d}
// </span>`;
// }
// });
this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);

//
this.legendTotals.map((d, i) => {
let barWidth = 110;
let rect = legendDot(
barWidth * i + 5,
'0',
5,
this.colors[i],
`${s.labels[i]}: ${d}`
);
this.legendArea.appendChild(rect);
});
}
}

+ 0
- 10
src/js/charts/PieChart.js View File

@@ -31,18 +31,8 @@ export default class PieChart extends AggregationChart {
calc() {
super.calc();
let s = this.state;

this.center = {
x: this.width / 2,
y: this.height / 2
};
this.radius = (this.height > this.width ? this.center.x : this.center.y);

this.calcSlices();
}

calcSlices() {
let s = this.state;
const { radius, clockWise } = this;

const prevSlicesProperties = s.slicesProperties || [];


+ 29
- 0
src/js/utils/draw.js View File

@@ -201,6 +201,35 @@ export function legendBar(x, y, size, fill='none', label) {
return group;
}

export function legendDot(x, y, size, fill='none', label) {
let args = {
className: 'legend-dot',
cx: 0,
cy: 0,
r: size,
fill: fill
};
let text = createSVG('text', {
className: 'legend-dataset-text',
x: 0,
y: 0,
dx: (FONT_SIZE) + 'px',
dy: (FONT_SIZE/3) + 'px',
'font-size': (FONT_SIZE * 1.2) + 'px',
'text-anchor': 'start',
fill: FONT_FILL,
innerHTML: label
});

let group = createSVG('g', {
transform: `translate(${x}, ${y})`
});
group.appendChild(createSVG("circle", args));
group.appendChild(text);

return group;
}

export function makeText(className, x, y, content, fontSize = FONT_SIZE) {
return createSVG('text', {
className: className,


Loading…
Cancel
Save