fixed some alignment
This commit is contained in:
@@ -11,7 +11,8 @@ export interface LineSeries {
|
|||||||
export class LineChart extends LitElement {
|
export class LineChart extends LitElement {
|
||||||
static styles = css`
|
static styles = css`
|
||||||
:host {
|
:host {
|
||||||
display: inline-flex;
|
display: block;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chart-wrapper {
|
.chart-wrapper {
|
||||||
@@ -23,6 +24,8 @@ export class LineChart extends LitElement {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 1.25rem;
|
gap: 1.25rem;
|
||||||
transition: border-color 0.25s ease;
|
transition: border-color 0.25s ease;
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chart-wrapper:hover {
|
.chart-wrapper:hover {
|
||||||
@@ -37,6 +40,7 @@ export class LineChart extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
@@ -54,8 +58,14 @@ export class LineChart extends LitElement {
|
|||||||
|
|
||||||
.svg-container {
|
.svg-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: visible;
|
min-height: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
aspect-ratio: 500 / 300;
|
aspect-ratio: 500 / 300;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([style*='height']) .svg-container {
|
||||||
|
aspect-ratio: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@@ -64,6 +74,7 @@ export class LineChart extends LitElement {
|
|||||||
overflow: visible;
|
overflow: visible;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-line {
|
.grid-line {
|
||||||
stroke: var(--color-border);
|
stroke: var(--color-border);
|
||||||
stroke-width: 0.5;
|
stroke-width: 0.5;
|
||||||
@@ -97,6 +108,7 @@ export class LineChart extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend-item {
|
.legend-item {
|
||||||
@@ -173,9 +185,7 @@ export class LineChart extends LitElement {
|
|||||||
const sx = (v: number) =>
|
const sx = (v: number) =>
|
||||||
p.left + ((v - xScale.min) / (xScale.max - xScale.min)) * w;
|
p.left + ((v - xScale.min) / (xScale.max - xScale.min)) * w;
|
||||||
const sy = (v: number) =>
|
const sy = (v: number) =>
|
||||||
p.top +
|
p.top + h - ((v - yScale.min) / (yScale.max - yScale.min)) * h;
|
||||||
h -
|
|
||||||
((v - yScale.min) / (yScale.max - yScale.min)) * h;
|
|
||||||
|
|
||||||
const gridLines = [];
|
const gridLines = [];
|
||||||
for (
|
for (
|
||||||
@@ -209,7 +219,10 @@ export class LineChart extends LitElement {
|
|||||||
if (!sorted.length) return svg``;
|
if (!sorted.length) return svg``;
|
||||||
|
|
||||||
const d = sorted
|
const d = sorted
|
||||||
.map((pt, j) => `${j === 0 ? 'M' : 'L'}${sx(pt.x)},${sy(pt.y)}`)
|
.map(
|
||||||
|
(pt, j) =>
|
||||||
|
`${j === 0 ? 'M' : 'L'}${sx(pt.x)},${sy(pt.y)}`
|
||||||
|
)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
const areaD =
|
const areaD =
|
||||||
@@ -238,13 +251,26 @@ export class LineChart extends LitElement {
|
|||||||
`
|
`
|
||||||
: null}
|
: null}
|
||||||
<div class="svg-container">
|
<div class="svg-container">
|
||||||
<svg viewBox="0 0 ${this.width} ${this.height}">
|
<svg
|
||||||
|
viewBox="0 0 ${this.width} ${this.height}"
|
||||||
|
preserveAspectRatio="none"
|
||||||
|
>
|
||||||
${gridLines} ${lines}
|
${gridLines} ${lines}
|
||||||
<text class="axis-label" x="${this.width / 2}" y="${this.height - 4}" text-anchor="middle">
|
<text
|
||||||
|
class="axis-label"
|
||||||
|
x="${this.width / 2}"
|
||||||
|
y="${this.height - 4}"
|
||||||
|
text-anchor="middle"
|
||||||
|
>
|
||||||
${this.xLabel}
|
${this.xLabel}
|
||||||
</text>
|
</text>
|
||||||
<text class="axis-label" x="12" y="${this.height / 2}" text-anchor="middle"
|
<text
|
||||||
transform="rotate(-90, 12, ${this.height / 2})">
|
class="axis-label"
|
||||||
|
x="12"
|
||||||
|
y="${this.height / 2}"
|
||||||
|
text-anchor="middle"
|
||||||
|
transform="rotate(-90, 12, ${this.height / 2})"
|
||||||
|
>
|
||||||
${this.yLabel}
|
${this.yLabel}
|
||||||
</text>
|
</text>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -255,10 +281,13 @@ export class LineChart extends LitElement {
|
|||||||
${this.series.map(
|
${this.series.map(
|
||||||
(s, i) => html`
|
(s, i) => html`
|
||||||
<div class="legend-item">
|
<div class="legend-item">
|
||||||
<span class="legend-line" style="background: ${s.color ||
|
<span
|
||||||
|
class="legend-line"
|
||||||
|
style="background: ${s.color ||
|
||||||
this.defaultColors[
|
this.defaultColors[
|
||||||
i % this.defaultColors.length
|
i % this.defaultColors.length
|
||||||
]}"></span>
|
]}"
|
||||||
|
></span>
|
||||||
<span class="legend-label">${s.label}</span>
|
<span class="legend-label">${s.label}</span>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user