WebWrappers/Apps/EchartsPharo/EcCalendar.class.st

121 lines
3.0 KiB
Smalltalk
Raw Normal View History

Class {
#name : #EcCalendar,
#superclass : #Object,
#instVars : [
'events'
],
#category : #EchartsPharo
}
{ #category : #accessing }
EcCalendar >> asEcScript [
2022-09-19 14:25:14 +00:00
^ 'var myCalendar = echarts.init(document.getElementById(','''', 'calendar', '''', '));', Character cr asString,
'var option = {
tooltip: {},
animation: true,
animationDuration: 500,
legend: {
data:', self eventsLabel, ',',
2022-09-19 14:25:14 +00:00
'left:', '''', '0', '''',
'},
calendar: {
2022-09-19 14:25:14 +00:00
top:', '''', 'middle', '''', ',',
'left:', '''','0', '''', ',',
'orient:', '''', 'horizontal', '''', ',',
'cellSize: 40,
yearLabel: {
margin: 50,
fontSize: 30,
2022-09-19 14:25:14 +00:00
color:', '''', '#999', '''',
'},
dayLabel: {
firstDay: 1,
2022-09-19 14:25:14 +00:00
nameMap:', '''', 'cn', '''',
'},
monthLabel: {
2022-09-19 14:25:14 +00:00
nameMap:', '''','cn', '''', ',',
'margin: 15,
fontSize: 20,
2022-09-19 14:25:14 +00:00
color:', '''', '#999', '''',
'},
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 |
2022-09-19 14:25:14 +00:00
datesRangeTemp := self datesRangeWithMargin collect: [ :date | '''', date yyyymmdd, '''' ].
^ '[', (',' 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 ].
2022-09-19 14:25:14 +00:00
tempEvents := tempEvents collect: [ :each | '''', each, '''' ].
^ '[', (',' join: tempEvents), ']'
]