121 lines
3.2 KiB
Smalltalk
121 lines
3.2 KiB
Smalltalk
|
Class {
|
||
|
#name : #EcCalendar,
|
||
|
#superclass : #Object,
|
||
|
#instVars : [
|
||
|
'events'
|
||
|
],
|
||
|
#category : #EchartsPharo
|
||
|
}
|
||
|
|
||
|
{ #category : #accessing }
|
||
|
EcCalendar >> asEcScript [
|
||
|
|
||
|
^ 'var myCalendar = echarts.init(document.getElementById(',($' asString), 'calendar', ($' asString), '));', Character cr asString,
|
||
|
'var option = {
|
||
|
tooltip: {},
|
||
|
animation: true,
|
||
|
animationDuration: 500,
|
||
|
|
||
|
legend: {
|
||
|
data:', self eventsLabel, ',',
|
||
|
'left:', ($' asString ), '0',($' asString),
|
||
|
'},
|
||
|
|
||
|
calendar: {
|
||
|
top:', ($' asString), 'middle', ($' asString), ',',
|
||
|
'left:', ($' asString),'0', ($' asString), ',',
|
||
|
'orient:', ($' asString), 'horizontal', ($' asString), ',',
|
||
|
'cellSize: 40,
|
||
|
yearLabel: {
|
||
|
margin: 50,
|
||
|
fontSize: 30,
|
||
|
color:', ($' asString), '#999', ($' asString),
|
||
|
'},
|
||
|
dayLabel: {
|
||
|
firstDay: 1,
|
||
|
nameMap:', ($' asString), 'cn', ($' asString),
|
||
|
'},
|
||
|
monthLabel: {
|
||
|
nameMap:', ($' asString),'cn', ($' asString), ',',
|
||
|
'margin: 15,
|
||
|
fontSize: 20,
|
||
|
color:', ($' asString), '#999', ($' asString),
|
||
|
'},
|
||
|
range:', self datesRangeWithMarginString,
|
||
|
'},
|
||
|
|
||
|
series: [', Character cr asString,
|
||
|
self eventsAsStringSnippets,
|
||
|
']
|
||
|
};
|
||
|
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 | ($' asString), date yyyymmdd, ($' asString) ].
|
||
|
^ '[', (',' join: datesRangeTemp), ']'
|
||
|
]
|
||
|
|
||
|
{ #category : #accessing }
|
||
|
EcCalendar >> events [
|
||
|
^ events ifNil: [ events := OrderedCollection new ].
|
||
|
]
|
||
|
|
||
|
{ #category : #accessing }
|
||
|
EcCalendar >> eventsAsStringSnippets [
|
||
|
|
||
|
| tempEvents |
|
||
|
tempEvents := self events.
|
||
|
tempEvents ifNil: [ ^ self ].
|
||
|
^ Character cr join: (tempEvents collect: [ :each | each asStringSnippet ])
|
||
|
]
|
||
|
|
||
|
{ #category : #accessing }
|
||
|
EcCalendar >> eventsLabel [
|
||
|
|
||
|
| tempEvents |
|
||
|
tempEvents := self events collect: [ :each | each name ].
|
||
|
tempEvents := tempEvents collect: [ :each | ($' asString), each, ($' asString) ].
|
||
|
^ '[', (',' join: tempEvents), ']'
|
||
|
]
|