Skip to content

Commit 8fef8ba

Browse files
committed
Adds a select border around time core of selected pin.
Changes axis label color of selected pin.
1 parent 9a7e19c commit 8fef8ba

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

src/components/colorbar-plot/colorbar-plot.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
3434
);
3535
}
3636

37-
const { pins } = pluginState;
37+
const { pins, selectedPins } = pluginState;
3838
if (!pins.length) {
3939
return (
4040
<div className="colorbar-container">
@@ -48,6 +48,8 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
4848
const labels: string[] = pins.map((pin) => {
4949
return pinLabel(pin);
5050
});
51+
// Filter selected pins
52+
const selectedPinLabels = selectedPins.map((pin) => pinLabel(pin));
5153

5254
const datasetMap = new Map<number, IDataset>();
5355
const yLabels: string[] = [];
@@ -145,15 +147,21 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
145147
// leave() {
146148
// stopAnnotationDragListener();
147149
// },
148-
annotations: {
149-
box1: {
150-
type: "box" as const,
151-
yMin: yLabels.indexOf(selectedYMDDate!),
152-
yMax: yLabels.indexOf(selectedYMDDate!) + 1,
153-
backgroundColor: "rgba(255, 99, 132, 0.25)"
154-
}
155-
}
156-
}
150+
annotations: selectedPinLabels.map((label) => {
151+
const xIndex = labels.indexOf(label); // Find the index of the selected pin label
152+
if (xIndex === -1) return null; // Skip if the label is not found
153+
return {
154+
type: "box",
155+
xMin: xIndex - 0.5, // Highlight the entire vertical bar
156+
xMax: xIndex + 0.5,
157+
yMin: 0, // Start from the bottom of the chart
158+
yMax: yLabels.length,
159+
backgroundColor: "rgba(255, 99, 132, 0.25)",
160+
borderColor: "rgba(255, 99, 132, 1)",
161+
borderWidth: 2,
162+
};
163+
}).filter(Boolean), // Remove null annotations
164+
},
157165
},
158166
responsive: true,
159167
maintainAspectRatio: false,
@@ -162,6 +170,25 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
162170
stacked: true,
163171
type: "category" as const,
164172
barPercentage: .5,
173+
ticks: {
174+
callback: (value: string, index: number) =>{
175+
if (selectedPinLabels.includes(labels[index])) {
176+
return `${labels[index]}`;
177+
}
178+
return labels[index];
179+
},
180+
color: (context: any) => {
181+
const label = labels[context.index];
182+
return selectedPinLabels.includes(label) ? "rgba(255, 99, 132, 1)" : "rgba(0, 0, 0, 1)";
183+
},
184+
font: (context: any) =>{
185+
// Change the font style of the selected labels
186+
const label = labels[context.index];
187+
return selectedPinLabels.includes(label)
188+
? { weight: "bold", size: 10 }
189+
: { weight: "normal", size: 10 };
190+
},
191+
},
165192
},
166193
y: {
167194
reverse: true,

0 commit comments

Comments
 (0)