Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full working code #515

Open
silvioba opened this issue Apr 2, 2024 · 3 comments
Open

Full working code #515

silvioba opened this issue Apr 2, 2024 · 3 comments

Comments

@silvioba
Copy link

silvioba commented Apr 2, 2024

It would be very useful to have a full working HTML file in the docs. The current getting started page is quite good, but the single steps do not add up to a working page (they use the render function, which is never imported or defined).

So it's difficult to get started with the library without prior knowledge.

@epugh
Copy link

epugh commented Apr 11, 2024

Funny, I am hitting the same issue, I don't understand what to use for render! I am migrating from a VERY OLD version of this library.

@restush
Copy link

restush commented Jul 30, 2024

Javascript doesn't support render(<div id="cal-heatmap"></div>); ?

edit: I use VITE and doesn't need render. Here is working code.

main.js

import CalHeatmap from 'cal-heatmap';
import 'cal-heatmap/cal-heatmap.css';
import Legend from 'cal-heatmap/plugins/Legend'
import Tooltip from 'cal-heatmap/plugins/Tooltip';
import CalendarLabel from 'cal-heatmap/plugins/CalendarLabel';

// Instantiate CalHeatmap
const cal = new CalHeatmap();

const m_Data = {
    source: 'https://raw.githubusercontent.com/vega/vega/main/docs/data/seattle-weather.csv',
    type: 'csv',
    x: 'date',
    y: d => +d['temp_max'],
    groupY: 'max',
}


cal.paint({
    theme: 'dark',
    data: m_Data,
    date: {
        locale: `id`,
        start: new Date('2012-01-01')
    },
    range: 1,
    scale: { color: { type: 'linear', scheme: 'PRGn', domain: [0, 40] } },
    domain: {
        type: 'year',
        label: { text: null },
    },
    subDomain: { type: 'day', radius: 2 },

}, [
    [Tooltip, {
        text: function (date, value, dayjsDate) {
            return (
                (value ? value + '°C' : 'No data') + ' on ' + dayjsDate.format('LL')
            );
        },

    }],
    [Legend,
        {
            tickSize: 0,
            width: 150,
            itemSelector: '#ex-year-legend',
            label: 'Seattle max temperature °C',
        },
    ],
    [CalendarLabel,
        {
            width: 30,
            textAlign: 'start',
            text: () => dayjs.weekdaysShort().map((d, i) => (i % 2 == 0 ? '' : d)),
        },
    ],

]);

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cal-Heatmap Example</title>
    <link rel="stylesheet" href="/node_modules/cal-heatmap/dist/cal-heatmap.css">
</head>
<body>
    <h1>Hello World</h1>
    <div id="cal-heatmap"></div>
    <script type="module" src="main.js"></script>
</body>
</html>

@Michael-Obele
Copy link

Any ideas how this would work on svelte I get an 'expression is not contrustable error.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants