Explorar el Código

[percentage] barDepth

tags/1.2.0
Prateeksha Singh hace 7 años
padre
commit
cbb69089db
Se han modificado 13 ficheros con 91 adiciones y 65 borrados
  1. +63
    -50
      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
    -1
      docs/assets/js/index.min.js.map
  9. +5
    -2
      src/js/charts/PercentageChart.js
  10. +1
    -1
      src/js/objects/ChartComponents.js
  11. +1
    -0
      src/js/utils/constants.js
  12. +13
    -3
      src/js/utils/draw.js
  13. +1
    -2
      src/scss/charts.scss

+ 63
- 50
dist/frappe-charts.esm.js Ver fichero

@@ -124,6 +124,7 @@ const LINE_CHART_DOT_SIZE = 4;
const DOT_OVERLAY_SIZE_INCR = 4; const DOT_OVERLAY_SIZE_INCR = 4;


const PERCENTAGE_BAR_DEFAULT_HEIGHT = 20; const PERCENTAGE_BAR_DEFAULT_HEIGHT = 20;
const PERCENTAGE_BAR_DEFAULT_DEPTH = 2;


// Fixed 5-color theme, // Fixed 5-color theme,
// More colors are difficult to parse visually // More colors are difficult to parse visually
@@ -352,6 +353,52 @@ function equilizeNoOfElements(array1, array2,
return [array1, array2]; return [array1, array2];
} }


const PRESET_COLOR_MAP = {
'light-blue': '#7cd6fd',
'blue': '#5e64ff',
'violet': '#743ee2',
'red': '#ff5858',
'orange': '#ffa00a',
'yellow': '#feef72',
'green': '#28a745',
'light-green': '#98d85b',
'purple': '#b554ff',
'magenta': '#ffa3ef',
'black': '#36114C',
'grey': '#bdd3e6',
'light-grey': '#f0f4f7',
'dark-grey': '#b8c2cc'
};

function limitColor(r){
if (r > 255) return 255;
else if (r < 0) return 0;
return r;
}

function lightenDarkenColor(color, amt) {
let col = getColor(color);
let usePound = false;
if (col[0] == "#") {
col = col.slice(1);
usePound = true;
}
let num = parseInt(col,16);
let r = limitColor((num >> 16) + amt);
let b = limitColor(((num >> 8) & 0x00FF) + amt);
let g = limitColor((num & 0x0000FF) + amt);
return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
}

function isValidColor(string) {
// https://stackoverflow.com/a/8027444/6495043
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(string);
}

const getColor = (color) => {
return PRESET_COLOR_MAP[color] || color;
};

const AXIS_TICK_LENGTH = 6; const AXIS_TICK_LENGTH = 6;
const LABEL_MARGIN = 4; const LABEL_MARGIN = 4;
const FONT_SIZE = 10; const FONT_SIZE = 10;
@@ -476,14 +523,23 @@ function makeGradient(svgDefElem, color, lighter = false) {
return gradientId; return gradientId;
} }


function percentageBar(x, y, width, height, fill='none') {
function percentageBar(x, y, width, height,
depth=PERCENTAGE_BAR_DEFAULT_DEPTH, fill='none') {

let args = { let args = {
className: 'percentage-bar', className: 'percentage-bar',
x: x, x: x,
y: y, y: y,
width: width, width: width,
height: height, height: height,
fill: fill
fill: fill,
styles: {
'stroke': lightenDarkenColor(fill, -25),
// Diabollically good: https://stackoverflow.com/a/9000859
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
'stroke-dasharray': `0, ${height + width}, ${width}, ${height}`,
'stroke-width': depth
},
}; };


return createSVG("rect", args); return createSVG("rect", args);
@@ -959,52 +1015,6 @@ let updateOverlay = {
}, },
}; };


const PRESET_COLOR_MAP = {
'light-blue': '#7cd6fd',
'blue': '#5e64ff',
'violet': '#743ee2',
'red': '#ff5858',
'orange': '#ffa00a',
'yellow': '#feef72',
'green': '#28a745',
'light-green': '#98d85b',
'purple': '#b554ff',
'magenta': '#ffa3ef',
'black': '#36114C',
'grey': '#bdd3e6',
'light-grey': '#f0f4f7',
'dark-grey': '#b8c2cc'
};

function limitColor(r){
if (r > 255) return 255;
else if (r < 0) return 0;
return r;
}

function lightenDarkenColor(color, amt) {
let col = getColor(color);
let usePound = false;
if (col[0] == "#") {
col = col.slice(1);
usePound = true;
}
let num = parseInt(col,16);
let r = limitColor((num >> 16) + amt);
let b = limitColor(((num >> 8) & 0x00FF) + amt);
let g = limitColor((num & 0x0000FF) + amt);
return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
}

function isValidColor(string) {
// https://stackoverflow.com/a/8027444/6495043
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(string);
}

const getColor = (color) => {
return PRESET_COLOR_MAP[color] || color;
};

const UNIT_ANIM_DUR = 350; const UNIT_ANIM_DUR = 350;
const PATH_ANIM_DUR = 350; const PATH_ANIM_DUR = 350;
const MARKER_LINE_ANIM_DUR = UNIT_ANIM_DUR; const MARKER_LINE_ANIM_DUR = UNIT_ANIM_DUR;
@@ -1694,7 +1704,7 @@ let componentConfigs = {
return data.xPositions.map((x, i) =>{ return data.xPositions.map((x, i) =>{
let y = 0; let y = 0;
let bar = percentageBar(x, y, data.widths[i], let bar = percentageBar(x, y, data.widths[i],
this.constants.barHeight, data.colors[i]);
this.constants.barHeight, this.constants.barDepth, data.colors[i]);
return bar; return bar;
}); });
}, },
@@ -2023,6 +2033,8 @@ class PercentageChart extends AggregationChart {
this.barOptions = args.barOptions || {}; this.barOptions = args.barOptions || {};
this.barOptions.height = this.barOptions.height this.barOptions.height = this.barOptions.height
|| PERCENTAGE_BAR_DEFAULT_HEIGHT; || PERCENTAGE_BAR_DEFAULT_HEIGHT;
this.barOptions.depth = this.barOptions.depth
|| PERCENTAGE_BAR_DEFAULT_DEPTH;


this.setup(); this.setup();
} }
@@ -2034,7 +2046,8 @@ class PercentageChart extends AggregationChart {
[ [
'percentageBars', 'percentageBars',
{ {
barHeight: this.barOptions.height
barHeight: this.barOptions.height,
barDepth: this.barOptions.depth,
}, },
function() { function() {
return { return {


+ 1
- 1
dist/frappe-charts.min.cjs.js
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
dist/frappe-charts.min.esm.js
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
dist/frappe-charts.min.iife.js
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
dist/frappe-charts.min.iife.js.map
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
docs/assets/js/frappe-charts.min.js
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
docs/assets/js/frappe-charts.min.js.map
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 1
- 1
docs/assets/js/index.min.js.map
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 5
- 2
src/js/charts/PercentageChart.js Ver fichero

@@ -1,7 +1,7 @@
import AggregationChart from './AggregationChart'; import AggregationChart from './AggregationChart';
import { $, getOffset } from '../utils/dom'; import { $, getOffset } from '../utils/dom';
import { getComponent } from '../objects/ChartComponents'; import { getComponent } from '../objects/ChartComponents';
import { PERCENTAGE_BAR_DEFAULT_HEIGHT } from '../utils/constants';
import { PERCENTAGE_BAR_DEFAULT_HEIGHT, PERCENTAGE_BAR_DEFAULT_DEPTH } from '../utils/constants';


export default class PercentageChart extends AggregationChart { export default class PercentageChart extends AggregationChart {
constructor(parent, args) { constructor(parent, args) {
@@ -11,6 +11,8 @@ export default class PercentageChart extends AggregationChart {
this.barOptions = args.barOptions || {}; this.barOptions = args.barOptions || {};
this.barOptions.height = this.barOptions.height this.barOptions.height = this.barOptions.height
|| PERCENTAGE_BAR_DEFAULT_HEIGHT; || PERCENTAGE_BAR_DEFAULT_HEIGHT;
this.barOptions.depth = this.barOptions.depth
|| PERCENTAGE_BAR_DEFAULT_DEPTH;


this.setup(); this.setup();
} }
@@ -22,7 +24,8 @@ export default class PercentageChart extends AggregationChart {
[ [
'percentageBars', 'percentageBars',
{ {
barHeight: this.barOptions.height
barHeight: this.barOptions.height,
barDepth: this.barOptions.depth,
}, },
function() { function() {
return { return {


+ 1
- 1
src/js/objects/ChartComponents.js Ver fichero

@@ -86,7 +86,7 @@ let componentConfigs = {
return data.xPositions.map((x, i) =>{ return data.xPositions.map((x, i) =>{
let y = 0; let y = 0;
let bar = percentageBar(x, y, data.widths[i], let bar = percentageBar(x, y, data.widths[i],
this.constants.barHeight, data.colors[i]);
this.constants.barHeight, this.constants.barDepth, data.colors[i]);
return bar; return bar;
}); });
}, },


+ 1
- 0
src/js/utils/constants.js Ver fichero

@@ -38,6 +38,7 @@ export const LINE_CHART_DOT_SIZE = 4;
export const DOT_OVERLAY_SIZE_INCR = 4; export const DOT_OVERLAY_SIZE_INCR = 4;


export const PERCENTAGE_BAR_DEFAULT_HEIGHT = 20; export const PERCENTAGE_BAR_DEFAULT_HEIGHT = 20;
export const PERCENTAGE_BAR_DEFAULT_DEPTH = 2;


// Fixed 5-color theme, // Fixed 5-color theme,
// More colors are difficult to parse visually // More colors are difficult to parse visually


+ 13
- 3
src/js/utils/draw.js Ver fichero

@@ -1,6 +1,7 @@
import { getBarHeightAndYAttr } from './draw-utils'; import { getBarHeightAndYAttr } from './draw-utils';
import { getStringWidth } from './helpers'; import { getStringWidth } from './helpers';
import { DOT_OVERLAY_SIZE_INCR } from './constants';
import { DOT_OVERLAY_SIZE_INCR, PERCENTAGE_BAR_DEFAULT_DEPTH } from './constants';
import { lightenDarkenColor } from './colors';


export const AXIS_TICK_LENGTH = 6; export const AXIS_TICK_LENGTH = 6;
const LABEL_MARGIN = 4; const LABEL_MARGIN = 4;
@@ -132,14 +133,23 @@ export function makeGradient(svgDefElem, color, lighter = false) {
return gradientId; return gradientId;
} }


export function percentageBar(x, y, width, height, fill='none') {
export function percentageBar(x, y, width, height,
depth=PERCENTAGE_BAR_DEFAULT_DEPTH, fill='none') {

let args = { let args = {
className: 'percentage-bar', className: 'percentage-bar',
x: x, x: x,
y: y, y: y,
width: width, width: width,
height: height, height: height,
fill: fill
fill: fill,
styles: {
'stroke': lightenDarkenColor(fill, -25),
// Diabolically good: https://stackoverflow.com/a/9000859
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
'stroke-dasharray': `0, ${height + width}, ${width}, ${height}`,
'stroke-width': depth
},
}; };


return createSVG("rect", args); return createSVG("rect", args);


+ 1
- 2
src/scss/charts.scss Ver fichero

@@ -8,7 +8,7 @@


.axis, .chart-label { .axis, .chart-label {
fill: #555b51; fill: #555b51;
// temp commented
line { line {
stroke: #dadada; stroke: #dadada;
} }
@@ -19,7 +19,6 @@
stroke-width: 2; stroke-width: 2;
} }


// temp
path { path {
fill: none; fill: none;
stroke-opacity: 1; stroke-opacity: 1;


Cargando…
Cancelar
Guardar