Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lu Xu
slapos
Commits
e98c9778
Commit
e98c9778
authored
Dec 14, 2022
by
Lu Xu
👀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/ors-amarisoft: add gadget for monitoring
parent
9e8d734e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
4143 additions
and
0 deletions
+4143
-0
software/ors-amarisoft/gadget/g-chart.line.js
software/ors-amarisoft/gadget/g-chart.line.js
+228
-0
software/ors-amarisoft/gadget/promise.gadget.js
software/ors-amarisoft/gadget/promise.gadget.js
+50
-0
software/ors-amarisoft/gadget/renderjs.js
software/ors-amarisoft/gadget/renderjs.js
+2839
-0
software/ors-amarisoft/gadget/rsvp.js
software/ors-amarisoft/gadget/rsvp.js
+1000
-0
software/ors-amarisoft/gadget/software.cfg.html
software/ors-amarisoft/gadget/software.cfg.html
+26
-0
No files found.
software/ors-amarisoft/gadget/g-chart.line.js
0 → 100644
View file @
e98c9778
function
LineChart
(
container
,
data
,
label
,
tooltip
)
{
this
.
container
=
container
;
this
.
context
=
this
.
container
.
getContext
(
"
2d
"
);
this
.
data
=
data
;
this
.
label
=
label
;
this
.
tooltip
=
tooltip
;
this
.
point_radius
=
5
;
this
.
data_length
=
this
.
data
.
length
;
this
.
data_max
=
this
.
getMax
();
this
.
data_min
=
this
.
getMin
();
this
.
width
=
this
.
container
.
width
;
this
.
height
=
this
.
container
.
height
;
this
.
x_padding
=
this
.
width
*
0.1
;
this
.
y_padding
=
this
.
height
*
0.1
;
this
.
x_step
=
(
this
.
width
-
this
.
x_padding
)
/
this
.
data_length
;
this
.
y_grid_steps
=
10
;
this
.
y_step
=
(
this
.
height
-
this
.
y_padding
*
2
)
/
this
.
y_grid_steps
this
.
coordinates
=
[];
}
LineChart
.
prototype
=
{
constructor
:
LineChart
,
tooltipOn
:
function
(
which
)
{
if
(
which
===
'
click
'
)
this
.
container
.
addEventListener
(
'
click
'
,
this
.
clickEvent
.
bind
(
this
));
else
if
(
which
===
'
mousemove
'
)
this
.
container
.
addEventListener
(
'
mousemove
'
,
this
.
hoverEvent
.
bind
(
this
));
else
console
.
log
(
'
Tooltip activation method not supported
'
);
},
prepareData
:
function
()
{
for
(
var
i
=
0
;
i
<
this
.
data_length
;
i
++
)
{
this
.
coordinates
.
push
({
x
:
this
.
calcCoordinateX
(
i
),
y
:
this
.
calcCoordinateY
(
i
)
});
}
},
draw
:
function
()
{
this
.
drawBorder
();
this
.
prepareData
();
this
.
drawGrid
();
var
coordinates
=
[];
for
(
var
i
=
0
;
i
<
this
.
data_length
-
1
;
i
++
)
{
coordinates
=
this
.
getLineCoordinates
(
i
);
this
.
drawLine
(
coordinates
,
'
#16D
'
,
0
);
this
.
drawPoint
(
coordinates
[
0
],
'
#16D
'
);
}
this
.
drawPoint
(
coordinates
[
1
]);
},
drawBorder
:
function
()
{
this
.
drawLine
([{
x
:
0
,
y
:
0
},{
x
:
this
.
width
,
y
:
0
}],
'
#000
'
,
0
);
this
.
drawLine
([{
x
:
this
.
width
,
y
:
0
},{
x
:
this
.
width
,
y
:
this
.
height
}],
'
#000
'
,
0
);
this
.
drawLine
([{
x
:
this
.
width
,
y
:
this
.
height
},{
x
:
0
,
y
:
this
.
height
}],
'
#000
'
,
0
);
this
.
drawLine
([{
x
:
0
,
y
:
this
.
height
},{
x
:
0
,
y
:
0
}],
'
#000
'
,
0
);
},
drawGrid
:
function
()
{
// Horizontal lines
for
(
var
i
=
0
;
i
<=
this
.
y_grid_steps
;
i
++
)
{
this
.
drawLine
([
{
x
:
this
.
x_padding
/
2
,
y
:
this
.
y_step
*
i
+
this
.
y_padding
},
{
x
:
this
.
width
-
this
.
x_padding
/
2
,
y
:
this
.
y_step
*
i
+
this
.
y_padding
}],
'
#DDD
'
,
0
);
}
// Vertical left line
this
.
drawLine
([
{
x
:
this
.
x_padding
/
2
,
y
:
this
.
y_padding
},
{
x
:
this
.
x_padding
/
2
,
y
:
this
.
height
-
this
.
y_padding
}],
'
#DDD
'
,
0
);
// Vertical dashed lines
for
(
var
i
=
0
;
i
<=
this
.
data_length
;
i
++
)
{
this
.
drawLine
([
{
x
:
this
.
x_step
*
i
+
this
.
x_padding
,
y
:
this
.
y_padding
},
{
x
:
this
.
x_step
*
i
+
this
.
x_padding
,
y
:
this
.
height
-
this
.
y_padding
}],
'
#DDD
'
,
5
);
}
// Draw label
this
.
drawLabel
();
},
drawLabel
:
function
()
{
for
(
var
i
=
0
;
i
<=
this
.
y_grid_steps
;
i
++
)
{
this
.
drawText
(
{
x
:
this
.
x_padding
/
4
,
y
:
this
.
y_step
*
i
+
this
.
y_padding
},
this
.
getLabelY
(
i
)
);
}
for
(
var
i
=
0
;
i
<
this
.
data_length
;
i
++
)
{
this
.
drawText
(
{
x
:
this
.
getCoordinate
(
i
).
x
,
y
:
this
.
height
-
this
.
y_padding
/
2
},
this
.
getLabelX
(
i
)
);
}
},
drawLine
:
function
(
coordinates
,
style
,
dash
)
{
this
.
context
.
setLineDash
([
dash
]);
this
.
context
.
beginPath
();
this
.
context
.
moveTo
(
coordinates
[
0
].
x
,
coordinates
[
0
].
y
);
this
.
context
.
lineTo
(
coordinates
[
1
].
x
,
coordinates
[
1
].
y
);
this
.
context
.
strokeStyle
=
style
;
this
.
context
.
stroke
();
},
drawPoint
:
function
(
coordinate
,
style
)
{
this
.
context
.
beginPath
();
this
.
context
.
arc
(
coordinate
.
x
,
coordinate
.
y
,
this
.
point_radius
,
0
,
2
*
Math
.
PI
,
false
);
this
.
context
.
fillStyle
=
'
#FFF
'
;
this
.
context
.
fill
();
this
.
context
.
strokeStyle
=
style
;
this
.
context
.
stroke
();
},
drawText
:
function
(
coordinate
,
text
)
{
this
.
context
.
fillStyle
=
'
#AAA
'
;
this
.
context
.
textBaseline
=
'
middle
'
;
this
.
context
.
textAlign
=
'
center
'
;
this
.
context
.
fillText
(
text
,
coordinate
.
x
,
coordinate
.
y
);
},
calcCoordinateX
:
function
(
index
)
{
return
this
.
x_step
*
index
+
this
.
x_padding
;
},
calcCoordinateY
:
function
(
index
)
{
var
proportion
=
this
.
data
[
index
]
/
this
.
data_max
;
var
top_without_padding
=
proportion
*
(
this
.
height
-
this
.
y_padding
*
2
);
return
this
.
height
-
(
top_without_padding
+
this
.
y_padding
);
},
getLineCoordinates
:
function
(
i
)
{
return
[
this
.
getCoordinate
(
i
),
this
.
getCoordinate
(
i
+
1
)
];
},
getCoordinate
:
function
(
i
)
{
return
this
.
coordinates
[
i
];
},
getMax
:
function
()
{
var
max
=
this
.
data
[
0
];
for
(
var
i
=
1
;
i
<
this
.
data_length
;
i
++
)
if
(
this
.
data
[
i
]
>
max
)
max
=
this
.
data
[
i
];
return
max
;
},
getMin
:
function
()
{
var
min
=
this
.
data
[
0
];
for
(
var
i
=
1
;
i
<
this
.
data_length
;
i
++
)
if
(
this
.
data
[
i
]
<
min
)
min
=
this
.
data
[
i
];
return
min
;
},
getLabelY
:
function
(
index
)
{
return
((
this
.
data_max
/
this
.
y_grid_steps
)
*
(
this
.
y_grid_steps
-
index
)).
toFixed
(
1
).
replace
(
/
[
.,
]
0$/
,
""
);
},
getLabelX
:
function
(
index
)
{
return
this
.
label
[
index
];
},
distanceBetweenTwoPoints
:
function
(
coordinates
)
{
return
Math
.
sqrt
(
Math
.
pow
(
(
coordinates
[
0
].
x
-
coordinates
[
1
].
x
)
,
2
)
+
Math
.
pow
(
(
coordinates
[
0
].
y
-
coordinates
[
1
].
y
)
,
2
)
);
},
getPointSelected
:
function
(
x
,
y
)
{
for
(
var
i
=
0
;
i
<
this
.
data_length
;
i
++
)
{
var
coordinates
=
[
{
x
:
x
,
y
:
y
},
{
x
:
this
.
coordinates
[
i
].
x
,
y
:
this
.
coordinates
[
i
].
y
}
];
var
dist
=
this
.
distanceBetweenTwoPoints
(
coordinates
);
if
(
dist
<=
this
.
point_radius
+
1
)
{
return
i
;
}
}
console
.
log
(
'
None
'
);
return
null
;
},
clickEvent
:
function
(
event
)
{
var
point
=
this
.
getPointSelected
(
event
.
layerX
,
event
.
layerY
);
if
(
point
!=
null
)
{
this
.
showTooltip
(
this
.
tooltip
[
point
],
{
x
:
event
.
clientX
,
y
:
event
.
clientY
});
}
else
{
this
.
removeTooltip
();
}
},
hoverEvent
:
function
(
event
)
{
var
point
=
this
.
getPointSelected
(
event
.
layerX
,
event
.
layerY
);
if
(
point
!=
null
)
{
this
.
showTooltip
(
this
.
tooltip
[
point
],
{
x
:
event
.
clientX
,
y
:
event
.
clientY
});
}
else
{
this
.
removeTooltip
();
}
},
showTooltip
:
function
(
text
,
coordinate
)
{
var
tooltip
=
document
.
getElementById
(
'
tooltip
'
);
if
(
tooltip
)
{
tooltip
.
style
.
top
=
coordinate
.
y
+
'
px
'
;
tooltip
.
style
.
left
=
coordinate
.
x
+
'
px
'
;
tooltip
.
innerHTML
=
text
;
}
else
{
tooltip
=
document
.
createElement
(
'
div
'
);
tooltip
.
setAttribute
(
'
id
'
,
'
tooltip
'
);
tooltip
.
classList
.
add
(
'
tooltip-chart
'
);
tooltip
.
style
.
top
=
coordinate
.
y
+
'
px
'
;
tooltip
.
style
.
left
=
coordinate
.
x
+
'
px
'
;
tooltip
.
innerHTML
=
text
;
this
.
container
.
parentNode
.
appendChild
(
tooltip
);
}
},
removeTooltip
:
function
()
{
var
tooltip
=
document
.
getElementById
(
'
tooltip
'
);
if
(
tooltip
)
this
.
container
.
parentNode
.
removeChild
(
tooltip
);
}
};
\ No newline at end of file
software/ors-amarisoft/gadget/promise.gadget.js
0 → 100644
View file @
e98c9778
/*global window, rJS, RSVP*/
/*jslint indent:2, maxlen:80, nomen:true */
(
function
()
{
"
use strict
"
;
rJS
(
window
)
.
declareAcquiredMethod
(
"
getPromiseDocument
"
,
"
getPromiseDocument
"
)
.
declareMethod
(
"
render
"
,
function
(
options
)
{
var
gadget
=
this
;
return
gadget
.
getPromiseDocument
(
"
check-cpu-temperature
"
,
"
log/monitor/promise/check-cpu-temperature.json.log
"
)
.
push
(
function
(
result
)
{
//gadget.element.textContent = result;
result
=
result
.
replace
(
/
\'
/g
,
"
\"
"
);
var
item
=
result
.
split
(
"
\n
"
),
tmp
=
""
,
data_tmp
=
""
,
data_list
=
[],
time
=
[],
data
=
[];
item
=
JSON
.
parse
(
JSON
.
stringify
(
item
));
for
(
var
i
=
0
;
i
<
30
;
i
++
)
{
data_list
.
push
(
item
[
i
]);
var
data_list_list
=
JSON
.
parse
(
data_list
[
i
]);
if
(
data_list_list
.
hasOwnProperty
(
"
time
"
)
&&
data_list_list
.
hasOwnProperty
(
"
data
"
))
{
tmp
=
data_list_list
.
time
.
split
(
"
"
)[
1
].
split
(
"
,
"
)[
0
];
data_tmp
=
data_list_list
.
data
.
cpu_temperature
;
}
time
.
push
(
tmp
);
data
.
push
(
data_tmp
);
gadget
.
time
=
time
;
gadget
.
data
=
data
;
}
var
canvas
=
gadget
.
element
.
children
.
line
,
data
=
gadget
.
data
,
label
=
gadget
.
time
,
tooltip
=
[
'
Twelve
'
,
'
Fifteen
'
,
'
Thirteen
'
,
'
Twenty-two
'
,
'
Eight
'
,
'
Twelve
'
,
'
Thirdy-one
'
,
'
Three
'
,
'
Five
'
];
var
line_chart
=
new
LineChart
(
canvas
,
data
,
label
,
tooltip
);
line_chart
.
draw
();
line_chart
.
tooltipOn
(
'
mousemove
'
);
});
});
}());
\ No newline at end of file
software/ors-amarisoft/gadget/renderjs.js
0 → 100644
View file @
e98c9778
This source diff could not be displayed because it is too large. You can
view the blob
instead.
software/ors-amarisoft/gadget/rsvp.js
0 → 100644
View file @
e98c9778
(
function
(
globals
)
{
var
define
,
requireModule
;
(
function
()
{
var
registry
=
{},
seen
=
{};
define
=
function
(
name
,
deps
,
callback
)
{
registry
[
name
]
=
{
deps
:
deps
,
callback
:
callback
};
};
requireModule
=
function
(
name
)
{
if
(
seen
[
name
])
{
return
seen
[
name
];
}
seen
[
name
]
=
{};
var
mod
=
registry
[
name
];
if
(
!
mod
)
{
throw
new
Error
(
"
Module '
"
+
name
+
"
' not found.
"
);
}
var
deps
=
mod
.
deps
,
callback
=
mod
.
callback
,
reified
=
[],
exports
;
for
(
var
i
=
0
,
l
=
deps
.
length
;
i
<
l
;
i
++
)
{
if
(
deps
[
i
]
===
'
exports
'
)
{
reified
.
push
(
exports
=
{});
}
else
{
reified
.
push
(
requireModule
(
deps
[
i
]));
}
}
var
value
=
callback
.
apply
(
this
,
reified
);
return
seen
[
name
]
=
exports
||
value
;
};
})();
define
(
"
rsvp/all
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
/* global toString */
function
promiseAtLeast
(
expected_count
,
promises
)
{
if
(
Object
.
prototype
.
toString
.
call
(
promises
)
!==
"
[object Array]
"
)
{
throw
new
TypeError
(
'
You must pass an array to all.
'
);
}
function
canceller
(
msg
)
{
var
promise
;
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
promise
=
promises
[
i
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
&&
typeof
promise
.
cancel
===
'
function
'
)
{
promise
.
cancel
(
msg
);
}
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
results
=
[],
remaining
=
promises
.
length
,
promise
,
remaining_count
=
promises
.
length
-
expected_count
;
if
(
remaining
===
0
)
{
if
(
expected_count
===
1
)
{
resolve
();
}
else
{
resolve
([]);
}
}
function
resolver
(
index
)
{
return
function
(
value
)
{
resolveAll
(
index
,
value
);
};
}
function
resolveAll
(
index
,
value
)
{
results
[
index
]
=
value
;
if
(
--
remaining
===
remaining_count
)
{
if
(
remaining_count
===
0
)
{
resolve
(
results
);
}
else
{
resolve
(
value
);
canceller
();
}
}
}
function
cancelAll
(
rejectionValue
)
{
reject
(
rejectionValue
);
canceller
();
}
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
promise
=
promises
[
i
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
)
{
promise
.
then
(
resolver
(
i
),
cancelAll
);
}
else
{
resolveAll
(
i
,
promise
);
}
}
},
canceller
);
}
function
all
(
promises
)
{
return
promiseAtLeast
(
promises
.
length
,
promises
);
}
function
any
(
promises
)
{
return
promiseAtLeast
(
1
,
promises
);
}
__exports__
.
all
=
all
;
__exports__
.
any
=
any
;
});
define
(
"
rsvp/async
"
,
[
"
exports
"
],
function
(
__exports__
)
{
"
use strict
"
;
var
browserGlobal
=
(
typeof
window
!==
'
undefined
'
)
?
window
:
{};
var
BrowserMutationObserver
=
browserGlobal
.
MutationObserver
||
browserGlobal
.
WebKitMutationObserver
;
var
async
;
var
local
=
(
typeof
global
!==
'
undefined
'
)
?
global
:
this
;
function
checkNativePromise
()
{
if
(
typeof
Promise
===
"
function
"
&&
typeof
Promise
.
resolve
===
"
function
"
)
{
try
{
/* global Promise */
var
promise
=
new
Promise
(
function
(){});
if
({}.
toString
.
call
(
promise
)
===
"
[object Promise]
"
)
{
return
true
;
}
}
catch
(
e
)
{}
}
return
false
;
}
function
useNativePromise
()
{
var
nativePromise
=
Promise
.
resolve
();
return
function
(
callback
,
arg
)
{
nativePromise
.
then
(
function
()
{
callback
(
arg
);
});
};
}
// old node
function
useNextTick
()
{
return
function
(
callback
,
arg
)
{
process
.
nextTick
(
function
()
{
callback
(
arg
);
});
};
}
// node >= 0.10.x
function
useSetImmediate
()
{
return
function
(
callback
,
arg
)
{
/* global setImmediate */
setImmediate
(
function
(){
callback
(
arg
);
});
};
}
function
useMutationObserver
()
{
var
queue
=
[];
var
observer
=
new
BrowserMutationObserver
(
function
()
{
var
toProcess
=
queue
.
slice
();
queue
=
[];
toProcess
.
forEach
(
function
(
tuple
)
{
var
callback
=
tuple
[
0
],
arg
=
tuple
[
1
];
callback
(
arg
);
});
});
var
element
=
document
.
createElement
(
'
div
'
);
observer
.
observe
(
element
,
{
attributes
:
true
});
// Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661
window
.
addEventListener
(
'
unload
'
,
function
(){
observer
.
disconnect
();
observer
=
null
;
},
false
);
return
function
(
callback
,
arg
)
{
queue
.
push
([
callback
,
arg
]);
element
.
setAttribute
(
'
drainQueue
'
,
'
drainQueue
'
);
};
}
function
useSetTimeout
()
{
return
function
(
callback
,
arg
)
{
local
.
setTimeout
(
function
()
{
callback
(
arg
);
},
1
);
};
}
if
(
checkNativePromise
())
{
async
=
useNativePromise
();
}
else
if
(
typeof
setImmediate
===
'
function
'
)
{
async
=
useSetImmediate
();
}
else
if
(
typeof
process
!==
'
undefined
'
&&
{}.
toString
.
call
(
process
)
===
'
[object process]
'
)
{
async
=
useNextTick
();
}
else
if
(
BrowserMutationObserver
)
{
async
=
useMutationObserver
();
}
else
{
async
=
useSetTimeout
();
}
__exports__
.
async
=
async
;
});
define
(
"
rsvp/cancellation_error
"
,
[
"
exports
"
],
function
(
__exports__
)
{
"
use strict
"
;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
function
CancellationError
(
message
)
{
this
.
name
=
"
cancel
"
;
if
((
message
!==
undefined
)
&&
(
typeof
message
!==
"
string
"
))
{
throw
new
TypeError
(
'
You must pass a string.
'
);
}
this
.
message
=
message
||
"
Default Message
"
;
}
CancellationError
.
prototype
=
new
Error
();
CancellationError
.
prototype
.
constructor
=
CancellationError
;
__exports__
.
CancellationError
=
CancellationError
;
});
define
(
"
rsvp/config
"
,
[
"
rsvp/async
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
async
=
__dependency1__
.
async
;
var
config
=
{};
config
.
async
=
async
;
__exports__
.
config
=
config
;
});
define
(
"
rsvp/defer
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
function
defer
()
{
var
deferred
=
{
// pre-allocate shape
resolve
:
undefined
,
reject
:
undefined
,
promise
:
undefined
};
deferred
.
promise
=
new
Promise
(
function
(
resolve
,
reject
)
{
deferred
.
resolve
=
resolve
;
deferred
.
reject
=
reject
;
});
return
deferred
;
}
__exports__
.
defer
=
defer
;
});
define
(
"
rsvp/events
"
,
[
"
exports
"
],
function
(
__exports__
)
{
"
use strict
"
;
var
Event
=
function
(
type
,
options
)
{
this
.
type
=
type
;
for
(
var
option
in
options
)
{
if
(
!
options
.
hasOwnProperty
(
option
))
{
continue
;
}
this
[
option
]
=
options
[
option
];
}
};
var
indexOf
=
function
(
callbacks
,
callback
)
{
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
)
{
if
(
callbacks
[
i
][
0
]
===
callback
)
{
return
i
;
}
}
return
-
1
;
};
var
callbacksFor
=
function
(
object
)
{
var
callbacks
=
object
.
_promiseCallbacks
;
if
(
!
callbacks
)
{
callbacks
=
object
.
_promiseCallbacks
=
{};
}
return
callbacks
;
};
var
EventTarget
=
{
mixin
:
function
(
object
)
{
object
.
on
=
this
.
on
;
object
.
off
=
this
.
off
;
object
.
trigger
=
this
.
trigger
;
return
object
;
},
on
:
function
(
eventNames
,
callback
,
binding
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
binding
=
binding
||
this
;
while
(
eventName
=
eventNames
.
shift
())
{
callbacks
=
allCallbacks
[
eventName
];
if
(
!
callbacks
)
{
callbacks
=
allCallbacks
[
eventName
]
=
[];
}
if
(
indexOf
(
callbacks
,
callback
)
===
-
1
)
{
callbacks
.
push
([
callback
,
binding
]);
}
}
},
off
:
function
(
eventNames
,
callback
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
,
index
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
while
(
eventName
=
eventNames
.
shift
())
{
if
(
!
callback
)
{
allCallbacks
[
eventName
]
=
[];
continue
;
}
callbacks
=
allCallbacks
[
eventName
];
index
=
indexOf
(
callbacks
,
callback
);
if
(
index
!==
-
1
)
{
callbacks
.
splice
(
index
,
1
);
}
}
},
trigger
:
function
(
eventName
,
options
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
callbackTuple
,
callback
,
binding
,
event
;
if
(
callbacks
=
allCallbacks
[
eventName
])
{
// Don't cache the callbacks.length since it may grow
for
(
var
i
=
0
;
i
<
callbacks
.
length
;
i
++
)
{
callbackTuple
=
callbacks
[
i
];
callback
=
callbackTuple
[
0
];
binding
=
callbackTuple
[
1
];
if
(
typeof
options
!==
'
object
'
)
{
options
=
{
detail
:
options
};
}
event
=
new
Event
(
eventName
,
options
);
callback
.
call
(
binding
,
event
);
}
}
}
};
__exports__
.
EventTarget
=
EventTarget
;
});
define
(
"
rsvp/hash
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
function
size
(
object
)
{
var
s
=
0
;
for
(
var
prop
in
object
)
{
s
++
;
}
return
s
;
}
function
hash
(
promises
)
{
function
canceller
(
msg
)
{
var
promise
,
key
;
for
(
key
in
promises
)
{
if
(
promises
.
hasOwnProperty
(
key
))
{
promise
=
promises
[
key
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
&&
typeof
promise
.
cancel
===
'
function
'
)
{
promise
.
cancel
(
msg
);
}
}
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
results
=
{},
remaining
=
size
(
promises
),
promise
;
if
(
remaining
===
0
)
{
resolve
(
results
);
}
function
resolver
(
key
)
{
return
function
(
value
)
{
resolveAll
(
key
,
value
);
};
}
function
resolveAll
(
key
,
value
)
{
results
[
key
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
}
function
cancelAll
(
rejectionValue
)
{
reject
(
rejectionValue
);
canceller
();
}
for
(
var
prop
in
promises
)
{
promise
=
promises
[
prop
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
)
{
promise
.
then
(
resolver
(
prop
),
cancelAll
);
}
else
{
resolveAll
(
prop
,
promise
);
}
}
},
canceller
);
}
__exports__
.
hash
=
hash
;
});
define
(
"
rsvp/node
"
,
[
"
rsvp/promise
"
,
"
rsvp/all
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
var
all
=
__dependency2__
.
all
;
function
makeNodeCallbackFor
(
resolve
,
reject
)
{
return
function
(
error
,
value
)
{
if
(
error
)
{
reject
(
error
);
}
else
if
(
arguments
.
length
>
2
)
{
resolve
(
Array
.
prototype
.
slice
.
call
(
arguments
,
1
));
}
else
{
resolve
(
value
);
}
};
}
function
denodeify
(
nodeFunc
)
{
return
function
()
{
var
nodeArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
),
resolve
,
reject
;
var
thisArg
=
this
;
var
promise
=
new
Promise
(
function
(
nodeResolve
,
nodeReject
)
{
resolve
=
nodeResolve
;
reject
=
nodeReject
;
});
all
(
nodeArgs
).
then
(
function
(
nodeArgs
)
{
nodeArgs
.
push
(
makeNodeCallbackFor
(
resolve
,
reject
));
try
{
nodeFunc
.
apply
(
thisArg
,
nodeArgs
);
}
catch
(
e
)
{
reject
(
e
);
}
});
return
promise
;
};
}
__exports__
.
denodeify
=
denodeify
;
});
define
(
"
rsvp/promise
"
,
[
"
rsvp/config
"
,
"
rsvp/events
"
,
"
rsvp/cancellation_error
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__exports__
)
{
"
use strict
"
;
var
config
=
__dependency1__
.
config
;
var
EventTarget
=
__dependency2__
.
EventTarget
;
var
CancellationError
=
__dependency3__
.
CancellationError
;
function
objectOrFunction
(
x
)
{
return
isFunction
(
x
)
||
(
typeof
x
===
"
object
"
&&
x
!==
null
);
}
function
isFunction
(
x
){
return
typeof
x
===
"
function
"
;
}
var
Promise
=
function
(
resolver
,
canceller
)
{
var
promise
=
this
,
resolved
=
false
;
if
(
typeof
resolver
!==
'
function
'
)
{
throw
new
TypeError
(
'
You must pass a resolver function as the sole argument to the promise constructor
'
);
}
if
((
canceller
!==
undefined
)
&&
(
typeof
canceller
!==
'
function
'
))
{
throw
new
TypeError
(
'
You can only pass a canceller function
'
+
'
as the second argument to the promise constructor
'
);
}
if
(
!
(
promise
instanceof
Promise
))
{
return
new
Promise
(
resolver
,
canceller
);
}
var
resolvePromise
=
function
(
value
)
{
if
(
resolved
)
{
return
;
}
resolved
=
true
;
resolve
(
promise
,
value
);
};
var
rejectPromise
=
function
(
value
)
{
if
(
resolved
)
{
return
;
}
resolved
=
true
;
reject
(
promise
,
value
);
};
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
this
.
trigger
(
'
error
'
,
{
detail
:
event
.
detail
});
},
this
);
this
.
on
(
'
error
'
,
onerror
);
this
.
cancel
=
function
(
msg
)
{
// For now, simply reject the promise and does not propagate the cancel
// to parent or children
if
(
resolved
)
{
return
;
}
promise
.
isCancelled
=
true
;
if
(
canceller
!==
undefined
)
{
try
{
canceller
(
msg
);
}
catch
(
e
)
{
rejectPromise
(
e
);
return
;
}
}
// Trigger cancel?
rejectPromise
(
new
CancellationError
(
msg
));
};
try
{
resolver
(
resolvePromise
,
rejectPromise
);
}
catch
(
e
)
{
rejectPromise
(
e
);
}
};
function
onerror
(
event
)
{
if
(
config
.
onerror
)
{
config
.
onerror
(
event
.
detail
);
}
}
var
invokeCallback
=
function
(
type
,
promise
,
callback
,
event
)
{
var
hasCallback
=
isFunction
(
callback
),
value
,
error
,
succeeded
,
failed
;
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
if
(
promise
.
isCancelled
)
{
return
;
}
if
(
hasCallback
)
{
try
{
value
=
callback
(
event
.
detail
);
succeeded
=
true
;
}
catch
(
e
)
{
failed
=
true
;
error
=
e
;
}
}
else
{
value
=
event
.
detail
;
succeeded
=
true
;
}
if
(
handleThenable
(
promise
,
value
))
{
return
;
}
else
if
(
hasCallback
&&
succeeded
)
{
resolve
(
promise
,
value
);
}
else
if
(
failed
)
{
reject
(
promise
,
error
);
}
else
if
(
type
===
'
resolve
'
)
{
resolve
(
promise
,
value
);
}
else
if
(
type
===
'
reject
'
)
{
reject
(
promise
,
value
);
}
};
Promise
.
prototype
=
{
constructor
:
Promise
,
isCancelled
:
undefined
,
isRejected
:
undefined
,
isFulfilled
:
undefined
,
rejectedReason
:
undefined
,
fulfillmentValue
:
undefined
,
then
:
function
(
done
,
fail
)
{
this
.
off
(
'
error
'
,
onerror
);
var
thenPromise
=
new
this
.
constructor
(
function
()
{},
function
(
msg
)
{
thenPromise
.
trigger
(
'
promise:cancelled
'
,
{
msg
:
msg
});
});
if
(
this
.
isFulfilled
)
{
config
.
async
(
function
(
promise
)
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
{
detail
:
promise
.
fulfillmentValue
});
},
this
);
}
if
(
this
.
isRejected
)
{
config
.
async
(
function
(
promise
)
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
{
detail
:
promise
.
rejectedReason
});
},
this
);
}
this
.
on
(
'
promise:resolved
'
,
function
(
event
)
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
event
);
});
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
event
);
});
return
thenPromise
;
},
fail
:
function
(
fail
)
{
return
this
.
then
(
null
,
fail
);
},
always
:
function
(
fail
)
{
return
this
.
then
(
fail
,
fail
);
}
};
EventTarget
.
mixin
(
Promise
.
prototype
);
function
resolve
(
promise
,
value
)
{
if
(
promise
===
value
)
{
fulfill
(
promise
,
value
);
}
else
if
(
!
handleThenable
(
promise
,
value
))
{
fulfill
(
promise
,
value
);
}
}
function
handleThenable
(
promise
,
value
)
{
var
then
=
null
,
resolved
;
try
{
if
(
promise
===
value
)
{
throw
new
TypeError
(
"
A promises callback cannot return that same promise.
"
);
}
if
(
objectOrFunction
(
value
))
{
then
=
value
.
then
;
if
(
isFunction
(
then
))
{
promise
.
on
(
'
promise:cancelled
'
,
function
(
event
)
{
if
(
isFunction
(
value
.
cancel
))
{
value
.
cancel
(
event
.
msg
);
}
});
then
.
call
(
value
,
function
(
val
)
{
if
(
resolved
)
{
return
true
;
}
resolved
=
true
;
if
(
value
!==
val
)
{
resolve
(
promise
,
val
);
}
else
{
fulfill
(
promise
,
val
);
}
},
function
(
val
)
{
if
(
resolved
)
{
return
true
;
}
resolved
=
true
;
reject
(
promise
,
val
);
});
return
true
;
}
}
}
catch
(
error
)
{
reject
(
promise
,
error
);
return
true
;
}
return
false
;
}
function
fulfill
(
promise
,
value
)
{
config
.
async
(
function
()
{
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
promise
.
trigger
(
'
promise:resolved
'
,
{
detail
:
value
});
promise
.
isFulfilled
=
true
;
promise
.
fulfillmentValue
=
value
;
});
}
function
reject
(
promise
,
value
)
{
config
.
async
(
function
()
{
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
promise
.
trigger
(
'
promise:failed
'
,
{
detail
:
value
});
promise
.
isRejected
=
true
;
promise
.
rejectedReason
=
value
;
});
}
__exports__
.
Promise
=
Promise
;
});
define
(
"
rsvp/queue
"
,
[
"
rsvp/promise
"
,
"
rsvp/resolve
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
var
resolve
=
__dependency2__
.
resolve
;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
function
ResolvedQueueError
(
message
)
{
this
.
name
=
"
resolved
"
;
if
((
message
!==
undefined
)
&&
(
typeof
message
!==
"
string
"
))
{
throw
new
TypeError
(
'
You must pass a string.
'
);
}
this
.
message
=
message
||
"
Default Message
"
;
}
ResolvedQueueError
.
prototype
=
new
Error
();
ResolvedQueueError
.
prototype
.
constructor
=
ResolvedQueueError
;
var
Queue
=
function
(
thenable
)
{
var
queue
=
this
,
promise_list
=
[],
promise
,
fulfill
,
reject
,
resolved
;
if
(
!
(
this
instanceof
Queue
))
{
return
new
Queue
(
thenable
);
}
function
canceller
(
msg
)
{
for
(
var
i
=
promise_list
.
length
;
i
>
0
;
i
--
)
{
promise_list
[
i
-
1
].
cancel
(
msg
);
}
}
function
checkPromise
(
next_promise
)
{
promise_list
.
push
(
next_promise
);
// Handle pop
promise_list
.
push
(
next_promise
.
then
(
function
(
fulfillmentValue
)
{
promise_list
.
splice
(
0
,
2
);
if
(
promise_list
.
length
===
0
)
{
fulfill
(
fulfillmentValue
);
}
else
{
return
fulfillmentValue
;
}
},
function
(
rejectedReason
)
{
promise_list
.
splice
(
0
,
2
);
if
(
promise_list
.
length
===
0
)
{
reject
(
rejectedReason
);
}
else
{
throw
rejectedReason
;
}
}));
}
promise
=
new
Promise
(
function
(
done
,
fail
)
{
fulfill
=
function
(
fulfillmentValue
)
{
if
(
resolved
)
{
return
;}
queue
.
isFulfilled
=
true
;
queue
.
fulfillmentValue
=
fulfillmentValue
;
resolved
=
true
;
return
done
(
fulfillmentValue
);
};
reject
=
function
(
rejectedReason
)
{
if
(
resolved
)
{
return
;}
queue
.
isRejected
=
true
;
queue
.
rejectedReason
=
rejectedReason
;
resolved
=
true
;
return
fail
(
rejectedReason
);
};
},
canceller
);
checkPromise
(
resolve
(
thenable
));
queue
.
cancel
=
function
(
msg
)
{
if
(
resolved
)
{
return
;}
resolved
=
true
;
promise
.
cancel
(
msg
);
promise
.
fail
(
function
(
rejectedReason
)
{
queue
.
isRejected
=
true
;
queue
.
rejectedReason
=
rejectedReason
;
});
};
queue
.
then
=
function
()
{
return
promise
.
then
.
apply
(
promise
,
arguments
);
};
queue
.
push
=
function
(
done
,
fail
)
{
var
last_promise
=
promise_list
[
promise_list
.
length
-
1
],
next_promise
;
if
(
resolved
)
{
throw
new
ResolvedQueueError
();
}
// Handle pop
checkPromise
(
last_promise
.
then
(
done
,
fail
));
return
this
;
};
};
Queue
.
prototype
=
Object
.
create
(
Promise
.
prototype
);
Queue
.
prototype
.
constructor
=
Queue
;
__exports__
.
Queue
=
Queue
;
__exports__
.
ResolvedQueueError
=
ResolvedQueueError
;
});
define
(
"
rsvp/reject
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
function
reject
(
reason
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
reject
(
reason
);
});
}
__exports__
.
reject
=
reject
;
});
define
(
"
rsvp/resolve
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
function
resolve
(
thenable
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
typeof
thenable
===
"
object
"
&&
thenable
!==
null
)
{
var
then
=
thenable
.
then
;
if
((
then
!==
undefined
)
&&
(
typeof
then
===
"
function
"
))
{
return
then
.
apply
(
thenable
,
[
resolve
,
reject
]);
}
}
return
resolve
(
thenable
);
},
function
(
msg
)
{
if
((
thenable
!==
undefined
)
&&
(
thenable
.
cancel
!==
undefined
))
{
thenable
.
cancel
(
msg
);
}
});
}
__exports__
.
resolve
=
resolve
;
});
define
(
"
rsvp/rethrow
"
,
[
"
exports
"
],
function
(
__exports__
)
{
"
use strict
"
;
var
local
=
(
typeof
global
===
"
undefined
"
)
?
this
:
global
;
function
rethrow
(
reason
)
{
local
.
setTimeout
(
function
()
{
throw
reason
;
});
throw
reason
;
}
__exports__
.
rethrow
=
rethrow
;
});
define
(
"
rsvp/timeout
"
,
[
"
rsvp/promise
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
function
promiseSetTimeout
(
millisecond
,
should_reject
,
message
)
{
var
timeout_id
;
function
resolver
(
resolve
,
reject
)
{
timeout_id
=
setTimeout
(
function
()
{
if
(
should_reject
)
{
reject
(
message
);
}
else
{
resolve
(
message
);
}
},
millisecond
);
}
function
canceller
()
{
clearTimeout
(
timeout_id
);
}
return
new
Promise
(
resolver
,
canceller
);
}
function
delay
(
millisecond
,
message
)
{
return
promiseSetTimeout
(
millisecond
,
false
,
message
);
}
function
timeout
(
millisecond
)
{
return
promiseSetTimeout
(
millisecond
,
true
,
"
Timed out after
"
+
millisecond
+
"
ms
"
);
}
Promise
.
prototype
.
delay
=
function
(
millisecond
)
{
return
this
.
then
(
function
(
fulfillmentValue
)
{
return
delay
(
millisecond
,
fulfillmentValue
);
});
};
__exports__
.
delay
=
delay
;
__exports__
.
timeout
=
timeout
;
});
define
(
"
rsvp
"
,
[
"
rsvp/events
"
,
"
rsvp/cancellation_error
"
,
"
rsvp/promise
"
,
"
rsvp/node
"
,
"
rsvp/all
"
,
"
rsvp/queue
"
,
"
rsvp/timeout
"
,
"
rsvp/hash
"
,
"
rsvp/rethrow
"
,
"
rsvp/defer
"
,
"
rsvp/config
"
,
"
rsvp/resolve
"
,
"
rsvp/reject
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__dependency4__
,
__dependency5__
,
__dependency6__
,
__dependency7__
,
__dependency8__
,
__dependency9__
,
__dependency10__
,
__dependency11__
,
__dependency12__
,
__dependency13__
,
__exports__
)
{
"
use strict
"
;
var
EventTarget
=
__dependency1__
.
EventTarget
;
var
CancellationError
=
__dependency2__
.
CancellationError
;
var
Promise
=
__dependency3__
.
Promise
;
var
denodeify
=
__dependency4__
.
denodeify
;
var
all
=
__dependency5__
.
all
;
var
any
=
__dependency5__
.
any
;
var
Queue
=
__dependency6__
.
Queue
;
var
ResolvedQueueError
=
__dependency6__
.
ResolvedQueueError
;
var
delay
=
__dependency7__
.
delay
;
var
timeout
=
__dependency7__
.
timeout
;
var
hash
=
__dependency8__
.
hash
;
var
rethrow
=
__dependency9__
.
rethrow
;
var
defer
=
__dependency10__
.
defer
;
var
config
=
__dependency11__
.
config
;
var
resolve
=
__dependency12__
.
resolve
;
var
reject
=
__dependency13__
.
reject
;
function
configure
(
name
,
value
)
{
config
[
name
]
=
value
;
}
__exports__
.
CancellationError
=
CancellationError
;
__exports__
.
Promise
=
Promise
;
__exports__
.
EventTarget
=
EventTarget
;
__exports__
.
all
=
all
;
__exports__
.
any
=
any
;
__exports__
.
Queue
=
Queue
;
__exports__
.
ResolvedQueueError
=
ResolvedQueueError
;
__exports__
.
delay
=
delay
;
__exports__
.
timeout
=
timeout
;
__exports__
.
hash
=
hash
;
__exports__
.
rethrow
=
rethrow
;
__exports__
.
defer
=
defer
;
__exports__
.
denodeify
=
denodeify
;
__exports__
.
configure
=
configure
;
__exports__
.
resolve
=
resolve
;
__exports__
.
reject
=
reject
;
});
window
.
RSVP
=
requireModule
(
"
rsvp
"
);
})(
window
);
\ No newline at end of file
software/ors-amarisoft/gadget/software.cfg.html
0 → 100644
View file @
e98c9778
<html>
<head>
<script
src=
"rsvp.js"
></script>
<script
src=
"renderjs.js"
></script>
<script
src=
"g-chart.line.js"
></script>
<script
src=
"promise.gadget.js"
></script>
<style
type=
"text/css"
>
.tooltip-chart
{
position
:
fixed
;
z-index
:
1000
;
transform
:
translate
(
-50%
,
-120%
);
padding
:
10px
;
background-color
:
white
;
border-radius
:
5px
;
text-align
:
center
;
min-width
:
100px
;
border
:
1px
solid
#000
;
box-shadow
:
0
0
10px
5px
#000
;
}
</style>
</head>
<body>
<canvas
id=
"line"
width=
"1600"
height=
"350"
></canvas>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment