mirror of
https://github.com/frappe/books.git
synced 2025-02-08 23:18:31 +00:00
fix(ui): tune charts a bit
This commit is contained in:
parent
0ed031a7bb
commit
2544687ab3
@ -50,7 +50,7 @@
|
|||||||
:x="xs[i - 1]"
|
:x="xs[i - 1]"
|
||||||
text-anchor="middle"
|
text-anchor="middle"
|
||||||
>
|
>
|
||||||
{{ xLabels[i - 1] || '' }}
|
{{ j % skipXLabel === 0 ? formatX(xLabels[i - 1] || '') : '' }}
|
||||||
</text>
|
</text>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -121,7 +121,7 @@
|
|||||||
class="text-sm shadow-md px-2 py-1 bg-white text-gray-900 border-l-2"
|
class="text-sm shadow-md px-2 py-1 bg-white text-gray-900 border-l-2"
|
||||||
:style="{ borderColor: activeColor }"
|
:style="{ borderColor: activeColor }"
|
||||||
>
|
>
|
||||||
{{ xi > -1 ? xLabels[xi] : '' }}
|
{{ xi > -1 ? xLabels[xi] : '' }} –
|
||||||
{{ yi > -1 ? format(points[yi][xi]) : '' }}
|
{{ yi > -1 ? format(points[yi][xi]) : '' }}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
@ -132,6 +132,7 @@ import Tooltip from '../Tooltip.vue';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
skipXLabel: { type: Number, default: 2 },
|
||||||
colors: { type: Array, default: () => [] },
|
colors: { type: Array, default: () => [] },
|
||||||
xLabels: { type: Array, default: () => [] },
|
xLabels: { type: Array, default: () => [] },
|
||||||
yLabelDivisions: { type: Number, default: 4 },
|
yLabelDivisions: { type: Number, default: 4 },
|
||||||
@ -139,27 +140,27 @@ export default {
|
|||||||
drawAxis: { type: Boolean, default: false },
|
drawAxis: { type: Boolean, default: false },
|
||||||
drawXGrid: { type: Boolean, default: true },
|
drawXGrid: { type: Boolean, default: true },
|
||||||
viewBoxHeight: { type: Number, default: 500 },
|
viewBoxHeight: { type: Number, default: 500 },
|
||||||
aspectRatio: { type: Number, default: 1.75 },
|
aspectRatio: { type: Number, default: 2.1 },
|
||||||
axisPadding: { type: Number, default: 30 },
|
axisPadding: { type: Number, default: 30 },
|
||||||
pointsPadding: { type: Number, default: 24 },
|
pointsPadding: { type: Number, default: 40 },
|
||||||
xLabelOffset: { type: Number, default: 5 },
|
xLabelOffset: { type: Number, default: 20 },
|
||||||
yLabelOffset: { type: Number, default: 5 },
|
yLabelOffset: { type: Number, default: 0 },
|
||||||
gridColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
gridColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
||||||
zeroLineColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
zeroLineColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
||||||
axisColor: { type: String, default: 'rgba(0, 0, 0, 0.5)' },
|
axisColor: { type: String, default: 'rgba(0, 0, 0, 0.5)' },
|
||||||
thickness: { type: Number, default: 5 },
|
|
||||||
axisThickness: { type: Number, default: 1 },
|
axisThickness: { type: Number, default: 1 },
|
||||||
gridThickness: { type: Number, default: 0.5 },
|
gridThickness: { type: Number, default: 0.5 },
|
||||||
yMin: { type: Number, default: null },
|
yMin: { type: Number, default: null },
|
||||||
yMax: { type: Number, default: null },
|
yMax: { type: Number, default: null },
|
||||||
format: { type: Function, default: (n) => n.toFixed(1) },
|
format: { type: Function, default: (n) => n.toFixed(1) },
|
||||||
formatY: { type: Function, default: prefixFormat },
|
formatY: { type: Function, default: prefixFormat },
|
||||||
fontSize: { type: Number, default: 18 },
|
formatX: { type: Function, default: (v) => v },
|
||||||
|
fontSize: { type: Number, default: 25 },
|
||||||
fontColor: { type: String, default: '#415668' },
|
fontColor: { type: String, default: '#415668' },
|
||||||
bottom: { type: Number, default: 0 },
|
bottom: { type: Number, default: 0 },
|
||||||
width: { type: Number, default: 30 },
|
width: { type: Number, default: 34 },
|
||||||
left: { type: Number, default: 55 },
|
left: { type: Number, default: 65 },
|
||||||
radius: { type: Number, default: 15 },
|
radius: { type: Number, default: 17 },
|
||||||
extendGridX: { type: Number, default: -20 },
|
extendGridX: { type: Number, default: -20 },
|
||||||
tooltipDispDistThreshold: { type: Number, default: 20 },
|
tooltipDispDistThreshold: { type: Number, default: 20 },
|
||||||
drawZeroLine: { type: Boolean, default: true },
|
drawZeroLine: { type: Boolean, default: true },
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
:x="xs[i - 1]"
|
:x="xs[i - 1]"
|
||||||
text-anchor="middle"
|
text-anchor="middle"
|
||||||
>
|
>
|
||||||
{{ xLabels[i - 1] || '' }}
|
{{ formatX(xLabels[i - 1] || '') }}
|
||||||
</text>
|
</text>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -119,7 +119,7 @@
|
|||||||
class="text-sm shadow-md px-2 py-1 bg-white text-gray-900 border-l-2"
|
class="text-sm shadow-md px-2 py-1 bg-white text-gray-900 border-l-2"
|
||||||
:style="{ borderColor: colors[yi] }"
|
:style="{ borderColor: colors[yi] }"
|
||||||
>
|
>
|
||||||
{{ xi > -1 ? xLabels[xi] : '' }}
|
{{ xi > -1 ? xLabels[xi] : '' }} –
|
||||||
{{ yi > -1 ? format(points[yi][xi]) : '' }}
|
{{ yi > -1 ? format(points[yi][xi]) : '' }}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
@ -140,7 +140,7 @@ export default {
|
|||||||
aspectRatio: { type: Number, default: 3.5 },
|
aspectRatio: { type: Number, default: 3.5 },
|
||||||
axisPadding: { type: Number, default: 30 },
|
axisPadding: { type: Number, default: 30 },
|
||||||
pointsPadding: { type: Number, default: 24 },
|
pointsPadding: { type: Number, default: 24 },
|
||||||
xLabelOffset: { type: Number, default: 5 },
|
xLabelOffset: { type: Number, default: 20 },
|
||||||
yLabelOffset: { type: Number, default: 5 },
|
yLabelOffset: { type: Number, default: 5 },
|
||||||
gridColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
gridColor: { type: String, default: 'rgba(0, 0, 0, 0.2)' },
|
||||||
axisColor: { type: String, default: 'rgba(0, 0, 0, 0.5)' },
|
axisColor: { type: String, default: 'rgba(0, 0, 0, 0.5)' },
|
||||||
@ -151,6 +151,7 @@ export default {
|
|||||||
yMax: { type: Number, default: null },
|
yMax: { type: Number, default: null },
|
||||||
format: { type: Function, default: (n) => n.toFixed(1) },
|
format: { type: Function, default: (n) => n.toFixed(1) },
|
||||||
formatY: { type: Function, default: prefixFormat },
|
formatY: { type: Function, default: prefixFormat },
|
||||||
|
formatX: { type: Function, default: (v) => v },
|
||||||
fontSize: { type: Number, default: 18 },
|
fontSize: { type: Number, default: 18 },
|
||||||
fontColor: { type: String, default: '#415668' },
|
fontColor: { type: String, default: '#415668' },
|
||||||
bottom: { type: Number, default: 0 },
|
bottom: { type: Number, default: 0 },
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
:points="chartData.points"
|
:points="chartData.points"
|
||||||
:x-labels="chartData.xLabels"
|
:x-labels="chartData.xLabels"
|
||||||
:format="chartData.format"
|
:format="chartData.format"
|
||||||
|
:format-x="chartData.formatX"
|
||||||
:y-max="chartData.yMax"
|
:y-max="chartData.yMax"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@ -102,6 +103,7 @@ import Cashflow from '../../../reports/Cashflow/Cashflow';
|
|||||||
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
||||||
import LineChart from '@/components/Charts/LineChart.vue';
|
import LineChart from '@/components/Charts/LineChart.vue';
|
||||||
import { getYMax } from '@/components/Charts/chartUtils';
|
import { getYMax } from '@/components/Charts/chartUtils';
|
||||||
|
import { formatXLabels } from '@/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Cashflow',
|
name: 'Cashflow',
|
||||||
@ -134,7 +136,7 @@ export default {
|
|||||||
const colors = ['#2490EF', '#B7BFC6'];
|
const colors = ['#2490EF', '#B7BFC6'];
|
||||||
const format = (value) => frappe.format(value ?? 0, 'Currency');
|
const format = (value) => frappe.format(value ?? 0, 'Currency');
|
||||||
const yMax = getYMax(points);
|
const yMax = getYMax(points);
|
||||||
return { points, xLabels, colors, format, yMax };
|
return { points, xLabels, colors, format, yMax, formatX:formatXLabels };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
:points="chartData.points"
|
:points="chartData.points"
|
||||||
:x-labels="chartData.xLabels"
|
:x-labels="chartData.xLabels"
|
||||||
:format="chartData.format"
|
:format="chartData.format"
|
||||||
|
:format-x="chartData.formatX"
|
||||||
:y-max="chartData.yMax"
|
:y-max="chartData.yMax"
|
||||||
:y-min="chartData.yMin"
|
:y-min="chartData.yMin"
|
||||||
/>
|
/>
|
||||||
@ -33,6 +34,7 @@ import ProfitAndLoss from '../../../reports/ProfitAndLoss/ProfitAndLoss';
|
|||||||
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
||||||
import BarChart from '@/components/Charts/BarChart.vue';
|
import BarChart from '@/components/Charts/BarChart.vue';
|
||||||
import { getYMax, getYMin } from '@/components/Charts/chartUtils';
|
import { getYMax, getYMin } from '@/components/Charts/chartUtils';
|
||||||
|
import { formatXLabels } from '@/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ProfitAndLoss',
|
name: 'ProfitAndLoss',
|
||||||
@ -50,22 +52,26 @@ export default {
|
|||||||
this.setData();
|
this.setData();
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
period: 'render',
|
period: 'setData',
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
chartData() {
|
chartData() {
|
||||||
const points = [this.periodList.map((p) => this.data[p])];
|
const points = [this.periodList.map((p) => this.data[p])];
|
||||||
|
console.log(this.period);
|
||||||
|
console.log(this.data, this.periodList);
|
||||||
|
console.log(points);
|
||||||
const colors = [{ positive: '#2490EF', negative: '#B7BFC6' }];
|
const colors = [{ positive: '#2490EF', negative: '#B7BFC6' }];
|
||||||
const format = (value) => frappe.format(value ?? 0, 'Currency');
|
const format = (value) => frappe.format(value ?? 0, 'Currency');
|
||||||
const yMax = getYMax(points);
|
const yMax = getYMax(points);
|
||||||
const yMin = getYMin(points);
|
const yMin = getYMin(points);
|
||||||
return {
|
return {
|
||||||
xLabels: this.periodList.map((p) => p.split(' ')[0]),
|
xLabels: this.periodList,
|
||||||
points,
|
points,
|
||||||
format,
|
format,
|
||||||
colors,
|
colors,
|
||||||
yMax,
|
yMax,
|
||||||
yMin,
|
yMin,
|
||||||
|
formatX: formatXLabels,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
hasData() {
|
hasData() {
|
||||||
|
@ -404,3 +404,11 @@ export function convertPesaValuesToFloat(obj) {
|
|||||||
obj[key] = obj[key].float;
|
obj[key] = obj[key].float;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatXLabels(label) {
|
||||||
|
// Format: Mmm YYYY -> Mm YY
|
||||||
|
let [month, year] = label.split(' ');
|
||||||
|
year = year.slice(2);
|
||||||
|
|
||||||
|
return `${month} ${year}`;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user