[aggregation] add dot legend

This commit is contained in:
Prateeksha Singh 2018-04-14 08:20:50 +05:30
parent 7ccb2c5a54
commit cf5985fd9a
13 changed files with 109 additions and 66 deletions

View File

@ -591,6 +591,35 @@ function legendBar(x, y, size, fill='none', label) {
return group; 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) { function makeText(className, x, y, content, fontSize = FONT_SIZE) {
return createSVG('text', { return createSVG('text', {
className: className, className: className,
@ -1594,31 +1623,30 @@ class AggregationChart extends BaseChart {
}); });
s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0); s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0);
this.center = {
x: this.width / 2,
y: this.height / 2
};
} }
renderLegend() { renderLegend() {
// let s = this.state; let s = this.state;
this.legendArea.textContent = '';
// this.statsWrapper.textContent = ''; this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);
// this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints); this.legendTotals.map((d, i) => {
let barWidth = 110;
// let xValues = s.labels; let rect = legendDot(
// this.legendTotals.map((d, i) => { barWidth * i + 5,
// if(d) { '0',
// let stats = $.create('div', { 5,
// className: 'stats', this.colors[i],
// inside: this.statsWrapper `${s.labels[i]}: ${d}`
// }); );
// stats.innerHTML = `<span class="indicator"> this.legendArea.appendChild(rect);
// <i style="background: ${this.colors[i]}"></i> });
// <span class="text-muted">${xValues[i]}:</span>
// ${d}
// </span>`;
// }
// });
//
} }
} }
@ -2130,17 +2158,9 @@ class PieChart extends AggregationChart {
calc() { calc() {
super.calc(); super.calc();
this.center = { let s = this.state;
x: this.width / 2,
y: this.height / 2
};
this.radius = (this.height > this.width ? this.center.x : this.center.y); this.radius = (this.height > this.width ? this.center.x : this.center.y);
this.calcSlices();
}
calcSlices() {
let s = this.state;
const { radius, clockWise } = this; const { radius, clockWise } = this;
const prevSlicesProperties = s.slicesProperties || []; const prevSlicesProperties = s.slicesProperties || [];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -50,6 +50,7 @@ lineCompositeChart.parent.addEventListener('data-select', (e) => {
// ================================================================================ // ================================================================================
let args = { let args = {
title: "My Awesome Chart",
data: typeData, data: typeData,
type: 'axis-mixed', type: 'axis-mixed',
height: 250, height: 250,

View File

@ -272,6 +272,8 @@ 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");
@ -316,6 +318,7 @@ lineCompositeChart.parent.addEventListener('data-select', function (e) {
// ================================================================================ // ================================================================================
var args = { var args = {
title: "My Awesome Chart",
data: typeData, data: typeData,
type: 'axis-mixed', type: 'axis-mixed',
height: 250, height: 250,

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
import BaseChart from './BaseChart'; import BaseChart from './BaseChart';
import { legendDot } from '../utils/draw';
export default class AggregationChart extends BaseChart { export default class AggregationChart extends BaseChart {
constructor(parent, args) { constructor(parent, args) {
@ -46,30 +47,29 @@ export default class AggregationChart extends BaseChart {
}); });
s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0); s.grandTotal = s.sliceTotals.reduce((a, b) => a + b, 0);
this.center = {
x: this.width / 2,
y: this.height / 2
};
} }
renderLegend() { renderLegend() {
// let s = this.state; let s = this.state;
this.legendArea.textContent = '';
// this.statsWrapper.textContent = ''; this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);
// this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints); this.legendTotals.map((d, i) => {
let barWidth = 110;
// let xValues = s.labels; let rect = legendDot(
// this.legendTotals.map((d, i) => { barWidth * i + 5,
// if(d) { '0',
// let stats = $.create('div', { 5,
// className: 'stats', this.colors[i],
// inside: this.statsWrapper `${s.labels[i]}: ${d}`
// }); );
// stats.innerHTML = `<span class="indicator"> this.legendArea.appendChild(rect);
// <i style="background: ${this.colors[i]}"></i> });
// <span class="text-muted">${xValues[i]}:</span>
// ${d}
// </span>`;
// }
// });
//
} }
} }

View File

@ -31,18 +31,8 @@ export default class PieChart extends AggregationChart {
calc() { calc() {
super.calc(); super.calc();
let s = this.state; 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.radius = (this.height > this.width ? this.center.x : this.center.y);
this.calcSlices();
}
calcSlices() {
let s = this.state;
const { radius, clockWise } = this; const { radius, clockWise } = this;
const prevSlicesProperties = s.slicesProperties || []; const prevSlicesProperties = s.slicesProperties || [];

View File

@ -201,6 +201,35 @@ export function legendBar(x, y, size, fill='none', label) {
return group; 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) { export function makeText(className, x, y, content, fontSize = FONT_SIZE) {
return createSVG('text', { return createSVG('text', {
className: className, className: className,