Why Your Mouse Won't Scroll Apache ECharts: The Right Way to Handle Horizontal Scrolling in Apache ECharts
Who this is for: Front-end engineers and dashboard developers. Whether you are getting started with Apache ECharts or inheriting a legacy dashboard component, this walkthrough covers the root hardware cause, ECharts interaction mechanics, and a clean, production-ready implementation in both vanilla JavaScript and React. I am always looking to refine these patterns if you have optimizations or…
In 2014 I was contacted by Subterranean Games (now Brightrock Games) and commissioned to develop the UI of their debut game, War for the Overworld. The mission was to take advantage of the web’s quick front-end prototyping technologies to interface with the team’s Unity C# game code.
I was approached with a very thorough UI report, which described the purpose and intended behaviour of each of the UI elements, as well as the photoshop designs, and some additional backstory to bring me up to speed with how they wanted the interface to feel. The requirements were as follows :
Implement as precisely as possible the UI design given in the PSDs
Ensure that the UI could be easily scaled up/down based on a variable from the settings menu
Create and implement animations & feedback for each interactable UI element
As the game was in a continuous state of development, so was the UI; when I was first approached, mission #1 was to release the UI in its most basic form so that a playable demo of the game could be available immediately. As such, a quick solution was put together almost immediately.
Here, we had two resource bars - mana, and gold; two panels - rooms and spells; buttons for each room and spell; two buttons that switch between both; and finally a sell button to enable the user to undo their room placements if needed.
One that placeholder was out, the game could be tested properly, the other developers could continue with their work, and development of the UI’s initial design could begin in earnest.
The first iteration added visual feedback and animation to the resource bars, hover and selected states to the buttons, and more of them to boot! With the consideration of requirement #2, the panel that would contain the rooms, spells, and units was expanded to fill the width of the screen, with its contents resizing to fit the width of the panel. However, as it was concluded that the size of its contents would vary from panel-group to group, this would later be dropped in favour of resizing the panel to be the width of its contents, up to a particular size.
Following rounds of testing and feedback, it was concluded that the number of panel-groups was too large; as a result, the number of buttons was reduced. This version also saw the width of the panel dynamically resize based on its contents, and the new implementation of the room/spell/etc buttons w/cost.
Clicking the third, new resource bar opened up the Veins of Evil - the game’s tech tree - with a simple slide-and-opacity transition to change between the two states. Each of the buttons contained had a disabled (invisible), cannot afford (greyed out), can afford (active), and hover (glowing) state; all through the manipulation of a single asset through CSS rather than an asset for each state.
At this stage, the javascript would respond to requests sent from the C# to enable/disable buttons and set any resource values.
The next iteration saw the stabilisation of the bottom panel’s design within the Goldilocks zone between the first and second versions; between ornate, stylised & in keeping with the theme, and more minimal and usable. In-panel information was removed in favour of tool-tips, and button themes were grouped into rows based on their functionality, as opposed to columns.
As for the resource bars...
...well, hell on toast came with the addition of a top bar to relocate the resource bars (from left-to-right): time until payday (radial progress), gold amount, ritual-progress (dual-progress from outside-in), sins (veins of evil; radial progress), mana; reduced/blocked by amount, defences, and minions (units), health of dungeon core (radial progress), and location of dungeon core (arrow mounted on radial progress).
The radial progress bars were particularly difficult to implement with a CSS; the final solution was to have two elements with half of a circle, rotate them both until half-way, then lock the first, and only rotate the second beyond the 50% point. The problem with this approach was that the background-image for the elements had to be absolutely uniform - which severely limited the design potential for each of these elements.
Finally, to facilitate the scaling of the interface based on the user’s settings, every single element’s height and width was specified in em where needed - this allowed for the scale to be changed by adjusting the font-size property of the body, which then propagated throughout the interface.
Disclaimer: due to obligations of study at the time, I was unable to work with the team up until the game’s launch - as such, if you play the game now (which I recommend that you do, for the record), the UI’s final implementation will be different to what you see here.
LOOKING BACK : 2016
The repeating problem here was the combination of tabular data, and the need for a responsive layout; inline-block/float could only solve so many problems. With the support of flexbox, this entire project’s layout problems would now be a breeze to overcome; removing all of the CSS calc() properties that caused issues when centering items and causing gaps in the design at particular resolutions.
The radial progress bars, in particular, were poorly implemented - although this was more due to the limitations within CSS. Now, this would absolutely be a HTML5 canvas/SVG solution; easier to manage from the javascript, easier to scale, and easier to handle.
From the javascript end, there were multiple issues with the implementation; this would have been an ideal project to implement with a Functional Programming methodology and, in hindsight, it should have been done so from the start. Issues in particular arose when the definition of this changed between functions depending on where it was called from, and the use of jQuery muddied the waters. ES6’s features could now be called upon to simply things - arrow functions within the listeners in particular - and make the entire project more readable.
Even now, it is taking all my self-restraint not to pause my current projects and refactor this. The struggle is real.