Skip to content

Commit

Permalink
Redesign and improve slider widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap committed Nov 26, 2023
1 parent 2555a4f commit 9ab3e89
Show file tree
Hide file tree
Showing 21 changed files with 513 additions and 227 deletions.
6 changes: 0 additions & 6 deletions bokehjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 0 additions & 67 deletions bokehjs/src/less/widgets/nouislider.less

This file was deleted.

59 changes: 59 additions & 0 deletions bokehjs/src/less/widgets/sliders.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
:host {
--handle-size: 1.0em;
--bar-size: 0.5em;
}

.bk-slider-title {
white-space: nowrap;
}

.bk-slider-value {
font-weight: 600;
}

.bk-slider {
display: flex;
position: relative;
width: 100%;
height: var(--handle-size);
}

.bk-bar {
align-self: center;
position: relative;
width: 100%;
height: var(--bar-size);
border-radius: var(--bar-size);
border: 1px solid #c0c0c0;
background-color: #e5e5e5;
}

.bk-connect {
position: relative;
left: 0;
top: 0;
width: 0;
height: 100%;
border-top-left-radius: var(--bar-size);
border-bottom-left-radius: var(--bar-size);
background-color: #c2d5f7;
}

.bk-handle {
position: absolute;
left: 0;
top: 50%;
width: var(--handle-size);
height: var(--handle-size);
border-radius: 50%;
background-color: #3b80f0;
transform: translate(-50%, -50%);
cursor: ew-resize;
}

:host(.bk-stealth) {
--handle-size: var(--bar-size);

.bk-handle {
opacity: 0;
}
}

:host(.bk-vertical) {
.bk-handle {
cursor: ns-resize;
}
}
10 changes: 8 additions & 2 deletions bokehjs/src/lib/core/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,15 @@ export function content_size(el: HTMLElement): Size {
return {width, height}
}

export function bounding_box(el: Element): BBox {
export function bounding_box(el: Element, relative_to?: Element): BBox {
const {x, y, width, height} = el.getBoundingClientRect()
return new BBox({x, y, width, height})
const bbox = new BBox({x, y, width, height})
if (relative_to != null) {
const {x, y} = relative_to.getBoundingClientRect()
return bbox.translate(-x, -y)
} else {
return bbox
}
}

export function box_size(el: Element): Size {
Expand Down
4 changes: 4 additions & 0 deletions bokehjs/src/lib/core/util/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export function linspace(start: number, stop: number, num: number = 100): number
return array
}

export function logspace(start: number, stop: number, num: number = 100, base: number = 10): number[] {
return linspace(start, stop, num).map((v) => base**v)
}

export function transpose<T>(array: T[][]): T[][] {
const rows = array.length
const cols = array[0].length
Expand Down
4 changes: 2 additions & 2 deletions bokehjs/src/lib/core/util/bbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ export class BBox implements Rect, Equatable {
})
}

relativize(x: number, y: number): [number, number] {
return [x - this.x, y - this.y]
relativize({x, y}: XY): XY {
return {x: x - this.x, y: y - this.y}
}

contains(x: number, y: number): boolean {
Expand Down
39 changes: 39 additions & 0 deletions bokehjs/src/lib/models/ui/slider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {UIElement, UIElementView} from "./ui_element"
import type * as p from "core/properties"

export class SliderView extends UIElementView {
declare model: Slider

override connect_signals(): void {
super.connect_signals()
}

override render(): void {
super.render()
}
}

export namespace Slider {
export type Attrs = p.AttrsOf<Props>

export type Props = UIElement.Props & {
}
}

export interface Slider extends Slider.Attrs {}

export class Slider extends UIElement {
declare properties: Slider.Props
declare __view_type__: SliderView

constructor(attrs?: Partial<Slider.Attrs>) {
super(attrs)
}

static {
this.prototype.default_view = SliderView

this.define<Slider.Props>(({}) => ({
}))
}
}

0 comments on commit 9ab3e89

Please sign in to comment.