Skip to content

Commit

Permalink
fix: format using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pu-raihan committed Aug 20, 2024
1 parent 3f9b902 commit f15b1cf
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 287 deletions.
3 changes: 2 additions & 1 deletion src/components/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
h-full
items-center
justify-center
text-white dark:text-gray-900
text-white
dark:text-gray-900
w-full
text-base
uppercase
Expand Down
124 changes: 27 additions & 97 deletions src/components/Charts/BarChart.vue
Original file line number Diff line number Diff line change
@@ -1,69 +1,33 @@
<template>
<div>
<svg
ref="chartSvg"
:viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`"
xmlns="http://www.w3.org/2000/svg"
>
<svg ref="chartSvg" :viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`" xmlns="http://www.w3.org/2000/svg">
<!-- x Grid Lines -->
<path
v-if="drawXGrid"
:d="xGrid"
:stroke="gridColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<path v-if="drawXGrid" :d="xGrid" :stroke="gridColor" :stroke-width="gridThickness" stroke-linecap="round"
fill="transparent" />

<!-- zero line -->
<path
v-if="drawZeroLine"
:d="zLine"
:stroke="zeroLineColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<path v-if="drawZeroLine" :d="zLine" :stroke="zeroLineColor" :stroke-width="gridThickness" stroke-linecap="round"
fill="transparent" />

<!-- Axis -->
<path
v-if="drawAxis"
:d="axis"
:stroke-width="axisThickness"
:stroke="axisColor"
fill="transparent"
/>
<path v-if="drawAxis" :d="axis" :stroke-width="axisThickness" :stroke="axisColor" fill="transparent" />

<!-- x Labels -->
<template v-if="xLabels.length > 0">
<text
v-for="(i, j) in count"
:key="j + '-xlabels'"
:style="fontStyle"
:y="
viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
"
:x="xs[i - 1]"
text-anchor="middle"
>
<text v-for="(i, j) in count" :key="j + '-xlabels'" :style="fontStyle" :y="viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
" :x="xs[i - 1]" text-anchor="middle">
{{ j % skipXLabel === 0 ? formatX(xLabels[i - 1] || '') : '' }}
</text>
</template>

<!-- y Labels -->
<template v-if="yLabelDivisions > 0">
<text
v-for="(i, j) in yLabelDivisions + 1"
:key="j + '-ylabels'"
:style="fontStyle"
:y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left"
text-anchor="end"
>
<text v-for="(i, j) in yLabelDivisions + 1" :key="j + '-ylabels'" :style="fontStyle" :y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left" text-anchor="end">
{{ yScalerValue(i - 1) }}
</text>
</template>
Expand All @@ -73,54 +37,21 @@
<rect x="0" y="0" :width="viewBoxWidth" :height="z" />
</clipPath>
<clipPath id="negative-rect-clip">
<rect
x="0"
:y="z"
:width="viewBoxWidth"
:height="viewBoxHeight - z"
/>
<rect x="0" :y="z" :width="viewBoxWidth" :height="viewBoxHeight - z" />
</clipPath>
</defs>

<rect
v-for="(rec, i) in positiveRects"
:key="i + 'prec'"
:rx="radius"
:ry="radius"
:x="rec.x"
:y="rec.y"
:width="width"
:height="rec.height"
:fill="rec.color"
clip-path="url(#positive-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)"
@mousemove="update"
@mouseleave="destroy"
/>
<rect v-for="(rec, i) in positiveRects" :key="i + 'prec'" :rx="radius" :ry="radius" :x="rec.x" :y="rec.y"
:width="width" :height="rec.height" :fill="rec.color" clip-path="url(#positive-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)" @mousemove="update" @mouseleave="destroy" />

<rect
v-for="(rec, i) in negativeRects"
:key="i + 'nrec'"
:rx="radius"
:ry="radius"
:x="rec.x"
:y="rec.y"
:width="width"
:height="rec.height"
:fill="rec.color"
clip-path="url(#negative-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)"
@mousemove="update"
@mouseleave="destroy"
/>
<rect v-for="(rec, i) in negativeRects" :key="i + 'nrec'" :rx="radius" :ry="radius" :x="rec.x" :y="rec.y"
:width="width" :height="rec.height" :fill="rec.color" clip-path="url(#negative-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)" @mousemove="update" @mouseleave="destroy" />
</svg>
<Tooltip
ref="tooltip"
:offset="15"
placement="top"
<Tooltip ref="tooltip" :offset="15" placement="top"
class="text-sm shadow-md px-2 py-1 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-200 border-s-4"
:style="{ borderColor: activeColor }"
>
:style="{ borderColor: activeColor }">
<div class="flex flex-col justify-center items-center">
<p>
{{ xi > -1 ? formatX(xLabels[xi]) : '' }}
Expand Down Expand Up @@ -196,7 +127,7 @@ export default {
this.padding +
this.left +
(i * (this.viewBoxWidth - this.left - 2 * this.padding)) /
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
);
},
z() {
Expand All @@ -215,9 +146,8 @@ export default {
return Math.max(...this.points.flat());
},
axis() {
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${
this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
},
padding() {
return this.axisPadding + this.pointsPadding;
Expand Down Expand Up @@ -305,7 +235,7 @@ export default {
return (
((this.yLabelDivisions - i) *
(this.viewBoxHeight - this.padding * 2 - this.bottom)) /
this.yLabelDivisions +
this.yLabelDivisions +
this.padding
);
},
Expand Down
115 changes: 27 additions & 88 deletions src/components/Charts/LineChart.vue
Original file line number Diff line number Diff line change
@@ -1,60 +1,30 @@
<template>
<div>
<svg
ref="chartSvg"
:viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`"
xmlns="http://www.w3.org/2000/svg"
@mousemove="update"
>
<svg ref="chartSvg" :viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`" xmlns="http://www.w3.org/2000/svg"
@mousemove="update">
<!-- x Grid Lines -->
<path
v-if="drawXGrid"
:d="xGrid"
:stroke="gridColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<path v-if="drawXGrid" :d="xGrid" :stroke="gridColor" :stroke-width="gridThickness" stroke-linecap="round"
fill="transparent" />

<!-- Axis -->
<path
v-if="drawAxis"
:d="axis"
:stroke-width="axisThickness"
:stroke="axisColor"
fill="transparent"
/>
<path v-if="drawAxis" :d="axis" :stroke-width="axisThickness" :stroke="axisColor" fill="transparent" />

<!-- x Labels -->
<template v-if="drawLabels && xLabels.length > 0">
<text
v-for="(i, j) in count"
:key="j + '-xlabels'"
:style="fontStyle"
:y="
viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
"
:x="xs[i - 1]"
text-anchor="middle"
>
<text v-for="(i, j) in count" :key="j + '-xlabels'" :style="fontStyle" :y="viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
" :x="xs[i - 1]" text-anchor="middle">
{{ formatX(xLabels[i - 1] || '') }}
</text>
</template>

<!-- y Labels -->
<template v-if="drawLabels && yLabelDivisions > 0">
<text
v-for="(i, j) in yLabelDivisions + 1"
:key="j + '-ylabels'"
:style="fontStyle"
:y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left"
text-anchor="end"
>
<text v-for="(i, j) in yLabelDivisions + 1" :key="j + '-ylabels'" :style="fontStyle" :y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left" text-anchor="end">
{{ yScalerValue(i - 1) }}
</text>
</template>
Expand All @@ -68,58 +38,28 @@
</linearGradient>

<mask v-for="(i, j) in num" :id="'rect-mask-' + i" :key="j + '-mask'">
<rect
x="0"
:y="gradY(j)"
:height="viewBoxHeight - gradY(j)"
width="100%"
fill="url('#grad')"
/>
<rect x="0" :y="gradY(j)" :height="viewBoxHeight - gradY(j)" width="100%" fill="url('#grad')" />
</mask>
</defs>

<g v-for="(i, j) in num" :key="j + '-gpath'">
<!-- Gradient Paths -->
<path
stroke-linejoin="round"
:d="getGradLine(i - 1)"
:stroke-width="thickness"
stroke-linecap="round"
:fill="colors[i - 1] || getRandomColor()"
:mask="`url('#rect-mask-${i}')`"
/>
<path stroke-linejoin="round" :d="getGradLine(i - 1)" :stroke-width="thickness" stroke-linecap="round"
:fill="colors[i - 1] || getRandomColor()" :mask="`url('#rect-mask-${i}')`" />

<!-- Lines -->
<path
stroke-linejoin="round"
:d="getLine(i - 1)"
:stroke="colors[i - 1] || getRandomColor()"
:stroke-width="thickness"
stroke-linecap="round"
fill="transparent"
/>
<path stroke-linejoin="round" :d="getLine(i - 1)" :stroke="colors[i - 1] || getRandomColor()"
:stroke-width="thickness" stroke-linecap="round" fill="transparent" />
</g>

<!-- Tooltip Reference -->
<circle
v-if="xi > -1 && yi > -1"
r="12"
:cx="cx"
:cy="cy"
:fill="colors[yi]"
style="
<circle v-if="xi > -1 && yi > -1" r="12" :cx="cx" :cy="cy" :fill="colors[yi]" style="
filter: brightness(115%) drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.25));
"
/>
" />
</svg>
<Tooltip
v-if="showTooltip"
ref="tooltip"
:offset="15"
placement="top"
<Tooltip v-if="showTooltip" ref="tooltip" :offset="15" placement="top"
class="text-sm shadow-md px-2 py-1 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-200 border-s-4"
:style="{ borderColor: colors[yi] }"
>
:style="{ borderColor: colors[yi] }">
<div class="flex flex-col justify-center items-center">
<p>
{{ xi > -1 ? formatX(xLabels[xi]) : '' }}
Expand Down Expand Up @@ -193,7 +133,7 @@ export default {
this.padding +
this.left +
(i * (this.viewBoxWidth - this.left - 2 * this.padding)) /
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
);
},
ys() {
Expand All @@ -204,7 +144,7 @@ export default {
(p) =>
this.padding +
(1 - (p - min) / (max - min)) *
(this.viewBoxHeight - 2 * this.padding - this.bottom)
(this.viewBoxHeight - 2 * this.padding - this.bottom)
)
);
},
Expand All @@ -218,9 +158,8 @@ export default {
return Math.max(...this.points.flat());
},
axis() {
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${
this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
},
padding() {
return this.axisPadding + this.pointsPadding;
Expand Down Expand Up @@ -261,7 +200,7 @@ export default {
return (
((this.yLabelDivisions - i) *
(this.viewBoxHeight - this.padding * 2 - this.bottom)) /
this.yLabelDivisions +
this.yLabelDivisions +
this.padding
);
},
Expand Down
Loading

0 comments on commit f15b1cf

Please sign in to comment.