added selectbox
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/hjacobs/kube-ops-view#readme",
|
"homepage": "https://github.com/hjacobs/kube-ops-view#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"pixi-display": "^1.0.1",
|
||||||
"pixi.js": "^4.3.0",
|
"pixi.js": "^4.3.0",
|
||||||
"webpack-dev-server": "^1.16.2"
|
"webpack-dev-server": "^1.16.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import Tooltip from './tooltip.js'
|
import Tooltip from './tooltip.js'
|
||||||
import Cluster from './cluster.js'
|
import Cluster from './cluster.js'
|
||||||
import { Pod, ALL_PODS } from './pod.js'
|
import {Pod, ALL_PODS} from './pod.js'
|
||||||
|
import SelectBox from './selectbox'
|
||||||
|
import 'pixi-display'
|
||||||
const PIXI = require('pixi.js')
|
const PIXI = require('pixi.js')
|
||||||
|
|
||||||
|
|
||||||
export default class App {
|
export default class App {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -20,7 +23,7 @@ export default class App {
|
|||||||
for (const pod of node.children) {
|
for (const pod of node.children) {
|
||||||
const name = pod.pod && pod.pod.name
|
const name = pod.pod && pod.pod.name
|
||||||
if (name) {
|
if (name) {
|
||||||
if (!name.includes(searchString)){
|
if (!name.includes(searchString)) {
|
||||||
pod.filters = [filter]
|
pod.filters = [filter]
|
||||||
} else {
|
} else {
|
||||||
// TODO: pod might have other filters set..
|
// TODO: pod might have other filters set..
|
||||||
@@ -46,11 +49,13 @@ export default class App {
|
|||||||
//Create a container object called the `stage`
|
//Create a container object called the `stage`
|
||||||
const stage = new PIXI.Container()
|
const stage = new PIXI.Container()
|
||||||
|
|
||||||
|
stage.displayList = new PIXI.DisplayList()
|
||||||
|
|
||||||
const searchPrompt = new PIXI.Text('>', {fontFamily: 'ShareTechMono', fontSize: 18, fill: 0xaaaaff})
|
const searchPrompt = new PIXI.Text('>', {fontFamily: 'ShareTechMono', fontSize: 18, fill: 0xaaaaff})
|
||||||
searchPrompt.x = 20
|
searchPrompt.x = 20
|
||||||
searchPrompt.y = 5
|
searchPrompt.y = 5
|
||||||
PIXI.ticker.shared.add(function(_) {
|
PIXI.ticker.shared.add(function (_) {
|
||||||
var v = Math.sin((PIXI.ticker.shared.lastTime % 2000)/2000.* Math.PI)
|
var v = Math.sin((PIXI.ticker.shared.lastTime % 2000) / 2000. * Math.PI)
|
||||||
searchPrompt.alpha = v
|
searchPrompt.alpha = v
|
||||||
})
|
})
|
||||||
stage.addChild(searchPrompt)
|
stage.addChild(searchPrompt)
|
||||||
@@ -60,6 +65,28 @@ export default class App {
|
|||||||
searchText.y = 5
|
searchText.y = 5
|
||||||
stage.addChild(searchText)
|
stage.addChild(searchText)
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
text: 'Name', sorterFn: () => {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Age', sorterFn: () => {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Memory', sorterFn: () => {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'CPU', sorterFn: () => {}
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
|
const selectBox = new SelectBox(items)
|
||||||
|
selectBox.x = 265
|
||||||
|
selectBox.y = 5
|
||||||
|
const mainLayer = new PIXI.DisplayGroup(1, true)
|
||||||
|
selectBox.displayGroup = mainLayer
|
||||||
|
stage.addChild(selectBox.draw())
|
||||||
|
|
||||||
const viewContainer = new PIXI.Container()
|
const viewContainer = new PIXI.Container()
|
||||||
viewContainer.x = 20
|
viewContainer.x = 20
|
||||||
viewContainer.y = 40
|
viewContainer.y = 40
|
||||||
@@ -77,7 +104,7 @@ export default class App {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
else if (event.key == 'Backspace') {
|
else if (event.key == 'Backspace') {
|
||||||
this.filterString = this.filterString.slice(0, Math.max(0, this.filterString.length-1))
|
this.filterString = this.filterString.slice(0, Math.max(0, this.filterString.length - 1))
|
||||||
this.filter()
|
this.filter()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
@@ -98,7 +125,7 @@ export default class App {
|
|||||||
const pod = new Pod(originalPod.pod, this.tooltip, false)
|
const pod = new Pod(originalPod.pod, this.tooltip, false)
|
||||||
pod.draw()
|
pod.draw()
|
||||||
const targetPosition = new PIXI.Point(globalX, globalY)
|
const targetPosition = new PIXI.Point(globalX, globalY)
|
||||||
const angle = Math.random()*Math.PI*2
|
const angle = Math.random() * Math.PI * 2
|
||||||
const cos = Math.cos(angle)
|
const cos = Math.cos(angle)
|
||||||
const sin = Math.sin(angle)
|
const sin = Math.sin(angle)
|
||||||
const distance = Math.max(200, Math.random() * Math.min(window.innerWidth, window.innerHeight))
|
const distance = Math.max(200, Math.random() * Math.min(window.innerWidth, window.innerHeight))
|
||||||
@@ -111,7 +138,7 @@ export default class App {
|
|||||||
pod._progress = 0
|
pod._progress = 0
|
||||||
originalPod.visible = false
|
originalPod.visible = false
|
||||||
const that = this
|
const that = this
|
||||||
const tick = function(t) {
|
const tick = function (t) {
|
||||||
// progress goes from 0 to 1
|
// progress goes from 0 to 1
|
||||||
const progress = Math.min(1, pod._progress + (0.01 * t))
|
const progress = Math.min(1, pod._progress + (0.01 * t))
|
||||||
const scale = 1 + ((1 - progress) * 140)
|
const scale = 1 + ((1 - progress) * 140)
|
||||||
@@ -132,6 +159,7 @@ export default class App {
|
|||||||
PIXI.ticker.shared.add(tick)
|
PIXI.ticker.shared.add(tick)
|
||||||
this.stage.addChild(pod)
|
this.stage.addChild(pod)
|
||||||
}
|
}
|
||||||
|
|
||||||
update(clusters) {
|
update(clusters) {
|
||||||
this.viewContainer.removeChildren()
|
this.viewContainer.removeChildren()
|
||||||
var y = 0
|
var y = 0
|
||||||
@@ -154,7 +182,7 @@ export default class App {
|
|||||||
this.seenPods[key] = pod
|
this.seenPods[key] = pod
|
||||||
const globalPos = pod.toGlobal({x: 0, y: 0})
|
const globalPos = pod.toGlobal({x: 0, y: 0})
|
||||||
if (!firstTime && i < 10) {
|
if (!firstTime && i < 10) {
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function () {
|
||||||
that.animatePodCreation(pod, globalPos.x, globalPos.y)
|
that.animatePodCreation(pod, globalPos.x, globalPos.y)
|
||||||
}, 100 * i)
|
}, 100 * i)
|
||||||
}
|
}
|
||||||
@@ -174,10 +202,10 @@ export default class App {
|
|||||||
|
|
||||||
function fetchData() {
|
function fetchData() {
|
||||||
fetch('kubernetes-clusters', {credentials: 'include'})
|
fetch('kubernetes-clusters', {credentials: 'include'})
|
||||||
.then(function(response) {
|
.then(function (response) {
|
||||||
return response.json()
|
return response.json()
|
||||||
})
|
})
|
||||||
.then(function(json) {
|
.then(function (json) {
|
||||||
const clusters = json.kubernetes_clusters
|
const clusters = json.kubernetes_clusters
|
||||||
that.update(clusters)
|
that.update(clusters)
|
||||||
})
|
})
|
||||||
|
|||||||
81
app/src/selectbox.js
Normal file
81
app/src/selectbox.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
const PIXI = require('pixi.js')
|
||||||
|
|
||||||
|
export default class SelectBox extends PIXI.Graphics {
|
||||||
|
constructor(items) {
|
||||||
|
super()
|
||||||
|
this.items = items
|
||||||
|
this.count = 0
|
||||||
|
this.text = new PIXI.Text(this.items[this.count].text, {
|
||||||
|
fontFamily: 'ShareTechMono',
|
||||||
|
fontSize: 14,
|
||||||
|
fill: 0xaaaaff,
|
||||||
|
align: 'center'
|
||||||
|
})
|
||||||
|
this.text.x = 10
|
||||||
|
this.text.y = 10
|
||||||
|
this.addChild(this.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
onForwardPressed() {
|
||||||
|
const selectBox = this
|
||||||
|
if (selectBox.count + 1 < this.items.length) {
|
||||||
|
selectBox.count++
|
||||||
|
} else {
|
||||||
|
selectBox.count = 0
|
||||||
|
}
|
||||||
|
selectBox.text.text = selectBox.items[selectBox.count].text
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackPressed() {
|
||||||
|
const selectBox = this
|
||||||
|
if (selectBox.count - 1 > 0) {
|
||||||
|
selectBox.count--
|
||||||
|
} else {
|
||||||
|
selectBox.count = selectBox.items.length - 1
|
||||||
|
}
|
||||||
|
selectBox.text.text = selectBox.items[selectBox.count].text
|
||||||
|
}
|
||||||
|
|
||||||
|
draw() {
|
||||||
|
const selectBox = this
|
||||||
|
|
||||||
|
const backArrow = new PIXI.Graphics()
|
||||||
|
const forwardArrow = new PIXI.Graphics()
|
||||||
|
backArrow.interactive = true
|
||||||
|
forwardArrow.interactive = true
|
||||||
|
selectBox.interactive = true
|
||||||
|
// set a fill and line style
|
||||||
|
|
||||||
|
// draw a triangle
|
||||||
|
backArrow.lineStyle(2, 0x000000, 1)
|
||||||
|
backArrow.beginFill(0x1b7c87, 0.5)
|
||||||
|
backArrow.moveTo(0, 2)
|
||||||
|
backArrow.lineTo(-20, 15)
|
||||||
|
backArrow.lineTo(0, 28)
|
||||||
|
backArrow.lineTo(0, 2)
|
||||||
|
backArrow.endFill()
|
||||||
|
selectBox.addChild(backArrow)
|
||||||
|
selectBox.lineStyle(2, 0x000000, 1)
|
||||||
|
selectBox.beginFill(0x1b7c87, 0.5)
|
||||||
|
selectBox.drawRoundedRect(4, 0, 100, 30, 10)
|
||||||
|
selectBox.endFill()
|
||||||
|
|
||||||
|
forwardArrow.lineStyle(2, 0x000000, 1)
|
||||||
|
forwardArrow.beginFill(0x1b7c87, 0.5)
|
||||||
|
forwardArrow.moveTo(108, 2)
|
||||||
|
forwardArrow.lineTo(128, 15)
|
||||||
|
forwardArrow.lineTo(108, 28)
|
||||||
|
forwardArrow.lineTo(108, 2)
|
||||||
|
forwardArrow.endFill()
|
||||||
|
selectBox.addChild(forwardArrow)
|
||||||
|
|
||||||
|
backArrow.on('mousedown', selectBox.onBackPressed.bind(this))
|
||||||
|
backArrow.on('touchstart', selectBox.onBackPressed.bind(this))
|
||||||
|
forwardArrow.on('mousedown', selectBox.onForwardPressed.bind(this))
|
||||||
|
forwardArrow.on('touchstart', selectBox.onForwardPressed.bind(this))
|
||||||
|
|
||||||
|
return selectBox
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user