Skip to content

Commit

Permalink
Modernize JS/TS codebase and upgrade to bokeh 3.4 (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap authored Mar 27, 2024
1 parent 80edeb1 commit 6d71fa5
Show file tree
Hide file tree
Showing 13 changed files with 3,856 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
MOZ_HEADLESS: 1
DISPLAY: ":99.0"
steps:
- uses: holoviz-dev/holoviz_tasks/install@v0.1a19
- uses: holoviz-dev/holoviz_tasks/install@v0
with:
name: Documentation
python-version: "3.10"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
name: Run pre-commit
runs-on: "ubuntu-latest"
steps:
- uses: holoviz-dev/holoviz_tasks/pre-commit@v0.1a19
- uses: holoviz-dev/holoviz_tasks/pre-commit@v0
setup:
name: Setup workflow
runs-on: ubuntu-latest
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
timeout-minutes: 60
steps:
- uses: holoviz-dev/holoviz_tasks/install@v0.1a19
- uses: holoviz-dev/holoviz_tasks/install@v0
if: needs.setup.outputs.code_change == 'true'
with:
name: unit_test_suite
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
timeout-minutes: 120
steps:
# Add back when this works on Python 3.12
# - uses: holoviz-dev/holoviz_tasks/install@v0.1a19
# - uses: holoviz-dev/holoviz_tasks/install@v0
# with:
# name: core_test_suite
# python-version: ${{ matrix.python-version }}
Expand Down
138 changes: 138 additions & 0 deletions geoviews/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json"],
tsconfigRootDir: __dirname,
sourceType: "module",
},
plugins: ["@typescript-eslint"],
extends: [],
rules: {
"@typescript-eslint/ban-types": ["error", {
types: {
Function: false,
object: false,
"{}": false,
},
}],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-imports": ["error", {
prefer: "type-imports",
fixStyle: "separate-type-imports",
}],
"@typescript-eslint/member-delimiter-style": ["error", {
multiline: {
delimiter: "none",
requireLast: true,
},
singleline: {
delimiter: "comma",
requireLast: false,
},
}],
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": ["error"],
"@typescript-eslint/no-unnecessary-condition": ["error", {allowConstantLoopConditions: true}],
"@typescript-eslint/strict-boolean-expressions": ["error", {
allowAny: true,
allowString: false,
allowNumber: false,
allowNullableObject: false,
allowNullableBoolean: false,
allowNullableString: false,
allowNullableNumber: false,
}],
"@typescript-eslint/no-unnecessary-type-assertion": ["error"],
"@typescript-eslint/no-unnecessary-type-constraint": ["error"],
"@typescript-eslint/switch-exhaustiveness-check": ["error"],
"no-self-assign": ["error", {
props: false,
}],
"comma-dangle": ["off"],
"@typescript-eslint/comma-dangle": ["error", {
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
functions: "always-multiline",
enums: "always-multiline",
generics: "always-multiline",
tuples: "always-multiline",
}],
"comma-spacing": ["error", {before: false, after: true}],
"dot-notation": "error",
"eol-last": ["error", "always"],
indent: "off",
"@typescript-eslint/indent": ["error", 2, {
SwitchCase: 1,
outerIIFEBody: 1,
ArrayExpression: "first",
ObjectExpression: "first",
ImportDeclaration: "first",
VariableDeclarator: "first",
CallExpression: {arguments: 1},
FunctionDeclaration: {body: 1, parameters: "off"},
FunctionExpression: {body: 1, parameters: "off"},
ignoredNodes: ["ConditionalExpression"],
}],
"@typescript-eslint/no-floating-promises": ["error", {ignoreVoid: true}],
"no-debugger": "error",
"no-floating-decimal": ["error"],
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}],
"no-new-wrappers": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
"no-trailing-spaces": ["error"],
"no-var": "error",
"object-shorthand": "error",
"prefer-const": ["error", {destructuring: "all"}],
"prefer-exponentiation-operator": "error",
"quote-props": ["error", "as-needed"],
"object-curly-spacing": ["error", "never"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {
anonymous: "never",
named: "never",
asyncArrow: "always",
}],
"space-in-parens": ["error", "never"],
"keyword-spacing": ["error", {
before: true,
after: true,
}],
"func-call-spacing": ["error", "never"],
"no-whitespace-before-property": ["error"],
"block-spacing": ["error", "always"],
"key-spacing": ["error", {
beforeColon: false,
afterColon: true,
mode: "minimum",
}],
"space-unary-ops": ["error", {
words: true,
nonwords: false,
overrides: {},
}],
"guard-for-in": ["error"],
quotes: ["error", "double", {
avoidEscape: true,
allowTemplateLiterals: false,
}],
"brace-style": ["error", "1tbs", {allowSingleLine: true}],
curly: ["error", "all"],
"prefer-template": ["error"],
"generator-star-spacing": ["error", {
before: false,
after: true,
anonymous: {before: false, after: true},
method: {before: true, after: false},
}],
"yield-star-spacing": ["error", {before: false, after: true}],
},
overrides: [
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: ["./**/*.js"],
},
],
}
32 changes: 18 additions & 14 deletions geoviews/models/checkpoint_tool.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import * as p from "@bokehjs/core/properties"
import type * as p from "@bokehjs/core/properties"
import {entries} from "@bokehjs/core/util/object"
import type {Data} from "@bokehjs/core/types"
import {copy} from "@bokehjs/core/util/array"
import {ActionTool, ActionToolView} from "@bokehjs/models/tools/actions/action_tool"
import {ColumnDataSource} from "@bokehjs/models/sources/column_data_source"
import {tool_icon_save} from "@bokehjs/styles/icons.css"

