121 lines
3.0 KiB
Smalltalk
121 lines
3.0 KiB
Smalltalk
Class {
|
|
#name : #EcCalendar,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'events'
|
|
],
|
|
#category : #EchartsPharo
|
|
}
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> asEcScript [
|
|
|
|
^ 'var myCalendar = echarts.init(document.getElementById(','''', 'calendar', '''', '));', Character cr asString,
|
|
'var option = {
|
|
tooltip: {},
|
|
animation: true,
|
|
animationDuration: 500,
|
|
|
|
legend: {
|
|
data:', self eventsLabel, ',',
|
|
'left:', '''', '0', '''',
|
|
'},
|
|
|
|
calendar: {
|
|
top:', '''', 'middle', '''', ',',
|
|
'left:', '''','0', '''', ',',
|
|
'orient:', '''', 'horizontal', '''', ',',
|
|
'cellSize: 40,
|
|
yearLabel: {
|
|
margin: 50,
|
|
fontSize: 30,
|
|
color:', '''', '#999', '''',
|
|
'},
|
|
dayLabel: {
|
|
firstDay: 1,
|
|
nameMap:', '''', 'cn', '''',
|
|
'},
|
|
monthLabel: {
|
|
nameMap:', '''','cn', '''', ',',
|
|
'margin: 15,
|
|
fontSize: 20,
|
|
color:', '''', '#999', '''',
|
|
'},
|
|
range:', self datesRangeWithMarginString,
|
|
'},
|
|
|
|
series: [', Character cr asString,
|
|
self eventsAsEcObjectsString,
|
|
']
|
|
};
|
|
myCalendar.setOption(option);'
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> asHTMLElement [
|
|
|
|
^ '<div id="calendar" style="width:90vw;height:400px;"></div>', Character cr asString,
|
|
'<script type="text/javascript">', Character cr asString,
|
|
self asEcScript, Character cr asString,
|
|
'</script>'
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> datesRange [
|
|
|
|
| tempEventsDates |
|
|
tempEventsDates := self events collect: [ :each | each dates ].
|
|
tempEventsDates := tempEventsDates flattened collect: [ :each | each asDate ].
|
|
^ {tempEventsDates asSortedCollection first .
|
|
tempEventsDates asSortedCollection last }.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> datesRangeString [
|
|
|
|
| datesRangeTemp |
|
|
datesRangeTemp := self datesRange collect: [ :date | ($' asString), date yyyymmdd, ($' asString) ].
|
|
^ '[', (',' join: datesRangeTemp), ']'
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> datesRangeWithMargin [
|
|
|
|
| tempEventsDates |
|
|
tempEventsDates := self events collect: [ :each | each dates ].
|
|
tempEventsDates := tempEventsDates flattened collect: [ :each | each asDate ].
|
|
^ {(tempEventsDates asSortedCollection first asDateAndTime - 10 days) asDate .
|
|
(tempEventsDates asSortedCollection last) addDays: 10 }.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> datesRangeWithMarginString [
|
|
|
|
| datesRangeTemp |
|
|
datesRangeTemp := self datesRangeWithMargin collect: [ :date | '''', date yyyymmdd, '''' ].
|
|
^ '[', (',' join: datesRangeTemp), ']'
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> events [
|
|
^ events ifNil: [ events := OrderedCollection new ].
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> eventsAsEcObjectsString [
|
|
|
|
| tempEvents |
|
|
tempEvents := self events.
|
|
tempEvents ifNil: [ ^ self ].
|
|
^ Character cr join: (tempEvents collect: [ :each | each asEcObjectString ])
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
EcCalendar >> eventsLabel [
|
|
|
|
| tempEvents |
|
|
tempEvents := self events collect: [ :each | each name ].
|
|
tempEvents := tempEvents collect: [ :each | '''', each, '''' ].
|
|
^ '[', (',' join: tempEvents), ']'
|
|
]
|