Skip to content

Commit 1a1592b

Browse files
authored
Merge pull request #79 from metrico/jacovinus-mutiple-label-tooltip
fix: chart responsive init
2 parents 693de7a + f8ca49e commit 1a1592b

File tree

4 files changed

+163
-83
lines changed

4 files changed

+163
-83
lines changed

Diff for: src/components/LabelBrowser/components/styled/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const HistoryIconStyled = styled(HistoryIcon)`
1313
`;
1414
export const HistoryButtonStyled = styled(BtnSmall)`
1515
background: none;
16-
color: ${theme.textColor};
16+
color: ${theme.buttonText};
1717
margin-left: 5px;
1818
background: ${theme.buttonHover};
1919
span {
@@ -30,7 +30,7 @@ export const ShowLabelsBtn = styled(BtnSmall)`
3030
text-overflow: ellipsis;
3131
transition: 0.25s all;
3232
justify-content: flex-start;
33-
color: ${theme.textColor};
33+
color: ${theme.buttonText};
3434
&:hover {
3535
background: ${theme.buttonHover};
3636
}
@@ -52,7 +52,7 @@ export const QueryBarContainer = styled.div`
5252
`;
5353
export const ShowLogsBtn = styled(BtnSmall)`
5454
background: ${theme.primaryDark};
55-
color: white;
55+
color: ${theme.buttonText};
5656
margin-left: 5px;
5757
transition: 0.25s all;
5858
justify-content: center;

Diff for: src/plugins/charts/ChartLabelList.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const LabelsContainer = styled("div")`
66
flex-wrap: wrap;
77
max-height: calc(100% - 300px);
88
overflow-y: auto;
9+
margin-top: 10px;
10+
padding-bottom: 10px;
911
&::-webkit-scrollbar {
1012
width: 10px;
1113
background: black;

Diff for: src/plugins/charts/index.js

+157-79
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,146 @@ import * as moment from "moment";
1212
import { useState, useEffect, useRef } from "react";
1313
import { format } from "date-fns";
1414
import { ChartLabelList } from "./ChartLabelList";
15-
1615
import styled from "@emotion/styled";
16+
import darkTheme from "../../theme/dark";
17+
import { useMediaQuery } from "react-responsive";
1718

19+
const theme = darkTheme;
1820
const ChartButton = styled.button`
19-
border: none;
20-
margin: 0px 5px;
21-
background: ${(props) => (props.isActive ? "#333" : "black")};
21+
background: ${(props) =>
22+
props.isActive ? theme.buttonDefault : theme.buttonInactive};
2223
color: #ddd;
23-
padding: 4px 8px;
24-
border-radius: 3px;
24+
padding: 3px 12px;
25+
border: none;
26+
border-right: ${(props) => (props.leftBtn ? "2px solid #242424" : "none")};
27+
border-left: ${(props) => (props.rightBtn ? "2px solid #242424" : "none")};
28+
border-radius: ${(props) =>
29+
props.rightBtn
30+
? "0px 3px 3px 0px"
31+
: props.leftBtn
32+
? "3px 0px 0px 3px"
33+
: "none"};
2534
cursor: pointer;
26-
font-size: 1em;
27-
line-height: 1.5;
35+
font-size: 12px;
36+
line-height: 20px;
2837
white-space: nowrap;
38+
flex: 1;
2939
`;
3040

41+
const ShowSeries = styled.div`
42+
font-size: 12px;
43+
line-height: 20px;
44+
padding: 3px 12px;
45+
white-space: nowrap;
46+
color: ${theme.textColor};
47+
background: ${theme.buttonInactive};
48+
border-radius: 3px;
49+
cursor: pointer;
50+
transition: 0.2s all;
51+
&:hover {
52+
background: ${theme.buttonHover};
53+
}
54+
`;
55+
56+
const ChartToolsCont = styled.div`
57+
display: flex;
58+
align-items: center;
59+
flex-direction: ${(props) => (props.isMobile ? "column" : "row")};
60+
margin: 5px 23px;
61+
margin-left: 0;
62+
margin-bottom: 10px;
63+
justify-content: space-between;
64+
.limit-cont {
65+
display: flex;
66+
align-items: center;
67+
justify-content: space-between;
68+
flex: 1;
69+
margin-bottom: ${(props) => (props.isMobile ? "10px" : "0px")};
70+
width: ${(props) => (props.isMobile ? "100%" : "auto")};
71+
div {
72+
flex: ${(props) => (props.isMobile ? "1" : "0")};
73+
text-align: ${(props) => (props.isMobile ? "center" : "left")};
74+
}
75+
}
76+
.chart-buttons-cont {
77+
display: flex;
78+
align-items: center;
79+
justify-content: center;
80+
flex: ${(props) => (props.isMobile ? "1" : "0")};
81+
width: ${(props) => (props.isMobile ? "100%" : "auto")};
82+
}
83+
`;
84+
85+
function HandleLimitButton({
86+
isSpliced,
87+
handleNoLimitData,
88+
handleLimitData,
89+
matrixData,
90+
}) {
91+
return isSpliced ? (
92+
<ShowSeries onClick={handleNoLimitData}>
93+
{matrixData.length > 20
94+
? "Showing: 20 Series, Show All "
95+
: "Showing: "}
96+
{matrixData.length}
97+
{" Series"}
98+
</ShowSeries>
99+
) : (
100+
<ShowSeries onClick={handleLimitData}>
101+
{"Showing: "}
102+
{matrixData.length}
103+
{" Series, Show Only 20 Series"}
104+
</ShowSeries>
105+
);
106+
}
107+
108+
function ChartTools({
109+
matrixData,
110+
chartType,
111+
handleNoLimitData,
112+
handleLimitData,
113+
isSpliced,
114+
setBarChart,
115+
setLineChart,
116+
setPointsChart,
117+
}) {
118+
const isMobile = useMediaQuery({ query: "(max-width: 565px)" });
119+
return (
120+
<ChartToolsCont isMobile={isMobile}>
121+
<div className="limit-cont">
122+
<HandleLimitButton
123+
isSpliced={isSpliced}
124+
handleNoLimitData={handleNoLimitData}
125+
handleLimitData={handleLimitData}
126+
matrixData={matrixData}
127+
/>
128+
</div>
129+
<div className="chart-buttons-cont">
130+
<ChartButton
131+
isActive={chartType === "bar"}
132+
onClick={setBarChart}
133+
leftBtn={true}
134+
>
135+
{"bar chart"}
136+
</ChartButton>
137+
<ChartButton
138+
onClick={setLineChart}
139+
isActive={chartType === "line"}
140+
>
141+
{"line chart"}
142+
</ChartButton>
143+
<ChartButton
144+
onClick={setPointsChart}
145+
isActive={chartType === "points"}
146+
rightBtn={true}
147+
>
148+
{"points chart"}
149+
</ChartButton>
150+
</div>
151+
</ChartToolsCont>
152+
);
153+
}
154+
31155
function ClokiChart({ matrixData }) {
32156
const APP_NAME = "cloki_view";
33157
const LOCAL_CHART_TYPE = `${APP_NAME}_chart_type`;
@@ -72,15 +196,22 @@ function ClokiChart({ matrixData }) {
72196
)
73197
.join("");
74198
}
75-
function formatDateRange(data) {
199+
200+
function getTimeSpan(data) {
76201
const tsArray = data
77-
.map((m) => m.data.map(([t, v]) => t))
202+
.map((tsItem) => tsItem?.data?.map(([t, v]) => t))
78203
.flat()
79204
.sort();
80205
const first = tsArray[0];
81206
const last = tsArray[tsArray.length - 1];
82207
const timeSpan = (last - first) / 1000 / 86400;
83208

209+
return { first, last, timeSpan };
210+
}
211+
212+
function formatDateRange(data) {
213+
const { timeSpan, first, last } = getTimeSpan(data);
214+
84215
const formatted =
85216
timeSpan > 1
86217
? "%m/%d %H:%M"
@@ -111,9 +242,11 @@ function ClokiChart({ matrixData }) {
111242
highlightColor: "blue",
112243
mouseActiveRadius: 30,
113244
borderWidth: 0,
114-
margin: { left: 0, right: 0 },
245+
margin: { left: 0, right: 0, top: 0, bottom: 0 },
246+
115247
labelMarginX: 0,
116-
reserveSpace: true,
248+
labelMarginY: 0,
249+
reserveSpace: false,
117250
},
118251
legend: {
119252
show: false,
@@ -733,73 +866,18 @@ function ClokiChart({ matrixData }) {
733866
};
734867

735868
return (
736-
<div>
737-
<div
738-
style={{
739-
display: "flex",
740-
alignItems: "center",
741-
fontSize: ".95rem",
742-
cursor: "pointer",
743-
margin: "0px 23px",
744-
}}
745-
>
746-
<div
747-
style={{
748-
flex: "1",
749-
display: "flex",
750-
justifyContent: "center",
751-
alignItems: "center",
752-
}}
753-
>
754-
{isSpliced ? (
755-
<div
756-
onClick={handleNoLimitData}
757-
style={{ color: "#aaa", fontSize: "13px" }}
758-
>
759-
{matrixData.length > 20
760-
? "Showing: 20 Series, Show All "
761-
: "Showing: "}
762-
{matrixData.length}
763-
{" Series"}
764-
</div>
765-
) : (
766-
<div
767-
onClick={handleLimitData}
768-
style={{ color: "#aaa", fontSize: "13px" }}
769-
>
770-
{"Showing: "}
771-
{matrixData.length}
772-
{" Series, Show Only 20 Series"}
773-
</div>
774-
)}
775-
</div>
776-
<div
777-
style={{
778-
display: "flex",
779-
alignItems: "center",
780-
justifyContent: "flex-end",
781-
}}
782-
>
783-
<ChartButton
784-
isActive={chartType === "bar"}
785-
onClick={setBarChart}
786-
>
787-
{"bar chart"}
788-
</ChartButton>
789-
<ChartButton
790-
onClick={setLineChart}
791-
isActive={chartType === "line"}
792-
>
793-
{"line chart"}
794-
</ChartButton>
795-
<ChartButton
796-
onClick={setPointsChart}
797-
isActive={chartType === "points"}
798-
>
799-
{"points chart"}
800-
</ChartButton>
801-
</div>
802-
</div>
869+
<div style={{ padding: "20px", paddingTop: "0", paddingRight: "0" }}>
870+
<ChartTools
871+
matrixData={matrixData}
872+
chartType={chartType}
873+
handleNoLimitData={handleNoLimitData}
874+
handleLimitData={handleLimitData}
875+
isSpliced={isSpliced}
876+
setBarChart={setBarChart}
877+
setLineChart={setLineChart}
878+
setPointsChart={setPointsChart}
879+
/>
880+
803881
<div
804882
ref={chartRef}
805883
id={"chart-container"}

Diff for: src/scss/modules/log-view.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
position: relative;
77
flex: 1;
88
border-radius: 3px;
9-
padding: 0.5rem;
9+
1010

1111
&::-webkit-scrollbar {
1212
width: 10px;

0 commit comments

Comments
 (0)