type BufferedColumnDataSource = ColumnDataSource & {buffer?: Data[]}

export class CheckpointToolView extends ActionToolView {
model: CheckpointTool
declare model: CheckpointTool

doit(): void {
const sources: any = this.model.sources;
const sources = this.model.sources as BufferedColumnDataSource[]
for (const source of sources) {
if (!source.buffer) { source.buffer = [] }
let data_copy: any = {};
for (const key in source.data) {
const column = source.data[key];
if (source.buffer == null) {
source.buffer = []
}
const data_copy: Data = {}
for (const [key, column] of entries(source.data)) {
const new_column = []
for (const arr of column) {
if (Array.isArray(arr) || (ArrayBuffer.isView(arr))) {
new_column.push(copy((arr as any)))
if (Array.isArray(arr) || ArrayBuffer.isView(arr)) {
new_column.push(copy(arr as any))
} else {
new_column.push(arr)
}
}
data_copy[key] = new_column;
data_copy[key] = new_column
}
source.buffer.push(data_copy)
}
Expand All @@ -40,13 +44,13 @@ export namespace CheckpointTool {
export interface CheckpointTool extends CheckpointTool.Attrs {}

export class CheckpointTool extends ActionTool {
properties: CheckpointTool.Props
declare properties: CheckpointTool.Props

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

static __module__ = "geoviews.models.custom_tools"
static override __module__ = "geoviews.models.custom_tools"

static {
this.prototype.default_view = CheckpointToolView
Expand All @@ -56,6 +60,6 @@ export class CheckpointTool extends ActionTool {
}))
}

tool_name = "Checkpoint"
tool_icon = tool_icon_save
override tool_name = "Checkpoint"
override tool_icon = tool_icon_save
}
21 changes: 8 additions & 13 deletions geoviews/models/clear_tool.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import * as p from "@bokehjs/core/properties"
import type * as p from "@bokehjs/core/properties"
import {ActionTool, ActionToolView} from "@bokehjs/models/tools/actions/action_tool"
import {ColumnDataSource} from "@bokehjs/models/sources/column_data_source"
import {tool_icon_reset} from "@bokehjs/styles/icons.css"


export class ClearToolView extends ActionToolView {
model: ClearTool
declare model: ClearTool

doit(): void {
for (var source of this.model.sources) {
for (const column in source.data) {
source.data[column] = []
}
source.change.emit();
source.properties.data.change.emit();
for (const source of this.model.sources) {
source.clear()
}
}
}
Expand All @@ -28,13 +23,13 @@ export namespace ClearTool {
export interface ClearTool extends ClearTool.Attrs {}

export class ClearTool extends ActionTool {
properties: ClearTool.Props
declare properties: ClearTool.Props

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

static __module__ = "geoviews.models.custom_tools"
static override __module__ = "geoviews.models.custom_tools"

static {
this.prototype.default_view = ClearToolView
Expand All @@ -44,6 +39,6 @@ export class ClearTool extends ActionTool {
}))
}

tool_name = "Clear data"
tool_icon = tool_icon_reset
override tool_name = "Clear data"
override tool_icon = tool_icon_reset
}
Loading

0 comments on commit 6d71fa5

Please sign in to comment.