Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(stacked-series-chart): Adding auto scrolling on horizontal overf…
Browse files Browse the repository at this point in the history
…low for column mode
  • Loading branch information
tonidalmases authored and ffriedl89 committed Jun 2, 2021
1 parent 2537701 commit 7432a29
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
barBtn,
barChart,
body,
chartWidth400Btn,
chartContainer,
chartWidth400Btn,
columnBtn,
columnChart,
fullTrackBtn,
Expand All @@ -46,6 +46,8 @@ import {
resetBtn,
selectableBtn,
selectBtn,
selectionModeNode,
selectionModeStack,
setLegendsBtn,
singleTrackBtn,
slices,
Expand All @@ -64,6 +66,9 @@ const hover: MouseActionOptions = {
speed: 0.6,
};

const selectableTrackClassname = 'dt-stacked-series-chart-track-selectable';
const selectableSliceClassname = 'dt-stacked-series-chart-slice-selectable';

const selectedSliceClassname = 'dt-stacked-series-chart-slice-selected';

const compactModeClassname = 'dt-stacked-series-chart-series-axis-compact-mode';
Expand Down Expand Up @@ -130,7 +135,7 @@ test('should change the mode and fillMode', async (testController) => {
// fillMode
.click(fullTrackBtn)
.expect(getSlice(0, 0).clientHeight)
.within(290, 300)
.within(285, 300)
.click(barBtn)
.expect(getSlice(0, 0).clientWidth)
.within(635, 650);
Expand Down Expand Up @@ -271,3 +276,26 @@ test('should switch from full to compact on labelAxisMode auto', async (testCont
.expect(chartContainer.classNames)
.contains(compactModeClassname);
});

test('should be selectable depending on the selection mode', async (testController: TestController) => {
await testController
// non selectable
.click(resetBtn)
.expect(getTrack(0).classNames)
.notContains(selectableTrackClassname)
.expect(getSlice(0, 0).classNames)
.notContains(selectableSliceClassname)
// selectable slice
.click(selectableBtn)
.click(selectionModeNode)
.expect(getTrack(0).classNames)
.notContains(selectableTrackClassname)
.expect(getSlice(0, 0).classNames)
.contains(selectableSliceClassname)
// selectable stack
.click(selectionModeStack)
.expect(getTrack(0).classNames)
.contains(selectableTrackClassname)
.expect(getSlice(0, 0).classNames)
.contains(selectableSliceClassname);
});
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,12 @@
<button (click)="setElementWidth('800px')" id="chart-width-800">800px</button>
<button (click)="setElementWidth('400px')" id="chart-width-400">400px</button>
</div>

<div>
<button (click)="selectionMode = 'node'" id="chart-selection-mode-node">
Node
</button>
<button (click)="selectionMode = 'stack'" id="chart-selection-mode-stack">
Stack
</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ export const unselectBtn = Selector('#chart-unselect');

export const chartWidth800Btn = Selector('#chart-width-800');
export const chartWidth400Btn = Selector('#chart-width-400');

export const selectionModeNode = Selector('#chart-selection-mode-node');
export const selectionModeStack = Selector('#chart-selection-mode-stack');
12 changes: 11 additions & 1 deletion libs/barista-components/stacked-series-chart/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,24 @@ sass_binary(
sass_binary(
name = "styles_column",
src = "src/stacked-series-chart-column.scss",
deps = [":styles_shared"],
deps = [
":styles_shared",
":theme",
],
)

sass_library(
name = "styles_shared",
srcs = ["src/_stacked-series-chart-shared.scss"],
)

sass_library(
name = "theme",
srcs = glob(
["src/_stacked-series-chart-theme.scss"],
),
)

stylelint(
name = "stylelint",
srcs = glob(["**/*.scss"]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import '../../core/src/style/colors';

.dt-theme-dark :host {
.dt-stacked-series-chart-value-axis.dt-stacked-series-chart-value-axis {
background-color: $gray-860;
}
}

.dt-theme-dark .dt-card :host {
.dt-stacked-series-chart-value-axis.dt-stacked-series-chart-value-axis {
background-color: #505050;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ See stacked-series-chart.layout.md
border-top: 1px solid $axis-color;
grid-row: calc(1 + var(--dt-stacked-series-chart-track-amount));
height: 40px;
position: relative;
}

.dt-stacked-series-chart-label-none .dt-stacked-series-chart-value-axis {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
@import './stacked-series-chart-shared';
@import './stacked-series-chart-theme';

/** HOW TO of layout
See stacked-series-chart.layout.md
*/

:host(.dt-stacked-series-chart-column) {
overflow-x: auto;

.dt-stacked-series-chart-container {
justify-items: center;
grid-template-rows: 1fr auto;
Expand All @@ -14,6 +17,7 @@ See stacked-series-chart.layout.md
var(--dt-stacked-series-chart-track-amount),
1fr
);
padding-top: 8px;
}

/* TRACK + LABEL */
Expand Down Expand Up @@ -59,6 +63,10 @@ See stacked-series-chart.layout.md
grid-auto-rows: 1fr;
flex-direction: column-reverse;
text-align: right;
padding-left: var(--dt-stacked-series-chart-value-axis-size);
position: sticky;
left: 0;
background-color: $white;
}

.dt-stacked-series-chart-axis-tick {
Expand Down Expand Up @@ -91,11 +99,6 @@ See stacked-series-chart.layout.md
}
}

:host(.dt-stacked-series-chart-with-value-axis.dt-stacked-series-chart-column)
.dt-stacked-series-chart-container {
padding-left: var(--dt-stacked-series-chart-value-axis-size);
}

.dt-stacked-series-chart-series-axis-compact-mode {
.dt-stacked-series-chart-track-label {
width: 14px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
class="dt-stacked-series-chart-track"
[class.dt-stacked-series-chart-node]="_isNodeSelectionMode"
[class.dt-stacked-series-chart-stack]="_isStackSelectionMode"
[class.dt-stacked-series-chart-track-selectable]="_selectable"
[class.dt-stacked-series-chart-track-selectable]="
_selectable && _isStackSelectionMode
"
[class.dt-stacked-series-chart-track-selected]="track.selected"
[class.dt-stacked-series-chart-track-background]="visibleTrackBackground"
[class.dt-stacked-series-chart-track-hoverable]="_overlay"
Expand All @@ -57,6 +59,7 @@
<span
*ngFor="let slice of track.nodes; trackBy: _trackByFn"
class="dt-stacked-series-chart-slice"
[class.dt-stacked-series-chart-slice-selectable]="_selectable"
[class.dt-stacked-series-chart-slice-selected]="slice.selected"
[attr.aria-label]="slice.ariaLabel"
[style]="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ See stacked-series-chart.layout.md
background: $track-color;
}

.dt-stacked-series-chart-track-selectable .dt-stacked-series-chart-slice {
.dt-stacked-series-chart-track-selectable {
cursor: pointer;
}

Expand All @@ -43,6 +43,10 @@ See stacked-series-chart.layout.md
}

.dt-stacked-series-chart-track-hoverable {
.dt-stacked-series-chart-slice-selectable {
cursor: pointer;
}

.dt-stacked-series-chart-slice:hover {
opacity: $hover-opacity;
}
Expand All @@ -51,7 +55,6 @@ See stacked-series-chart.layout.md
/** Slice **/
.dt-stacked-series-chart-node .dt-stacked-series-chart-slice-selected,
.dt-stacked-series-chart-track-selected.dt-stacked-series-chart-stack {
cursor: default;
position: relative;

&::before {
Expand All @@ -64,10 +67,6 @@ See stacked-series-chart.layout.md
}

/** Axis */
.dt-stacked-series-chart-value-axis {
position: relative;
}

.dt-stacked-series-chart-axis-tick {
position: absolute;

Expand Down

0 comments on commit 7432a29

Please sign in to comment.