@ -1,30 +1,50 @@
/ * *
import {
* Created by zcf on 2016 / 9 / 26.
shortcut ,
* /
createWidget ,
BI . IntervalSlider = BI . inherit ( BI . Single , {
toPix ,
_constant : {
parseFloat ,
Layout ,
AbsoluteLayout ,
clamp ,
VerticalLayout ,
isEmptyString ,
isNumeric ,
isNull ,
isInteger ,
i18nText ,
size ,
parseInt ,
isNotEmptyString ,
MouseMoveTracker
} from "@/core" ;
import { Single , Editor } from "@/base" ;
import { AccurateCalculationModel } from "./model.accuratecalculation" ;
import { SignTextEditor , SliderIconButton } from "../singleslider" ;
@ shortcut ( )
export class IntervalSlider extends Single {
static xtype = "bi.interval_slider" ;
_constant = {
EDITOR _WIDTH : 58 ,
EDITOR _WIDTH : 58 ,
EDITOR _R _GAP : 60 ,
EDITOR _R _GAP : 60 ,
EDITOR _HEIGHT : 20 ,
EDITOR _HEIGHT : 20 ,
SLIDER _WIDTH _HALF : 15 ,
SLIDER _WIDTH _HALF : 15 ,
SLIDER _WIDTH : 30 ,
SLIDER _WIDTH : 30 ,
SLIDER _HEIGHT : 30 ,
SLIDER _HEIGHT : 30 ,
TRACK _HEIGHT : 24
TRACK _HEIGHT : 24 ,
} ,
}
props = {
props : {
baseCls : "bi-interval-slider bi-slider-track" ,
baseCls : "bi-interval-slider bi-slider-track" ,
digit : false ,
digit : false ,
unit : "" ,
unit : "" ,
min : 0 ,
min : 0 ,
max : 100 ,
max : 100 ,
value : {
value : { min : "" , max : "" } ,
min : "" ,
} ;
max : "" ,
}
} ,
beforeMount : function ( ) {
static EVENT _CHANGE = "EVENT_CHANGE" ;
beforeMount ( ) {
const { value , min , max } = this . options ;
const { value , min , max } = this . options ;
this . _setMinAndMax ( {
this . _setMinAndMax ( {
min ,
min ,
@ -32,90 +52,104 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
} ) ;
} ) ;
this . setValue ( value ) ;
this . setValue ( value ) ;
this . populate ( ) ;
this . populate ( ) ;
} ,
}
render : function ( ) {
var self = this ;
render ( ) {
var c = this . _constant ;
const c = this . _constant ;
this . enable = false ;
this . enable = false ;
this . valueOne = "" ;
this . valueOne = "" ;
this . valueTwo = "" ;
this . valueTwo = "" ;
this . calculation = new BI . AccurateCalculationModel ( ) ;
this . calculation = new AccurateCalculationModel ( ) ;
this . grayTrack = BI . createWidget ( {
this . grayTrack = createWidget ( {
type : "bi.layout" ,
type : Layout . xtype ,
cls : "gray-track" ,
cls : "gray-track" ,
height : 6
height : 6 ,
} ) ;
} ) ;
this . blueTrack = BI . createWidget ( {
this . blueTrack = createWidget ( {
type : "bi.layout" ,
type : Layout . xtype ,
cls : "blue-track bi-high-light-background" ,
cls : "blue-track bi-high-light-background" ,
height : 6
height : 6 ,
} ) ;
} ) ;
this . track = this . _createTrackWrapper ( ) ;
this . track = this . _createTrackWrapper ( ) ;
this . labelOne = BI . createWidget ( {
this . labelOne = createWidget ( {
type : "bi.sign_text_editor" ,
type : SignTextEditor . xtype ,
cls : "slider-editor-button" ,
cls : "slider-editor-button" ,
text : this . options . unit ,
text : this . options . unit ,
allowBlank : false ,
allowBlank : false ,
width : BI . toPix ( c . EDITOR _WIDTH , 2 ) ,
width : toPix ( c . EDITOR _WIDTH , 2 ) ,
height : BI . toPix ( c . EDITOR _HEIGHT , 2 ) ,
height : toPix ( c . EDITOR _HEIGHT , 2 ) ,
validationChecker : function ( v ) {
validationChecker : v => this . _checkValidation ( v ) ,
return self . _checkValidation ( v ) ;
}
} ) ;
this . labelOne . element . hover ( function ( ) {
self . labelOne . element . removeClass ( "bi-border" ) . addClass ( "bi-border" ) ;
} , function ( ) {
self . labelOne . element . removeClass ( "bi-border" ) ;
} ) ;
} ) ;
this . labelOne . on ( BI . Editor . EVENT _CONFIRM , function ( ) {
this . labelOne . element . hover (
var oldValueOne = self . valueOne ;
( ) => {
var v = BI . parseFloat ( this . getValue ( ) ) ;
this . labelOne . element
self . valueOne = v ;
. removeClass ( "bi-border" )
var percent = self . _getPercentByValue ( v ) ;
. addClass ( "bi-border" ) ;
var significantPercent = BI . parseFloat ( percent . toFixed ( 1 ) ) ; // 分成1000份
} ,
self . _setSliderOnePosition ( significantPercent ) ;
( ) => {
self . _setBlueTrack ( ) ;
this . labelOne . element . removeClass ( "bi-border" ) ;
self . _checkLabelPosition ( oldValueOne , self . valueTwo , self . valueOne , self . valueTwo ) ;
}
self . fireEvent ( BI . IntervalSlider . EVENT _CHANGE ) ;
) ;
this . labelOne . on ( Editor . EVENT _CONFIRM , ( ) => {
const oldValueOne = this . valueOne ;
const v = parseFloat ( this . getValue ( ) ) ;
this . valueOne = v ;
const percent = this . _getPercentByValue ( v ) ;
const significantPercent = parseFloat ( percent . toFixed ( 1 ) ) ; // 分成1000份
this . _setSliderOnePosition ( significantPercent ) ;
this . _setBlueTrack ( ) ;
this . _checkLabelPosition (
oldValueOne ,
this . valueTwo ,
this . valueOne ,
this . valueTwo
) ;
this . fireEvent ( IntervalSlider . EVENT _CHANGE ) ;
} ) ;
} ) ;
this . labelTwo = BI . createWidget ( {
this . labelTwo = createWidget ( {
type : "bi.sign_text_editor" ,
type : SignTextEditor . xtype ,
cls : "slider-editor-button" ,
cls : "slider-editor-button" ,
text : this . options . unit ,
text : this . options . unit ,
allowBlank : false ,
allowBlank : false ,
width : BI . toPix ( c . EDITOR _WIDTH , 2 ) ,
width : toPix ( c . EDITOR _WIDTH , 2 ) ,
height : BI . toPix ( c . EDITOR _HEIGHT , 2 ) ,
height : toPix ( c . EDITOR _HEIGHT , 2 ) ,
validationChecker : function ( v ) {
validationChecker : v => this . _checkValidation ( v ) ,
return self . _checkValidation ( v ) ;
}
} ) ;
} ) ;
this . labelTwo . element . hover ( function ( ) {
this . labelTwo . element . hover (
self . labelTwo . element . removeClass ( "bi-border" ) . addClass ( "bi-border" ) ;
( ) => {
} , function ( ) {
this . labelTwo . element
self . labelTwo . element . removeClass ( "bi-border" ) ;
. removeClass ( "bi-border" )
} ) ;
. addClass ( "bi-border" ) ;
this . labelTwo . on ( BI . Editor . EVENT _CONFIRM , function ( ) {
} ,
var oldValueTwo = self . valueTwo ;
( ) => {
var v = BI . parseFloat ( this . getValue ( ) ) ;
this . labelTwo . element . removeClass ( "bi-border" ) ;
self . valueTwo = v ;
}
var percent = self . _getPercentByValue ( v ) ;
) ;
var significantPercent = BI . parseFloat ( percent . toFixed ( 1 ) ) ;
this . labelTwo . on ( Editor . EVENT _CONFIRM , ( ) => {
self . _setSliderTwoPosition ( significantPercent ) ;
const oldValueTwo = this . valueTwo ;
self . _setBlueTrack ( ) ;
const v = parseFloat ( this . getValue ( ) ) ;
self . _checkLabelPosition ( self . valueOne , oldValueTwo , self . valueOne , self . valueTwo ) ;
this . valueTwo = v ;
self . fireEvent ( BI . IntervalSlider . EVENT _CHANGE ) ;
const percent = this . _getPercentByValue ( v ) ;
const significantPercent = parseFloat ( percent . toFixed ( 1 ) ) ;
this . _setSliderTwoPosition ( significantPercent ) ;
this . _setBlueTrack ( ) ;
this . _checkLabelPosition (
this . valueOne ,
oldValueTwo ,
this . valueOne ,
this . valueTwo
) ;
this . fireEvent ( IntervalSlider . EVENT _CHANGE ) ;
} ) ;
} ) ;
this . sliderOne = BI . createWidget ( {
this . sliderOne = createWidget ( {
type : "bi.single_slider_button"
type : SliderIconButton . xtype ,
} ) ;
} ) ;
this . sliderTwo = BI . createWidget ( {
this . sliderTwo = createWidget ( {
type : "bi.single_slider_button"
type : SliderIconButton . xtype ,
} ) ;
} ) ;
this . _draggable ( this . sliderOne , true ) ;
this . _draggable ( this . sliderOne , true ) ;
this . _draggable ( this . sliderTwo , false ) ;
this . _draggable ( this . sliderTwo , false ) ;
@ -127,7 +161,7 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
items : [
items : [
this . _createLabelWrapper ( ) ,
this . _createLabelWrapper ( ) ,
{
{
type : "bi.absolute" ,
type : AbsoluteLayout . xtype ,
items : [
items : [
{
{
el : {
el : {
@ -135,64 +169,82 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
horizontalAlign : "stretch" ,
horizontalAlign : "stretch" ,
verticalAlign : "middle" ,
verticalAlign : "middle" ,
columnSize : [ "fill" ] ,
columnSize : [ "fill" ] ,
items : [ {
items : [
{
el : this . track ,
el : this . track ,
} ] ,
}
] ,
hgap : 10 ,
hgap : 10 ,
} ,
} ,
inset : 0
inset : 0 ,
} ,
} ,
this . _createSliderWrapper ( ) ,
this . _createSliderWrapper ( )
]
] ,
}
}
]
] ,
} ;
} ;
} ,
}
_rePosBySizeAfterMove : function ( size , isLeft ) {
_rePosBySizeAfterMove ( size , isLeft ) {
var o = this . options ;
const o = this . options ;
var percent = size * 100 / ( this . _getGrayTrackLength ( ) ) ;
const percent = ( size * 100 ) / this . _getGrayTrackLength ( ) ;
var significantPercent = BI . parseFloat ( percent . toFixed ( 1 ) ) ;
const significantPercent = parseFloat ( percent . toFixed ( 1 ) ) ;
var v = this . _getValueByPercent ( significantPercent ) ;
let v = this . _getValueByPercent ( significantPercent ) ;
v = this . _assertValue ( v ) ;
v = this . _assertValue ( v ) ;
v = o . digit === false ? v : v . toFixed ( o . digit ) ;
v = o . digit === false ? v : v . toFixed ( o . digit ) ;
var oldValueOne = this . valueOne , oldValueTwo = this . valueTwo ;
const oldValueOne = this . valueOne ,
oldValueTwo = this . valueTwo ;
if ( isLeft ) {
if ( isLeft ) {
this . _setSliderOnePosition ( significantPercent ) ;
this . _setSliderOnePosition ( significantPercent ) ;
this . labelOne . setValue ( v ) ;
this . labelOne . setValue ( v ) ;
this . valueOne = v ;
this . valueOne = v ;
this . _checkLabelPosition ( oldValueOne , oldValueTwo , v , this . valueTwo ) ;
this . _checkLabelPosition (
oldValueOne ,
oldValueTwo ,
v ,
this . valueTwo
) ;
} else {
} else {
this . _setSliderTwoPosition ( significantPercent ) ;
this . _setSliderTwoPosition ( significantPercent ) ;
this . labelTwo . setValue ( v ) ;
this . labelTwo . setValue ( v ) ;
this . valueTwo = v ;
this . valueTwo = v ;
this . _checkLabelPosition ( oldValueOne , oldValueTwo , this . valueOne , v ) ;
this . _checkLabelPosition (
oldValueOne ,
oldValueTwo ,
this . valueOne ,
v
) ;
}
}
this . _setBlueTrack ( ) ;
this . _setBlueTrack ( ) ;
} ,
}
_rePosBySizeAfterStop : function ( size , isLeft ) {
_rePosBySizeAfterStop ( size , isLeft ) {
var percent = size * 100 / ( this . _getGrayTrackLength ( ) ) ;
const percent = ( size * 100 ) / this . _getGrayTrackLength ( ) ;
var significantPercent = BI . parseFloat ( percent . toFixed ( 1 ) ) ;
const significantPercent = parseFloat ( percent . toFixed ( 1 ) ) ;
isLeft ? this . _setSliderOnePosition ( significantPercent ) : this . _setSliderTwoPosition ( significantPercent ) ;
isLeft
} ,
? this . _setSliderOnePosition ( significantPercent )
: this . _setSliderTwoPosition ( significantPercent ) ;
}
_draggable : function ( widget , isLeft ) {
_draggable ( widget , isLeft ) {
var self = this , o = this . options ;
let startDrag = false ;
var startDrag = false ;
let size = 0 ,
var size = 0 , offset = 0 , defaultSize = 0 ;
offset = 0 ,
var mouseMoveTracker = new BI . MouseMoveTracker ( function ( deltaX ) {
defaultSize = 0 ;
const mouseMoveTracker = new MouseMoveTracker (
( deltaX => {
if ( mouseMoveTracker . isDragging ( ) ) {
if ( mouseMoveTracker . isDragging ( ) ) {
startDrag = true ;
startDrag = true ;
offset += deltaX ;
offset += deltaX ;
size = optimizeSize ( defaultSize + offset ) ;
size = optimizeSize ( defaultSize + offset ) ;
widget . element . addClass ( "dragging" ) ;
widget . element . addClass ( "dragging" ) ;
self . _rePosBySizeAfterMove ( size , isLeft ) ;
this . _rePosBySizeAfterMove ( size , isLeft ) ;
}
}
} , function ( ) {
} ) ,
( ( ) => {
if ( startDrag === true ) {
if ( startDrag === true ) {
size = optimizeSize ( size ) ;
size = optimizeSize ( size ) ;
self . _rePosBySizeAfterStop ( size , isLeft ) ;
this . _rePosBySizeAfterStop ( size , isLeft ) ;
size = 0 ;
size = 0 ;
offset = 0 ;
offset = 0 ;
defaultSize = size ;
defaultSize = size ;
@ -200,8 +252,10 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
}
}
widget . element . removeClass ( "dragging" ) ;
widget . element . removeClass ( "dragging" ) ;
mouseMoveTracker . releaseMouseMoves ( ) ;
mouseMoveTracker . releaseMouseMoves ( ) ;
self . fireEvent ( BI . IntervalSlider . EVENT _CHANGE ) ;
this . fireEvent ( IntervalSlider . EVENT _CHANGE ) ;
} , window ) ;
} ) ,
window
) ;
widget . element . on ( "mousedown" , function ( event ) {
widget . element . on ( "mousedown" , function ( event ) {
if ( ! widget . isEnabled ( ) ) {
if ( ! widget . isEnabled ( ) ) {
return ;
return ;
@ -211,42 +265,47 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
mouseMoveTracker . captureMouseMoves ( event ) ;
mouseMoveTracker . captureMouseMoves ( event ) ;
} ) ;
} ) ;
function optimizeSize ( s ) {
const optimizeSize = s => clamp ( s , 0 , this . _getGrayTrackLength ( ) ) ;
return BI . clamp ( s , 0 , self . _getGrayTrackLength ( ) ) ;
}
}
} ,
_createLabelWrapper : function ( ) {
_createLabelWrapper ( ) {
var c = this . _constant ;
const c = this . _constant ;
return {
return {
el : {
el : {
type : "bi.vertical" ,
type : VerticalLayout . xtype ,
items : [ {
items : [
type : "bi.absolute" ,
{
items : [ {
type : AbsoluteLayout . xtype ,
items : [
{
el : this . labelOne ,
el : this . labelOne ,
top : 0 ,
top : 0 ,
left : 0 ,
left : 0 ,
} ]
}
} , {
] ,
type : "bi.absolute" ,
} ,
items : [ {
{
type : AbsoluteLayout . xtype ,
items : [
{
el : this . labelTwo ,
el : this . labelTwo ,
top : 0 ,
top : 0 ,
right : 0 ,
right : 0 ,
} ]
}
} ] ,
] ,
}
] ,
rgap : c . EDITOR _R _GAP ,
rgap : c . EDITOR _R _GAP ,
height : c . SLIDER _HEIGHT
height : c . SLIDER _HEIGHT ,
} ,
} ,
top : 0 ,
top : 0 ,
left : 0 ,
left : 0 ,
width : "100%"
width : "100%" ,
} ;
} ;
} ,
}
_createSliderWrapper : function ( ) {
_createSliderWrapper ( ) {
var c = this . _constant ;
return {
return {
el : {
el : {
type : "bi.horizontal" ,
type : "bi.horizontal" ,
@ -254,7 +313,7 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
verticalAlign : "middle" ,
verticalAlign : "middle" ,
items : [
items : [
{
{
type : "bi.absolute" ,
type : AbsoluteLayout . xtype ,
height : 12 ,
height : 12 ,
width : "fill" ,
width : "fill" ,
items : [
items : [
@ -262,24 +321,25 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
el : this . sliderOne ,
el : this . sliderOne ,
top : 0 ,
top : 0 ,
bottom : 0 ,
bottom : 0 ,
left : 0
left : 0 ,
} , {
} ,
{
el : this . sliderTwo ,
el : this . sliderTwo ,
top : 0 ,
top : 0 ,
bottom : 0 ,
bottom : 0 ,
left : "100%"
left : "100%" ,
}
}
] ,
] ,
}
}
] ,
] ,
hgap : 10 ,
hgap : 10 ,
} ,
} ,
inset : 0
inset : 0 ,
} ;
} ;
} ,
}
_createTrackWrapper : function ( ) {
_createTrackWrapper ( ) {
return BI . createWidget ( {
return createWidget ( {
type : "bi.horizontal" ,
type : "bi.horizontal" ,
cls : "track-wrapper" ,
cls : "track-wrapper" ,
horizontalAlign : "stretch" ,
horizontalAlign : "stretch" ,
@ -288,100 +348,110 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
scrollx : false ,
scrollx : false ,
items : [
items : [
{
{
type : "bi.absolute" ,
type : AbsoluteLayout . xtype ,
height : 6 ,
height : 6 ,
items : [ {
items : [
{
el : this . grayTrack ,
el : this . grayTrack ,
top : 0 ,
top : 0 ,
left : 0 ,
left : 0 ,
bottom : 0 ,
bottom : 0 ,
width : "100%"
width : "100%" ,
} , {
} ,
{
el : this . blueTrack ,
el : this . blueTrack ,
top : 0 ,
top : 0 ,
left : 0 ,
left : 0 ,
bottom : 0 ,
bottom : 0 ,
width : "0%"
width : "0%" ,
} ]
}
] ,
}
}
] ,
] ,
} ) ;
} ) ;
} ,
}
_checkValidation : function ( v ) {
_checkValidation ( v ) {
var o = this . options ;
const o = this . options ;
var valid = false ;
let valid = false ;
// 像90.这样的既不属于整数又不属于小数,是不合法的值
// 像90.这样的既不属于整数又不属于小数,是不合法的值
var dotText = ( v + "" ) . split ( "." ) [ 1 ] ;
let dotText = ( ` ${ v } ` ) . split ( "." ) [ 1 ] ;
if ( BI . isEmptyString ( dotText ) ) {
// eslint-disable-next-line no-empty
if ( isEmptyString ( dotText ) ) {
} else {
} else {
if ( BI . isNumeric ( v ) && ! ( BI . isNull ( v ) || v < this . min || v > this . max ) ) {
if ( isNumeric ( v ) && ! ( isNull ( v ) || v < this . min || v > this . max ) ) {
// 虽然规定了所填写的小数位数,但是我们认为所有的整数都是满足设置的小数位数的
// 虽然规定了所填写的小数位数,但是我们认为所有的整数都是满足设置的小数位数的
// 100等价于100.0 100.00 100.000
// 100等价于100.0 100.00 100.000
if ( o . digit === false || BI . isInteger ( v ) ) {
if ( o . digit === false || isInteger ( v ) ) {
valid = true ;
valid = true ;
} else {
} else {
dotText = dotText || "" ;
dotText = dotText || "" ;
valid = ( dotText . length === o . digit ) ;
valid = dotText . length === o . digit ;
}
}
}
}
}
}
return valid ;
return valid ;
} ,
}
_checkOverlap : function ( ) {
_checkOverlap ( ) {
var labelOneLeft = this . labelOne . element [ 0 ] . offsetLeft ;
const labelOneLeft = this . labelOne . element [ 0 ] . offsetLeft ;
var labelTwoLeft = this . labelTwo . element [ 0 ] . offsetLeft ;
const labelTwoLeft = this . labelTwo . element [ 0 ] . offsetLeft ;
if ( labelOneLeft <= labelTwoLeft ) {
if ( labelOneLeft <= labelTwoLeft ) {
if ( ( labelTwoLeft - labelOneLeft ) < 90 ) {
if ( labelTwoLeft - labelOneLeft < 90 ) {
this . labelTwo . element . css ( { top : 40 } ) ;
this . labelTwo . element . css ( { top : 40 } ) ;
} else {
} else {
this . labelTwo . element . css ( { top : 0 } ) ;
this . labelTwo . element . css ( { top : 0 } ) ;
}
}
} else {
} else {
if ( ( labelOneLeft - labelTwoLeft ) < 90 ) {
if ( labelOneLeft - labelTwoLeft < 90 ) {
this . labelTwo . element . css ( { top : 40 } ) ;
this . labelTwo . element . css ( { top : 40 } ) ;
} else {
} else {
this . labelTwo . element . css ( { top : 0 } ) ;
this . labelTwo . element . css ( { top : 0 } ) ;
}
}
}
}
} ,
}
_checkLabelPosition : function ( oldValueOne , oldValueTwo , valueOne , valueTwo , isLeft ) {
_checkLabelPosition ( oldValueOne , oldValueTwo , valueOne , valueTwo , isLeft ) {
oldValueOne = BI . parseFloat ( oldValueOne ) ;
oldValueOne = parseFloat ( oldValueOne ) ;
oldValueTwo = BI . parseFloat ( oldValueTwo ) ;
oldValueTwo = parseFloat ( oldValueTwo ) ;
valueOne = BI . parseFloat ( valueOne ) ;
valueOne = parseFloat ( valueOne ) ;
valueTwo = BI . parseFloat ( valueTwo ) ;
valueTwo = parseFloat ( valueTwo ) ;
if ( ( oldValueOne <= oldValueTwo && valueOne > valueTwo ) || ( oldValueOne >= oldValueTwo && valueOne < valueTwo ) ) {
if (
var isSliderOneLeft = BI . parseFloat ( this . labelOne . getValue ( ) ) < BI . parseFloat ( this . labelTwo . getValue ( ) ) ;
( oldValueOne <= oldValueTwo && valueOne > valueTwo ) ||
( oldValueOne >= oldValueTwo && valueOne < valueTwo )
) {
const isSliderOneLeft =
parseFloat ( this . labelOne . getValue ( ) ) <
parseFloat ( this . labelTwo . getValue ( ) ) ;
this . _resetLabelPosition ( ! isSliderOneLeft ) ;
this . _resetLabelPosition ( ! isSliderOneLeft ) ;
}
}
} ,
}
_resetLabelPosition : function ( needReverse ) {
_resetLabelPosition ( needReverse ) {
this . labelOne . element . css ( { left : needReverse ? "100%" : "0%" } ) ;
this . labelOne . element . css ( { left : needReverse ? "100%" : "0%" } ) ;
this . labelTwo . element . css ( { left : needReverse ? "0%" : "100%" } ) ;
this . labelTwo . element . css ( { left : needReverse ? "0%" : "100%" } ) ;
} ,
}
_setSliderOnePosition : function ( percent ) {
_setSliderOnePosition ( percent ) {
this . sliderOne . element . css ( { left : percent + "%" } ) ;
this . sliderOne . element . css ( { left : ` ${ percent } % ` } ) ;
} ,
}
_setSliderTwoPosition : function ( percent ) {
_setSliderTwoPosition ( percent ) {
this . sliderTwo . element . css ( { left : percent + "%" } ) ;
this . sliderTwo . element . css ( { left : ` ${ percent } % ` } ) ;
} ,
}
_setBlueTrackLeft : function ( percent ) {
_setBlueTrackLeft ( percent ) {
this . blueTrack . element . css ( { left : percent + "%" } ) ;
this . blueTrack . element . css ( { left : ` ${ percent } % ` } ) ;
} ,
}
_setBlueTrackWidth : function ( percent ) {
_setBlueTrackWidth ( percent ) {
this . blueTrack . element . css ( { width : percent + "%" } ) ;
this . blueTrack . element . css ( { width : ` ${ percent } % ` } ) ;
} ,
}
_setBlueTrack : function ( ) {
_setBlueTrack ( ) {
var percentOne = this . _getPercentByValue ( this . labelOne . getValue ( ) ) ;
const percentOne = this . _getPercentByValue ( this . labelOne . getValue ( ) ) ;
var percentTwo = this . _getPercentByValue ( this . labelTwo . getValue ( ) ) ;
const percentTwo = this . _getPercentByValue ( this . labelTwo . getValue ( ) ) ;
if ( percentOne <= percentTwo ) {
if ( percentOne <= percentTwo ) {
this . _setBlueTrackLeft ( percentOne ) ;
this . _setBlueTrackLeft ( percentOne ) ;
this . _setBlueTrackWidth ( percentTwo - percentOne ) ;
this . _setBlueTrackWidth ( percentTwo - percentOne ) ;
@ -389,133 +459,165 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
this . _setBlueTrackLeft ( percentTwo ) ;
this . _setBlueTrackLeft ( percentTwo ) ;
this . _setBlueTrackWidth ( percentOne - percentTwo ) ;
this . _setBlueTrackWidth ( percentOne - percentTwo ) ;
}
}
} ,
}
_setAllPosition : function ( one , two ) {
_setAllPosition ( one , two ) {
this . _setSliderOnePosition ( one ) ;
this . _setSliderOnePosition ( one ) ;
this . _setSliderTwoPosition ( two ) ;
this . _setSliderTwoPosition ( two ) ;
this . _setBlueTrack ( ) ;
this . _setBlueTrack ( ) ;
} ,
}
_setVisible : function ( visible ) {
_setVisible ( visible ) {
this . sliderOne . setVisible ( visible ) ;
this . sliderOne . setVisible ( visible ) ;
this . sliderTwo . setVisible ( visible ) ;
this . sliderTwo . setVisible ( visible ) ;
this . labelOne . setVisible ( visible ) ;
this . labelOne . setVisible ( visible ) ;
this . labelTwo . setVisible ( visible ) ;
this . labelTwo . setVisible ( visible ) ;
} ,
}
_setErrorText : function ( ) {
_setErrorText ( ) {
var errorText = BI . i18nText ( "BI-Basic_Please_Enter_Number_Between" , this . min , this . max ) ;
const errorText = i18nText (
"BI-Basic_Please_Enter_Number_Between" ,
this . min ,
this . max
) ;
this . labelOne . setErrorText ( errorText ) ;
this . labelOne . setErrorText ( errorText ) ;
this . labelTwo . setErrorText ( errorText ) ;
this . labelTwo . setErrorText ( errorText ) ;
} ,
}
_getGrayTrackLength : function ( ) {
_getGrayTrackLength ( ) {
return this . grayTrack . element [ 0 ] . scrollWidth ;
return this . grayTrack . element [ 0 ] . scrollWidth ;
} ,
}
// 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度
_getValueByPercent ( percent ) {
// 端点处的值有可能因为min,max相差量级很大(precision很大)而丢失精度,此时直接返回端点值即可
// return (((max-min)*percent)/100+min)
_getValueByPercent : function ( percent ) { // return (((max-min)*percent)/100+min)
if ( percent === 0 ) {
if ( percent === 0 ) {
return this . min ;
return this . min ;
}
}
if ( percent === 100 ) {
if ( percent === 100 ) {
return this . max ;
return this . max ;
}
}
var sub = this . calculation . accurateSubtraction ( this . max , this . min ) ;
const sub = this . calculation . accurateSubtraction ( this . max , this . min ) ;
var mul = this . calculation . accurateMultiplication ( sub , percent ) ;
const mul = this . calculation . accurateMultiplication ( sub , percent ) ;
var div = this . calculation . accurateDivisionTenExponent ( mul , 2 ) ;
const div = this . calculation . accurateDivisionTenExponent ( mul , 2 ) ;
if ( this . precision < 0 ) {
if ( this . precision < 0 ) {
var value = BI . parseFloat ( this . calculation . accurateAddition ( div , this . min ) ) ;
const value = parseFloat (
var reduceValue = Math . round ( this . calculation . accurateDivisionTenExponent ( value , - this . precision ) ) ;
this . calculation . accurateAddition ( div , this . min )
return this . calculation . accurateMultiplication ( reduceValue , Math . pow ( 10 , - this . precision ) ) ;
) ;
const reduceValue = Math . round (
this . calculation . accurateDivisionTenExponent (
value ,
- this . precision
)
) ;
return this . calculation . accurateMultiplication (
reduceValue ,
Math . pow ( 10 , - this . precision )
) ;
}
}
return BI . parseFloat ( this . calculation . accurateAddition ( div , this . min ) . toFixed ( this . precision ) ) ;
} ,
return parseFloat (
this . calculation
. accurateAddition ( div , this . min )
. toFixed ( this . precision )
) ;
}
_getPercentByValue : function ( v ) {
_getPercentByValue ( v ) {
return ( v - this . min ) * 100 / ( this . max - this . min ) ;
return ( ( v - this . min ) * 100 ) / ( this . max - this . min ) ;
} ,
}
_getPrecision : function ( ) {
_getPrecision ( ) {
// 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度)
// 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度)
// 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5
// 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5
// 返回非负值: 保留的小数位数
// 返回非负值: 保留的小数位数
// 返回负值: 保留的10^n精度中的n
// 返回负值: 保留的10^n精度中的n
var sub = this . calculation . accurateSubtraction ( this . max , this . min ) ;
const sub = this . calculation . accurateSubtraction ( this . max , this . min ) ;
var pre = sub . toPrecision ( 4 ) ;
const pre = sub . toPrecision ( 4 ) ;
// 科学计数法
// 科学计数法
var eIndex = pre . indexOf ( "e" ) ;
const eIndex = pre . indexOf ( "e" ) ;
var arr = [ ] ;
let arr = [ ] ;
if ( eIndex > - 1 ) {
if ( eIndex > - 1 ) {
arr = pre . split ( "e" ) ;
arr = pre . split ( "e" ) ;
var decimalPartLength = BI . size ( arr [ 0 ] . split ( "." ) [ 1 ] ) ;
const decimalPartLength = size ( arr [ 0 ] . split ( "." ) [ 1 ] ) ;
var sciencePartLength = BI . parseInt ( arr [ 1 ] . substring ( 1 ) ) ;
const sciencePartLength = parseInt ( arr [ 1 ] . substring ( 1 ) ) ;
return decimalPartLength - sciencePartLength ;
return decimalPartLength - sciencePartLength ;
}
}
arr = pre . split ( "." ) ;
arr = pre . split ( "." ) ;
return arr . length > 1 ? arr [ 1 ] . length : 0 ;
} ,
return arr . length > 1 ? arr [ 1 ] . length : 0 ;
}
_assertValue : function ( value ) {
_assertValue ( value ) {
if ( value <= this . min ) {
if ( value <= this . min ) {
return this . min ;
return this . min ;
}
}
if ( value >= this . max ) {
if ( value >= this . max ) {
return this . max ;
return this . max ;
}
}
return value ;
return value ;
} ,
}
_setEnable : function ( b ) {
_setEnable ( b ) {
BI . IntervalSlider . superclass . _setEnable . apply ( this , [ b ] ) ;
super . _setEnable . apply ( this , [ b ] ) ;
if ( b ) {
if ( b ) {
this . blueTrack . element . removeClass ( "disabled-blue-track" ) . addClass ( "blue-track" ) ;
this . blueTrack . element
. removeClass ( "disabled-blue-track" )
. addClass ( "blue-track" ) ;
} else {
} else {
this . blueTrack . element . removeClass ( "blue-track" ) . addClass ( "disabled-blue-track" ) ;
this . blueTrack . element
. removeClass ( "blue-track" )
. addClass ( "disabled-blue-track" ) ;
}
}
}
} ,
getValue : function ( ) {
getValue ( ) {
if ( this . valueOne <= this . valueTwo ) {
if ( this . valueOne <= this . valueTwo ) {
return { min : this . valueOne , max : this . valueTwo } ;
return { min : this . valueOne , max : this . valueTwo } ;
}
}
return { min : this . valueTwo , max : this . valueOne } ;
} ,
return { min : this . valueTwo , max : this . valueOne } ;
}
_setMinAndMax : function ( v ) {
_setMinAndMax ( v ) {
var minNumber = BI . parseFloat ( v . min ) ;
const minNumber = parseFloat ( v . min ) ;
var maxNumber = BI . parseFloat ( v . max ) ;
const maxNumber = parseFloat ( v . max ) ;
if ( ( ! isNaN ( minNumber ) ) && ( ! isNaN ( maxNumber ) ) && ( maxNumber >= minNumber ) ) {
if ( ! isNaN ( minNumber ) && ! isNaN ( maxNumber ) && maxNumber >= minNumber ) {
this . min = minNumber ;
this . min = minNumber ;
this . max = maxNumber ;
this . max = maxNumber ;
this . valueOne = minNumber ;
this . valueOne = minNumber ;
this . valueTwo = maxNumber ;
this . valueTwo = maxNumber ;
this . precision = this . _getPrecision ( ) ;
this . precision = this . _getPrecision ( ) ;
}
}
} ,
}
setMinAndMax : function ( v ) {
setMinAndMax ( v ) {
this . _setMinAndMax ( v ) ;
this . _setMinAndMax ( v ) ;
this . setEnable ( v . min <= v . max ) ;
this . setEnable ( v . min <= v . max ) ;
} ,
}
setValue : function ( v ) {
setValue ( v ) {
var o = this . options ;
const o = this . options ;
var valueOne = BI . parseFloat ( v . min ) ;
let valueOne = parseFloat ( v . min ) ;
var valueTwo = BI . parseFloat ( v . max ) ;
let valueTwo = parseFloat ( v . max ) ;
valueOne = o . digit === false ? valueOne : BI . parseFloat ( valueOne . toFixed ( o . digit ) ) ;
valueOne =
valueTwo = o . digit === false ? valueTwo : BI . parseFloat ( valueTwo . toFixed ( o . digit ) ) ;
o . digit === false
? valueOne
: parseFloat ( valueOne . toFixed ( o . digit ) ) ;
valueTwo =
o . digit === false
? valueTwo
: parseFloat ( valueTwo . toFixed ( o . digit ) ) ;
if ( ! isNaN ( valueOne ) && ! isNaN ( valueTwo ) ) {
if ( ! isNaN ( valueOne ) && ! isNaN ( valueTwo ) ) {
if ( this . _checkValidation ( valueOne ) ) {
if ( this . _checkValidation ( valueOne ) ) {
this . valueOne = ( this . valueOne <= this . valueTwo ? valueOne : valueTwo ) ;
this . valueOne =
this . valueOne <= this . valueTwo ? valueOne : valueTwo ;
}
}
if ( this . _checkValidation ( valueTwo ) ) {
if ( this . _checkValidation ( valueTwo ) ) {
this . valueTwo = ( this . valueOne <= this . valueTwo ? valueTwo : valueOne ) ;
this . valueTwo =
this . valueOne <= this . valueTwo ? valueTwo : valueOne ;
}
}
if ( valueOne < this . min ) {
if ( valueOne < this . min ) {
this . valueOne = this . min ;
this . valueOne = this . min ;
@ -524,9 +626,9 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
this . valueTwo = this . max ;
this . valueTwo = this . max ;
}
}
}
}
} ,
}
reset : function ( ) {
reset ( ) {
this . _setVisible ( false ) ;
this . _setVisible ( false ) ;
this . enable = false ;
this . enable = false ;
this . valueOne = "" ;
this . valueOne = "" ;
@ -534,18 +636,32 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
this . min = NaN ;
this . min = NaN ;
this . max = NaN ;
this . max = NaN ;
this . _setBlueTrackWidth ( 0 ) ;
this . _setBlueTrackWidth ( 0 ) ;
} ,
}
populate : function ( ) {
populate ( ) {
var o = this . options ;
const o = this . options ;
if ( ! isNaN ( this . min ) && ! isNaN ( this . max ) ) {
if ( ! isNaN ( this . min ) && ! isNaN ( this . max ) ) {
this . enable = true ;
this . enable = true ;
this . _setVisible ( true ) ;
this . _setVisible ( true ) ;
this . _setErrorText ( ) ;
this . _setErrorText ( ) ;
if ( ( BI . isNumeric ( this . valueOne ) || BI . isNotEmptyString ( this . valueOne ) ) && ( BI . isNumeric ( this . valueTwo ) || BI . isNotEmptyString ( this . valueTwo ) ) ) {
if (
this . labelOne . setValue ( o . digit === false ? this . valueOne : BI . parseFloat ( this . valueOne ) . toFixed ( o . digit ) ) ;
( isNumeric ( this . valueOne ) || isNotEmptyString ( this . valueOne ) ) &&
this . labelTwo . setValue ( o . digit === false ? this . valueTwo : BI . parseFloat ( this . valueTwo ) . toFixed ( o . digit ) ) ;
( isNumeric ( this . valueTwo ) || isNotEmptyString ( this . valueTwo ) )
this . _setAllPosition ( this . _getPercentByValue ( this . valueOne ) , this . _getPercentByValue ( this . valueTwo ) ) ;
) {
this . labelOne . setValue (
o . digit === false
? this . valueOne
: parseFloat ( this . valueOne ) . toFixed ( o . digit )
) ;
this . labelTwo . setValue (
o . digit === false
? this . valueTwo
: parseFloat ( this . valueTwo ) . toFixed ( o . digit )
) ;
this . _setAllPosition (
this . _getPercentByValue ( this . valueOne ) ,
this . _getPercentByValue ( this . valueTwo )
) ;
} else {
} else {
this . labelOne . setValue ( this . min ) ;
this . labelOne . setValue ( this . min ) ;
this . labelTwo . setValue ( this . max ) ;
this . labelTwo . setValue ( this . max ) ;
@ -554,6 +670,4 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
this . _resetLabelPosition ( this . valueOne > this . valueTwo ) ;
this . _resetLabelPosition ( this . valueOne > this . valueTwo ) ;
}
}
}
}
} ) ;
}
BI . IntervalSlider . EVENT _CHANGE = "EVENT_CHANGE" ;
BI . shortcut ( "bi.interval_slider" , BI . IntervalSlider ) ;